Go to the documentation of this file.
22 #ifndef ENGINE_CLIENT_INTERFACE_H
23 #define ENGINE_CLIENT_INTERFACE_H
54 virtual const std::string
engineName()
const = 0;
89 virtual void reset() = 0;
190 template<
class ENGINE, const
char *SCHEMA>
201 template<const
char *ENGINE_TYPE>
226 switch (engine->launchEngine())
230 "\"{}\" Engine (type: \"{}\") could NOT be launched.", engine->engineName(), this->engineType());
234 "\"{}\" EngineClient (type: \"{}\") won't launch an EngineServer. Assume it's already been launched.", engine->engineName(), this->engineType());
238 "\"{}\" Engine (type: \"{}\") launched successfully", engine->engineName(), this->engineType());
259 setDefaultProperty<std::vector<std::string>>(
"EngineProcStartParams", std::vector<std::string>());
260 setDefaultProperty<std::vector<std::string>>(
"EngineEnvParams", std::vector<std::string>());
261 setDefaultProperty<nlohmann::json>(
"EngineExtraConfigs",
nlohmann::json(json::value_t::object));
272 return toSimulationTime<float, std::ratio<1>>(this->
engineConfig().at(
"EngineTimestep"));
279 {
return engineConfig_; }
285 {
return engineConfig_; }
302 return this->_engineTime;
318 if(this->_loopStepThread.valid())
342 if(!this->_loopStepThread.valid())
346 if(timeOut > SimulationTime::zero())
348 if(this->_loopStepThread.wait_for(timeOut) != std::future_status::ready)
354 this->_engineTime = this->_loopStepThread.get();
373 json_utils::setDefault<T>(this->
engineConfig(), key, value);
391 std::string schema = std::string(SCHEMA);
395 std::future<SimulationTime> _loopStepThread;
403 #endif // ENGINE_CLIENT_INTERFACE_H
virtual datapacks_vector_t getDataPacksFromEngine(const datapack_identifiers_set_t &datapackIdentifiers)=0
Gets requested datapacks from engine.
std::vector< std::shared_ptr< const DataPackInterface > > datapacks_vector_t
Definition: datapack_interface.h:220
virtual void shutdown()=0
Shutdown engine.
nlohmann::json & engineConfig() override final
Get Engine Configuration.
Definition: engine_client_interface.h:284
virtual pid_t launchEngine()
Launch the engine.
Definition: engine_client_interface.cpp:31
std::set< std::shared_ptr< const DataPackInterface >, DataPackPointerComparator > datapacks_set_t
Definition: datapack_interface.h:219
std::unique_ptr< ProcessLauncherInterface > unique_ptr
Definition: ptr_templates.h:34
virtual ~EngineClientInterface()
decltype(DataPackIdentifier::Type) engine_type_t
Definition: engine_client_interface.h:168
void validateJson(nlohmann::json &instance, std::string schema_path, bool addPatch)
Validates a json object using a given json schema.
Definition: json_schema_utils.cpp:65
std::string Type
DataPack Type.
Definition: datapack_interface.h:54
virtual void sendDataPacksToEngine(const datapacks_set_t &dataPacks)=0
Sends datapacks to engine.
virtual void runLoopStepAsyncGet(SimulationTime timeOut)=0
Waits and gets the results of the loop step started by EngineClientInterface::runLoopStepAsync()
void runLoopStepAsync(SimulationTime timeStep) override
Concrete implementation of EngineClientInterface::runLoopStepAsync()
Definition: engine_client_interface.h:316
const std::string engineName() const override final
Get Engine Name.
Definition: engine_client_interface.h:266
~EngineClient() override=default
Interface to engines.
Definition: engine_client_interface.h:43
ProcessLauncherInterface::unique_ptr _process
Process Launcher. Will be used to stop process at end.
Definition: engine_client_interface.h:158
virtual SimulationTime getEngineTime() const =0
Get current engine time.
virtual void reset()=0
Reset engine.
Base class for all Engines.
Definition: engine_client_interface.h:191
EngineLauncherInterface(const engine_type_t &engineType)
Definition: engine_client_interface.cpp:43
std::shared_ptr< const EngineClientInterface > const_shared_ptr
Definition: ptr_templates.h:32
virtual const nlohmann::json & engineConfig() const =0
Get engine config data.
EngineLauncher(const engine_type_t &engineType)
Definition: engine_client_interface.h:210
const nlohmann::json & engineConfig() const override final
Get Engine Configuration.
Definition: engine_client_interface.h:278
SimulationTime getEngineTimestep() const override final
Get engine timestep.
Definition: engine_client_interface.h:269
static void info(const FormatString &fmt, const Args &...args)
NRP logging function with message formatting for info level.
Definition: nrp_logger.h:138
void runLoopStepAsyncGet(SimulationTime timeOut) override
Concrete implementation of EngineClientInterface::runLoopStepAsyncGet()
Definition: engine_client_interface.h:337
virtual SimulationTime getEngineTimestep() const =0
Get engine timestep.
virtual SimulationTime runLoopStepCallback(SimulationTime timeStep)=0
Executes a single loop step.
PythonGRPCEngine client.
Definition: python_engine_grpc_nrp_client.h:48
std::set< DataPackIdentifier > datapack_identifiers_set_t
Definition: datapack_interface.h:221
~EngineLauncher() override=default
virtual void initialize()=0
Initialize engine.
EngineClientInterface::const_shared_ptr EngineClientInterfaceConstSharedPtr
Definition: engine_client_interface.h:162
virtual EngineClientInterfaceSharedPtr launchEngine(nlohmann::json &engineConfig, ProcessLauncherInterface::unique_ptr &&launcher)=0
const std::string engineSchema() const override final
Get json schema for this engine type.
Definition: engine_client_interface.h:290
EngineLauncher()
Definition: engine_client_interface.h:206
Definition: ptr_templates.h:28
virtual void resetEngineTime()
Definition: engine_client_interface.h:359
static EXCEPTION logCreate(LOG_EXCEPTION_T &exception, const std::string &msg, NRPLogger::spdlog_out_fcn_t spdlogCall=NRPLogger::critical)
Definition: nrp_exceptions.h:73
virtual const std::string engineSchema() const =0
Get json schema for this specific engine type.
std::shared_ptr< EngineClientInterface > shared_ptr
Definition: ptr_templates.h:31
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 ...
Definition: engine_client_interface.h:371
EngineLauncherInterface::const_shared_ptr EngineLauncherInterfaceConstSharedPtr
Definition: engine_client_interface.h:184
Class for launching engine.
Definition: engine_client_interface.h:202
virtual void runLoopStepAsync(SimulationTime timeStep)=0
Starts a single loop step in a separate thread.
EngineLauncherInterface::shared_ptr EngineLauncherInterfaceSharedPtr
Definition: engine_client_interface.h:183
virtual const std::string engineName() const =0
Get Engine Name.
static void error(const FormatString &fmt, const Args &...args)
NRP logging function with message formatting for error level.
Definition: nrp_logger.h:160
EngineClientInterface::shared_ptr EngineClientInterfaceSharedPtr
Definition: engine_client_interface.h:161
virtual ~EngineLauncherInterface()=default
SimulationTime getEngineTime() const override
Returns current engine (simulation) time.
Definition: engine_client_interface.h:300
Definition: engine_client_interface.h:164
const engine_type_t & engineType() const
Definition: engine_client_interface.cpp:47
EngineClient(nlohmann::json &engineConfig, ProcessLauncherInterface::unique_ptr &&launcher)
Constructor.
Definition: engine_client_interface.h:251
EngineClientInterfaceSharedPtr launchEngine(nlohmann::json &engineConfig, ProcessLauncherInterface::unique_ptr &&launcher) override
Launches an engine. Configures config and forks a new child process for the engine.
Definition: engine_client_interface.h:222
EngineClientInterface(ProcessLauncherInterface::unique_ptr &&launcher)
Definition: engine_client_interface.cpp:25
std::chrono::nanoseconds SimulationTime
Definition: time_utils.h:31
virtual const std::vector< std::string > engineProcStartParams() const =0
Get all Engine Process Startup parameters.
#define NRP_LOGGER_TRACE(...)
trace log macro. It is voided by defining \PRODUCTION_RELEASE
Definition: nrp_logger.h:39
nlohmann::json json
Definition: engine_json_server.cpp:31