| helics 3.6.1

Endpoints.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 "Federate.hpp"
10 #include "data_view.hpp"
11
12 #include <memory>
13 #include <string>
14 #include <type_traits>
15 #include <utility>
16
17 namespace helics {
18 class MessageFederate;
19
21 class HELICS_CXX_EXPORT Endpoint: public Interface {
22 private:
23 MessageFederate* fed{nullptr};
24 int referenceIndex{-1};
25 void* dataReference{nullptr};
26 bool disableAssign{false};
27 bool receiveOnly{false};
28 std::string defDest;
29 public:
31 Endpoint() = default;
32
33 // constructor used by messageFederateManager
34 Endpoint(MessageFederate* mFed, std::string_view name, InterfaceHandle hid);
35
36 Endpoint(MessageFederate* mFed,
37 std::string_view name,
38 std::string_view type = std::string_view{});
39
40 template<class FedPtr>
41 Endpoint(FedPtr& mFed, std::string_view name, std::string_view type = std::string_view{}):
42 Endpoint(std::addressof(*mFed), name, type)
43 {
44 static_assert(
45 std::is_base_of<MessageFederate, std::remove_reference_t<decltype(*mFed)>>::value,
46 "first argument must be a pointer to a MessageFederate");
47 }
54 Endpoint(InterfaceVisibility locality,
55 MessageFederate* mFed,
56 std::string_view name,
57 std::string_view type = std::string_view{});
64 template<class FedPtr>
65 Endpoint(InterfaceVisibility locality,
66 FedPtr& mFed,
67 std::string_view name,
68 std::string_view type = std::string_view{}):
69 Endpoint(locality, std::addressof(*mFed), name, type)
70 {
71 static_assert(
72 std::is_base_of<MessageFederate, std::remove_reference_t<decltype(*mFed)>>::value,
73 "second argument must be a pointer to a MessageFederate");
74 }
75 const std::string& getType() const { return getExtractionType(); }
80 void send(const char* data, size_t data_size) const;
81
83 void subscribe(std::string_view key);
84
90 void sendTo(const char* data, size_t data_size, std::string_view dest) const;
96 void sendAt(const char* data, size_t data_size, Time sendTime) const;
97
104 void sendTo(const data_view& data, std::string_view dest) const
105 {
106 sendTo(data.data(), data.size(), dest);
107 }
115 void sendToAt(const data_view& data, std::string_view dest, Time sendTime) const
116 {
117 sendToAt(data.data(), data.size(), dest, sendTime);
118 }
125 void sendToAt(const char* data, size_t data_size, std::string_view dest, Time sendTime) const;
126
131 void send(const void* data, size_t data_size) const;
132
138 void send(const data_view& data) const { send(data.data(), data.size()); }
145 void sendAt(const data_view& data, Time sendTime) const
146 {
147 sendAt(data.data(), data.size(), sendTime);
148 }
150 void send(std::unique_ptr<Message> mess) const;
151
156 void send(const Message& mess) const { send(std::make_unique<Message>(mess)); }
157
159 std::unique_ptr<Message> getMessage() const;
161 bool hasMessage() const;
163 std::uint64_t pendingMessageCount() const;
170 void setCallback(const std::function<void(const Endpoint&, Time)>& callback);
171
173 void addSourceFilter(std::string_view filterName);
175 void addDestinationFilter(std::string_view filterName);
177 void setDefaultDestination(std::string_view target);
178 void addSourceEndpoint(std::string_view endpointName);
179 void addDestinationEndpoint(std::string_view endpointName);
180
182 const std::string& getDefaultDestination() const;
183 virtual const std::string& getDisplayName() const override { return getName(); }
184
185 private:
186 friend class MessageFederateManager;
187 };
188 } // namespace helics
helics::Endpoint
Definition: Endpoints.hpp:21
helics::Endpoint::send
void send(const data_view &data) const
Definition: Endpoints.hpp:138
helics::Endpoint::sendTo
void sendTo(const data_view &data, std::string_view dest) const
Definition: Endpoints.hpp:104
helics::Endpoint::Endpoint
Endpoint()=default
helics::Endpoint::getDisplayName
virtual const std::string & getDisplayName() const override
Definition: Endpoints.hpp:183
helics::Endpoint::sendAt
void sendAt(const data_view &data, Time sendTime) const
Definition: Endpoints.hpp:145
helics::Endpoint::Endpoint
Endpoint(InterfaceVisibility locality, FedPtr &mFed, std::string_view name, std::string_view type=std::string_view{})
Definition: Endpoints.hpp:65
helics::Endpoint::sendToAt
void sendToAt(const data_view &data, std::string_view dest, Time sendTime) const
Definition: Endpoints.hpp:115
helics::Endpoint::send
void send(const Message &mess) const
Definition: Endpoints.hpp:156
helics::InterfaceHandle
Definition: LocalFederateId.hpp:65
helics::Interface
Definition: application_api/Federate.hpp:880
helics::MessageFederateManager
Definition: MessageFederateManager.hpp:34
helics::MessageFederate
Definition: application_api/MessageFederate.hpp:24
helics::Message
Definition: core-data.hpp:29
helics::data_view
Definition: data_view.hpp:22
helics::data_view::size
size_t size() const noexcept
Definition: data_view.hpp:114
helics::data_view::data
const char * data() const noexcept
Definition: data_view.hpp:107
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::InterfaceVisibility
InterfaceVisibility
Definition: helicsTypes.hpp:40
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27