| helics 3.6.1

MultiBroker.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
8 #pragma once
9 #include "../core/CoreBroker.hpp"
10 #include "../network/NetworkBroker.hpp"
11
12 #include <memory>
13 #include <string>
14 #include <utility>
15 #include <vector>
16
17 namespace helics {
18 class ActionMessage;
19 class CommsInterface;
20
21 // small function to call to force symbol linkages
22 bool allowMultiBroker();
23
26 class MultiBroker: public CoreBroker {
27 protected:
28 std::atomic<int> disconnectionStage{0};
29 std::vector<std::unique_ptr<CommsInterface>> comms;
31 std::unique_ptr<CommsInterface> masterComm;
33 NetworkBrokerData netInfo{gmlc::networking::InterfaceTypes::TCP};
34 std::string configFile;
35 std::atomic<bool> brokerInitialized{false};
36 CoreType type{CoreType::MULTI};
37 std::vector<std::pair<route_id, int>> routingTable; // index of the routes
38 public:
40 MultiBroker() noexcept;
41
45 explicit MultiBroker(std::string_view brokerName);
46
48 ~MultiBroker();
49
50 private:
51 virtual bool brokerConnect() override;
52 virtual void brokerDisconnect() override;
53 virtual bool tryReconnect() override;
55 virtual std::shared_ptr<helicsCLI11App> generateCLI() override;
56
57 protected:
59 virtual std::string generateLocalAddressString() const override;
60
61 public:
62 virtual void transmit(route_id rid, const ActionMessage& cmd) override;
63 virtual void transmit(route_id rid, ActionMessage&& cmd) override;
64
65 virtual void addRoute(route_id rid, int interfaceId, std::string_view routeInfo) override;
66
67 virtual void removeRoute(route_id rid) override;
68 };
69 } // namespace helics
helics::ActionMessage
Definition: ActionMessage.hpp:30
helics::CoreBroker
Definition: CoreBroker.hpp:98
helics::MultiBroker
Definition: MultiBroker.hpp:26
helics::MultiBroker::comms
std::vector< std::unique_ptr< CommsInterface > > comms
Definition: MultiBroker.hpp:29
helics::MultiBroker::disconnectionStage
std::atomic< int > disconnectionStage
the stage of disconnection
Definition: MultiBroker.hpp:28
helics::MultiBroker::masterComm
std::unique_ptr< CommsInterface > masterComm
the primary comms object or the one that links with the master
Definition: MultiBroker.hpp:31
helics::MultiBroker::configFile
std::string configFile
the name of the config file in use
Definition: MultiBroker.hpp:34
helics::MultiBroker::netInfo
NetworkBrokerData netInfo
structure containing the networking information
Definition: MultiBroker.hpp:33
helics::MultiBroker::removeRoute
virtual void removeRoute(route_id rid) override
Definition: MultiBroker.cpp:296
helics::MultiBroker::transmit
virtual void transmit(route_id rid, const ActionMessage &cmd) override
Definition: MultiBroker.cpp:239
helics::MultiBroker::brokerInitialized
std::atomic< bool > brokerInitialized
atomic protecting local initialization
Definition: MultiBroker.hpp:35
helics::MultiBroker::generateLocalAddressString
virtual std::string generateLocalAddressString() const override
Definition: MultiBroker.cpp:221
helics::MultiBroker::addRoute
virtual void addRoute(route_id rid, int interfaceId, std::string_view routeInfo) override
Definition: MultiBroker.cpp:281
helics::MultiBroker::MultiBroker
MultiBroker() noexcept
Definition: MultiBroker.cpp:72
helics::MultiBroker::type
CoreType type
the core type of the master controller
Definition: MultiBroker.hpp:36
helics::NetworkBrokerData
Definition: NetworkBrokerData.hpp:23
helics::helicsCLI11App
Definition: helicsCLI11.hpp:50
helics::route_id
Definition: GlobalFederateId.hpp:187
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::CoreType
CoreType
Definition: CoreTypes.hpp:46
helics::CoreType::MULTI
@ MULTI
use the multi-broker