helics  3.3.0
EndpointInfo.hpp
1 /*
2 Copyright (c) 2017-2022,
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 
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:
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  int32_t required_connections{0};
59 
60  std::unique_ptr<Message> getMessage(Time maxTime);
62  int32_t availableMessages() const;
64  int32_t queueSize(Time maxTime) const;
66  int32_t queueSizeUpTo(Time maxTime) const;
68  void addMessage(std::unique_ptr<Message> message);
73  bool updateTimeUpTo(Time newTime);
78  bool updateTimeInclusive(Time newTime);
79 
84  bool updateTimeNextIteration(Time newTime);
86  Time firstMessageTime() const;
88  void clearQueue();
90  void addDestination(GlobalHandle dest, std::string_view destName, std::string_view destType);
92  void addSource(GlobalHandle source, std::string_view sourceName, std::string_view sourceType);
94  void removeTarget(GlobalHandle targetId);
96  const std::vector<std::pair<GlobalHandle, std::string_view>>& getTargets() const
97  {
98  return targets;
99  }
101  const std::string& getSourceTargets() const;
103  const std::string& getDestinationTargets() const;
104 
106  void checkInterfacesForIssues(std::vector<std::pair<int, std::string>>& issues);
107 
108  void setProperty(int32_t option, int32_t value);
109  int32_t getProperty(int32_t option) const;
110 };
111 } // namespace helics
helics::EndpointInfo::removeTarget
void removeTarget(GlobalHandle targetId)
Definition: EndpointInfo.cpp:195
helics::EndpointInfo::updateTimeUpTo
bool updateTimeUpTo(Time newTime)
Definition: EndpointInfo.cpp:22
helics::EndpointInfo::queueSize
int32_t queueSize(Time maxTime) const
Definition: EndpointInfo.cpp:135
helics::EndpointInfo::addDestination
void addDestination(GlobalHandle dest, std::string_view destName, std::string_view destType)
Definition: EndpointInfo.cpp:163
helics::EndpointInfo
Definition: EndpointInfo.hpp:32
helics::EndpointInfo::id
const GlobalHandle id
identifier for the handle
Definition: EndpointInfo.hpp:40
helics_definitions.hpp
base helics enumerations for C++ API's, a namespace wrapper for the definitions defined in helics_enu...
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27
helics::EndpointInfo::targetedEndpoint
bool targetedEndpoint
indicator that the endpoint is a targeted endpoint only
Definition: EndpointInfo.hpp:57
helics::EndpointInfo::queueSizeUpTo
int32_t queueSizeUpTo(Time maxTime) const
Definition: EndpointInfo.cpp:149
helics::EndpointInfo::addSource
void addSource(GlobalHandle source, std::string_view sourceName, std::string_view sourceType)
Definition: EndpointInfo.cpp:182
helics::EndpointInfo::getMessage
std::unique_ptr< Message > getMessage(Time maxTime)
Definition: EndpointInfo.cpp:85
helics::EndpointInfo::hasFilter
bool hasFilter
indicator that the message has a filter
Definition: EndpointInfo.hpp:55
helics::CONNECTIONS
@ CONNECTIONS
print summary+federate level connection information
Definition: logging.hpp:27
helics::EndpointInfo::EndpointInfo
EndpointInfo(GlobalHandle handle, std::string_view key_, std::string_view type_)
Definition: EndpointInfo.hpp:35
helics::EndpointInfo::required_connections
int32_t required_connections
an exact number of connections required
Definition: EndpointInfo.hpp:58
helics::EndpointInfo::key
const std::string key
name of the endpoint
Definition: EndpointInfo.hpp:41
helics::EndpointInfo::clearQueue
void clearQueue()
Definition: EndpointInfo.cpp:124
helics::EndpointInfo::checkInterfacesForIssues
void checkInterfacesForIssues(std::vector< std::pair< int, std::string >> &issues)
Definition: EndpointInfo.cpp:255
helics::EndpointInfo::type
const std::string type
type of the endpoint
Definition: EndpointInfo.hpp:42
helics::EndpointInfo::firstMessageTime
Time firstMessageTime() const
Definition: EndpointInfo.cpp:104
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::EndpointInfo::getTargets
const std::vector< std::pair< GlobalHandle, std::string_view > > & getTargets() const
Definition: EndpointInfo.hpp:96
helics::EndpointInfo::addMessage
void addMessage(std::unique_ptr< Message > message)
Definition: EndpointInfo.cpp:117
helics::EndpointInfo::updateTimeNextIteration
bool updateTimeNextIteration(Time newTime)
Definition: EndpointInfo.cpp:43
helics::EndpointInfo::getSourceTargets
const std::string & getSourceTargets() const
Definition: EndpointInfo.cpp:217
gmlc::libguarded::shared_guarded
Definition: application_api/Federate.hpp:28
helics::GlobalHandle
Definition: GlobalFederateId.hpp:144
helics::EndpointInfo::getDestinationTargets
const std::string & getDestinationTargets() const
Definition: EndpointInfo.cpp:236
helics::EndpointInformation
Definition: EndpointInfo.hpp:21
helics::EndpointInfo::availableMessages
int32_t availableMessages() const
Definition: EndpointInfo.cpp:130
helics::EndpointInfo::updateTimeInclusive
bool updateTimeInclusive(Time newTime)
Definition: EndpointInfo.cpp:64