NRP Core  1.4.1
event_loop.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 EVENT_LOOP_H
23 #define EVENT_LOOP_H
24 
26 
30 
33 
35 
36 #include <nlohmann/json.hpp>
37 
42 {
43  public:
44 
48  EventLoop(const nlohmann::json &graph_config, std::chrono::milliseconds timestep, std::chrono::milliseconds timestepThres,
49  ComputationalGraph::ExecMode execMode = ComputationalGraph::ExecMode::ALL_NODES,
50  bool ownGIL = true, bool spinROS = false);
51 
52  ~EventLoop();
53 
54  protected:
55 
56  void initializeCB() override;
57 
58  void runLoopCB() override;
59 
60  void shutdownCB() override;
61 
62  private:
63 
65  nlohmann::json _graph_config;
69  bool _ownGIL;
71  bool _spinROS;
73  PyGILState_STATE _pyGILState;
75  InputClockNode* _clock = nullptr;
77  InputIterationNode* _iteration = nullptr;
78 
79 };
80 
81 
82 #endif // EVENT_LOOP_H
EventLoop
EventLoop implementation which runs a Computational Graph.
Definition: event_loop.h:41
EventLoop::shutdownCB
void shutdownCB() override
Shutdown loop.
Definition: event_loop.cpp:98
input_node.h
InputClockNode
Specialization of InputTimeBaseNode which stores and sends system clock in milliseconds.
Definition: input_time.h:77
EventLoopInterface
Manages simulation loop. Runs physics and brain interface, and synchronizes them via Transfer Functio...
Definition: event_loop_interface.h:34
event_loop_interface.h
python_interpreter_state.h
output_node.h
computational_graph_manager.h
EventLoop::~EventLoop
~EventLoop()
Definition: event_loop.cpp:43
ComputationalGraph::ExecMode
ExecMode
Definition: computational_graph.h:62
time_utils.h
EventLoop::runLoopCB
void runLoopCB() override
Execute actions which must be performed every loop.
Definition: event_loop.cpp:68
InputIterationNode
Specialization of InputTimeBaseNode which stores and sends system iteration number.
Definition: input_time.h:109
input_time.h
EventLoop::initializeCB
void initializeCB() override
Initialize loop.
Definition: event_loop.cpp:46
EventLoop::EventLoop
EventLoop(const nlohmann::json &graph_config, std::chrono::milliseconds timestep, std::chrono::milliseconds timestepThres, ComputationalGraph::ExecMode execMode=ComputationalGraph::ExecMode::ALL_NODES, bool ownGIL=true, bool spinROS=false)
Constructor.
Definition: event_loop.cpp:32
json
nlohmann::json json
Definition: engine_json_server.cpp:31