helics
3.5.2
|
#include <FederateState.hpp>
Public Member Functions | |
FederateState (const std::string &fedName, const CoreFederateInfo &fedInfo) | |
FederateState (const FederateState &)=delete | |
FederateState & | operator= (const FederateState &)=delete |
~FederateState () | |
void | reset (const CoreFederateInfo &fedInfo) |
const std::string & | getIdentifier () const |
FederateStates | getState () const |
InterfaceInfo & | interfaces () |
const InterfaceInfo & | interfaces () const |
uint64_t | getQueueSize (InterfaceHandle hid) const |
uint64_t | getQueueSize () const |
int32_t | getCurrentIteration () const |
std::unique_ptr< Message > | receive (InterfaceHandle hid) |
std::unique_ptr< Message > | receiveAny (InterfaceHandle &hid) |
const std::shared_ptr< const SmallBuffer > & | getValue (InterfaceHandle handle, uint32_t *inputIndex) |
const std::vector< std::shared_ptr< const SmallBuffer > > & | getAllValues (InterfaceHandle handle) |
std::pair< SmallBuffer, Time > | getPublishedValue (InterfaceHandle handle) |
void | setParent (CommonCore *coreObject) |
void | setProperties (const ActionMessage &cmd) |
void | setInterfaceProperty (const ActionMessage &cmd) |
void | setProperty (int timeProperty, Time propertyVal) |
void | setProperty (int intProperty, int propertyVal) |
void | setOptionFlag (int optionFlag, bool value) |
Time | getTimeProperty (int timeProperty) const |
bool | getOptionFlag (int optionFlag) const |
int32_t | getHandleOption (InterfaceHandle handle, char iType, int32_t option) const |
uint16_t | getInterfaceFlags () const |
int | getIntegerProperty (int intProperty) const |
int | publicationCount () const |
int | endpointCount () const |
int | inputCount () const |
void | spinlock () const |
void | sleeplock () const |
void | lock () |
bool | try_lock () const |
void | unlock () const |
int | loggingLevel () const |
void | setTag (std::string_view tag, std::string_view value) |
const std::string & | getTag (std::string_view tag) const |
const std::pair< std::string, std::string > & | getTagByIndex (size_t index) const |
auto | tagCount () const |
bool | isCallbackFederate () const |
Time | grantedTime () const |
Time | nextAllowedSendTime () const |
const std::vector< InterfaceHandle > & | getEvents () const |
std::vector< GlobalFederateId > | getDependencies () const |
std::vector< GlobalFederateId > | getDependents () const |
const std::string & | lastErrorString () const |
int | lastErrorCode () const noexcept |
void | setCoreObject (CommonCore *parent) |
IterationResult | waitSetup () |
IterationResult | enterInitializingMode (IterationRequest request) |
iteration_time | enterExecutingMode (IterationRequest iterate, bool sendRequest=false) |
iteration_time | requestTime (Time nextTime, IterationRequest iterate, bool sendRequest=false) |
std::vector< GlobalHandle > | getSubscribers (InterfaceHandle handle) |
std::vector< std::pair< GlobalHandle, std::string_view > > | getMessageDestinations (InterfaceHandle handle) |
MessageProcessingResult | genericUnspecifiedQueueProcess (bool busyReturn) |
void | finalize () |
void | processCommunications (std::chrono::milliseconds period) |
void | addAction (const ActionMessage &action) |
void | addAction (ActionMessage &&action) |
std::optional< ActionMessage > | processPostTerminationAction (const ActionMessage &action) |
void | forceProcessMessage (ActionMessage &action) |
void | logMessage (int level, std::string_view logMessageSource, std::string_view message, bool fromRemote=false) const |
void | setLogger (std::function< void(int, std::string_view, std::string_view)> logFunction) |
void | setCallbackOperator (std::shared_ptr< FederateOperator > fed) |
void | setQueryCallback (std::function< std::string(std::string_view)> queryCallbackFunction, int order) |
std::string | processQuery (std::string_view query, bool force_ordering=false) const |
bool | checkAndSetValue (InterfaceHandle pub_id, const char *data, uint64_t len) |
void | routeMessage (const ActionMessage &msg) |
void | routeMessage (ActionMessage &&msg) |
void | createInterface (InterfaceType htype, InterfaceHandle handle, std::string_view key, std::string_view type, std::string_view units, uint16_t flags) |
void | closeInterface (InterfaceHandle handle, InterfaceType type) |
void | sendCommand (ActionMessage &command) |
std::pair< std::string, std::string > | getCommand () |
std::pair< std::string, std::string > | waitCommand () |
Public Attributes | |
LocalFederateId | local_id |
id code for the local federate descriptor | |
std::atomic< GlobalFederateId > | global_id |
global id code, default to invalid | |
std::atomic< bool > | init_transmitted {false} |
int | indexGroup {0} |
storage for index group location (this only matters on construction so can be public) | |
std::atomic< bool > | initRequested {false} |
std::atomic< bool > | requestingMode {false} |
std::atomic< bool > | initIterating {false} |
class managing the information about a single federate
helics::FederateState::FederateState | ( | const std::string & | fedName, |
const CoreFederateInfo & | fedInfo | ||
) |
constructor from name and information structure
References routeMessage().
|
delete |
DISABLE_COPY_AND_ASSIGN
|
default |
destructor
void helics::FederateState::addAction | ( | ActionMessage && | action | ) |
move a message to the queue
void helics::FederateState::addAction | ( | const ActionMessage & | action | ) |
add an action message to the queue
References helics::ActionMessage::action().
Referenced by helics::CommonCore::enterExecutingMode(), helics::CommonCore::removeTarget(), helics::CommonCore::requestTimeIterative(), and helics::CommonCore::timeRequest().
bool helics::FederateState::checkAndSetValue | ( | InterfaceHandle | pub_id, |
const char * | data, | ||
uint64_t | len | ||
) |
check if a value should be published or not and if needed archive it as a changed value for future change detection
pub_id | the handle of the publication |
data | the raw data to check |
len | the length of the data |
References helics::PublicationInfo::CheckSetValue().
Referenced by helics::CommonCore::setValue().
void helics::FederateState::closeInterface | ( | InterfaceHandle | handle, |
InterfaceType | type | ||
) |
close an interface
References helics::ActionMessage::actionTime, helics::ActionMessage::setDestination(), and helics::ActionMessage::setSource().
void helics::FederateState::createInterface | ( | InterfaceType | htype, |
InterfaceHandle | handle, | ||
std::string_view | key, | ||
std::string_view | type, | ||
std::string_view | units, | ||
uint16_t | flags | ||
) |
int helics::FederateState::endpointCount | ( | ) | const |
get the number of endpoints
iteration_time helics::FederateState::enterExecutingMode | ( | IterationRequest | iterate, |
bool | sendRequest = false |
||
) |
function to call when entering execution state
iterate | indicator of whether the fed should iterate if need be or not |
sendRequest | generates the local actionMessage inside the function leaving to false assumes the caller generated the message returns either converged or nonconverged depending on whether an iteration is needed |
References helics::indicator_flag, helics::setActionFlag(), helics::setIterationFlags(), helics::ActionMessage::source_id, and helics::timeZero.
Referenced by helics::CommonCore::enterExecutingMode().
IterationResult helics::FederateState::enterInitializingMode | ( | IterationRequest | request | ) |
process until the initialization state has been entered, an iteration request granted or there is a failure
request | the desired iteration condition |
Referenced by helics::CommonCore::enterInitializingMode().
void helics::FederateState::finalize | ( | ) |
function to process the queue until a disconnect_fed_ack is received
References helics::ActionMessage::actionTime, helics::ActionMessage::counter, helics::ActionMessage::setExtraData(), and helics::timeZero.
void helics::FederateState::forceProcessMessage | ( | ActionMessage & | action | ) |
force processing of a specific message out of order
MessageProcessingResult helics::FederateState::genericUnspecifiedQueueProcess | ( | bool | busyReturn | ) |
function to process the queue in a generic fashion used to just process messages with no specific end in mind
busyReturn | if set to true will return if the federate is already processing |
const std::vector< std::shared_ptr< const SmallBuffer > > & helics::FederateState::getAllValues | ( | InterfaceHandle | handle | ) |
Return all the available data for the specified handle or the latest input
Referenced by helics::CommonCore::getAllValues().
std::pair< std::string, std::string > helics::FederateState::getCommand | ( | ) |
get a command for a federate from its queue
References HELICS_SEQUENCING_MODE_FAST.
Referenced by helics::CommonCore::getCommand().
int32_t helics::FederateState::getCurrentIteration | ( | ) | const |
get the current iteration counter for an iterative call
this will work properly even when a federate is processing
Referenced by helics::CommonCore::requestTimeIterative(), and helics::CommonCore::setValue().
std::vector< GlobalFederateId > helics::FederateState::getDependencies | ( | ) | const |
get a vector of the federates this one depends on
std::vector< GlobalFederateId > helics::FederateState::getDependents | ( | ) | const |
get a vector to the global ids of dependent federates
const std::vector< InterfaceHandle > & helics::FederateState::getEvents | ( | ) | const |
get a reference to the handles of subscriptions with value updates
Referenced by helics::CommonCore::getValueUpdates().
int32_t helics::FederateState::getHandleOption | ( | InterfaceHandle | handle, |
char | iType, | ||
int32_t | option | ||
) | const |
get the currently active option for a handle
|
inline |
get the name of the federate
Referenced by helics::CommonCore::getFederateName(), and helics::CommonCore::setValue().
int helics::FederateState::getIntegerProperty | ( | int | intProperty | ) | const |
get an option flag value
Referenced by helics::CommonCore::getIntegerProperty().
|
inline |
get the currently active interface flags
Referenced by helics::CommonCore::registerDataSink(), helics::CommonCore::registerEndpoint(), helics::CommonCore::registerInput(), helics::CommonCore::registerPublication(), and helics::CommonCore::registerTargetedEndpoint().
std::vector< std::pair< GlobalHandle, std::string_view > > helics::FederateState::getMessageDestinations | ( | InterfaceHandle | handle | ) |
get a list of the endpoints a message should be sent to
handle | the endpoint handle to use |
Referenced by helics::CommonCore::send(), helics::CommonCore::sendAt(), helics::CommonCore::sendMessage(), helics::CommonCore::sendTo(), and helics::CommonCore::sendToAt().
bool helics::FederateState::getOptionFlag | ( | int | optionFlag | ) | const |
get an option flag value
Referenced by helics::CommonCore::registerFederate().
std::pair< SmallBuffer, Time > helics::FederateState::getPublishedValue | ( | InterfaceHandle | handle | ) |
getPublishedValue
uint64_t helics::FederateState::getQueueSize | ( | ) | const |
get the sum of all message queue sizes i.e. the total number of messages available in all endpoints
uint64_t helics::FederateState::getQueueSize | ( | InterfaceHandle | hid | ) | const |
get the size of a message queue for a specific endpoint or filter handle
References helics::EndpointInfo::availableMessages().
Referenced by helics::CommonCore::receiveCount(), and helics::CommonCore::receiveCountAny().
FederateStates helics::FederateState::getState | ( | ) | const |
get the current state of the federate
Referenced by helics::CommonCore::enterExecutingMode(), helics::CommonCore::enterInitializingMode(), helics::CommonCore::processCommunications(), helics::CommonCore::receive(), helics::CommonCore::receiveAny(), helics::CommonCore::receiveCountAny(), helics::CommonCore::registerFederate(), helics::CommonCore::requestTimeIterative(), and helics::CommonCore::timeRequest().
std::vector< GlobalHandle > helics::FederateState::getSubscribers | ( | InterfaceHandle | handle | ) |
get a list of current subscribers to a publication
handle | the publication handle to use |
Referenced by helics::CommonCore::setValue().
const std::string & helics::FederateState::getTag | ( | std::string_view | tag | ) | const |
search for a tag by name
|
inline |
get a tag (key-value pair) by index
Time helics::FederateState::getTimeProperty | ( | int | timeProperty | ) | const |
get a time Property
Referenced by helics::CommonCore::getTimeProperty().
const std::shared_ptr< const SmallBuffer > & helics::FederateState::getValue | ( | InterfaceHandle | handle, |
uint32_t * | inputIndex | ||
) |
Return the data for the specified handle or the latest input
Referenced by helics::CommonCore::getValue().
|
inline |
get the granted time of a federate
Referenced by helics::CommonCore::enterExecutingMode(), helics::CommonCore::getCurrentTime(), and helics::CommonCore::removeTarget().
int helics::FederateState::inputCount | ( | ) | const |
get the number of inputs
|
inline |
get the information that comes from the interface including timing information
Referenced by helics::CommonCore::getDestinationTargets(), helics::CommonCore::getInjectionType(), helics::CommonCore::getInjectionUnits(), and helics::CommonCore::getSourceTargets().
|
inline |
const version of the interface info retrieval function
|
inline |
return true if the federate is callback based
Referenced by helics::CommonCore::enterExecutingMode(), helics::CommonCore::enterInitializingMode(), helics::CommonCore::processCommunications(), helics::CommonCore::requestTimeIterative(), and helics::CommonCore::timeRequest().
|
inlinenoexcept |
get the last error code
Referenced by helics::CommonCore::timeRequest().
|
inline |
get the last error string
Referenced by helics::CommonCore::timeRequest().
|
inline |
locks the processing so FederateState can be used with lock_guard
References sleeplock().
int helics::FederateState::loggingLevel | ( | ) | const |
get the current logging level
Referenced by helics::CommonCore::sendMessage(), and helics::CommonCore::setValue().
void helics::FederateState::logMessage | ( | int | level, |
std::string_view | logMessageSource, | ||
std::string_view | message, | ||
bool | fromRemote = false |
||
) | const |
log a message to the federate Logger
level | the logging level of the message |
logMessageSource | the name of the object that sent the message |
message | the message to log |
fromRemote | indicator that the message is from a remote source and should be treated accordingly |
References helics::fedStateString(), and helics::timeZero.
Referenced by helics::CommonCore::sendMessage(), and helics::CommonCore::setValue().
|
inline |
get allowable message time
Referenced by helics::CommonCore::send(), helics::CommonCore::sendAt(), helics::CommonCore::sendMessage(), helics::CommonCore::sendTo(), helics::CommonCore::sendToAt(), and helics::CommonCore::setValue().
void helics::FederateState::processCommunications | ( | std::chrono::milliseconds | period | ) |
process incoming messages for a certain amount of time
References helics::ActionMessage::messageID, and helics::ActionMessage::source_id.
Referenced by helics::CommonCore::processCommunications().
std::optional< ActionMessage > helics::FederateState::processPostTerminationAction | ( | const ActionMessage & | action | ) |
sometime a message comes in after a federate has terminated and may require a response
References helics::ActionMessage::action(), and helics::ActionMessage::source_id.
std::string helics::FederateState::processQuery | ( | std::string_view | query, |
bool | force_ordering = false |
||
) | const |
generate the result of a query string
query | a query string |
force_ordering | true if the query should be processed in a force_ordering way |
References helics::fedStateString().
int helics::FederateState::publicationCount | ( | ) | const |
get the number of publications
std::unique_ptr< Message > helics::FederateState::receive | ( | InterfaceHandle | hid | ) |
get the next available message for an endpoint
hid | the handle of an endpoint or filter |
References helics::EndpointInfo::getMessage().
Referenced by helics::CommonCore::receive().
std::unique_ptr< Message > helics::FederateState::receiveAny | ( | InterfaceHandle & | hid | ) |
get any message ready for reception
[out] | hid | the endpoint related to the message |
References helics::EndpointInfo::getMessage(), helics::GlobalHandle::handle, and helics::EndpointInfo::id.
Referenced by helics::CommonCore::receiveAny().
iteration_time helics::FederateState::requestTime | ( | Time | nextTime, |
IterationRequest | iterate, | ||
bool | sendRequest = false |
||
) |
request a time advancement
nextTime | the time of the requested advancement |
iterate | the type of iteration requested |
sendRequest | generates the local actionMessage inside the function leaving to false assumes the caller generated the message |
Referenced by helics::CommonCore::requestTimeIterative(), and helics::CommonCore::timeRequest().
void helics::FederateState::reset | ( | const CoreFederateInfo & | fedInfo | ) |
reset the federate to created state
References HELICS_LOG_LEVEL_NO_PRINT, init_transmitted, initRequested, helics::NO_ITERATIONS, helics::InterfaceInfo::reset(), routeMessage(), and helics::timeZero.
Referenced by helics::CommonCore::registerFederate().
void helics::FederateState::routeMessage | ( | ActionMessage && | msg | ) |
move a message either to parent or add to queue
void helics::FederateState::routeMessage | ( | const ActionMessage & | msg | ) |
route a message either forward to parent or add to queue
References helics::ActionMessage::action().
Referenced by FederateState(), and reset().
void helics::FederateState::sendCommand | ( | ActionMessage & | command | ) |
send a command to a federate
References helics::ActionMessage::action(), helics::ActionMessage::dest_id, HELICS_LOG_LEVEL_NO_PRINT, helics::ActionMessage::payload, helics::ActionMessage::source_id, and helics::SmallBuffer::to_string().
|
inline |
set the federate callback operator
void helics::FederateState::setCoreObject | ( | CommonCore * | parent | ) |
set the managing core object
void helics::FederateState::setInterfaceProperty | ( | const ActionMessage & | cmd | ) |
set a property on a specific interface
References helics::ActionMessage::action(), helics::checkActionFlag(), helics::ActionMessage::counter, helics::ActionMessage::dest_handle, helics::ActionMessage::getExtraDestData(), helics::indicator_flag, and helics::ActionMessage::messageID.
void helics::FederateState::setLogger | ( | std::function< void(int, std::string_view, std::string_view)> | logFunction | ) |
set the logging function
function must have signature void(int level, const std::string &sourceName, const std::string &message)
Referenced by helics::CommonCore::registerFederate(), and helics::CommonCore::setLoggingCallback().
void helics::FederateState::setOptionFlag | ( | int | optionFlag, |
bool | value | ||
) |
set an option Flag on the federate
Referenced by helics::CommonCore::registerFederate().
|
inline |
set the CommonCore object that is managing this Federate
Referenced by helics::CommonCore::registerFederate().
void helics::FederateState::setProperties | ( | const ActionMessage & | cmd | ) |
update the info structure
public call so it also calls the federate lock before calling private update function the action Message should be CMD_FED_CONFIGURE
References helics::ActionMessage::action(), helics::ActionMessage::actionTime, helics::checkActionFlag(), helics::ActionMessage::getExtraData(), helics::indicator_flag, and helics::ActionMessage::messageID.
Referenced by helics::CommonCore::setHandleOption(), helics::CommonCore::setIntegerProperty(), and helics::CommonCore::setTimeProperty().
void helics::FederateState::setProperty | ( | int | intProperty, |
int | propertyVal | ||
) |
set an integral property on the federate
void helics::FederateState::setProperty | ( | int | timeProperty, |
Time | propertyVal | ||
) |
set a timeProperty on the federate
|
inline |
set the query callback function
function must have signature std::string(const std::string &query)
Referenced by helics::CommonCore::setQueryCallback().
void helics::FederateState::setTag | ( | std::string_view | tag, |
std::string_view | value | ||
) |
set a tag (key-value pair)
|
inline |
locks the processing with a sleep loop
Referenced by lock().
|
inline |
locks the processing with a busy loop
|
inline |
get the number of tags associated with an interface
|
inline |
tries to lock the processing return true if successful and false if not
|
inline |
unlocks the processing
std::pair< std::string, std::string > helics::FederateState::waitCommand | ( | ) |
wait for a command to a federate
References HELICS_SEQUENCING_MODE_FAST.
Referenced by helics::CommonCore::waitCommand().
IterationResult helics::FederateState::waitSetup | ( | ) |
process until the federate has verified its membership and assigned a global id number
std::atomic<bool> helics::FederateState::init_transmitted {false} |
the initialization request has been transmitted
Referenced by reset().
std::atomic<bool> helics::FederateState::initRequested {false} |
atomic flag indicating this federate has requested entry to initialization
Referenced by helics::CommonCore::enterInitializingMode(), and reset().