| helics 3.6.1

EndpointInfo.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 "basic_CoreTypes.hpp"
11
12 #include <atomic>
13 #include <deque>
14 #include <memory>
15 #include <string>
16 #include <utility>
17 #include <vector>
18
19 namespace helics {
20
21 struct EndpointInformation {
22 GlobalHandle id;
23 std::string key;
24 std::string type;
25 EndpointInformation() = default;
26 EndpointInformation(GlobalHandle gid, std::string_view key_, std::string_view type_):
27 id(gid), key(key_), type(type_)
28 {
29 }
30 };
32 class EndpointInfo {
33 public:
35 EndpointInfo(GlobalHandle handle, std::string_view key_, std::string_view type_):
36 id(handle), key(key_), type(type_)
37 {
38 }
39
40 const GlobalHandle id;
41 const std::string key;
42 const std::string type;
43 private:
45 shared_guarded<std::deque<std::unique_ptr<Message>>> message_queue;
46 std::atomic<int32_t> mAvailableMessages{0};
47
48 std::vector<EndpointInformation> sourceInformation;
49 std::vector<EndpointInformation> targetInformation;
50 std::vector<std::pair<GlobalHandle, std::string_view>> targets;
51 mutable std::string sourceTargets;
52 mutable std::string destinationTargets;
53
54 public:
55 bool hasFilter{false};
56 bool required{false};
57 bool targetedEndpoint{false};
58 bool sourceOnly{false};
59 bool receiveOnly{false};
60 int32_t requiredConnections{0};
62 std::unique_ptr<Message> getMessage(Time maxTime);
64 int32_t availableMessages() const;
66 int32_t queueSize(Time maxTime) const;
68 int32_t queueSizeUpTo(Time maxTime) const;
70 void addMessage(std::unique_ptr<Message> message);
75 bool updateTimeUpTo(Time newTime);
80 bool updateTimeInclusive(Time newTime);
81
83 bool hasConnection() const;
85 bool hasSource() const;
87 bool hasTarget() const;
92 bool updateTimeNextIteration(Time newTime);
94 Time firstMessageTime() const;
96 void clearQueue();
98 void addDestination(GlobalHandle dest, std::string_view destName, std::string_view destType);
100 void addSource(GlobalHandle source, std::string_view sourceName, std::string_view sourceType);
102 void removeTarget(GlobalHandle targetId);
104 void disconnectFederate(GlobalFederateId fedToDisconnect);
106 const std::vector<std::pair<GlobalHandle, std::string_view>>& getTargets() const
107 {
108 return targets;
109 }
111 const std::string& getSourceTargets() const;
113 const std::string& getDestinationTargets() const;
114
116 void checkInterfacesForIssues(std::vector<std::pair<int, std::string>>& issues);
117
118 void setProperty(int32_t option, int32_t value);
119 int32_t getProperty(int32_t option) const;
120 };
121 } // namespace helics
gmlc::libguarded::shared_guarded
Definition: application_api/Federate.hpp:27
helics::EndpointInfo
Definition: EndpointInfo.hpp:32
helics::EndpointInfo::requiredConnections
int32_t requiredConnections
an exact number of connections required
Definition: EndpointInfo.hpp:60
helics::EndpointInfo::receiveOnly
bool receiveOnly
the endpoint can only receive data and cannot send
Definition: EndpointInfo.hpp:59
helics::EndpointInfo::type
const std::string type
type of the endpoint
Definition: EndpointInfo.hpp:42
helics::EndpointInfo::disconnectFederate
void disconnectFederate(GlobalFederateId fedToDisconnect)
Definition: EndpointInfo.cpp:237
helics::EndpointInfo::addSource
void addSource(GlobalHandle source, std::string_view sourceName, std::string_view sourceType)
Definition: EndpointInfo.cpp:199
helics::EndpointInfo::hasSource
bool hasSource() const
Definition: EndpointInfo.cpp:142
helics::EndpointInfo::updateTimeNextIteration
bool updateTimeNextIteration(Time newTime)
Definition: EndpointInfo.cpp:44
helics::EndpointInfo::addDestination
void addDestination(GlobalHandle dest, std::string_view destName, std::string_view destType)
Definition: EndpointInfo.cpp:180
helics::EndpointInfo::sourceOnly
bool sourceOnly
the endpoint can only be a source of data and cannot receive data
Definition: EndpointInfo.hpp:58
helics::EndpointInfo::hasFilter
bool hasFilter
indicator that the message has a filter
Definition: EndpointInfo.hpp:55
helics::EndpointInfo::queueSizeUpTo
int32_t queueSizeUpTo(Time maxTime) const
Definition: EndpointInfo.cpp:166
helics::EndpointInfo::getTargets
const std::vector< std::pair< GlobalHandle, std::string_view > > & getTargets() const
Definition: EndpointInfo.hpp:106
helics::EndpointInfo::updateTimeInclusive
bool updateTimeInclusive(Time newTime)
Definition: EndpointInfo.cpp:65
helics::EndpointInfo::checkInterfacesForIssues
void checkInterfacesForIssues(std::vector< std::pair< int, std::string >> &issues)
Definition: EndpointInfo.cpp:300
helics::EndpointInfo::updateTimeUpTo
bool updateTimeUpTo(Time newTime)
Definition: EndpointInfo.cpp:23
helics::EndpointInfo::removeTarget
void removeTarget(GlobalHandle targetId)
Definition: EndpointInfo.cpp:212
helics::EndpointInfo::id
const GlobalHandle id
identifier for the handle
Definition: EndpointInfo.hpp:40
helics::EndpointInfo::targetedEndpoint
bool targetedEndpoint
indicator that the endpoint is a targeted endpoint only
Definition: EndpointInfo.hpp:57
helics::EndpointInfo::queueSize
int32_t queueSize(Time maxTime) const
Definition: EndpointInfo.cpp:152
helics::EndpointInfo::clearQueue
void clearQueue()
Definition: EndpointInfo.cpp:126
helics::EndpointInfo::getDestinationTargets
const std::string & getDestinationTargets() const
Definition: EndpointInfo.cpp:281
helics::EndpointInfo::getSourceTargets
const std::string & getSourceTargets() const
Definition: EndpointInfo.cpp:262
helics::EndpointInfo::availableMessages
int32_t availableMessages() const
Definition: EndpointInfo.cpp:132
helics::EndpointInfo::EndpointInfo
EndpointInfo(GlobalHandle handle, std::string_view key_, std::string_view type_)
Definition: EndpointInfo.hpp:35
helics::EndpointInfo::hasConnection
bool hasConnection() const
Definition: EndpointInfo.cpp:137
helics::EndpointInfo::getMessage
std::unique_ptr< Message > getMessage(Time maxTime)
Definition: EndpointInfo.cpp:86
helics::EndpointInfo::hasTarget
bool hasTarget() const
Definition: EndpointInfo.cpp:147
helics::EndpointInfo::firstMessageTime
Time firstMessageTime() const
Definition: EndpointInfo.cpp:105
helics::EndpointInfo::key
const std::string key
name of the endpoint
Definition: EndpointInfo.hpp:41
helics::EndpointInfo::addMessage
void addMessage(std::unique_ptr< Message > message)
Definition: EndpointInfo.cpp:119
helics::GlobalFederateId
Definition: GlobalFederateId.hpp:75
helics::GlobalHandle
Definition: GlobalFederateId.hpp:147
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::EndpointInformation
Definition: EndpointInfo.hpp:21