Manages communication with the NRP. Uses a REST server to send/receive data. Singleton class. More...
#include <engine_json_server.h>
Public Types | |
using | mutex_t = std::timed_mutex |
using | lock_t = std::unique_lock< EngineJSONServer::mutex_t > |
Public Member Functions | |
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. More... | |
EngineJSONServer ()=delete | |
No dummy servers without name and address. More... | |
virtual | ~EngineJSONServer () |
EngineJSONServer (const EngineJSONServer &)=delete | |
EngineJSONServer & | operator= (const EngineJSONServer &)=delete |
bool | isServerRunning () const |
Is the server running? More... | |
void | startServerAsync () |
Start the server in asynchronous mode. More... | |
void | startServer () |
Start the server synchronously. More... | |
void | shutdownServer () |
Stop running server. More... | |
uint16_t | serverPort () const |
Get running server port. More... | |
std::string | serverAddress () const |
Get server address. More... | |
void | registerDataPack (const std::string &datapackName, JsonDataPackController *interface) |
Registers a datapack. More... | |
void | registerDataPackNoLock (const std::string &datapackName, JsonDataPackController *interface) |
Registers a datapack. Skips locking the mutex. Should only be used if thread-safe access to _datapacksControllers can be guaranteed. More... | |
virtual SimulationTime | runLoopStep (SimulationTime timeStep)=0 |
Run a single loop step. More... | |
virtual nlohmann::json | initialize (const nlohmann::json &data, EngineJSONServer::lock_t &datapackLock)=0 |
Engine Initialization routine. More... | |
virtual nlohmann::json | reset (EngineJSONServer::lock_t &datapackLock)=0 |
Engine reset routine. More... | |
virtual nlohmann::json | shutdown (const nlohmann::json &data)=0 |
Engine Shutdown routine. More... | |
bool | shutdownFlag () |
Has a shutdown command been received? More... | |
Protected Member Functions | |
void | clearRegisteredDataPacks () |
Remove all registered datapacks. More... | |
virtual nlohmann::json | getDataPackData (const nlohmann::json &reqData) |
Retrieves datapack data. Takes an array of datapack names for which to get data. More... | |
virtual void | setDataPackData (const nlohmann::json &reqData) |
Set datapack data. More... | |
const std::string & | getEngineName () |
Get the Engine name. More... | |
Protected Attributes | |
mutex_t | _datapackLock |
Lock access to _datapacks to make execution thread-safe. More... | |
Static Protected Attributes | |
static constexpr std::string_view | GetDataPackInformationRoute = EngineJSONConfigConst::EngineServerGetDataPacksRoute |
static constexpr std::string_view | SetDataPackRoute = EngineJSONConfigConst::EngineServerSetDataPacksRoute |
static constexpr std::string_view | RunLoopStepRoute = EngineJSONConfigConst::EngineServerRunLoopStepRoute |
static constexpr std::string_view | InitializeRoute = EngineJSONConfigConst::EngineServerInitializeRoute |
static constexpr std::string_view | ResetRoute = EngineJSONConfigConst::EngineServerResetRoute |
static constexpr std::string_view | ShutdownRoute = EngineJSONConfigConst::EngineServerShutdownRoute |
Friends | |
class | EngineJSONServerTest_Functions_Test |
class | TestEngineJSONServer |
Manages communication with the NRP. Uses a REST server to send/receive data. Singleton class.
using EngineJSONServer::lock_t = std::unique_lock<EngineJSONServer::mutex_t> |
using EngineJSONServer::mutex_t = std::timed_mutex |
EngineJSONServer::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.
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 EngineJSONConfigConst::MaxAddrBindTries times |
engineName | Engine Name |
clientAddress | Client Address. The server will try to register itself under this address |
|
delete |
No dummy servers without name and address.
|
virtual |
|
delete |
|
protected |
Remove all registered datapacks.
|
protectedvirtual |
Retrieves datapack data. Takes an array of datapack names for which to get data.
reqData | A JSON array containing datapack names. |
|
inlineprotected |
Get the Engine name.
|
pure virtual |
Engine Initialization routine.
data | Initialization data |
datapackLock | DataPack Lock. Prevents access to _datapacksControllers |
Implemented in NestJSONServer.
bool EngineJSONServer::isServerRunning | ( | ) | const |
Is the server running?
|
delete |
void EngineJSONServer::registerDataPack | ( | const std::string & | datapackName, |
JsonDataPackController * | interface | ||
) |
Registers a datapack.
datapackName | Name of datapack |
interface | Pointer to interface |
void EngineJSONServer::registerDataPackNoLock | ( | const std::string & | datapackName, |
JsonDataPackController * | interface | ||
) |
Registers a datapack. Skips locking the mutex. Should only be used if thread-safe access to _datapacksControllers can be guaranteed.
datapackName | Name of datapack |
interface | Pointer to interface |
|
pure virtual |
Engine reset routine.
datapackLock | DataPack Lock. Prevents access to _datapacksControllers |
Implemented in NestJSONServer.
|
pure virtual |
Run a single loop step.
timeStep | Step to take |
Implemented in NestJSONServer.
std::string EngineJSONServer::serverAddress | ( | ) | const |
Get server address.
uint16_t EngineJSONServer::serverPort | ( | ) | const |
Get running server port.
|
protectedvirtual |
Set datapack data.
reqData | A JSON array containing datapack names linked to the individual datapack's data |
|
pure virtual |
Engine Shutdown routine.
data | Shutdown data |
Implemented in NestJSONServer.
bool EngineJSONServer::shutdownFlag | ( | ) |
Has a shutdown command been received?
void EngineJSONServer::shutdownServer | ( | ) |
Stop running server.
void EngineJSONServer::startServer | ( | ) |
Start the server synchronously.
void EngineJSONServer::startServerAsync | ( | ) |
Start the server in asynchronous mode.
|
friend |
|
friend |
|
protected |
Lock access to _datapacks to make execution thread-safe.
|
staticconstexprprotected |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
staticconstexprprotected |