.. index:: pair: class; EngineJSONServer .. _doxid-class_engine_j_s_o_n_server: class EngineJSONServer ====================== .. toctree:: :hidden: Overview ~~~~~~~~ Manages communication with the NRP. Uses a REST server to send/receive data. Singleton class. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class EngineJSONServer { public: // typedefs typedef std::timed_mutex :target:`mutex_t`; typedef std::unique_lock<:ref:`EngineJSONServer::mutex_t`> :target:`lock_t`; // construction :ref:`EngineJSONServer`( const std::string& engineAddress, const std::string& engineName, const std::string& clientAddress ); :ref:`EngineJSONServer`(); :target:`EngineJSONServer`(const EngineJSONServer&); // methods EngineJSONServer& :target:`operator =` (const EngineJSONServer&); bool :ref:`isServerRunning`() const; void :ref:`startServerAsync`(); void :ref:`startServer`(); void :ref:`shutdownServer`(); uint16_t :ref:`serverPort`() const; std::string :ref:`serverAddress`() const; void :ref:`registerDataPack`( const std::string& datapackName, :ref:`JsonDataPackController`* interface ); void :ref:`registerDataPackNoLock`( const std::string& datapackName, :ref:`JsonDataPackController`* interface ); virtual :ref:`SimulationTime` :ref:`runLoopStep`(:ref:`SimulationTime` timeStep) = 0; virtual :ref:`nlohmann::json` :ref:`initialize`( const :ref:`nlohmann::json`& data, :ref:`EngineJSONServer::lock_t`& datapackLock ) = 0; virtual :ref:`nlohmann::json` :ref:`reset`(:ref:`EngineJSONServer::lock_t`& datapackLock) = 0; virtual :ref:`nlohmann::json` :ref:`shutdown`(const :ref:`nlohmann::json`& data) = 0; bool :ref:`shutdownFlag`(); }; // direct descendants class :ref:`NestJSONServer`; class :ref:`NRPJSONCommunicationController`; .. _details-class_engine_j_s_o_n_server: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Manages communication with the NRP. Uses a REST server to send/receive data. Singleton class. Construction ------------ .. index:: pair: function; EngineJSONServer .. _doxid-class_engine_j_s_o_n_server_1ac9d6e1071b1d64cdf6585a6a97e66922: .. ref-code-block:: cpp :class: doxyrest-title-code-block EngineJSONServer( const std::string& engineAddress, const std::string& engineName, const std::string& clientAddress ) Constructor. Tries to bind to a port and register itself with clientAddress. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - engineAddress - Server Address. If it contains a port, will try to bind to said port. If that fails, will increment port number and try again. This will continue for at most :ref:`EngineJSONConfigConst::MaxAddrBindTries ` times * - engineName - Engine Name * - clientAddress - Client Address. The server will try to register itself under this address .. index:: pair: function; EngineJSONServer .. _doxid-class_engine_j_s_o_n_server_1aa477be196bc34141ef7c448384f65bec: .. ref-code-block:: cpp :class: doxyrest-title-code-block EngineJSONServer() No dummy servers without name and address. Methods ------- .. index:: pair: function; isServerRunning .. _doxid-class_engine_j_s_o_n_server_1a0f65133b9a3a09f6bd2141d135d21e7c: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool isServerRunning() const Is the server running? .. rubric:: Returns: Returns true if the server is running .. index:: pair: function; startServerAsync .. _doxid-class_engine_j_s_o_n_server_1a33acfbda554050d3d47cab00e3d4869e: .. ref-code-block:: cpp :class: doxyrest-title-code-block void startServerAsync() Start the server in asynchronous mode. .. index:: pair: function; startServer .. _doxid-class_engine_j_s_o_n_server_1a10dbdbcbf4ee934d1b7740c4e3bb11d7: .. ref-code-block:: cpp :class: doxyrest-title-code-block void startServer() Start the server synchronously. .. index:: pair: function; shutdownServer .. _doxid-class_engine_j_s_o_n_server_1ad3a67a6b3fb7889725d8474b8631eb10: .. ref-code-block:: cpp :class: doxyrest-title-code-block void shutdownServer() Stop running server. .. index:: pair: function; serverPort .. _doxid-class_engine_j_s_o_n_server_1add529a3d33c10daff532d50790f206e6: .. ref-code-block:: cpp :class: doxyrest-title-code-block uint16_t serverPort() const Get running server port. .. rubric:: Returns: Returns port of running server, 0 if server is not running .. index:: pair: function; serverAddress .. _doxid-class_engine_j_s_o_n_server_1ab98b796faed11c13f43300fc8fdbacb2: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::string serverAddress() const Get server address. .. index:: pair: function; registerDataPack .. _doxid-class_engine_j_s_o_n_server_1a20aa263c3e4605edc9b461b270bd6b3b: .. ref-code-block:: cpp :class: doxyrest-title-code-block void registerDataPack( const std::string& datapackName, :ref:`JsonDataPackController`* interface ) Registers a datapack. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - datapackName - Name of datapack * - interface - Pointer to interface .. index:: pair: function; registerDataPackNoLock .. _doxid-class_engine_j_s_o_n_server_1a64df4ef44c6a98b8d125cd77bd43bcb6: .. ref-code-block:: cpp :class: doxyrest-title-code-block void registerDataPackNoLock( const std::string& datapackName, :ref:`JsonDataPackController`* interface ) Registers a datapack. Skips locking the mutex. Should only be used if thread-safe access to _datapacksControllers can be guaranteed. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - datapackName - Name of datapack * - interface - Pointer to interface .. index:: pair: function; runLoopStep .. _doxid-class_engine_j_s_o_n_server_1a0345dec840e4827786442050a6589787: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual :ref:`SimulationTime` runLoopStep(:ref:`SimulationTime` timeStep) = 0 Run a single loop step. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - timeStep - Step to take .. rubric:: Returns: Returns the time registered by this engine at the end of the loop .. index:: pair: function; initialize .. _doxid-class_engine_j_s_o_n_server_1ac8df612106fa7d2d92663f8fd6cfcfe5: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual :ref:`nlohmann::json` initialize( const :ref:`nlohmann::json`& data, :ref:`EngineJSONServer::lock_t`& datapackLock ) = 0 Engine Initialization routine. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - data - Initialization data * - datapackLock - :ref:`DataPack ` Lock. Prevents access to _datapacksControllers .. rubric:: Returns: Returns data about initialization status .. index:: pair: function; reset .. _doxid-class_engine_j_s_o_n_server_1a76b6062e7a83a6b5adefb01c07547de0: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual :ref:`nlohmann::json` reset(:ref:`EngineJSONServer::lock_t`& datapackLock) = 0 Engine reset routine. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - datapackLock - :ref:`DataPack ` Lock. Prevents access to _datapacksControllers .. rubric:: Returns: Returns data about initialization status .. index:: pair: function; shutdown .. _doxid-class_engine_j_s_o_n_server_1a83f8f54978e715ce341af674e1813f90: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual :ref:`nlohmann::json` shutdown(const :ref:`nlohmann::json`& data) = 0 Engine Shutdown routine. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - data - Shutdown data .. rubric:: Returns: Returns data about shutdown status .. index:: pair: function; shutdownFlag .. _doxid-class_engine_j_s_o_n_server_1ae91f2b2f343cae0bd152ca906820377a: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool shutdownFlag() Has a shutdown command been received? .. rubric:: Returns: Returns true if a shutdown command has been received