helics
3.5.2
|
#include <Federate.hpp>
Public Types | |
enum class | Modes : char { STARTUP = 0 , INITIALIZING = 1 , EXECUTING = 2 , FINALIZE = 3 , ERROR_STATE = 4 , PENDING_INIT = 5 , PENDING_EXEC = 6 , PENDING_TIME = 7 , PENDING_ITERATIVE_TIME = 8 , PENDING_FINALIZE = 9 , FINISHED = 10 , PENDING_ITERATIVE_INIT = 12 } |
Public Member Functions | |
Federate (std::string_view fedname, const FederateInfo &fedInfo) | |
Federate (std::string_view fedname, const std::shared_ptr< Core > &core, const FederateInfo &fedInfo=FederateInfo{}) | |
Federate (std::string_view fedname, CoreApp &core, const FederateInfo &fedInfo=FederateInfo{}) | |
Federate (const std::string &configString) | |
Federate (std::string_view fedname, const std::string &configString) | |
Federate () noexcept | |
Federate (Federate &&fed) noexcept | |
Federate (const Federate &fed)=delete | |
virtual | ~Federate () |
Federate & | operator= (Federate &&fed) noexcept |
Federate & | operator= (const Federate &fed)=delete |
void | enterInitializingMode () |
void | enterInitializingModeAsync () |
bool | isAsyncOperationCompleted () const |
void | enterInitializingModeComplete () |
void | enterInitializingModeIterative () |
void | enterInitializingModeIterativeAsync () |
void | enterInitializingModeIterativeComplete () |
IterationResult | enterExecutingMode (IterationRequest iterate=IterationRequest::NO_ITERATIONS) |
void | enterExecutingModeAsync (IterationRequest iterate=IterationRequest::NO_ITERATIONS) |
IterationResult | enterExecutingModeComplete () |
void | finalize () |
void | finalizeAsync () |
void | finalizeComplete () |
void | processCommunication (std::chrono::milliseconds period=std::chrono::milliseconds(0)) |
virtual void | disconnect () |
void | localError (int errorcode, std::string_view message) |
void | globalError (int errorcode, std::string_view message) |
void | localError (int errorcode) |
void | globalError (int errorcode) |
void | setSeparator (char separator) |
Time | requestTime (Time nextInternalTimeStep) |
Time | requestNextStep () |
Time | requestTimeAdvance (Time timeDelta) |
iteration_time | requestTimeIterative (Time nextInternalTimeStep, IterationRequest iterate) |
void | requestTimeAsync (Time nextInternalTimeStep) |
void | requestTimeIterativeAsync (Time nextInternalTimeStep, IterationRequest iterate) |
Time | requestTimeComplete () |
iteration_time | requestTimeIterativeComplete () |
void | setTag (std::string_view tag, std::string_view value) |
const std::string & | getTag (std::string_view tag) const |
virtual void | setProperty (int32_t option, double timeValue) |
virtual void | setProperty (int32_t option, Time timeValue) |
virtual void | setFlagOption (int flag, bool flagValue=true) |
virtual void | setProperty (int32_t option, int32_t optionValue) |
virtual Time | getTimeProperty (int32_t option) const |
virtual bool | getFlagOption (int flag) const |
virtual int | getIntegerProperty (int32_t option) const |
void | setLoggingCallback (const std::function< void(int, std::string_view, std::string_view)> &logFunction) |
void | setInitializingEntryCallback (std::function< void(bool)> callback) |
void | setExecutingEntryCallback (std::function< void()> callback) |
void | setTimeRequestEntryCallback (std::function< void(Time, Time, bool)> callback) |
void | setTimeUpdateCallback (std::function< void(Time, bool)> callback) |
void | setModeUpdateCallback (std::function< void(Modes, Modes)> callback) |
void | setTimeRequestReturnCallback (std::function< void(Time, bool)> callback) |
void | setCosimulationTerminatedCallback (std::function< void()> callback) |
void | setErrorHandlerCallback (std::function< void(int, std::string_view)> errorHandlerCallback) |
std::string | query (std::string_view target, std::string_view queryStr, HelicsSequencingModes mode=HELICS_SEQUENCING_MODE_FAST) |
std::string | query (std::string_view queryStr, HelicsSequencingModes mode=HELICS_SEQUENCING_MODE_FAST) |
QueryId | queryAsync (std::string_view target, std::string_view queryStr, HelicsSequencingModes mode=HELICS_SEQUENCING_MODE_FAST) |
QueryId | queryAsync (std::string_view queryStr, HelicsSequencingModes mode=HELICS_SEQUENCING_MODE_FAST) |
std::string | queryComplete (QueryId queryIndex) |
bool | isQueryCompleted (QueryId queryIndex) const |
void | setQueryCallback (const std::function< std::string(std::string_view)> &queryFunction) |
void | setGlobal (std::string_view valueName, std::string_view value) |
void | addAlias (std::string_view interfaceName, std::string_view alias) |
void | sendCommand (std::string_view target, std::string_view commandStr, HelicsSequencingModes mode=HelicsSequencingModes::HELICS_SEQUENCING_MODE_FAST) |
std::pair< std::string, std::string > | getCommand () |
std::pair< std::string, std::string > | waitCommand () |
void | addDependency (std::string_view fedName) |
Filter & | registerGlobalFilter (std::string_view filterName, std::string_view inputType=std::string_view{}, std::string_view outputType=std::string_view{}) |
CloningFilter & | registerGlobalCloningFilter (std::string_view filterName, std::string_view inputType=std::string_view{}, std::string_view outputType=std::string_view{}) |
Filter & | registerFilter (std::string_view filterName, std::string_view inputType=std::string_view{}, std::string_view outputType=std::string_view{}) |
CloningFilter & | registerCloningFilter (std::string_view filterName, std::string_view inputType=std::string_view{}, std::string_view outputType=std::string_view{}) |
Filter & | registerFilter () |
Translator & | registerGlobalTranslator (std::int32_t translatorType, std::string_view translatorName, std::string_view endpointType=std::string_view{}, std::string_view units=std::string_view{}) |
Translator & | registerTranslator (std::int32_t translatorType, std::string_view translatorName, std::string_view endpointType=std::string_view{}, std::string_view units=std::string_view{}) |
Translator & | registerGlobalTranslator (std::string_view translatorName, std::string_view endpointType=std::string_view{}, std::string_view units=std::string_view{}) |
Translator & | registerTranslator (std::string_view translatorName, std::string_view endpointType=std::string_view{}, std::string_view units=std::string_view{}) |
Translator & | registerTranslator () |
CloningFilter & | registerCloningFilter () |
const Filter & | getFilter (std::string_view filterName) const |
const Filter & | getFilter (int index) const |
Filter & | getFilter (std::string_view filterName) |
Filter & | getFilter (int index) |
void | setFilterOperator (const Filter &filt, std::shared_ptr< FilterOperator > filtOp) |
register a operator for the specified filter More... | |
int | getFilterCount () const |
const Translator & | getTranslator (std::string_view translatorName) const |
const Translator & | getTranslator (int index) const |
Translator & | getTranslator (std::string_view translatorName) |
Translator & | getTranslator (int index) |
void | setTranslatorOperator (const Translator &trans, std::shared_ptr< TranslatorOperator > transOp) |
register an operator for the specified translator More... | |
int | getTranslatorCount () const |
const std::string & | getConfigFile () const |
virtual void | registerInterfaces (const std::string &configString) |
void | registerConnectorInterfaces (const std::string &configString) |
void | registerFilterInterfaces (const std::string &configString) |
auto | getID () const noexcept |
Modes | getCurrentMode () const noexcept |
Time | getCurrentTime () const noexcept |
const std::string & | getName () const |
const std::shared_ptr< Core > & | getCorePointer () |
void | logMessage (int level, std::string_view message) const |
void | logErrorMessage (std::string_view message) const |
void | logWarningMessage (std::string_view message) const |
void | logInfoMessage (std::string_view message) const |
void | logDebugMessage (std::string_view message) const |
void | completeOperation () |
Protected Member Functions | |
void | enteringInitializingMode (IterationResult iterating) |
void | enteringExecutingMode (iteration_time res) |
void | finalizeOperations () |
void | preTimeRequestOperations (Time nextStep, bool iterating) |
void | postTimeRequestOperations (Time newTime, bool iterating) |
virtual void | updateTime (Time newTime, Time oldTime) |
virtual void | startupToInitializeStateTransition () |
virtual void | initializeToExecuteStateTransition (iteration_time iterate) |
virtual void | disconnectTransition () |
virtual std::string | localQuery (std::string_view queryStr) const |
std::string | localNameGenerator (std::string_view addition) const |
void | handleError (int errorCode, std::string_view errorString, bool noThrow) |
void | setAsyncCheck (std::function< bool()> asyncCheck) |
Protected Attributes | |
std::atomic< Modes > | currentMode {Modes::STARTUP} |
the current state of the simulation | |
char | nameSegmentSeparator = '/' |
the separator between automatically prependend names | |
bool | strictConfigChecking {true} |
bool | useJsonSerialization {false} |
bool | observerMode {false} |
bool | retriggerTimeRequest {false} |
bool | singleThreadFederate {false} |
bool | hasPotentialInterfaces {false} |
std::shared_ptr< Core > | coreObject |
reference to the core simulation API | |
Time | mCurrentTime = Time::minVal() |
the current simulation time | |
Time | mStopTime = Time::maxVal() |
the stopping time for the federate | |
std::string | configFile |
any config file used | |
base class for a federate in the application API
|
strong |
the allowable operation modes of the federate
helics::Federate::Federate | ( | std::string_view | fedname, |
const FederateInfo & | fedInfo | ||
) |
constructor taking a federate information structure
fedname | the name of the federate can be empty to use a name from the federateInfo |
fedInfo | a federate information structure |
References helics::FederateInfo::defName.
helics::Federate::Federate | ( | std::string_view | fedname, |
const std::shared_ptr< Core > & | core, | ||
const FederateInfo & | fedInfo = FederateInfo{} |
||
) |
constructor taking a core and a federate information structure
fedname | the name of the federate can be empty to use a name from the federateInfo |
core | a shared pointer to a core object, the pointer will be copied |
fedInfo | a federate information structure |
References helics::FederateInfo::defName.
helics::Federate::Federate | ( | std::string_view | fedname, |
CoreApp & | core, | ||
const FederateInfo & | fedInfo = FederateInfo{} |
||
) |
|
explicit |
constructor taking a file with the required information
configString | can be either a JSON file or a string containing JSON code or a TOML file |
helics::Federate::Federate | ( | std::string_view | fedname, |
const std::string & | configString | ||
) |
constructor taking a file with the required information and the name of the federate
fedname | the name of the federate |
configString | can be either a JSON file or a string containing JSON code or a TOML file with extension (.toml, .TOML) |
|
noexcept |
default constructor
|
noexcept |
move constructor
References helics::CoreFactory::getEmptyCore().
|
delete |
deleted copy constructor
|
virtual |
virtual destructor function
References currentMode, FINALIZE, and finalize().
void helics::Federate::addAlias | ( | std::string_view | interfaceName, |
std::string_view | alias | ||
) |
add a global alias for an interface
interfaceName | the given name of the interface |
alias | the new name by which the interface can be referenced |
References coreObject.
void helics::Federate::addDependency | ( | std::string_view | fedName | ) |
add a dependency for this federate
adds an additional internal time dependency for the federate
fedName | the name of the federate to add a dependency on |
References coreObject.
void helics::Federate::completeOperation | ( | ) |
call to complete async operation with no output
References currentMode, enterExecutingModeComplete(), enterInitializingModeComplete(), finalizeComplete(), PENDING_EXEC, PENDING_FINALIZE, PENDING_INIT, PENDING_ITERATIVE_TIME, PENDING_TIME, requestTimeComplete(), and requestTimeIterativeComplete().
Referenced by globalError(), and localError().
|
virtual |
disconnect a simulation from the core (will also call finalize before disconnecting if necessary)
Reimplemented in helics::ValueFederate, helics::MessageFederate, and helics::CombinationFederate.
References coreObject, finalize(), and helics::CoreFactory::getEmptyCore().
Referenced by helics::MessageFederate::disconnect(), and helics::ValueFederate::disconnect().
|
protectedvirtual |
function to handle any disconnect operations
IterationResult helics::Federate::enterExecutingMode | ( | IterationRequest | iterate = IterationRequest::NO_ITERATIONS | ) |
enter the normal execution mode
call will block until all federates have entered this mode
iterate | an optional flag indicating the desired iteration mode |
References coreObject, currentMode, enterExecutingModeComplete(), enteringExecutingMode(), enterInitializingMode(), EXECUTING, INITIALIZING, helics::ITERATING, helics::NEXT_STEP, PENDING_EXEC, PENDING_INIT, PENDING_ITERATIVE_TIME, PENDING_TIME, requestTimeComplete(), requestTimeIterativeComplete(), and STARTUP.
Referenced by enterExecutingModeComplete().
void helics::Federate::enterExecutingModeAsync | ( | IterationRequest | iterate = IterationRequest::NO_ITERATIONS | ) |
enter the normal execution mode
call will return immediately but enterExecutingModeComplete should be called to complete the operation
iterate | an optional flag indicating the desired iteration mode |
References coreObject, currentMode, enterInitializingModeComplete(), EXECUTING, INITIALIZING, mCurrentTime, PENDING_EXEC, PENDING_INIT, PENDING_ITERATIVE_TIME, PENDING_TIME, STARTUP, and startupToInitializeStateTransition().
IterationResult helics::Federate::enterExecutingModeComplete | ( | ) |
complete the async call for entering Execution state
call will not block but will return quickly. The enterInitializingModeComplete must be called before doing other operations
References currentMode, enterExecutingMode(), enteringExecutingMode(), ERROR_STATE, and PENDING_EXEC.
Referenced by completeOperation(), enterExecutingMode(), and finalizeAsync().
|
protected |
function to run required operations for entering executing Mode
References enteringInitializingMode(), helics::ERROR_RESULT, ERROR_STATE, EXECUTING, FINISHED, helics::iteration_time::grantedTime, helics::HALTED, helics::initializationTime, initializeToExecuteStateTransition(), helics::ITERATING, mCurrentTime, helics::NEXT_STEP, and helics::iteration_time::state.
Referenced by enterExecutingMode(), and enterExecutingModeComplete().
|
protected |
function to run required operations for entering initializingMode
References coreObject, INITIALIZING, mCurrentTime, helics::NEXT_STEP, and startupToInitializeStateTransition().
Referenced by enteringExecutingMode(), enterInitializingMode(), and enterInitializingModeComplete().
void helics::Federate::enterInitializingMode | ( | ) |
enter the initialization mode after all interfaces have been defined
the call will block until all federates have entered initialization mode
References coreObject, currentMode, enteringInitializingMode(), enterInitializingModeComplete(), ERROR_STATE, INITIALIZING, helics::NEXT_STEP, PENDING_INIT, and STARTUP.
Referenced by enterExecutingMode(), and enterInitializingModeComplete().
void helics::Federate::enterInitializingModeAsync | ( | ) |
enter the initialization mode after all interfaces have been defined
the call will not block but a call to enterInitializingModeComplete should be made to complete the call sequence
References coreObject, currentMode, INITIALIZING, PENDING_INIT, and STARTUP.
void helics::Federate::enterInitializingModeComplete | ( | ) |
second part of the async process for entering initializationState call after a call to enterInitializingModeAsync if call any other time it will throw an InvalidFunctionCall exception
References currentMode, enteringInitializingMode(), enterInitializingMode(), ERROR_STATE, INITIALIZING, helics::NEXT_STEP, PENDING_INIT, and STARTUP.
Referenced by completeOperation(), enterExecutingModeAsync(), enterInitializingMode(), and finalizeAsync().
void helics::Federate::enterInitializingModeIterative | ( | ) |
iterate in the created mode.
the call will block until all federates have flagged they are ready for the next stage of initialization all federates requesting iterations on the created mode will be notified they can continue with setup.
References coreObject, currentMode, enterInitializingModeIterativeComplete(), ERROR_STATE, helics::FORCE_ITERATION, PENDING_ITERATIVE_INIT, and STARTUP.
void helics::Federate::enterInitializingModeIterativeAsync | ( | ) |
iterate in the created mode.
the call will not block but a call to enterInitializingModeIterativeComplete should be made to complete the call sequence
References coreObject, currentMode, helics::FORCE_ITERATION, PENDING_ITERATIVE_INIT, and STARTUP.
void helics::Federate::enterInitializingModeIterativeComplete | ( | ) |
second part of the async process for entering initialization mode iterative call after a call to enterInitializingModeIterativeAsync; if called any other time it will throw an InvalidFunctionCall exception. The federate will be in the created state(or ERROR state) after this call
References currentMode, ERROR_STATE, PENDING_ITERATIVE_INIT, and STARTUP.
Referenced by enterInitializingModeIterative().
void helics::Federate::finalize | ( | ) |
terminate the simulation
call is will block until the finalize has been acknowledged, no commands that interact with the core may be called after this function function
References coreObject, currentMode, ERROR_STATE, EXECUTING, FINALIZE, finalizeComplete(), finalizeOperations(), FINISHED, INITIALIZING, PENDING_EXEC, PENDING_FINALIZE, PENDING_INIT, PENDING_ITERATIVE_TIME, PENDING_TIME, and STARTUP.
Referenced by disconnect(), finalizeComplete(), and ~Federate().
void helics::Federate::finalizeAsync | ( | ) |
terminate the simulation in a non-blocking call
finalizeComplete must be called after this call to complete the finalize procedure
References coreObject, currentMode, enterExecutingModeComplete(), enterInitializingModeComplete(), ERROR_STATE, FINALIZE, PENDING_EXEC, PENDING_FINALIZE, PENDING_INIT, PENDING_ITERATIVE_TIME, PENDING_TIME, requestTimeComplete(), and requestTimeIterativeComplete().
void helics::Federate::finalizeComplete | ( | ) |
complete the asynchronous terminate pair
References currentMode, finalize(), finalizeOperations(), and PENDING_FINALIZE.
Referenced by completeOperation(), and finalize().
|
protected |
function tor run required operations when finalizing
References FINALIZE.
Referenced by finalize(), and finalizeComplete().
std::pair< std::string, std::string > helics::Federate::getCommand | ( | ) |
get a command for the Federate
References coreObject.
|
inline |
get the primary config file actually used by the federate for setup
|
inline |
get a shared pointer to the core object used by the federate
Referenced by helics::make_cloning_filter().
|
inlinenoexcept |
get the current state of the federate
|
inlinenoexcept |
get the current Time
the most recent granted time of the federate
Filter & helics::Federate::getFilter | ( | int | index | ) |
get a filter from its index
index | the index of a filter |
const Filter & helics::Federate::getFilter | ( | int | index | ) | const |
get a filter from its index
index | the index of a filter |
Filter & helics::Federate::getFilter | ( | std::string_view | filterName | ) |
get a filter from its name
filterName | the name of the filter |
References helics::Interface::isValid(), and localNameGenerator().
const Filter & helics::Federate::getFilter | ( | std::string_view | filterName | ) | const |
get a filter from its name
filterName | the name of the filter |
References helics::Interface::isValid(), and localNameGenerator().
int helics::Federate::getFilterCount | ( | ) | const |
get the number of filters registered through this federate
|
virtual |
get the value of a flag option
flag | an index into the flag /ref flag-definitions.h |
References coreObject, retriggerTimeRequest, and useJsonSerialization.
|
inlinenoexcept |
get the underlying federateID for the core
|
virtual |
get an integer option for the federate
option | the option to inquire see /ref defs |
References coreObject.
|
inline |
get the federate name
Referenced by localNameGenerator(), query(), and sendCommand().
const std::string & helics::Federate::getTag | ( | std::string_view | tag | ) | const |
get the value of a specific tag (key-value pair) for a federate
the tag is an arbitrary user defined string and value; the tags for a federate are queryable
tag | the name of the tag to get the value for |
References coreObject.
|
virtual |
get the value of a time option for the federate
option | the option to get |
Translator & helics::Federate::getTranslator | ( | int | index | ) |
get a translator from its index
index | the index of a translator |
const Translator & helics::Federate::getTranslator | ( | int | index | ) | const |
get a translator from its index
index | the index of a translator |
Translator & helics::Federate::getTranslator | ( | std::string_view | translatorName | ) |
get a translator from its name
translatorName | the name of the translator |
References helics::Interface::isValid(), and localNameGenerator().
const Translator & helics::Federate::getTranslator | ( | std::string_view | translatorName | ) | const |
get a translator from its name
translatorName | the name of the translator |
References helics::Interface::isValid(), and localNameGenerator().
int helics::Federate::getTranslatorCount | ( | ) | const |
get the number of translators registered through this federate
void helics::Federate::globalError | ( | int | errorcode | ) |
specify the simulator had a global error with error code
errorcode | an integral code for the error |
References globalError().
void helics::Federate::globalError | ( | int | errorcode, |
std::string_view | message | ||
) |
specify the simulator had a global error with error code and message
global errors propagate through the entire federation and will halt operations
errorcode | an integral code for the error |
message | a string describing the error to display in the log |
References completeOperation(), coreObject, and ERROR_STATE.
Referenced by globalError().
|
protected |
process an error
References ERROR_STATE.
|
protectedvirtual |
function to deal with any operations that need to occur on the transition from startup to initialize
Reimplemented in helics::ValueFederate, helics::MessageFederate, and helics::CombinationFederate.
Referenced by enteringExecutingMode().
bool helics::Federate::isAsyncOperationCompleted | ( | ) | const |
called after one of the async calls and will indicate true if an async operation has completed
only call from the same thread as the one that called the initial async call and will return false if called when no async operation is in flight
References currentMode, PENDING_EXEC, PENDING_FINALIZE, PENDING_INIT, PENDING_ITERATIVE_INIT, PENDING_ITERATIVE_TIME, and PENDING_TIME.
bool helics::Federate::isQueryCompleted | ( | QueryId | queryIndex | ) | const |
check if an asynchronous query call has been completed
void helics::Federate::localError | ( | int | errorcode | ) |
specify the simulator had a local error with error code
errorcode | an integral code for the error |
References localError().
void helics::Federate::localError | ( | int | errorcode, |
std::string_view | message | ||
) |
specify the simulator had a local error with error code and message
errorcode | an integral code for the error |
message | a string describing the error to display in a log |
References completeOperation(), coreObject, and ERROR_STATE.
Referenced by localError().
|
protected |
generate a string with the local variant of the name with the specified suffix
[in] | addition | the suffix to append to the current object name |
References getName(), and nameSegmentSeparator.
Referenced by helics::MessageFederate::getEndpoint(), getFilter(), helics::ValueFederate::getInput(), helics::ValueFederate::getPublication(), getTranslator(), registerCloningFilter(), helics::MessageFederate::registerEndpoint(), registerFilter(), helics::ValueFederate::registerInput(), helics::ValueFederate::registerPublication(), helics::MessageFederate::registerTargetedEndpoint(), and registerTranslator().
|
protectedvirtual |
function to generate results for a local Query
should return an empty string if the query is not recognized
Reimplemented in helics::ValueFederate, helics::MessageFederate, and helics::CombinationFederate.
Referenced by query().
|
inline |
log a debug message to the federate Logger
message | the message to log |
References HELICS_LOG_LEVEL_DEBUG.
|
inline |
log an error message to the federate Logger
message | the message to log |
References HELICS_LOG_LEVEL_ERROR.
|
inline |
log an info message to the federate Logger
message | the message to log |
References HELICS_LOG_LEVEL_SUMMARY.
void helics::Federate::logMessage | ( | int | level, |
std::string_view | message | ||
) | const |
log a message to the federate Logger
level | the logging level of the message |
message | the message to log |
References coreObject, and HELICS_LOG_LEVEL_WARNING.
|
inline |
log a warning message to the federate Logger
message | the message to log |
References HELICS_LOG_LEVEL_WARNING.
default move assignment
References currentMode, and helics::CoreFactory::getEmptyCore().
Referenced by helics::MessageFederate::operator=(), and helics::ValueFederate::operator=().
void helics::Federate::processCommunication | ( | std::chrono::milliseconds | period = std::chrono::milliseconds(0) | ) |
Run a processing loop for X amount of time. If the period is set to 0 it just processes currently pending communications.
References coreObject.
std::string helics::Federate::query | ( | std::string_view | queryStr, |
HelicsSequencingModes | mode = HELICS_SEQUENCING_MODE_FAST |
||
) |
make a query of the core
this call is blocking until the value is returned which make take some time depending on the size of the federation and the specific string being queried
queryStr | a string with the query see other documentation for specific properties to query, can be defined by the federate if the local federate does not recognize the query it sends it on to the federation |
mode | fast (asynchronous; default) means the query goes on priority channels, ordered (synchronous) is slower but has more ordering guarantees |
References coreObject, getName(), localQuery(), and mCurrentTime.
std::string helics::Federate::query | ( | std::string_view | target, |
std::string_view | queryStr, | ||
HelicsSequencingModes | mode = HELICS_SEQUENCING_MODE_FAST |
||
) |
make a query of the core
this call is blocking until the value is returned which make take some time depending on the size of the federation and the specific string being queried
target | the target of the query can be "federation", "federate", "broker", "core", or a specific name of a federate, core, or broker |
queryStr | a string with the query see other documentation for specific properties to query, can be defined by the federate |
mode | fast (asynchronous; default) means the query goes on priority channels, ordered (synchronous) is slower but has more ordering guarantees |
References coreObject, and getName().
Referenced by queryAsync(), helics::queryFederateSubscriptions(), helics::waitForFed(), and helics::waitForInit().
QueryId helics::Federate::queryAsync | ( | std::string_view | queryStr, |
HelicsSequencingModes | mode = HELICS_SEQUENCING_MODE_FAST |
||
) |
make a query of the core in an async fashion
this call is blocking until the value is returned which make take some time depending on the size of the federation and the specific string being queried
queryStr | a string with the query see other documentation for specific properties to query, can be defined by the federate |
mode | fast (asynchronous; default) means the query goes on priority channels, ordered(synchronous) is slower but has more ordering guarantees |
References query().
QueryId helics::Federate::queryAsync | ( | std::string_view | target, |
std::string_view | queryStr, | ||
HelicsSequencingModes | mode = HELICS_SEQUENCING_MODE_FAST |
||
) |
make a query of the core in an async fashion
this call is blocking until the value is returned which make take some time depending on the size of the federation and the specific string being queried
target | the target of the query can be "federation", "federate", "broker", "core", or a specific name of a federate, core, or broker |
queryStr | a string with the query see other documentation for specific properties to query, can be defined by the federate |
mode | fast (asynchronous; default) means the query goes on priority channels, ordered(synchronous) is slower but has more ordering guarantees |
References coreObject.
std::string helics::Federate::queryComplete | ( | QueryId | queryIndex | ) |
get the results of an async query
the call will block until the results are returned inquiry of queryCompleted() to check if the results have been returned or not yet
queryIndex | the int value returned from the queryAsync call |
References helics::generateJsonErrorResponse().
|
inline |
define a nameless cloning filter interface on a source
CloningFilter & helics::Federate::registerCloningFilter | ( | std::string_view | filterName, |
std::string_view | inputType = std::string_view{} , |
||
std::string_view | outputType = std::string_view{} |
||
) |
define a cloning filter interface on a source
a source filter will be sent any packets that come from a particular source if multiple filters are defined on the same source, they will be placed in some order defined by the core
filterName | the name of the filter |
inputType | the inputType which the filter can handle |
outputType | the outputType of the filter which the filter produces |
References localNameGenerator().
Referenced by helics::CloningFilter::CloningFilter(), and helics::make_cloning_filter().
void helics::Federate::registerConnectorInterfaces | ( | const std::string & | configString | ) |
register filter/translator interfaces defined in a file or string
call is only valid in startup mode
configString | the location of the file or config String to load to generate the interfaces |
Referenced by registerInterfaces(), and helics::MessageFederate::registerInterfaces().
|
inline |
define a nameless filter interface
Filter & helics::Federate::registerFilter | ( | std::string_view | filterName, |
std::string_view | inputType = std::string_view{} , |
||
std::string_view | outputType = std::string_view{} |
||
) |
define a filter interface
a filter will modify messages coming from or going to target endpoints
filterName | the name of the filter |
inputType | the inputType which the filter can handle |
outputType | the outputType of the filter which the filter produces |
References localNameGenerator().
|
inline |
register filter/translator interfaces defined in a file or string
call is only valid in startup mode will be deprecated
configString | the location of the file or config String to load to generate the interfaces |
Referenced by helics::CombinationFederate::registerInterfaces().
CloningFilter & helics::Federate::registerGlobalCloningFilter | ( | std::string_view | filterName, |
std::string_view | inputType = std::string_view{} , |
||
std::string_view | outputType = std::string_view{} |
||
) |
define a cloning filter interface on a source
a cloning filter will modify copy of messages coming from or going to target endpoints
filterName | the name of the filter |
inputType | the inputType which the filter can handle |
outputType | the outputType of the filter which the filter produces |
Filter & helics::Federate::registerGlobalFilter | ( | std::string_view | filterName, |
std::string_view | inputType = std::string_view{} , |
||
std::string_view | outputType = std::string_view{} |
||
) |
define a named global filter interface
filterName | the name of the globally visible filter |
inputType | the inputType which the filter can handle |
outputType | the outputType of the filter which the filter produces |
Translator & helics::Federate::registerGlobalTranslator | ( | std::int32_t | translatorType, |
std::string_view | translatorName, | ||
std::string_view | endpointType = std::string_view{} , |
||
std::string_view | units = std::string_view{} |
||
) |
define a named global translator interface
translatorType | a code defining a known type of translator (0 for custom) |
translatorName | the name of the globally visible translator |
endpointType | the type associated with the translator endpoint |
units | the units associated with the translator value interfaces |
References helics::Translator::setTranslatorType().
|
inline |
define a named global translator interface
translatorName | the name of the globally visible translator |
endpointType | the type associated with the translator endpoint |
units | the units associated with the translator value interfaces |
|
virtual |
register a set of interfaces defined in a file
call is only valid in startup mode
configString | the location of the file or config String to load to generate the interfaces |
Reimplemented in helics::ValueFederate, helics::MessageFederate, and helics::CombinationFederate.
References registerConnectorInterfaces().
Referenced by helics::ValueFederate::registerInterfaces().
|
inline |
define a nameless translator interface
Translator & helics::Federate::registerTranslator | ( | std::int32_t | translatorType, |
std::string_view | translatorName, | ||
std::string_view | endpointType = std::string_view{} , |
||
std::string_view | units = std::string_view{} |
||
) |
define a translator interface
a translator acts as a bridge between value and message interfaces
translatorType | a code defining a known type of translator (0 for custom) |
translatorName | the name of the translator; can be an empty string |
endpointType | the type associated with the translator endpoint |
units | the units associated with the translator value interfaces |
References localNameGenerator(), and helics::Translator::setTranslatorType().
|
inline |
define a translator interface
a translator acts as a bridge between value and message interfaces
translatorName | the name of the translator |
endpointType | the type associated with the translator endpoint |
units | the units associated with the translator value interfaces |
|
inline |
request a time advancement to the next allowed time
References helics::timeZero.
request a time advancement
nextInternalTimeStep | the next requested time step |
References coreObject, currentMode, ERROR_STATE, EXECUTING, FINALIZE, FINISHED, and retriggerTimeRequest.
request a time advancement by a certain amount
timeDelta | the amount of time to advance |
void helics::Federate::requestTimeAsync | ( | Time | nextInternalTimeStep | ) |
request a time advancement and return immediately for asynchronous function.
/ref requestTimeComplete should be called to finish the operation and get the result
nextInternalTimeStep | the next requested time step |
References coreObject, currentMode, EXECUTING, and PENDING_TIME.
Time helics::Federate::requestTimeComplete | ( | ) |
request a time advancement
References currentMode, EXECUTING, and PENDING_TIME.
Referenced by completeOperation(), enterExecutingMode(), and finalizeAsync().
iteration_time helics::Federate::requestTimeIterative | ( | Time | nextInternalTimeStep, |
IterationRequest | iterate | ||
) |
request a time advancement
nextInternalTimeStep | the next requested time step |
iterate | a requested iteration mode |
References coreObject, currentMode, helics::ERROR_RESULT, ERROR_STATE, EXECUTING, FINALIZE, FINISHED, helics::HALTED, helics::ITERATING, mCurrentTime, helics::NEXT_STEP, and helics::NO_ITERATIONS.
void helics::Federate::requestTimeIterativeAsync | ( | Time | nextInternalTimeStep, |
IterationRequest | iterate | ||
) |
request a time advancement with iterative call and return for asynchronous function.
/ref requestTimeIterativeComplete should be called to finish the operation and get the result
nextInternalTimeStep | the next requested time step |
iterate | a requested iteration level (none, require, optional) |
References coreObject, currentMode, EXECUTING, helics::NO_ITERATIONS, and PENDING_ITERATIVE_TIME.
iteration_time helics::Federate::requestTimeIterativeComplete | ( | ) |
finalize the time advancement request
finalize the time advancement request
References currentMode, helics::ERROR_RESULT, ERROR_STATE, EXECUTING, FINISHED, helics::HALTED, helics::ITERATING, mCurrentTime, helics::NEXT_STEP, and PENDING_ITERATIVE_TIME.
Referenced by completeOperation(), enterExecutingMode(), and finalizeAsync().
void helics::Federate::sendCommand | ( | std::string_view | target, |
std::string_view | commandStr, | ||
HelicsSequencingModes | mode = HelicsSequencingModes::HELICS_SEQUENCING_MODE_FAST |
||
) |
send a command to another core or federate
target | the target of the command can be "federation", "federate", "broker", "core", or a specific name of a federate, core, or broker |
commandStr | a string with the command instructions, see other documentation for specific properties to command, can be defined by a federate |
mode | fast (asynchronous; default) means the command goes on priority channels, ordered(synchronous) is slower but has more ordering guarantees |
References coreObject, and getName().
void helics::Federate::setCosimulationTerminatedCallback | ( | std::function< void()> | callback | ) |
register a callback function to call when the cosimulation is completed for this federate
this callback will execute once when time has reached max value or when finalize is called and
callback | the function to call; the function signature is void(void) |
References currentMode, FINALIZE, and PENDING_FINALIZE.
void helics::Federate::setErrorHandlerCallback | ( | std::function< void(int, std::string_view)> | errorHandlerCallback | ) |
register a callback function that executes when an error is generated
if set this function will execute instead of throwing an exception in some cases( NOTE: this is currently only used for callback federates)
errorHandlerCallback | the function to call; the function signature is void(int errorCode, std::string_view errorString) |
void helics::Federate::setExecutingEntryCallback | ( | std::function< void()> | callback | ) |
register a callback function to call when the system enters executingMode
this callback will execute once in the calling thread just prior to calling timeUpdateCallback for the first time and
callback | the function to call; the function signature is void(void) |
References currentMode, PENDING_EXEC, and PENDING_INIT.
void helics::Federate::setFilterOperator | ( | const Filter & | filt, |
std::shared_ptr< FilterOperator > | filtOp | ||
) |
register a operator for the specified filter
The FilterOperator gets called when there is a message to filter, There is no order or state to this messages can come in any order.
filt | the filter object to set the operation on |
filtOp | a shared_ptr to a FilterOperator |
References coreObject, and helics::Interface::getHandle().
|
virtual |
set a flag for the federate
flag | an index into the flag /ref flag-definitions.h |
flagValue | the value of the flag defaults to true |
Reimplemented in helics::CombinationFederate, and helics::ValueFederate.
References coreObject, currentMode, INITIALIZING, observerMode, and retriggerTimeRequest.
Referenced by helics::ValueFederate::setFlagOption().
void helics::Federate::setGlobal | ( | std::string_view | valueName, |
std::string_view | value | ||
) |
set a federation global value
this overwrites any previous value for this name
valueName | the name of the global to set |
value | the value of the global |
References coreObject.
void helics::Federate::setInitializingEntryCallback | ( | std::function< void(bool)> | callback | ) |
register a callback function to call when the system enters initializingMode
this callback will execute in the calling thread just prior to returning control to the caller
callback | the function to call; the function signature is void(bool) where the boolean is set to true if the iterating to true if the request is possibly iterating |
References currentMode, and PENDING_INIT.
void helics::Federate::setLoggingCallback | ( | const std::function< void(int, std::string_view, std::string_view)> & | logFunction | ) |
define a logging function to use for logging message and notices from the federation and individual federate
logFunction | the callback function for doing something with a log message it takes 3 inputs an integer for logLevel /ref helics_log_level A string indicating the source of the message and another string with the actual message |
References coreObject.
register a callback function to call when the federate mode is changed from one state to another
this callback is executed before other callbacks updating values and times, no values will have been updated when this callback is executed. It will execute before timeUpdateCallback in situations where both would be called.
callback | the function to call; the function signature is void(Modes, Modes) the first argument is the new Mode and the second is the old Mode |
References currentMode, PENDING_EXEC, PENDING_FINALIZE, PENDING_INIT, PENDING_ITERATIVE_TIME, and PENDING_TIME.
|
virtual |
set a time property for a federate
option | the option to set |
timeValue | the value to be set |
|
virtual |
set an integer option for the federate
option | an index of the option to set |
optionValue | an integer option value for an integer based property |
References coreObject.
|
virtual |
set a time option for the federate
option | the option to set |
timeValue | the value to be set |
void helics::Federate::setQueryCallback | ( | const std::function< std::string(std::string_view)> & | queryFunction | ) |
supply a query callback function
the intention of the query callback is to allow federates to answer particular requests through the query interface this allows other federates to make requests or queries of other federates in an asynchronous fashion.
queryFunction | a function object that returns a string as a result of a query in the form of const string ref. This callback will be called when a federate received a query that cannot be answered internally that is directed at that particular federate |
References coreObject.
|
inline |
specify a separator to use for naming separation between the federate name and the interface name setSeparator('.') will result in future registrations of local endpoints such as fedName.endpoint setSeparator('/') will result in fedName/endpoint the default is '/' any character can be used though many will not make that much sense. This call is not thread safe and should be called before any local interfaces are created otherwise it may not be possible to retrieve them without using the full name. recommended possibilities are ('.','/', ':','-','_')
void helics::Federate::setTag | ( | std::string_view | tag, |
std::string_view | value | ||
) |
set a tag (key-value pair) for a federate
the tag is an arbitrary user defined string and value; the tags for a federate are queryable through a "tags" query or "tag/<tagname>"
tag | the name of the tag to set the value for |
value | the value for the given tag |
References coreObject.
void helics::Federate::setTimeRequestEntryCallback | ( | std::function< void(Time, Time, bool)> | callback | ) |
register a callback function to call when a timeRequest function is called
this callback is executed prior to any blocking operation on any valid timeRequest method it will execute in the calling thread
callback | the function to call; the function signature is void(Time, Time, bool) where the first Time value is the current time and the second is the requested time. The boolean is set to true if the request is possibly iterating |
References currentMode, PENDING_ITERATIVE_TIME, and PENDING_TIME.
void helics::Federate::setTimeRequestReturnCallback | ( | std::function< void(Time, bool)> | callback | ) |
register a callback function to call when a timeRequest function returns
this callback is executed after all other callbacks and is the last thing executed before returning
callback | the function to call; the function signature is void(Time, bool) where the Time value is the new time and the boolean is set to true if the request is an iteration |
References currentMode, PENDING_ITERATIVE_TIME, and PENDING_TIME.
void helics::Federate::setTimeUpdateCallback | ( | std::function< void(Time, bool)> | callback | ) |
register a callback function to call when the time gets updated and before other value callbacks are executed
this callback is executed before other callbacks updating values, no values will have been updated when this callback is executed it is intended purely for updating time before value callbacks are executed.
callback | the function to call; the function signature is void(Time, bool) where the Time value is the new time and bool is true if this is an iteration |
References currentMode, PENDING_ITERATIVE_TIME, and PENDING_TIME.
void helics::Federate::setTranslatorOperator | ( | const Translator & | trans, |
std::shared_ptr< TranslatorOperator > | transOp | ||
) |
register an operator for the specified translator
The TranslatorOperator gets called when there is a message or value to translate, there is no order or state to this as messages can come in any order.
trans | the translator object to set the operation on |
transOp | a shared_ptr to a TranslatorOperator |
References coreObject, and helics::Interface::getHandle().
|
protectedvirtual |
function to deal with any operations that need to occur on the transition from startup to initialize
Reimplemented in helics::ValueFederate, helics::MessageFederate, and helics::CombinationFederate.
Referenced by enterExecutingModeAsync(), and enteringInitializingMode().
function to deal with any operations that need to occur on a time update
Reimplemented in helics::ValueFederate, helics::MessageFederate, and helics::CombinationFederate.
std::pair< std::string, std::string > helics::Federate::waitCommand | ( | ) |
get a command for the Federate, if there is none the call will block until a command is received
References coreObject.
|
protected |
set to true for observer mode, no outgoing synchronized communications
Referenced by setFlagOption().
|
protected |
allow to retrigger time requests from callbacks (user specified)
Referenced by getFlagOption(), requestTime(), and setFlagOption().
|
protected |
set to false to allow some invalid configurations to be ignored instead of error
|
protected |
set to true to force all outgoing data to json serialization
Referenced by getFlagOption(), and helics::ValueFederate::setFlagOption().