SOLA
Loading...
Searching...
No Matches
logical_agent.h
1// Copyright 2023 The SOLA authors
2//
3// This file is part of DAISI.
4//
5// DAISI is free software: you can redistribute it and/or modify it under the terms of the GNU
6// General Public License as published by the Free Software Foundation; version 2.
7//
8// DAISI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
9// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
10// Public License for more details.
11//
12// You should have received a copy of the GNU General Public License along with DAISI. If not, see
13// <https://www.gnu.org/licenses/>.
14//
15// SPDX-License-Identifier: GPL-2.0-only
16
17#ifndef DAISI_CPPS_LOGICAL_LOGICAL_AGENT_H_
18#define DAISI_CPPS_LOGICAL_LOGICAL_AGENT_H_
19
20#include <memory>
21#include <vector>
22
23#include "cpps/common/cpps_communicator.h"
24#include "cpps/common/cpps_logger_ns3.h"
25#include "cpps/logical/algorithms/algorithm_config.h"
26#include "cpps/logical/algorithms/algorithm_interface.h"
27#include "cpps/logical/message/serializer.h"
28#include "solanet/network_udp/message.h"
29
30namespace daisi::cpps::logical {
31
33public:
34 LogicalAgent(std::shared_ptr<CppsLoggerNs3> logger, AlgorithmConfig config_algo, bool first_node);
35
36 virtual ~LogicalAgent() = default;
37
40 void processMessage(const Message &msg);
41
42 virtual void start() = 0;
43
45 bool isRunning() const;
46
48 bool canStop() const;
49
51 void prepareStop();
52
53protected:
56 void initCommunication();
57
61 virtual void initAlgorithms() = 0;
62
65 virtual void messageReceiveFunction(const solanet::Message &msg) = 0;
66
69 virtual void topicMessageReceiveFunction(const sola::TopicMessage &msg) = 0;
70
72 std::vector<std::unique_ptr<AlgorithmInterface>> algorithms_;
73
75 daisi::cpps::common::CppsCommunicatorPtr communicator_;
76
78 std::shared_ptr<CppsLoggerNs3> logger_;
79
83
85 std::string uuid_;
86
87 bool first_node_;
88};
89
90} // namespace daisi::cpps::logical
91
92#endif
Definition logical_agent.h:32
virtual void initAlgorithms()=0
Initializing algorithm interfaces depending on information from algorithm_config_....
bool canStop() const
Helper method for event scheduling.
Definition logical_agent.cpp:89
bool isRunning() const
Helper method for event scheduling.
Definition logical_agent.cpp:87
std::string uuid_
Needed for initialization of Sola.
Definition logical_agent.h:85
void prepareStop()
Helper method for event scheduling.
Definition logical_agent.cpp:91
void processMessage(const Message &msg)
Forwarding a received message to the appropriate algorithm interface for processing.
Definition logical_agent.cpp:65
virtual void topicMessageReceiveFunction(const sola::TopicMessage &msg)=0
Method being called by sola when we receive a message via a topic.
Definition logical_agent.cpp:82
std::vector< std::unique_ptr< AlgorithmInterface > > algorithms_
The algorithms which logical messages will be forwarded to for processing.
Definition logical_agent.h:72
void initCommunication()
Initializing communication via Sola which all logical agents require.
Definition logical_agent.cpp:36
daisi::cpps::common::CppsCommunicatorPtr communicator_
Collection of members to communicate.
Definition logical_agent.h:75
virtual void messageReceiveFunction(const solanet::Message &msg)=0
Method being called by solanet when we receive a 1-to-1 message.
Definition logical_agent.cpp:77
std::shared_ptr< CppsLoggerNs3 > logger_
Logging relevant information into Database.
Definition logical_agent.h:78
const AlgorithmConfig algorithm_config_
Information about which algorithm interfaces will be initialized after the initialization of Sola is ...
Definition logical_agent.h:82
Definition message.h:14
Modified Round Robin Algorithm that centrally assigns tasks of incoming material flows to the corresp...
Definition algorithm_config.h:22
Definition algorithm_config.h:31
Definition message.h:20