NRP Core  1.4.1
event_loop_engine.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_ENGINE_H
23 #define EVENT_LOOP_ENGINE_H
24 
28 #include "nrp_protobuf/engine_grpc.pb.h"
29 
30 #include <nlohmann/json.hpp>
31 
36 {
37  using mutex_t = std::timed_mutex;
38  using lock_t = std::unique_lock<EventLoopEngine::mutex_t>;
39 
40  public:
41 
45  EventLoopEngine(std::chrono::milliseconds timestep, std::chrono::milliseconds timestepThres,
46  size_t storeCapacity, bool doProcessLast,
47  const nlohmann::json &engineConfig, EngineProtoWrapper* engineWrapper);
48 
50 
51  protected:
52 
53  void initializeCB() override;
54 
55  void runLoopCB() override;
56 
57  void shutdownCB() override;
58 
59  private:
60 
66  void topic_callback(const std::string& dpName, const std::string& msgStr);
67 
68  std::map<std::string, std::vector<EngineGrpc::DataPackMessage>> _datapackStore;
69  std::shared_ptr<EngineGrpc::DataPackMessage> _datapackPub;
70  size_t _storeCapacity;
71  bool _doProcessLast;
72  std::vector<std::string> _datapackNames;
73  NRPMQTTProxy* _mqttProxy;
74 
78  std::unique_ptr<EngineProtoWrapper> _engineWrapper;
79 
84  std::string datapackTopicSet(const std::string& dpName);
85 
90  std::string datapackTopicGet(const std::string& dpName);
91 
93  nlohmann::json _engineConfig;
95  mutex_t _datapackLock;
96 
97 };
98 
99 
100 #endif // EVENT_LOOP_ENGINE_H
engine_proto_wrapper.h
EventLoopEngine::~EventLoopEngine
~EventLoopEngine()
Definition: event_loop_engine.cpp:37
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
EventLoopEngine::shutdownCB
void shutdownCB() override
Shutdown loop.
Definition: event_loop_engine.cpp:88
nrp_mqtt_proxy.h
NRPMQTTProxy
Definition: nrp_mqtt_proxy.h:27
EventLoopEngine::EventLoopEngine
EventLoopEngine(std::chrono::milliseconds timestep, std::chrono::milliseconds timestepThres, size_t storeCapacity, bool doProcessLast, const nlohmann::json &engineConfig, EngineProtoWrapper *engineWrapper)
Constructor.
Definition: event_loop_engine.cpp:26
EngineProtoWrapper
Abstract class defining an interface to interact with an Engine with data exchange via protobuf messa...
Definition: engine_proto_wrapper.h:48
EventLoopEngine::runLoopCB
void runLoopCB() override
Execute actions which must be performed every loop.
Definition: event_loop_engine.cpp:60
EventLoopEngine::initializeCB
void initializeCB() override
Initialize loop.
Definition: event_loop_engine.cpp:40
EventLoopEngine
EventLoop implementation which runs an EngineProtoWrapper.
Definition: event_loop_engine.h:35
json
nlohmann::json json
Definition: engine_json_server.cpp:31