NRP Core  1.4.1
nest_json_server.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_JSON_SERVER_H
23 #define NEST_JSON_SERVER_H
24 
28 
30 
31 
32 #include <boost/python.hpp>
33 
35  : public EngineJSONServer
36 {
37  public:
38  NestJSONServer(const std::string &serverAddress, const std::string &engineName, const std::string &registrationAddress, boost::python::dict globals);
39  virtual ~NestJSONServer() override;
40 
45  bool initRunFlag() const;
46 
47  virtual SimulationTime runLoopStep(SimulationTime timeStep) override;
48  virtual nlohmann::json initialize(const nlohmann::json &data, EngineJSONServer::lock_t &datapackLock) override;
49  virtual nlohmann::json reset(EngineJSONServer::lock_t &datapackLock) override;
50  virtual nlohmann::json shutdown(const nlohmann::json &data) override;
51 
52  private:
56  bool _initRunFlag = false;
57 
61  bool _nestPreparedFlag = false;
62 
66  boost::python::dict _pyGlobals;
67 
71  boost::python::dict _pyNest;
72 
76  boost::python::dict _pyNRPNest;
77 
81  boost::python::dict _devMap;
82 
86  std::list<std::shared_ptr<DataPackController<nlohmann::json>>> _datapackControllerPtrs;
87 
91  PyGILState_STATE _pyGILState;
92 
98  static constexpr float convertSecToMill(const float sec);
99 
105  static constexpr float convertMillToSec(const float millsec);
106 
112  static nlohmann::json formatInitErrorMessage(const std::string &errMsg);
113 
114  nlohmann::json getDataPackData(const nlohmann::json &reqData) override;
115 
116  void setDataPackData(const nlohmann::json &reqData) override;
117 
118  nlohmann::json _initData;
119 };
120 
121 #endif // NEST_JSON_SERVER_H
NestJSONServer
Definition: nest_json_server.h:34
engine_json_server.h
NestJSONServer::runLoopStep
virtual SimulationTime runLoopStep(SimulationTime timeStep) override
Run a single loop step.
Definition: nest_json_server.cpp:80
NestJSONServer::reset
virtual nlohmann::json reset(EngineJSONServer::lock_t &datapackLock) override
Engine reset routine.
Definition: nest_json_server.cpp:229
python_interpreter_state.h
NestJSONServer::initRunFlag
bool initRunFlag() const
Has the initialization been executed?
Definition: nest_json_server.cpp:75
EngineJSONServer::lock_t
std::unique_lock< EngineJSONServer::mutex_t > lock_t
Definition: engine_json_server.h:58
NestJSONServer::initialize
virtual nlohmann::json initialize(const nlohmann::json &data, EngineJSONServer::lock_t &datapackLock) override
Engine Initialization routine.
Definition: nest_json_server.cpp:104
EngineJSONServer::serverAddress
std::string serverAddress() const
Get server address.
Definition: engine_json_server.cpp:146
create_datapack_class.h
EngineJSONServer
Manages communication with the NRP. Uses a REST server to send/receive data. Singleton class.
Definition: engine_json_server.h:41
NestJSONServer::~NestJSONServer
virtual ~NestJSONServer() override
Definition: nest_json_server.cpp:47
nest_engine_datapack_controller.h
NestJSONServer::NestJSONServer
NestJSONServer(const std::string &serverAddress, const std::string &engineName, const std::string &registrationAddress, boost::python::dict globals)
Definition: nest_json_server.cpp:40
SimulationTime
std::chrono::nanoseconds SimulationTime
Definition: time_utils.h:31
NestJSONServer::shutdown
virtual nlohmann::json shutdown(const nlohmann::json &data) override
Engine Shutdown routine.
Definition: nest_json_server.cpp:255
json
nlohmann::json json
Definition: engine_json_server.cpp:31