NRP Core  1.4.1
EngineClient< ENGINE, SCHEMA > Class Template Referenceabstract

Base class for all Engines. More...

#include <engine_client_interface.h>

Inheritance diagram for EngineClient< ENGINE, SCHEMA >:
EngineClientInterface PtrTemplates< EngineClientInterface > EngineGrpcClient< ENGINE, SCHEMA > EngineJSONNRPClient< ENGINE, SCHEMA > PythonEngineJSONNRPClientBase< ENGINE, SCHEMA >

Classes

class  EngineLauncher
 Class for launching engine. More...
 

Public Types

using engine_t = ENGINE
 
- Public Types inherited from PtrTemplates< EngineClientInterface >
using shared_ptr = std::shared_ptr< EngineClientInterface >
 
using const_shared_ptr = std::shared_ptr< const EngineClientInterface >
 
using unique_ptr = std::unique_ptr< EngineClientInterface >
 
using const_unique_ptr = std::unique_ptr< const EngineClientInterface >
 

Public Member Functions

 EngineClient (nlohmann::json &engineConfig, ProcessLauncherInterface::unique_ptr &&launcher)
 Constructor. More...
 
 ~EngineClient () override=default
 
const std::string engineName () const override final
 Get Engine Name. More...
 
SimulationTime getEngineTimestep () const override final
 Get engine timestep. More...
 
const nlohmann::jsonengineConfig () const override final
 Get Engine Configuration. More...
 
nlohmann::jsonengineConfig () override final
 Get Engine Configuration. More...
 
const std::string engineSchema () const override final
 Get json schema for this engine type. More...
 
SimulationTime getEngineTime () const override
 Returns current engine (simulation) time. More...
 
void runLoopStepAsync (SimulationTime timeStep) override
 Concrete implementation of EngineClientInterface::runLoopStepAsync() More...
 
void runLoopStepAsyncGet (SimulationTime timeOut) override
 Concrete implementation of EngineClientInterface::runLoopStepAsyncGet() More...
 
- Public Member Functions inherited from EngineClientInterface
 EngineClientInterface (ProcessLauncherInterface::unique_ptr &&launcher)
 
virtual ~EngineClientInterface ()
 
virtual const std::vector< std::string > engineProcStartParams () const =0
 Get all Engine Process Startup parameters. More...
 
virtual pid_t launchEngine ()
 Launch the engine. More...
 
virtual void initialize ()=0
 Initialize engine. More...
 
virtual void reset ()=0
 Reset engine. More...
 
virtual void shutdown ()=0
 Shutdown engine. More...
 
virtual void sendDataPacksToEngine (const datapacks_set_t &dataPacks)=0
 Sends datapacks to engine. More...
 
virtual datapacks_vector_t getDataPacksFromEngine (const datapack_identifiers_set_t &datapackIdentifiers)=0
 Gets requested datapacks from engine. More...
 

Protected Member Functions

virtual void resetEngineTime ()
 
template<class T >
void setDefaultProperty (std::string key, T value)
 Attempts to set a default value for a property in the engine configuration. If the property has been already set either in the engine configuration file or from the engine schema, its value is not overwritten. More...
 
virtual SimulationTime runLoopStepCallback (SimulationTime timeStep)=0
 Executes a single loop step. More...
 

Additional Inherited Members

- Protected Attributes inherited from EngineClientInterface
ProcessLauncherInterface::unique_ptr _process
 Process Launcher. Will be used to stop process at end. More...
 

Detailed Description

template<class ENGINE, const char * SCHEMA>
class EngineClient< ENGINE, SCHEMA >

Base class for all Engines.

Template Parameters
ENGINEFinal derived engine class

Member Typedef Documentation

◆ engine_t

template<class ENGINE , const char * SCHEMA>
using EngineClient< ENGINE, SCHEMA >::engine_t = ENGINE

Constructor & Destructor Documentation

◆ EngineClient()

template<class ENGINE , const char * SCHEMA>
EngineClient< ENGINE, SCHEMA >::EngineClient ( nlohmann::json engineConfig,
ProcessLauncherInterface::unique_ptr &&  launcher 
)
inline

Constructor.

Parameters
engineConfigEngine Configuration
launcherProcess Forker

◆ ~EngineClient()

template<class ENGINE , const char * SCHEMA>
EngineClient< ENGINE, SCHEMA >::~EngineClient ( )
overridedefault

Member Function Documentation

◆ engineConfig() [1/2]

template<class ENGINE , const char * SCHEMA>
const nlohmann::json& EngineClient< ENGINE, SCHEMA >::engineConfig ( ) const
inlinefinaloverridevirtual

Get Engine Configuration.

Implements EngineClientInterface.

◆ engineConfig() [2/2]

template<class ENGINE , const char * SCHEMA>
nlohmann::json& EngineClient< ENGINE, SCHEMA >::engineConfig ( )
inlinefinaloverridevirtual

Get Engine Configuration.

Implements EngineClientInterface.

◆ engineName()

template<class ENGINE , const char * SCHEMA>
const std::string EngineClient< ENGINE, SCHEMA >::engineName ( ) const
inlinefinaloverridevirtual

Get Engine Name.

Returns
Returns engine name

Implements EngineClientInterface.

◆ engineSchema()

template<class ENGINE , const char * SCHEMA>
const std::string EngineClient< ENGINE, SCHEMA >::engineSchema ( ) const
inlinefinaloverridevirtual

Get json schema for this engine type.

Implements EngineClientInterface.

◆ getEngineTime()

template<class ENGINE , const char * SCHEMA>
SimulationTime EngineClient< ENGINE, SCHEMA >::getEngineTime ( ) const
inlineoverridevirtual

Returns current engine (simulation) time.

The time is updated by EngineClient::runLoopStepAsyncGet() method.

Returns
Current engine (simulation) time

Implements EngineClientInterface.

◆ getEngineTimestep()

template<class ENGINE , const char * SCHEMA>
SimulationTime EngineClient< ENGINE, SCHEMA >::getEngineTimestep ( ) const
inlinefinaloverridevirtual

Get engine timestep.

Exceptions
Throwson error

Implements EngineClientInterface.

◆ resetEngineTime()

template<class ENGINE , const char * SCHEMA>
virtual void EngineClient< ENGINE, SCHEMA >::resetEngineTime ( )
inlineprotectedvirtual

◆ runLoopStepAsync()

template<class ENGINE , const char * SCHEMA>
void EngineClient< ENGINE, SCHEMA >::runLoopStepAsync ( SimulationTime  timeStep)
inlineoverridevirtual

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
[in]timeStepRequested duration of the simulation loop step.
Exceptions
NRPExceptionIf the future object is still valid (EngineClient::runLoopStepAsyncGet() was not called)

Implements EngineClientInterface.

◆ runLoopStepAsyncGet()

template<class ENGINE , const char * SCHEMA>
void EngineClient< ENGINE, SCHEMA >::runLoopStepAsyncGet ( SimulationTime  timeOut)
inlineoverridevirtual

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
[in]timeOutTimeout of the loop step. If it's less or equal to 0, the function will wait indefinitely.
Exceptions
NRPExceptionOn timeout

Implements EngineClientInterface.

◆ runLoopStepCallback()

template<class ENGINE , const char * SCHEMA>
virtual SimulationTime EngineClient< ENGINE, SCHEMA >::runLoopStepCallback ( SimulationTime  timeStep)
protectedpure virtual

Executes a single loop step.

This function is going to be called by runLoopStep using std::async. It will be executed by a worker thread, which allows for runLoopStepFunction from multiple engines to run simultaneously.

Parameters
[in]timeStepA time step by which the simulation should be advanced
Returns
Engine time after loop step execution

Implemented in NestEngineServerNRPClient, EngineGrpcClient< ENGINE, SCHEMA >, EngineGrpcClient< PythonEngineGRPCNRPClient, PythonGrpcConfigConst::EngineSchema >, and EngineGrpcClient< GazeboEngineGrpcNRPClient, GazeboGrpcConfigConst::EngineSchema >.

◆ setDefaultProperty()

template<class ENGINE , const char * SCHEMA>
template<class T >
void EngineClient< ENGINE, SCHEMA >::setDefaultProperty ( std::string  key,
value 
)
inlineprotected

Attempts to set a default value for a property in the engine configuration. If the property has been already set either in the engine configuration file or from the engine schema, its value is not overwritten.

Parameters
keyName of the property to be set
valueDefault value to set

The documentation for this class was generated from the following file: