helics  3.0.1
EndpointInfo.hpp
1 /*
2 Copyright (c) 2017-2021,
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, const std::string& key_, const std::string& type_):
27  id(gid), key(key_), type(type_)
28  {
29  }
30 };
32 class EndpointInfo {
33  public:
35  EndpointInfo(GlobalHandle handle, const std::string& key_, const std::string& 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  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 targettedEndpoint{false};
58 
59  std::unique_ptr<Message> getMessage(Time maxTime);
61  int32_t availableMessages() const;
63  int32_t queueSize(Time maxTime) const;
65  int32_t queueSizeUpTo(Time maxTime) const;
67  void addMessage(std::unique_ptr<Message> message);
72  bool updateTimeUpTo(Time newTime);
77  bool updateTimeInclusive(Time newTime);
78 
83  bool updateTimeNextIteration(Time newTime);
85  Time firstMessageTime() const;
87  void clearQueue();
90  const std::string& destName,
91  const std::string& destType);
93  void addSourceTarget(GlobalHandle dest,
94  const std::string& sourceName,
95  const std::string& sourceType);
97  void removeTarget(GlobalHandle targetId);
99  const std::vector<std::pair<GlobalHandle, std::string_view>>& getTargets() const
100  {
101  return targets;
102  }
104  const std::string& getSourceTargets() const;
106  const std::string& getDestinationTargets() const;
107 };
108 } // namespace helics
helics::EndpointInfo::removeTarget
void removeTarget(GlobalHandle targetId)
Definition: EndpointInfo.cpp:192
helics::EndpointInfo::updateTimeUpTo
bool updateTimeUpTo(Time newTime)
Definition: EndpointInfo.cpp:19
helics::EndpointInfo::queueSize
int32_t queueSize(Time maxTime) const
Definition: EndpointInfo.cpp:132
helics::EndpointInfo
Definition: EndpointInfo.hpp:32
helics::EndpointInfo::id
const GlobalHandle id
identifier for the handle
Definition: EndpointInfo.hpp:40
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27
helics::EndpointInfo::EndpointInfo
EndpointInfo(GlobalHandle handle, const std::string &key_, const std::string &type_)
Definition: EndpointInfo.hpp:35
helics::EndpointInfo::queueSizeUpTo
int32_t queueSizeUpTo(Time maxTime) const
Definition: EndpointInfo.cpp:146
helics::EndpointInfo::getMessage
std::unique_ptr< Message > getMessage(Time maxTime)
Definition: EndpointInfo.cpp:82
helics::EndpointInfo::hasFilter
bool hasFilter
indicator that the message has a filter
Definition: EndpointInfo.hpp:55
helics::EndpointInfo::targettedEndpoint
bool targettedEndpoint
indicator that the endpoint is a targeted endpoint only
Definition: EndpointInfo.hpp:57
helics::EndpointInfo::key
const std::string key
name of the endpoint
Definition: EndpointInfo.hpp:41
helics::EndpointInfo::clearQueue
void clearQueue()
Definition: EndpointInfo.cpp:121
helics::EndpointInfo::type
const std::string type
type of the endpoint
Definition: EndpointInfo.hpp:42
helics::EndpointInfo::firstMessageTime
Time firstMessageTime() const
Definition: EndpointInfo.cpp:101
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:99
helics::EndpointInfo::addMessage
void addMessage(std::unique_ptr< Message > message)
Definition: EndpointInfo.cpp:114
helics::EndpointInfo::updateTimeNextIteration
bool updateTimeNextIteration(Time newTime)
Definition: EndpointInfo.cpp:40
helics::EndpointInfo::getSourceTargets
const std::string & getSourceTargets() const
Definition: EndpointInfo.cpp:214
helics::EndpointInfo::addDestinationTarget
void addDestinationTarget(GlobalHandle dest, const std::string &destName, const std::string &destType)
Definition: EndpointInfo.cpp:160
gmlc::libguarded::shared_guarded
Definition: application_api/Federate.hpp:28
helics::GlobalHandle
Definition: GlobalFederateId.hpp:128
helics::EndpointInfo::addSourceTarget
void addSourceTarget(GlobalHandle dest, const std::string &sourceName, const std::string &sourceType)
Definition: EndpointInfo.cpp:179
helics::EndpointInfo::getDestinationTargets
const std::string & getDestinationTargets() const
Definition: EndpointInfo.cpp:233
helics::EndpointInformation
Definition: EndpointInfo.hpp:21
helics::EndpointInfo::availableMessages
int32_t availableMessages() const
Definition: EndpointInfo.cpp:127
helics::EndpointInfo::updateTimeInclusive
bool updateTimeInclusive(Time newTime)
Definition: EndpointInfo.cpp:61