helics 3.7.0
Loading...
Searching...
No Matches
BrokerFactory.hpp
1/*
2Copyright (c) 2017-2026,
3Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Energy
4Innovation LLC. See the top-level NOTICE for additional details. All rights reserved.
5SPDX-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
18namespace helics {
22namespace BrokerFactory {
23
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
140
142 void terminateAllBrokers();
144 void abortAllBrokers(int errorCode, std::string_view errorString);
145} // namespace BrokerFactory
146} // namespace helics
Definition BrokerFactory.hpp:24
virtual std::shared_ptr< Broker > build(std::string_view name)=0
Definition BrokerFactory.hpp:32
virtual std::shared_ptr< Broker > build(std::string_view name) override
Definition BrokerFactory.hpp:38
std::shared_ptr< BrokerBuilder > addBrokerType(std::string_view brokerTypeName, int code)
Definition BrokerFactory.hpp:51
std::shared_ptr< Broker > create(CoreType type, std::string_view configureString)
Definition BrokerFactory.cpp:167
void unregisterBroker(std::string_view name)
Definition BrokerFactory.cpp:397
void displayHelp(CoreType type)
Definition BrokerFactory.cpp:414
bool copyBrokerIdentifier(std::string_view copyFromName, std::string_view copyToName)
Definition BrokerFactory.cpp:391
void abortAllBrokers(int errorCode, std::string_view errorString)
Definition BrokerFactory.cpp:378
std::vector< std::shared_ptr< Broker > > getAllBrokers()
Definition BrokerFactory.cpp:296
std::shared_ptr< Broker > getConnectedBroker()
Definition BrokerFactory.cpp:279
std::shared_ptr< Broker > findBroker(std::string_view brokerName)
Definition BrokerFactory.cpp:262
std::shared_ptr< Broker > findJoinableBrokerOfType(CoreType type)
Definition BrokerFactory.cpp:290
void defineBrokerBuilder(std::shared_ptr< BrokerBuilder > builder, std::string_view name, int code)
Definition BrokerFactory.cpp:162
void terminateAllBrokers()
Definition BrokerFactory.cpp:366
void addAssociatedBrokerType(std::string_view name, CoreType type)
Definition BrokerFactory.cpp:405
size_t cleanUpBrokers()
Definition BrokerFactory.cpp:345
bool brokersActive()
Definition BrokerFactory.cpp:301
std::shared_ptr< Broker > getBrokerByIndex(size_t index)
Definition BrokerFactory.cpp:284
bool registerBroker(const std::shared_ptr< Broker > &broker, CoreType type)
Definition BrokerFactory.cpp:325
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition AsyncFedCallInfo.hpp:14
CoreType
Definition CoreTypes.hpp:46
@ UNRECOGNIZED
unknown