 |
helics
3.0.1
|
Go to the documentation of this file.
14 #include "ActionMessage.hpp"
15 #include "FederateIdExtra.hpp"
16 #include "gmlc/containers/BlockingPriorityQueue.hpp"
29 class ForwardingTimeCoordinator;
36 static constexpr
double mInvalidSimulationTime{-98763.2};
50 int32_t maxFederateCount{(std::numeric_limits<int32_t>::max)()};
51 int32_t maxBrokerCount{(std::numeric_limits<int32_t>::max)()};
69 std::shared_ptr<spdlog::logger>
71 std::shared_ptr<spdlog::logger>
88 std::atomic<bool> mainLoopIsRunning{
91 std::atomic<bool> forceLoggingFlush{
false};
94 bool disable_timer{
false};
96 std::atomic<std::size_t> messageCounter{0};
102 gmlc::containers::BlockingPriorityQueue<ActionMessage>
actionQueue;
120 enum class TickForwardingReasons : uint32_t {
123 PING_RESPONSE = 0x02,
138 decltype(std::chrono::steady_clock::now())
144 std::shared_ptr<ProfilerBuffer> prBuff;
147 bool forwardTick{
false};
149 uint32_t forwardingReasons{0U};
154 explicit BrokerBase(
bool DisableQueue =
false) noexcept;
155 explicit BrokerBase(const std::
string& broker_name,
bool DisableQueue = false);
157 virtual ~BrokerBase();
165 int parseArgs(std::vector<std::
string> args);
169 int parseArgs(const std::
string& initializationString);
185 std::function<
void(
int level, std::string_view
identifier, std::string_view message)>
190 bool isRunning()
const {
return mainLoopIsRunning.load(); }
197 void setLogLevels(int32_t consoleLevel, int32_t fileLevel);
203 void queueProcessingLoop();
209 std::shared_ptr<helicsCLI11App> generateBaseCLI();
211 void generateLoggers();
219 return ((
static_cast<std::uint32_t
>(reason) & code) != 0);
223 BrokerState getBrokerState()
const {
return brokerState.load(); }
246 std::string_view name,
247 std::string_view message)
const;
257 virtual std::shared_ptr<helicsCLI11App>
generateCLI();
269 std::function<void(
int,
const std::string&,
const std::string&)>
getLoggingCallback()
const;
275 return messageCounter.load(std::memory_order_acquire);
constexpr Time timeZero
Definition: helicsTime.hpp:31
@ SUMMARY
print/log summary information
Definition: loggingHelper.hpp:25
void joinAllThreads()
Definition: BrokerBase.cpp:91
@ TIMING
print interfaces+ timing(exec/grant/disconnect)
Definition: loggingHelper.hpp:30
void setLoggerFunction(std::function< void(int level, std::string_view identifier, std::string_view message)> logFunction)
Definition: BrokerBase.cpp:541
bool isRunning() const
Definition: BrokerBase.hpp:190
constexpr BaseType baseValue() const
Definition: GlobalFederateId.hpp:80
int32_t minBrokerCount
Definition: BrokerBase.hpp:49
GlobalBrokerId higher_broker_id
the id code of the broker 1 level about this broker
Definition: BrokerBase.hpp:41
bool useJsonSerialization
Definition: BrokerBase.hpp:136
std::string brokerKey
Definition: BrokerBase.hpp:63
Time timeout
timeout to wait to establish a broker connection before giving up
Definition: BrokerBase.hpp:56
virtual bool sendToLogger(GlobalFederateId federateID, int logLevel, std::string_view name, std::string_view message) const
Definition: BrokerBase.cpp:396
static std::shared_ptr< AsioContextManager > getContextPointer(const std::string &contextName=std::string())
Definition: AsioContextManager.cpp:38
bool noAutomaticID
the broker should not automatically generate an ID
Definition: BrokerBase.hpp:126
bool enable_profiling
indicator that profiling is enabled
Definition: BrokerBase.hpp:137
action_t
Definition: ActionMessageDefintions.hpp:20
@ HELICS_LOG_LEVEL_NO_PRINT
Definition: helics_enums.h:179
@ HELICS_LOG_LEVEL_CONNECTIONS
Definition: helics_enums.h:190
virtual bool tryReconnect()=0
Definition: BrokerBase.cpp:664
GlobalBrokerId getGlobalId() const
Definition: BrokerBase.hpp:199
bool hasTimeDependency
set to true if the broker has Time dependencies
Definition: BrokerBase.hpp:127
bool getFlagValue(int32_t flag) const
Definition: BrokerBase.cpp:529
@ HELICS_LOG_LEVEL_WARNING
Definition: helics_enums.h:185
std::thread queueProcessingThread
thread for running the broker
Definition: BrokerBase.hpp:73
@ FED
special logging command for message coming from a fed
Definition: loggingHelper.hpp:34
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27
bool hasFilters
flag indicating filters come through the broker
Definition: BrokerBase.hpp:131
std::atomic< GlobalBrokerId > global_id
Definition: BrokerBase.hpp:38
Definition: GlobalFederateId.hpp:68
Definition: ActionMessage.hpp:30
const std::string & brokerStateName(BrokerBase::BrokerState state)
Definition: BrokerBase.cpp:946
int32_t maxIterationCount
the maximum number of iterative loops that are allowed
Definition: BrokerBase.hpp:54
bool uuid_like
will be set to true if the name looks like a uuid
Definition: BrokerBase.hpp:134
constexpr GlobalBrokerId parent_broker_id
Definition: GlobalFederateId.hpp:60
int32_t fileLogLevel
the logging level for logging to a file
Definition: BrokerBase.hpp:45
virtual double getSimulationTime() const
Definition: BrokerBase.hpp:265
const friend std::string & brokerStateName(BrokerState state)
Definition: BrokerBase.cpp:946
int parseArgs(int argc, char *argv[])
Definition: BrokerBase.cpp:312
std::atomic< bool > haltOperations
flag indicating that no further message should be processed
Definition: BrokerBase.hpp:77
std::atomic< int32_t > maxLogLevel
Definition: BrokerBase.hpp:43
virtual void configureBase()
Definition: BrokerBase.cpp:339
@ ERROR_LEVEL
only print errors
Definition: loggingHelper.hpp:22
std::unique_ptr< ForwardingTimeCoordinator > timeCoord
object managing the time control
Definition: BrokerBase.hpp:101
bool checkActionFlag(uint16_t flags, FlagIndex flag)
Definition: flagOperations.hpp:85
int32_t minChildCount
Definition: BrokerBase.hpp:53
bool no_ping
indicator that the broker is not very responsive to ping requests
Definition: BrokerBase.hpp:133
virtual std::shared_ptr< helicsCLI11App > generateCLI()
Definition: BrokerBase.cpp:99
@ HELICS_LOG_LEVEL_DEBUG
Definition: helics_enums.h:198
std::string lastErrorString
storage for last error string
Definition: BrokerBase.hpp:141
void setLogLevel(int32_t level)
Definition: BrokerBase.cpp:547
void addActionMessage(const ActionMessage &m)
Definition: BrokerBase.cpp:572
Time errorDelay
time to delay before terminating after error state
Definition: BrokerBase.hpp:60
std::function< void(int, const std::string &, const std::string &)> getLoggingCallback() const
Definition: BrokerBase.cpp:84
virtual std::string generateLocalAddressString() const =0
BrokerState
Definition: BrokerBase.hpp:107
virtual void processCommand(ActionMessage &&cmd)=0
std::size_t currentMessageCounter() const
Definition: BrokerBase.hpp:273
@ indicator_flag
flag used for setting values
Definition: flagOperations.hpp:21
std::shared_ptr< spdlog::logger > fileLogger
default logging object to use if the logging callback is not specified
Definition: BrokerBase.hpp:72
bool enteredExecutionMode
flag indicating that the broker has entered execution mode
Definition: BrokerBase.hpp:128
Definition: GlobalFederateId.hpp:26
void setActionFlag(FlagContainer &M, FlagIndex flag)
Definition: flagOperations.hpp:77
bool terminate_on_error
flag indicating that the federation should halt on any error
Definition: BrokerBase.hpp:81
std::atomic< int > lastErrorCode
storage for last error code
Definition: BrokerBase.hpp:140
Time networkTimeout
timeout to establish a socket connection before giving up
Definition: BrokerBase.hpp:57
@ HELICS_FLAG_FORCE_LOGGING_FLUSH
Definition: helics_enums.h:166
std::string prettyPrintString(const ActionMessage &command)
Definition: ActionMessage.cpp:841
@ HELICS_LOG_LEVEL_DATA
Definition: helics_enums.h:196
bool isDisconnectCommand(const ActionMessage &command) noexcept
Definition: ActionMessage.hpp:276
void generateNewIdentifier()
Definition: BrokerBase.cpp:470
@ PROFILING
profiling log level
Definition: loggingHelper.hpp:23
virtual void processPriorityCommand(ActionMessage &&command)=0
void writeProfilingData()
Definition: BrokerBase.cpp:485
@ configured
the broker itself has been configured and is ready to connect
std::function< void(int, std::string_view, std::string_view)> loggerFunction
Definition: BrokerBase.hpp:75
@ error_flag
flag indicating an error condition associated with the command
Definition: flagOperations.hpp:20
void saveProfilingData(std::string_view message)
Definition: BrokerBase.cpp:476
void setLoggingFile(const std::string &lfile)
Definition: BrokerBase.cpp:514
@ configuring
the broker is in the processing of configuring
void setLogLevels(int32_t consoleLevel, int32_t fileLevel)
Definition: BrokerBase.cpp:565
Time tickTimer
the length of each heartbeat tick
Definition: BrokerBase.hpp:55
virtual void processDisconnect(bool skipUnregister=false)=0
@ terminated
the termination process has started
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
bool debugging
flag indicating operation in a user debugging mode
Definition: BrokerBase.hpp:83
@ connecting
the connection process has started
@ HELICS_LOG_LEVEL_SUMMARY
Definition: helics_enums.h:187
Time queryTimeout
Definition: BrokerBase.hpp:58
int32_t consoleLogLevel
the logging level for console display
Definition: BrokerBase.hpp:44
@ terminating
the termination process has started
@ HELICS_LOG_LEVEL_ERROR
Definition: helics_enums.h:181
@ connected
the connection process has completed
void setTickForwarding(TickForwardingReasons reason, bool value=true)
Definition: BrokerBase.cpp:866
bool restrictive_time_policy
flag indicating the broker should use a conservative time policy
Definition: BrokerBase.hpp:79
bool waitingForBrokerPingReply
flag indicating we are waiting for a ping reply
Definition: BrokerBase.hpp:130
Definition: TimeoutMonitor.h:27
Time grantTimeout
timeout for triggering diagnostic action waiting for a time grant
Definition: BrokerBase.hpp:61
void logFlush()
Definition: BrokerBase.cpp:552
static bool isReasonForTick(std::uint32_t code, TickForwardingReasons reason)
Definition: BrokerBase.hpp:217
std::shared_ptr< spdlog::logger > consoleLogger
default logging object to use if the logging callback is not specified
Definition: BrokerBase.hpp:70
bool observer
flag indicating that the broker is an observer only
Definition: BrokerBase.hpp:85
@ TRACE
trace level printing (all processed messages)
Definition: loggingHelper.hpp:33
@ operating
normal operating conditions
@ WARNING
print/log warning and errors
Definition: loggingHelper.hpp:24
gmlc::containers::BlockingPriorityQueue< ActionMessage > actionQueue
primary routing queue
Definition: BrokerBase.hpp:102
@ HELICS_LOG_LEVEL_TRACE
Definition: helics_enums.h:200
int32_t minFederateCount
Definition: BrokerBase.hpp:47
@ initializing
the enter initialization process has started
std::string identifier
an identifier for the broker
Definition: BrokerBase.hpp:62
@ HELICS_LOG_LEVEL_TIMING
Definition: helics_enums.h:194
@ HELICS_LOG_LEVEL_INTERFACES
Definition: helics_enums.h:192
HelicsConfigJSON * addJsonConfig(CLI::App *app)
Add the HELICS JSON configuration processor to the app.
Definition: helicsCLI11JsonConfig.cpp:96
Definition: BrokerBase.hpp:34
void setErrorState(int eCode, std::string_view estring)
Definition: BrokerBase.cpp:496
bool isPriorityCommand(const ActionMessage &command) noexcept
Definition: ActionMessage.hpp:232
std::string logFile
the file to log message to
Definition: BrokerBase.hpp:100
@ errored
an error was encountered
@ created
the broker has been created
std::string address
network location of the broker
Definition: BrokerBase.hpp:68
@ HELICS_FLAG_DUMPLOG
Definition: helics_enums.h:168
GlobalBrokerId global_broker_id_local
Definition: BrokerBase.hpp:39
decltype(std::chrono::steady_clock::now()) errorTimeStart
time when the error condition started related to the errorDelay
Definition: BrokerBase.hpp:139