LCOV - code coverage report
Current view: top level - iroha-cli - query_response_handler.hpp (source / functions) Hit Total Coverage
Test: cleared_cor.info Lines: 0 1 0.0 %
Date: 2019-03-07 14:46:43 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #ifndef IROHA_CLI_QUERY_RESPONSE_HANDLER_HPP
       7             : #define IROHA_CLI_QUERY_RESPONSE_HANDLER_HPP
       8             : 
       9             : #include <map>
      10             : #include <memory>
      11             : #include <typeindex>
      12             : #include <unordered_map>
      13             : 
      14             : #include "logger/logger_fwd.hpp"
      15             : #include "qry_responses.pb.h"
      16             : 
      17             : namespace iroha_cli {
      18             :   /*
      19             :   workaround for circle-ci compilation issue; see
      20             :   http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2148 and
      21             :   https://stackoverflow.com/questions/18837857/cant-use-enum-class-as-unordered-map-key
      22             :   for more details
      23             :   */
      24             :   struct EnumTypeHash {
      25             :     template <typename T>
      26             :     std::size_t operator()(T t) const {
      27           0 :       return static_cast<std::size_t>(t);
      28             :     }
      29             :   };
      30             : 
      31             :   class QueryResponseHandler {
      32             :    public:
      33             :     explicit QueryResponseHandler(logger::LoggerPtr log);
      34             : 
      35             :     /**
      36             :      * Handle query response
      37             :      * @param response - iroha protocol object
      38             :      */
      39             :     void handle(const iroha::protocol::QueryResponse &response);
      40             : 
      41             :    private:
      42             :     void handleErrorResponse(const iroha::protocol::QueryResponse &response);
      43             :     void handleAccountResponse(const iroha::protocol::QueryResponse &response);
      44             :     void handleAccountAssetsResponse(
      45             :         const iroha::protocol::QueryResponse &response);
      46             :     void handleTransactionsResponse(
      47             :         const iroha::protocol::QueryResponse &response);
      48             :     void handleSignatoriesResponse(
      49             :         const iroha::protocol::QueryResponse &response);
      50             :     void handleRolesResponse(const iroha::protocol::QueryResponse &response);
      51             :     void handleRolePermissionsResponse(
      52             :         const iroha::protocol::QueryResponse &response);
      53             :     void handleAssetResponse(const iroha::protocol::QueryResponse &response);
      54             :     // -- --
      55             :     using Handler =
      56             :         void (QueryResponseHandler::*)(const iroha::protocol::QueryResponse &);
      57             :     using QueryResponseCode = iroha::protocol::QueryResponse::ResponseCase;
      58             :     using ErrorResponseCode = iroha::protocol::ErrorResponse::Reason;
      59             : 
      60             :     // Map  QueryResponse code -> Handle Method
      61             :     std::unordered_map<QueryResponseCode, Handler, EnumTypeHash> handler_map_;
      62             :     // Map ErrorResponse code -> String to print
      63             :     std::unordered_map<ErrorResponseCode, std::string, EnumTypeHash>
      64             :         error_handler_map_;
      65             : 
      66             :     logger::LoggerPtr log_;
      67             :   };
      68             : 
      69             : }  // namespace iroha_cli
      70             : #endif  // IROHA_QUERY_RESPONSE_HANDLER_HPP

Generated by: LCOV version 1.13