| helics 3.6.1

BrokerFactory.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 "Broker.hpp"
10 #include "CoreTypes.hpp"
11
12 #include <chrono>
13 #include <memory>
14 #include <string>
15 #include <type_traits>
16 #include <vector>
17
18 namespace helics {
22 namespace BrokerFactory {
23
24 class BrokerBuilder {
25 public:
27 virtual std::shared_ptr<Broker> build(std::string_view name) = 0;
28 };
29
31 template<class BrokerTYPE>
32 class BrokerTypeBuilder final: public BrokerBuilder {
33 public:
34 static_assert(std::is_base_of<Broker, BrokerTYPE>::value,
35 "Type does not inherit from helics::Broker");
36
37 using broker_build_type = BrokerTYPE;
38 virtual std::shared_ptr<Broker> build(std::string_view name) override
39 {
40 return std::make_shared<BrokerTYPE>(name);
41 }
42 };
43
45 void defineBrokerBuilder(std::shared_ptr<BrokerBuilder> builder,
46 std::string_view name,
47 int code);
48
50 template<class BrokerTYPE>
51 std::shared_ptr<BrokerBuilder> addBrokerType(std::string_view brokerTypeName, int code)
52 {
53 auto bld = std::make_shared<BrokerTypeBuilder<BrokerTYPE>>();
54 std::shared_ptr<BrokerBuilder> bbld = std::static_pointer_cast<BrokerBuilder>(bld);
55 defineBrokerBuilder(bbld, brokerTypeName, code);
56 return bbld;
57 }
58
64 std::shared_ptr<Broker> create(CoreType type, std::string_view configureString);
66 std::shared_ptr<Broker> create(CoreType type, int argc, char* argv[]);
68 std::shared_ptr<Broker> create(CoreType type, std::vector<std::string> args);
69
70 std::shared_ptr<Broker>
71 create(CoreType type, std::string_view brokerName, std::string_view configureString);
72
73 std::shared_ptr<Broker>
74 create(CoreType type, std::string_view brokerName, int argc, char* argv[]);
75
77 std::shared_ptr<Broker>
78 create(CoreType type, std::string_view brokerName, std::vector<std::string> args);
79
83 std::shared_ptr<Broker> findBroker(std::string_view brokerName);
86 std::shared_ptr<Broker> getConnectedBroker();
90 std::shared_ptr<Broker> getBrokerByIndex(size_t index);
91
93 std::shared_ptr<Broker> findJoinableBrokerOfType(CoreType type);
94
96 std::vector<std::shared_ptr<Broker>> getAllBrokers();
97
99 bool brokersActive();
100
107 bool registerBroker(const std::shared_ptr<Broker>& broker, CoreType type);
111 void unregisterBroker(std::string_view name);
112
114 void addAssociatedBrokerType(std::string_view name, CoreType type);
115
122 size_t cleanUpBrokers();
123
131 size_t cleanUpBrokers(std::chrono::milliseconds delay);
132
136 bool copyBrokerIdentifier(std::string_view copyFromName, std::string_view copyToName);
137
139 void displayHelp(CoreType type = CoreType::UNRECOGNIZED);
140
142 void terminateAllBrokers();
144 void abortAllBrokers(int errorCode, std::string_view errorString);
145 } // namespace BrokerFactory
146 } // namespace helics
CoreTypes.hpp
helics::BrokerFactory::BrokerBuilder
Definition: BrokerFactory.hpp:24
helics::BrokerFactory::BrokerBuilder::build
virtual std::shared_ptr< Broker > build(std::string_view name)=0
helics::BrokerFactory::BrokerTypeBuilder
Definition: BrokerFactory.hpp:32
helics::BrokerFactory::BrokerTypeBuilder::build
virtual std::shared_ptr< Broker > build(std::string_view name) override
Definition: BrokerFactory.hpp:38
helics::BrokerFactory::addBrokerType
std::shared_ptr< BrokerBuilder > addBrokerType(std::string_view brokerTypeName, int code)
Definition: BrokerFactory.hpp:51
helics::BrokerFactory::create
std::shared_ptr< Broker > create(CoreType type, std::string_view configureString)
Definition: BrokerFactory.cpp:104
helics::BrokerFactory::unregisterBroker
void unregisterBroker(std::string_view name)
Definition: BrokerFactory.cpp:337
helics::BrokerFactory::displayHelp
void displayHelp(CoreType type)
Definition: BrokerFactory.cpp:354
helics::BrokerFactory::copyBrokerIdentifier
bool copyBrokerIdentifier(std::string_view copyFromName, std::string_view copyToName)
Definition: BrokerFactory.cpp:332
helics::BrokerFactory::abortAllBrokers
void abortAllBrokers(int errorCode, std::string_view errorString)
Definition: BrokerFactory.cpp:319
helics::BrokerFactory::getAllBrokers
std::vector< std::shared_ptr< Broker > > getAllBrokers()
Definition: BrokerFactory.cpp:252
helics::BrokerFactory::getConnectedBroker
std::shared_ptr< Broker > getConnectedBroker()
Definition: BrokerFactory.cpp:235
helics::BrokerFactory::findBroker
std::shared_ptr< Broker > findBroker(std::string_view brokerName)
Definition: BrokerFactory.cpp:218
helics::BrokerFactory::findJoinableBrokerOfType
std::shared_ptr< Broker > findJoinableBrokerOfType(CoreType type)
Definition: BrokerFactory.cpp:246
helics::BrokerFactory::defineBrokerBuilder
void defineBrokerBuilder(std::shared_ptr< BrokerBuilder > builder, std::string_view name, int code)
Definition: BrokerFactory.cpp:88
helics::BrokerFactory::terminateAllBrokers
void terminateAllBrokers()
Definition: BrokerFactory.cpp:310
helics::BrokerFactory::addAssociatedBrokerType
void addAssociatedBrokerType(std::string_view name, CoreType type)
Definition: BrokerFactory.cpp:345
helics::BrokerFactory::cleanUpBrokers
size_t cleanUpBrokers()
Definition: BrokerFactory.cpp:301
helics::BrokerFactory::brokersActive
bool brokersActive()
Definition: BrokerFactory.cpp:257
helics::BrokerFactory::getBrokerByIndex
std::shared_ptr< Broker > getBrokerByIndex(size_t index)
Definition: BrokerFactory.cpp:240
helics::BrokerFactory::registerBroker
bool registerBroker(const std::shared_ptr< Broker > &broker, CoreType type)
Definition: BrokerFactory.cpp:281
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::UNRECOGNIZED
@ UNRECOGNIZED
unknown