| helics 3.6.1

application_api/MessageFederate.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 "Endpoints.hpp"
10 #include "Federate.hpp"
11 #include "data_view.hpp"
12
13 #include <functional>
14 #include <memory>
15 #include <string>
16 #include <string_view>
17
18 namespace helics {
19 class MessageFederateManager;
20 class Endpoint;
22 class HELICS_CXX_EXPORT MessageFederate:
23 public virtual Federate // using virtual inheritance to allow combination federate
24 {
25 public:
31 MessageFederate(std::string_view fedName, const FederateInfo& fedInfo);
39 MessageFederate(std::string_view fedName,
40 const std::shared_ptr<Core>& core,
41 const FederateInfo& fedInfo = FederateInfo{});
42
50 MessageFederate(std::string_view fedName,
51 CoreApp& core,
52 const FederateInfo& fedInfo = FederateInfo{});
53
58 MessageFederate(std::string_view name, const std::string& configString);
63 explicit MessageFederate(const std::string& configString);
64
71 explicit MessageFederate(const char* configString);
73 MessageFederate(MessageFederate&& mFed) noexcept;
75 MessageFederate(const MessageFederate& mFed) = delete;
77 MessageFederate();
80 explicit MessageFederate(bool res);
81 // copy constructor and copy assignment are disabled
83 virtual ~MessageFederate();
85 MessageFederate& operator=(MessageFederate&& mFed) noexcept;
87 MessageFederate& operator=(const MessageFederate& mFed) = delete;
88
89 protected:
90 virtual void startupToInitializeStateTransition() override;
91 virtual void initializeToExecuteStateTransition(iteration_time result) override;
92 virtual void updateTime(Time newTime, Time oldTime) override;
93 virtual std::string localQuery(std::string_view queryStr) const override;
94
95 public:
100 Endpoint& registerEndpoint(std::string_view eptName = std::string_view(),
101 std::string_view type = std::string_view());
102
108 Endpoint& registerTargetedEndpoint(std::string_view eptName = std::string_view(),
109 std::string_view type = std::string_view());
110
116 Endpoint& registerGlobalEndpoint(std::string_view eptName,
117 std::string_view type = std::string_view());
118
124 Endpoint& registerGlobalTargetedEndpoint(std::string_view eptName,
125 std::string_view type = std::string_view());
126
133 Endpoint& registerIndexedEndpoint(std::string_view eptName,
134 int index1,
135 std::string_view type = std::string_view())
136 {
137 return registerGlobalEndpoint(std::string(eptName) + '_' + std::to_string(index1), type);
138 }
139
144 Endpoint& registerDataSink(std::string_view sinkName = std::string_view());
145
146 virtual void registerInterfaces(const std::string& configString) override;
147
153 void registerMessageInterfaces(const std::string& configString);
154
155 private:
157 void loadFederateData();
162 void registerMessageInterfacesJson(const std::string& jsonString);
163
165 void registerMessageInterfacesJsonDetail(const fileops::JsonBuffer&, bool defaultGlobal);
166
171 void registerMessageInterfacesToml(const std::string& tomlString);
172
174 Endpoint& registerEndpoint(std::string_view eptName,
175 std::string_view type,
176 bool global,
177 bool targeted);
178
179 public:
184 void subscribe(const Endpoint& ept, std::string_view key);
186 bool hasMessage() const;
187 /* check if a given endpoint has any unread messages*/
188 bool hasMessage(const Endpoint& ept) const;
189
193 uint64_t pendingMessageCount(const Endpoint& ept) const;
197 uint64_t pendingMessageCount() const;
201 std::unique_ptr<Message> getMessage(const Endpoint& ept);
206 std::unique_ptr<Message> getMessage();
207
211 Endpoint& getEndpoint(std::string_view name) const;
212
216 Endpoint& getEndpoint(int index) const;
217
221 Endpoint& getDataSink(std::string_view name) const;
222
226 void setMessageNotificationCallback(const std::function<void(Endpoint&, Time)>& callback);
231 void setMessageNotificationCallback(const Endpoint& ept,
232 const std::function<void(Endpoint&, Time)>& callback);
233
234 virtual void disconnect() override;
235
237 int getEndpointCount() const;
238
239 private:
241 std::unique_ptr<MessageFederateManager> mfManager;
242 };
243 } // namespace helics
helics::CoreApp
Definition: application_api/CoreApp.hpp:25
helics::Endpoint
Definition: Endpoints.hpp:21
helics::FederateInfo
Definition: FederateInfo.hpp:28
helics::Federate
Definition: application_api/Federate.hpp:48
helics::MessageFederate
Definition: application_api/MessageFederate.hpp:24
helics::MessageFederate::registerIndexedEndpoint
Endpoint & registerIndexedEndpoint(std::string_view eptName, int index1, std::string_view type=std::string_view())
Definition: application_api/MessageFederate.hpp:133
helics::MessageFederate::operator=
MessageFederate & operator=(const MessageFederate &mFed)=delete
helics::MessageFederate::~MessageFederate
virtual ~MessageFederate()
helics::MessageFederate::MessageFederate
MessageFederate(MessageFederate &&mFed) noexcept
helics::MessageFederate::setMessageNotificationCallback
void setMessageNotificationCallback(const Endpoint &ept, const std::function< void(Endpoint &, Time)> &callback)
helics::MessageFederate::MessageFederate
MessageFederate(const MessageFederate &mFed)=delete
helics::MessageFederate::setMessageNotificationCallback
void setMessageNotificationCallback(const std::function< void(Endpoint &, Time)> &callback)
helics::fileops::JsonBuffer
Definition: JsonProcessingFunctions.hpp:25
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