NRP Core  1.4.1
nest_engine_server_nrp_client.h
Go to the documentation of this file.
1 /* * NRP Core - Backend infrastructure to synchronize simulations
2  *
3  * Copyright 2020-2023 NRP Team
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * This project has received funding from the European Union’s Horizon 2020
18  * Framework Programme for Research and Innovation under the Specific Grant
19  * Agreement No. 945539 (Human Brain Project SGA3).
20  */
21 
22 #ifndef NEST_ENGINE_SERVER_NRP_CLIENT_H
23 #define NEST_ENGINE_SERVER_NRP_CLIENT_H
24 
28 
29 #include <future>
30 #include <string>
31 #include <unistd.h>
32 
37  : public EngineClient<NestEngineServerNRPClient, NestServerConfigConst::EngineSchema>
38 {
42  static constexpr size_t _killWait = 10;
43 
47  static constexpr uint16_t PortSearchStart = 5000;
48 
49  public:
51  virtual ~NestEngineServerNRPClient() override;
52 
53  virtual void initialize() override;
54  virtual void reset() override;
55  virtual void shutdown() override;
56 
58 
59  virtual void sendDataPacksToEngine(const datapacks_set_t & datapacksArray) override;
60 
61  virtual const std::vector<std::string> engineProcStartParams() const override;
62 
63  using population_mapping_t = std::map<std::string, std::string>;
64 
65  using get_connection_population_mapping_t = std::map<std::string, std::pair<std::string,std::string> >;
66 
67  virtual datapacks_vector_t getDataPacksFromEngine(const datapack_identifiers_set_t &datapackIdentifiers) override;
68 
69  private:
70 
74  std::future<bool> _runStepThread;
75 
85  population_mapping_t _populations;
86 
90  float _simulationResolution = 0.0f;
91 
95  std::string _serverAddress;
96 
104  get_connection_population_mapping_t _getConnectionsPopulationToArgs;
105 
106  bool runStepFcn(SimulationTime timestep);
107 
113  std::string serverAddress() const;
114 
121  const std::string & getDataPackIdList(const std::string & datapackName) const;
122 
123 };
124 
125 using NestEngineServerNRPClientLauncher = NestEngineServerNRPClient::EngineLauncher<NestServerConfigConst::EngineType>;
126 
127 
129 
130 
131 #endif // NEST_ENGINE_SERVER_NRP_CLIENT_H
datapacks_vector_t
std::vector< std::shared_ptr< const DataPackInterface > > datapacks_vector_t
Definition: datapack_interface.h:220
NestEngineServerNRPClient::sendDataPacksToEngine
virtual void sendDataPacksToEngine(const datapacks_set_t &datapacksArray) override
Sends datapacks to engine.
Definition: nest_engine_server_nrp_client.cpp:494
datapacks_set_t
std::set< std::shared_ptr< const DataPackInterface >, DataPackPointerComparator > datapacks_set_t
Definition: datapack_interface.h:219
PtrTemplates< ProcessLauncherInterface >::unique_ptr
std::unique_ptr< ProcessLauncherInterface > unique_ptr
Definition: ptr_templates.h:34
NestEngineServerNRPClient::NestEngineServerNRPClient
NestEngineServerNRPClient(nlohmann::json &config, ProcessLauncherInterface::unique_ptr &&launcher)
Definition: nest_engine_server_nrp_client.cpp:296
plugin.h
EngineClient
Base class for all Engines.
Definition: engine_client_interface.h:191
NestEngineServerNRPClient::reset
virtual void reset() override
Reset engine.
Definition: nest_engine_server_nrp_client.cpp:401
engine_client_interface.h
NestEngineServerNRPClient::population_mapping_t
std::map< std::string, std::string > population_mapping_t
Definition: nest_engine_server_nrp_client.h:63
datapack_identifiers_set_t
std::set< DataPackIdentifier > datapack_identifiers_set_t
Definition: datapack_interface.h:221
NestEngineServerNRPClient::runLoopStepCallback
SimulationTime runLoopStepCallback(SimulationTime timeStep) override
Executes a single loop step.
Definition: nest_engine_server_nrp_client.cpp:521
NestEngineServerNRPClientLauncher
NestEngineServerNRPClient::EngineLauncher< NestServerConfigConst::EngineType > NestEngineServerNRPClientLauncher
Definition: nest_engine_server_nrp_client.h:125
NestEngineServerNRPClient::engineProcStartParams
virtual const std::vector< std::string > engineProcStartParams() const override
Get all Engine Process Startup parameters.
Definition: nest_engine_server_nrp_client.cpp:536
NestEngineServerNRPClient::~NestEngineServerNRPClient
virtual ~NestEngineServerNRPClient() override
Definition: nest_engine_server_nrp_client.cpp:321
nest_server_config.h
NestEngineServerNRPClient::initialize
virtual void initialize() override
Initialize engine.
Definition: nest_engine_server_nrp_client.cpp:324
CREATE_NRP_ENGINE_LAUNCHER
CREATE_NRP_ENGINE_LAUNCHER(NestEngineServerNRPClientLauncher)
NestEngineServerNRPClient::shutdown
virtual void shutdown() override
Shutdown engine.
Definition: nest_engine_server_nrp_client.cpp:424
NestEngineServerNRPClient::getDataPacksFromEngine
virtual datapacks_vector_t getDataPacksFromEngine(const datapack_identifiers_set_t &datapackIdentifiers) override
Gets requested datapacks from engine.
Definition: nest_engine_server_nrp_client.cpp:448
NestEngineServerNRPClient::get_connection_population_mapping_t
std::map< std::string, std::pair< std::string, std::string > > get_connection_population_mapping_t
Definition: nest_engine_server_nrp_client.h:65
SimulationTime
std::chrono::nanoseconds SimulationTime
Definition: time_utils.h:31
NestEngineServerNRPClient
NRP - Nest Communicator on the NRP side. Converts DataPackInterface classes from/to JSON objects.
Definition: nest_engine_server_nrp_client.h:36
json
nlohmann::json json
Definition: engine_json_server.cpp:31