@brief RPC Server implementation for the JSONRPC Logic. This class holds a transport which implements @see BaseCommInterface Objects of this class can start @see start_thread , stop @see stop_thread the server at any? time. More than one instance of this class can be created as long as they use different transport configuration.
| 46 | /// Objects of this class can start @see start_thread , stop @see stop_thread the server at any? time. More than one instance of |
| 47 | /// this class can be created as long as they use different transport configuration. |
| 48 | class RPCServer |
| 49 | { |
| 50 | public: |
| 51 | RPCServer() = default; |
| 52 | /// |
| 53 | /// @brief Construct a new Rpc Server object |
| 54 | /// This function have one main goal, select the transport type base on the configuration and initialize it. |
| 55 | /// |
| 56 | /// @throw std::runtime_error if: |
| 57 | /// 1 - It the configured transport isn't valid for the server to create it, then an exception will be thrown. |
| 58 | /// 2 - The transport layer cannot be initialized. |
| 59 | /// @param conf the configuration object. |
| 60 | /// |
| 61 | RPCServer(config::RPCConfig const &conf); |
| 62 | |
| 63 | /// @brief The destructor will join the thread. |
| 64 | ~RPCServer(); |
| 65 | |
| 66 | /// @brief Returns a descriptive name that was set by the transport. Check @see BaseCommInterface |
| 67 | std::string_view selected_comm_name() const noexcept; |
| 68 | |
| 69 | /// @brief Thread function that runs the transport. |
| 70 | void start_thread(std::function<TSThread()> const &cb_init = std::function<TSThread()>(), |
| 71 | std::function<void(TSThread)> const &cb_destroy = std::function<void(TSThread)>()); |
| 72 | |
| 73 | /// @brief Function to stop the transport and join the thread to finish. |
| 74 | void stop_thread(); |
| 75 | |
| 76 | private: |
| 77 | /// @brief Actual thread routine. This will start the socket. |
| 78 | static void *run_thread(void *); |
| 79 | |
| 80 | std::function<TSThread()> _init; |
| 81 | std::function<void(TSThread)> _destroy; |
| 82 | ink_thread _this_thread{ink_thread_null()}; |
| 83 | TSThread _rpcThread{nullptr}; |
| 84 | |
| 85 | std::thread running_thread; |
| 86 | std::unique_ptr<comm::BaseCommInterface> _socketImpl; |
| 87 | }; |
| 88 | } // namespace rpc |
| 89 | |
| 90 | extern rpc::RPCServer *jsonrpcServer; |
nothing calls this directly
no test coverage detected