.. index:: pair: class; EngineJSONRegistrationServer .. _doxid-class_engine_j_s_o_n_registration_server: class EngineJSONRegistrationServer ================================== .. toctree:: :hidden: struct_EngineJSONRegistrationServer_RequestHandler.rst Overview ~~~~~~~~ Singleton. Creates an HTTP REST server to register newly created EngineJSONServers and store their addresses. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class EngineJSONRegistrationServer { public: // structs struct :ref:`RequestHandler`; // fields static constexpr std::string_view :ref:`JSONEngineName` = "engine_name"; static constexpr std::string_view :ref:`JSONAddress` = "address"; // construction :target:`EngineJSONRegistrationServer`(const EngineJSONRegistrationServer&); :target:`EngineJSONRegistrationServer`(EngineJSONRegistrationServer&&); // methods static EngineJSONRegistrationServer* :ref:`getInstance`(); static EngineJSONRegistrationServer* :ref:`resetInstance`(const std::string& serverAddress); static void :ref:`clearInstance`(); static std::string :ref:`tryInstantiate`( const std::string& initialAddress, const unsigned numRetries ); static bool :ref:`sendClientEngineRequest`( const std::string& address, const engine_name_t& engineName, const std::string& engineAddress, const unsigned int numTries = 1, const unsigned int waitTime = 0 ); EngineJSONRegistrationServer& :target:`operator =` (const EngineJSONRegistrationServer&); EngineJSONRegistrationServer& :target:`operator =` (EngineJSONRegistrationServer&&); void :ref:`startServerAsync`(); void :ref:`shutdownServer`(); const std::string :ref:`serverAddress`() const; bool :ref:`isRunning`() const; size_t :ref:`getNumWaitingEngines`(); std::string :ref:`retrieveEngineAddress`(const engine_name_t& engineName); std::string :ref:`requestEngine`(const engine_name_t& engineName); void :ref:`registerEngineAddress`( const engine_name_t& engineName, const std::string& address ); }; .. _details-class_engine_j_s_o_n_registration_server: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Singleton. Creates an HTTP REST server to register newly created EngineJSONServers and store their addresses. Fields ------ .. index:: pair: variable; JSONEngineName .. _doxid-class_engine_j_s_o_n_registration_server_1a35616f199c4824ab392ba46419f20d4e: .. ref-code-block:: cpp :class: doxyrest-title-code-block static constexpr std::string_view JSONEngineName = "engine_name" JSON Engine Name locator used during registration. .. index:: pair: variable; JSONAddress .. _doxid-class_engine_j_s_o_n_registration_server_1ac9350fd41611da35b3d027706aded2f0: .. ref-code-block:: cpp :class: doxyrest-title-code-block static constexpr std::string_view JSONAddress = "address" JSON Engine Address locator used during registration. Methods ------- .. index:: pair: function; getInstance .. _doxid-class_engine_j_s_o_n_registration_server_1a01804bc675e83fbe9a13beb6c3ad5e0a: .. ref-code-block:: cpp :class: doxyrest-title-code-block static EngineJSONRegistrationServer* getInstance() Get Instance of :ref:`EngineJSONRegistrationServer `. .. rubric:: Returns: Returns ptr to :ref:`EngineJSONRegistrationServer ` if it exists, nullptr otherwise .. index:: pair: function; resetInstance .. _doxid-class_engine_j_s_o_n_registration_server_1ae9547c569a289f60d1cbe63f14a38534: .. ref-code-block:: cpp :class: doxyrest-title-code-block static EngineJSONRegistrationServer* resetInstance(const std::string& serverAddress) Reset :ref:`EngineJSONRegistrationServer ` with the given address. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - serverAddress - Server Address to bind to .. rubric:: Returns: Returns pointer to created instance .. index:: pair: function; clearInstance .. _doxid-class_engine_j_s_o_n_registration_server_1ae359e0c3b9e18ac4389aaa63e59c26c7: .. ref-code-block:: cpp :class: doxyrest-title-code-block static void clearInstance() Delete Instance. .. index:: pair: function; tryInstantiate .. _doxid-class_engine_j_s_o_n_registration_server_1a5df3201686b15e39316c831f82a95235: .. ref-code-block:: cpp :class: doxyrest-title-code-block static std::string tryInstantiate( const std::string& initialAddress, const unsigned numRetries ) Attempts to instantiate and start the registration server. The function will try to start the registration server at the given address. If the initial attempt fails, then the function will try again, until numRetries limit is exceeded. On every attempt, except for the first one, the address will be modified. The host will be taken from the initialAddress argument, but the port will be changed - the function will ask the OS to provide an unused port for the server. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - initialAddress - Initial address that the server will try to use * - numRetries - Maximum number of attempts to start the server * - When - numRetires has been exceeded. .. rubric:: Returns: The actual address of the server. If the first attempt to start was successful, then it will be the initialAddress. Otherwise, the address will consist of the hostname from the initialAddress and a random port. .. index:: pair: function; sendClientEngineRequest .. _doxid-class_engine_j_s_o_n_registration_server_1a6885323dcb8530362e6e6944f44d0b99: .. ref-code-block:: cpp :class: doxyrest-title-code-block static bool sendClientEngineRequest( const std::string& address, const engine_name_t& engineName, const std::string& engineAddress, const unsigned int numTries = 1, const unsigned int waitTime = 0 ) Send Engine Name and address to specified address. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - address - Address to send data to * - engineName - Name of engine * - engineAddress - Address of engine * - numTries - Number of times to try and contact the registration server * - waitTime - Time (in seconds) to wait between contact attempts .. rubric:: Returns: Returns true on success, false otherwise .. index:: pair: function; startServerAsync .. _doxid-class_engine_j_s_o_n_registration_server_1a016279cbccdd31b35e3ae9963f8f9a9b: .. ref-code-block:: cpp :class: doxyrest-title-code-block void startServerAsync() Start the server if it's not already running. .. index:: pair: function; shutdownServer .. _doxid-class_engine_j_s_o_n_registration_server_1aaad1ad1cf0417e9df8cee0002b2472a7: .. ref-code-block:: cpp :class: doxyrest-title-code-block void shutdownServer() Stop the Server. .. index:: pair: function; serverAddress .. _doxid-class_engine_j_s_o_n_registration_server_1a2811eb1e246bae09305537325a64ea82: .. ref-code-block:: cpp :class: doxyrest-title-code-block const std::string serverAddress() const Get server address. .. index:: pair: function; isRunning .. _doxid-class_engine_j_s_o_n_registration_server_1aa76af550e1b1f51f0fc2af978cbe8543: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool isRunning() const Returns true when server is running, false otherwise. .. index:: pair: function; getNumWaitingEngines .. _doxid-class_engine_j_s_o_n_registration_server_1a7ca7f180ee20ad5f9c15396dafb97f45: .. ref-code-block:: cpp :class: doxyrest-title-code-block size_t getNumWaitingEngines() Get the number of engines that are still waiting for registration. .. index:: pair: function; retrieveEngineAddress .. _doxid-class_engine_j_s_o_n_registration_server_1adb9a0ea5659ef28f09c229ff671489dc: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::string retrieveEngineAddress(const engine_name_t& engineName) Retrieve a registered engine address. If available and non-empty, erase it from _registeredAddresses. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - engineName - Engine Name for which to find the address .. rubric:: Returns: If address available, return it. Otherwise return empty string .. index:: pair: function; requestEngine .. _doxid-class_engine_j_s_o_n_registration_server_1a7c1c8ee2ecc0417e1f21dd637678df5c: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::string requestEngine(const engine_name_t& engineName) Request an engine's address. If available, erases entry from _registeredAddresses. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - engineName - Name of engine to wait for .. rubric:: Returns: If available, returns name of engine. Else, returns empty string .. index:: pair: function; registerEngineAddress .. _doxid-class_engine_j_s_o_n_registration_server_1aee4adaba680e0aceeee432fc12bb3679: .. ref-code-block:: cpp :class: doxyrest-title-code-block void registerEngineAddress( const engine_name_t& engineName, const std::string& address ) Register an engine's address. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - engineName - Name of engine * - address - Address of engine