template class EngineClient¶
Overview¶
Base class for all Engines. More…
#include <engine_client_interface.h> template <class ENGINE, const char* SCHEMA> class EngineClient: public EngineClientInterface { public: // typedefs typedef ENGINE engine_t; // classes template <const char* ENGINE_TYPE> class EngineLauncher; // construction EngineClient( nlohmann::json& engineConfig, ProcessLauncherInterface::unique_ptr&& launcher ); // methods virtual const std::string engineName() const; virtual SimulationTime getEngineTimestep() const; virtual const nlohmann::json& engineConfig() const; virtual nlohmann::json& engineConfig(); virtual const std::string engineSchema() const; virtual SimulationTime getEngineTime() const; virtual void runLoopStepAsync(SimulationTime timeStep); virtual void runLoopStepAsyncGet(SimulationTime timeOut); }; // direct descendants template <class ENGINE, const char* SCHEMA> class EngineGrpcClient; template <class ENGINE, const char* SCHEMA> class EngineJSONNRPClient;
Inherited Members¶
public: // typedefs typedef std::shared_ptr<T> shared_ptr; typedef std::shared_ptr<const T> const_shared_ptr; typedef std::unique_ptr<T> unique_ptr; typedef std::unique_ptr<const T> const_unique_ptr; // methods virtual const std::string engineName() const = 0; virtual const nlohmann::json& engineConfig() const = 0; virtual nlohmann::json& engineConfig() = 0; virtual const std::vector<std::string> engineProcStartParams() const = 0; virtual pid_t launchEngine(); virtual void initialize() = 0; virtual void reset() = 0; virtual void shutdown() = 0; virtual SimulationTime getEngineTimestep() const = 0; virtual SimulationTime getEngineTime() const = 0; virtual const std::string engineSchema() const = 0; virtual void runLoopStepAsync(SimulationTime timeStep) = 0; virtual void runLoopStepAsyncGet(SimulationTime timeOut) = 0; virtual void sendDataPacksToEngine(const datapacks_set_t& dataPacks) = 0; virtual datapacks_vector_t getDataPacksFromEngine(const datapack_identifiers_set_t& datapackIdentifiers) = 0;
Detailed Documentation¶
Base class for all Engines.
Parameters:
ENGINE |
Final derived engine class |
Construction¶
EngineClient( nlohmann::json& engineConfig, ProcessLauncherInterface::unique_ptr&& launcher )
Constructor.
Parameters:
engineConfig |
Engine Configuration |
launcher |
Process Forker |
Methods¶
virtual const std::string engineName() const
Get Engine Name.
Returns:
Returns engine name
virtual SimulationTime getEngineTimestep() const
Get engine timestep.
Parameters:
Throws |
on error |
virtual const nlohmann::json& engineConfig() const
Get Engine Configuration.
virtual nlohmann::json& engineConfig()
Get Engine Configuration.
virtual const std::string engineSchema() const
Get json schema for this engine type.
virtual SimulationTime getEngineTime() const
Returns current engine (simulation) time.
The time is updated by EngineClient::runLoopStepAsyncGet() method.
Returns:
Current engine (simulation) time
virtual void runLoopStepAsync(SimulationTime timeStep)
Concrete implementation of EngineClientInterface::runLoopStepAsync()
The function starts EngineClient::runLoopStepCallback() asynchronously using std::async. The callback function should be provided by concrete engine implementation. The result of the callback is going to be retrieved using an std::future object in EngineClient::runLoopStepAsyncGet().
Parameters:
timeStep |
Requested duration of the simulation loop step. |
If the future object is still valid (EngineClient::runLoopStepAsyncGet() was not called) |
virtual void runLoopStepAsyncGet(SimulationTime timeOut)
Concrete implementation of EngineClientInterface::runLoopStepAsyncGet()
The function should be called after EngineClient::runLoopStepAsync(). It will wait for the worker thread to finish and retrieve the results from the future object. The value returned by the future should be the simulation (engine) time after running the loop step. It will be saved in the engine object, and can be accessed with EngineClient::getEngineTime().
Parameters:
timeOut |
Timeout of the loop step. If it’s less or equal to 0, the function will wait indefinitely. |
On timeout |