| helics 3.6.1

MessageFederateManager.hpp
1 /*
2 Copyright (c) 2017-2025,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7 #pragma once
8
9 #include "../common/GuardedTypes.hpp"
10 #include "../core/Core.hpp"
11 #include "../core/FederateIdExtra.hpp"
12 #include "Endpoints.hpp"
13 #include "data_view.hpp"
14 #include "gmlc/containers/DualStringMappedVector.hpp"
15 #include "gmlc/containers/SimpleQueue.hpp"
16
17 #include <cstdint>
18 #include <deque>
19 #include <functional>
20 #include <map>
21 #include <memory>
22 #include <string>
23 #include <unordered_map>
24 #include <unordered_set>
25 #include <utility>
26 #include <vector>
27 namespace helics {
28 class Core;
29 class MessageFederate;
34 class MessageFederateManager {
35 public:
38 MessageFederateManager(Core* coreOb,
39 MessageFederate* mFed,
40 LocalFederateId id,
41 bool singleThreaded);
42 ~MessageFederateManager();
47 Endpoint& registerEndpoint(std::string_view name, std::string_view type);
48
53 Endpoint& registerTargetedEndpoint(std::string_view name, std::string_view type);
54
58 Endpoint& registerDataSink(std::string_view name);
59
61 bool hasMessage() const;
62 /* check if a given endpoint has any unread messages*/
63 static bool hasMessage(const Endpoint& ept);
64
68 static uint64_t pendingMessageCount(const Endpoint& ept);
72 uint64_t pendingMessageCount() const;
76 static std::unique_ptr<Message> getMessage(const Endpoint& ept);
77 /* receive a communication message for any endpoint in the federate*/
78 std::unique_ptr<Message> getMessage();
79
84 void updateTime(Time newTime, Time oldTime);
86 void startupToInitializeStateTransition();
88 void initializeToExecuteStateTransition(iteration_time result);
90 std::string localQuery(std::string_view queryStr) const;
91
95 Endpoint& getEndpoint(std::string_view name);
96 const Endpoint& getEndpoint(std::string_view name) const;
97
98 Endpoint& getEndpoint(int index);
99 const Endpoint& getEndpoint(int index) const;
100
105 Endpoint& getDataSink(std::string_view name);
106 const Endpoint& getDataSink(std::string_view name) const;
107
112 void setEndpointNotificationCallback(const std::function<void(Endpoint&, Time)>& callback);
117 static void
118 setEndpointNotificationCallback(const Endpoint& ept,
119 const std::function<void(Endpoint&, Time)>& callback);
120
122 void disconnect();
124 int getEndpointCount() const;
125
126 private:
127 class EndpointData {
128 public:
129 gmlc::containers::SimpleQueue<std::unique_ptr<Message>> messages;
130 std::function<void(Endpoint&, Time)> callback;
131 };
133 shared_guarded_opt<gmlc::containers::DualStringMappedVector<Endpoint, InterfaceHandle>>
134 mLocalEndpoints;
135 atomic_guarded<std::function<void(Endpoint&, Time)>> allCallback;
136 Time CurrentTime = Time::minVal();
137 Core* coreObject;
138 MessageFederate* mFed;
139 const LocalFederateId fedID;
141 shared_guarded_opt<std::deque<EndpointData>> eptData;
143 guarded_opt<std::vector<unsigned int>> messageOrder;
144
145 private:
146 void removeOrderedMessage(unsigned int index);
147 };
148 } // namespace helics
helics::Core
Definition: core/Core.hpp:41
helics::Endpoint
Definition: Endpoints.hpp:21
helics::LocalFederateId
Definition: LocalFederateId.hpp:22
helics::MessageFederateManager
Definition: MessageFederateManager.hpp:34
helics::MessageFederateManager::getEndpointCount
int getEndpointCount() const
Definition: MessageFederateManager.cpp:300
helics::MessageFederateManager::getMessage
static std::unique_ptr< Message > getMessage(const Endpoint &ept)
Definition: MessageFederateManager.cpp:157
helics::MessageFederateManager::registerTargetedEndpoint
Endpoint & registerTargetedEndpoint(std::string_view name, std::string_view type)
Definition: MessageFederateManager.cpp:83
helics::MessageFederateManager::getDataSink
Endpoint & getDataSink(std::string_view name)
Definition: MessageFederateManager.cpp:258
helics::MessageFederateManager::registerDataSink
Endpoint & registerDataSink(std::string_view name)
Definition: MessageFederateManager.cpp:60
helics::MessageFederateManager::startupToInitializeStateTransition
void startupToInitializeStateTransition()
Definition: MessageFederateManager.cpp:223
helics::MessageFederateManager::updateTime
void updateTime(Time newTime, Time oldTime)
Definition: MessageFederateManager.cpp:184
helics::MessageFederateManager::getEndpoint
Endpoint & getEndpoint(std::string_view name)
Definition: MessageFederateManager.cpp:245
helics::MessageFederateManager::setEndpointNotificationCallback
void setEndpointNotificationCallback(const std::function< void(Endpoint &, Time)> &callback)
Definition: MessageFederateManager.cpp:305
helics::MessageFederateManager::initializeToExecuteStateTransition
void initializeToExecuteStateTransition(iteration_time result)
Definition: MessageFederateManager.cpp:225
helics::MessageFederateManager::disconnect
void disconnect()
Definition: MessageFederateManager.cpp:32
helics::MessageFederateManager::MessageFederateManager
MessageFederateManager(Core *coreOb, MessageFederate *mFed, LocalFederateId id, bool singleThreaded)
Definition: MessageFederateManager.cpp:20
helics::MessageFederateManager::registerEndpoint
Endpoint & registerEndpoint(std::string_view name, std::string_view type)
Definition: MessageFederateManager.cpp:38
helics::MessageFederateManager::hasMessage
bool hasMessage() const
Definition: MessageFederateManager.cpp:105
helics::MessageFederateManager::localQuery
std::string localQuery(std::string_view queryStr) const
Definition: MessageFederateManager.cpp:230
helics::MessageFederateManager::pendingMessageCount
uint64_t pendingMessageCount() const
Definition: MessageFederateManager.cpp:142
helics::MessageFederate
Definition: application_api/MessageFederate.hpp:24
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27
helics::iteration_time
Definition: helicsTime.hpp:43