| helics 3.6.1

InterfaceInfo.hpp
Go to the documentation of this file.
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 #include "../common/GuardedTypes.hpp"
9 #include "EndpointInfo.hpp"
10 #include "FederateIdExtra.hpp"
11 #include "InputInfo.hpp"
12 #include "PublicationInfo.hpp"
13 #include "gmlc/containers/DualMappedPointerVector.hpp"
14 #include "nlohmann/json_fwd.hpp"
15
16 #include <atomic>
17 #include <string>
18 #include <utility>
19 #include <vector>
20
24 namespace helics {
26 class InterfaceInfo {
27 public:
28 InterfaceInfo() = default;
29 const PublicationInfo* getPublication(const std::string& pubName) const;
30 const PublicationInfo* getPublication(InterfaceHandle handle) const;
31 PublicationInfo* getPublication(const std::string& pubName);
32 PublicationInfo* getPublication(InterfaceHandle handle);
33 const InputInfo* getInput(const std::string& inputName) const;
34 const InputInfo* getInput(InterfaceHandle handle) const;
35 InputInfo* getInput(const std::string& inputName);
36 InputInfo* getInput(InterfaceHandle handle);
37 const EndpointInfo* getEndpoint(const std::string& endpointName) const;
38 const EndpointInfo* getEndpoint(InterfaceHandle handle) const;
39 EndpointInfo* getEndpoint(const std::string& endpointName);
40 EndpointInfo* getEndpoint(InterfaceHandle handle);
41
42 void createPublication(InterfaceHandle handle,
43 std::string_view key,
44 std::string_view type,
45 std::string_view units,
46 std::uint16_t flags);
47 void createInput(InterfaceHandle handle,
48 std::string_view key,
49 std::string_view type,
50 std::string_view units,
51 std::uint16_t flags);
52 void createEndpoint(InterfaceHandle handle,
53 std::string_view endpointName,
54 std::string_view type,
55 std::uint16_t flags);
56
57 auto getEndpoints() { return endpoints.lock(); }
58 auto getPublications() { return publications.lock(); }
59 auto getInputs() { return inputs.lock(); }
60 auto getEndpoints() const { return endpoints.lock_shared(); }
61 auto getPublications() const { return publications.lock_shared(); }
62 auto getInputs() const { return inputs.lock_shared(); }
63 auto cgetEndpoints() const { return endpoints.lock_shared(); }
64 auto cgetPublications() const { return publications.lock_shared(); }
65 auto cgetInputs() const { return inputs.lock_shared(); }
67 void setGlobalId(GlobalFederateId newglobalId) { global_id = newglobalId; }
69 void setChangeUpdateFlag(bool updateFlag);
71 bool getChangeUpdateFlag() const { return only_update_on_change; }
73 bool setInputProperty(InterfaceHandle hid, int32_t option, int32_t value);
74 bool setPublicationProperty(InterfaceHandle hid, int32_t option, int32_t value);
75 bool setEndpointProperty(InterfaceHandle hid, int32_t option, int32_t value);
77 int32_t getInputProperty(InterfaceHandle hid, int32_t option) const;
78 int32_t getPublicationProperty(InterfaceHandle hid, int32_t option) const;
79 int32_t getEndpointProperty(InterfaceHandle hid, int32_t option) const;
80
82 std::vector<std::pair<int, std::string>> checkInterfacesForIssues();
84 void generateInferfaceConfig(nlohmann::json& base) const;
86 void generateDataFlowGraph(nlohmann::json& base) const;
88 void getUnconnectedInterfaces(nlohmann::json& base) const;
90 void reset();
92 void disconnectFederate(GlobalFederateId fedToDisconnect, Time disconnectTime);
93
94 private:
95 std::atomic<GlobalFederateId> global_id;
97 bool only_update_on_change{false};
98 shared_guarded<
99 gmlc::containers::DualMappedPointerVector<PublicationInfo, std::string, InterfaceHandle>>
100 publications;
101 shared_guarded<
102 gmlc::containers::DualMappedPointerVector<EndpointInfo, std::string, InterfaceHandle>>
103 endpoints;
104 shared_guarded<
105 gmlc::containers::DualMappedPointerVector<InputInfo, std::string, InterfaceHandle>>
106 inputs;
107 };
108 } // namespace helics
gmlc::libguarded::shared_guarded
Definition: application_api/Federate.hpp:27
helics::EndpointInfo
Definition: EndpointInfo.hpp:32
helics::GlobalFederateId
Definition: GlobalFederateId.hpp:75
helics::InputInfo
Definition: InputInfo.hpp:20
helics::InterfaceHandle
Definition: LocalFederateId.hpp:65
helics::InterfaceInfo
Definition: InterfaceInfo.hpp:26
helics::InterfaceInfo::generateInferfaceConfig
void generateInferfaceConfig(nlohmann::json &base) const
Definition: InterfaceInfo.cpp:388
helics::InterfaceInfo::checkInterfacesForIssues
std::vector< std::pair< int, std::string > > checkInterfacesForIssues()
Definition: InterfaceInfo.cpp:235
helics::InterfaceInfo::getChangeUpdateFlag
bool getChangeUpdateFlag() const
Definition: InterfaceInfo.hpp:71
helics::InterfaceInfo::generateDataFlowGraph
void generateDataFlowGraph(nlohmann::json &base) const
Definition: InterfaceInfo.cpp:445
helics::InterfaceInfo::getInputProperty
int32_t getInputProperty(InterfaceHandle hid, int32_t option) const
Definition: InterfaceInfo.cpp:208
helics::InterfaceInfo::disconnectFederate
void disconnectFederate(GlobalFederateId fedToDisconnect, Time disconnectTime)
Definition: InterfaceInfo.cpp:513
helics::InterfaceInfo::setGlobalId
void setGlobalId(GlobalFederateId newglobalId)
Definition: InterfaceInfo.hpp:67
helics::InterfaceInfo::getUnconnectedInterfaces
void getUnconnectedInterfaces(nlohmann::json &base) const
Definition: InterfaceInfo.cpp:329
helics::InterfaceInfo::reset
void reset()
Definition: InterfaceInfo.cpp:21
helics::InterfaceInfo::setInputProperty
bool setInputProperty(InterfaceHandle hid, int32_t option, int32_t value)
Definition: InterfaceInfo.cpp:177
helics::InterfaceInfo::setChangeUpdateFlag
void setChangeUpdateFlag(bool updateFlag)
Definition: InterfaceInfo.cpp:106
helics::PublicationInfo
Definition: PublicationInfo.hpp:27
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