helics  3.5.2
Public Member Functions | Public Attributes | List of all members
helics::FederateState Class Reference

#include <FederateState.hpp>

Public Member Functions

 FederateState (const std::string &fedName, const CoreFederateInfo &fedInfo)
 
 FederateState (const FederateState &)=delete
 
FederateStateoperator= (const FederateState &)=delete
 
 ~FederateState ()
 
void reset (const CoreFederateInfo &fedInfo)
 
const std::string & getIdentifier () const
 
FederateStates getState () const
 
InterfaceInfointerfaces ()
 
const InterfaceInfointerfaces () const
 
uint64_t getQueueSize (InterfaceHandle hid) const
 
uint64_t getQueueSize () const
 
int32_t getCurrentIteration () const
 
std::unique_ptr< Messagereceive (InterfaceHandle hid)
 
std::unique_ptr< MessagereceiveAny (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, TimegetPublishedValue (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< GlobalFederateIdgetDependencies () const
 
std::vector< GlobalFederateIdgetDependents () 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< GlobalHandlegetSubscribers (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< ActionMessageprocessPostTerminationAction (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< GlobalFederateIdglobal_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}
 

Detailed Description

class managing the information about a single federate

Constructor & Destructor Documentation

◆ FederateState() [1/2]

helics::FederateState::FederateState ( const std::string &  fedName,
const CoreFederateInfo fedInfo 
)

constructor from name and information structure

References routeMessage().

◆ FederateState() [2/2]

helics::FederateState::FederateState ( const FederateState )
delete

DISABLE_COPY_AND_ASSIGN

◆ ~FederateState()

helics::FederateState::~FederateState ( )
default

destructor

Member Function Documentation

◆ addAction() [1/2]

void helics::FederateState::addAction ( ActionMessage &&  action)

move a message to the queue

◆ addAction() [2/2]

void helics::FederateState::addAction ( const ActionMessage action)

◆ checkAndSetValue()

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

Parameters
pub_idthe handle of the publication
datathe raw data to check
lenthe length of the data
Returns
true if it should be published, false if not

References helics::PublicationInfo::CheckSetValue().

Referenced by helics::CommonCore::setValue().

◆ closeInterface()

void helics::FederateState::closeInterface ( InterfaceHandle  handle,
InterfaceType  type 
)

◆ createInterface()

void helics::FederateState::createInterface ( InterfaceType  htype,
InterfaceHandle  handle,
std::string_view  key,
std::string_view  type,
std::string_view  units,
uint16_t  flags 
)

◆ endpointCount()

int helics::FederateState::endpointCount ( ) const

get the number of endpoints

◆ enterExecutingMode()

iteration_time helics::FederateState::enterExecutingMode ( IterationRequest  iterate,
bool  sendRequest = false 
)

function to call when entering execution state

Parameters
iterateindicator of whether the fed should iterate if need be or not
sendRequestgenerates 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
Returns
an iteration time with two elements the granted time and the iteration result. The time will usually be 0 unless the federate is joining dynamically

References helics::indicator_flag, helics::setActionFlag(), helics::setIterationFlags(), helics::ActionMessage::source_id, and helics::timeZero.

Referenced by helics::CommonCore::enterExecutingMode().

◆ enterInitializingMode()

IterationResult helics::FederateState::enterInitializingMode ( IterationRequest  request)

process until the initialization state has been entered, an iteration request granted or there is a failure

Parameters
requestthe desired iteration condition
Returns
the result of the iteration request

Referenced by helics::CommonCore::enterInitializingMode().

◆ finalize()

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.

◆ forceProcessMessage()

void helics::FederateState::forceProcessMessage ( ActionMessage action)

force processing of a specific message out of order

◆ genericUnspecifiedQueueProcess()

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

Parameters
busyReturnif set to true will return if the federate is already processing

◆ getAllValues()

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().

◆ getCommand()

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().

◆ getCurrentIteration()

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().

◆ getDependencies()

std::vector< GlobalFederateId > helics::FederateState::getDependencies ( ) const

get a vector of the federates this one depends on

◆ getDependents()

std::vector< GlobalFederateId > helics::FederateState::getDependents ( ) const

get a vector to the global ids of dependent federates

◆ getEvents()

const std::vector< InterfaceHandle > & helics::FederateState::getEvents ( ) const

get a reference to the handles of subscriptions with value updates

Referenced by helics::CommonCore::getValueUpdates().

◆ getHandleOption()

int32_t helics::FederateState::getHandleOption ( InterfaceHandle  handle,
char  iType,
int32_t  option 
) const

get the currently active option for a handle

◆ getIdentifier()

const std::string& helics::FederateState::getIdentifier ( ) const
inline

get the name of the federate

Referenced by helics::CommonCore::getFederateName(), and helics::CommonCore::setValue().

◆ getIntegerProperty()

int helics::FederateState::getIntegerProperty ( int  intProperty) const

get an option flag value

Referenced by helics::CommonCore::getIntegerProperty().

◆ getInterfaceFlags()

uint16_t helics::FederateState::getInterfaceFlags ( ) const
inline

◆ getMessageDestinations()

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

Parameters
handlethe endpoint handle to use

Referenced by helics::CommonCore::send(), helics::CommonCore::sendAt(), helics::CommonCore::sendMessage(), helics::CommonCore::sendTo(), and helics::CommonCore::sendToAt().

◆ getOptionFlag()

bool helics::FederateState::getOptionFlag ( int  optionFlag) const

get an option flag value

Referenced by helics::CommonCore::registerFederate().

◆ getPublishedValue()

std::pair< SmallBuffer, Time > helics::FederateState::getPublishedValue ( InterfaceHandle  handle)

getPublishedValue

◆ getQueueSize() [1/2]

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

◆ getQueueSize() [2/2]

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().

◆ getState()

FederateStates helics::FederateState::getState ( ) const

◆ getSubscribers()

std::vector< GlobalHandle > helics::FederateState::getSubscribers ( InterfaceHandle  handle)

get a list of current subscribers to a publication

Parameters
handlethe publication handle to use

Referenced by helics::CommonCore::setValue().

◆ getTag()

const std::string & helics::FederateState::getTag ( std::string_view  tag) const

search for a tag by name

◆ getTagByIndex()

const std::pair<std::string, std::string>& helics::FederateState::getTagByIndex ( size_t  index) const
inline

get a tag (key-value pair) by index

◆ getTimeProperty()

Time helics::FederateState::getTimeProperty ( int  timeProperty) const

get a time Property

Referenced by helics::CommonCore::getTimeProperty().

◆ getValue()

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().

◆ grantedTime()

Time helics::FederateState::grantedTime ( ) const
inline

◆ inputCount()

int helics::FederateState::inputCount ( ) const

get the number of inputs

◆ interfaces() [1/2]

InterfaceInfo& helics::FederateState::interfaces ( )
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().

◆ interfaces() [2/2]

const InterfaceInfo& helics::FederateState::interfaces ( ) const
inline

const version of the interface info retrieval function

◆ isCallbackFederate()

bool helics::FederateState::isCallbackFederate ( ) const
inline

◆ lastErrorCode()

int helics::FederateState::lastErrorCode ( ) const
inlinenoexcept

get the last error code

Referenced by helics::CommonCore::timeRequest().

◆ lastErrorString()

const std::string& helics::FederateState::lastErrorString ( ) const
inline

get the last error string

Referenced by helics::CommonCore::timeRequest().

◆ lock()

void helics::FederateState::lock ( )
inline

locks the processing so FederateState can be used with lock_guard

References sleeplock().

◆ loggingLevel()

int helics::FederateState::loggingLevel ( ) const

get the current logging level

Referenced by helics::CommonCore::sendMessage(), and helics::CommonCore::setValue().

◆ logMessage()

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

Parameters
levelthe logging level of the message
logMessageSourcethe name of the object that sent the message
messagethe message to log
fromRemoteindicator 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().

◆ nextAllowedSendTime()

Time helics::FederateState::nextAllowedSendTime ( ) const
inline

◆ processCommunications()

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().

◆ processPostTerminationAction()

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.

◆ processQuery()

std::string helics::FederateState::processQuery ( std::string_view  query,
bool  force_ordering = false 
) const

generate the result of a query string

Parameters
querya query string
force_orderingtrue if the query should be processed in a force_ordering way
Returns
the resulting string from the query or "#wait" if the federate is not available to answer immediately

References helics::fedStateString().

◆ publicationCount()

int helics::FederateState::publicationCount ( ) const

get the number of publications

◆ receive()

std::unique_ptr< Message > helics::FederateState::receive ( InterfaceHandle  hid)

get the next available message for an endpoint

Parameters
hidthe handle of an endpoint or filter
Returns
a pointer to a message -the ownership of the message is transferred to the caller

References helics::EndpointInfo::getMessage().

Referenced by helics::CommonCore::receive().

◆ receiveAny()

std::unique_ptr< Message > helics::FederateState::receiveAny ( InterfaceHandle hid)

get any message ready for reception

Parameters
[out]hidthe endpoint related to the message

References helics::EndpointInfo::getMessage(), helics::GlobalHandle::handle, and helics::EndpointInfo::id.

Referenced by helics::CommonCore::receiveAny().

◆ requestTime()

iteration_time helics::FederateState::requestTime ( Time  nextTime,
IterationRequest  iterate,
bool  sendRequest = false 
)

request a time advancement

Parameters
nextTimethe time of the requested advancement
iteratethe type of iteration requested
sendRequestgenerates the local actionMessage inside the function leaving to false assumes the caller generated the message
Returns
an iteration time with two elements the granted time and the iteration result

Referenced by helics::CommonCore::requestTimeIterative(), and helics::CommonCore::timeRequest().

◆ reset()

void helics::FederateState::reset ( const CoreFederateInfo fedInfo)

◆ routeMessage() [1/2]

void helics::FederateState::routeMessage ( ActionMessage &&  msg)

move a message either to parent or add to queue

◆ routeMessage() [2/2]

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().

◆ sendCommand()

void helics::FederateState::sendCommand ( ActionMessage command)

◆ setCallbackOperator()

void helics::FederateState::setCallbackOperator ( std::shared_ptr< FederateOperator fed)
inline

set the federate callback operator

◆ setCoreObject()

void helics::FederateState::setCoreObject ( CommonCore parent)

set the managing core object

◆ setInterfaceProperty()

void helics::FederateState::setInterfaceProperty ( const ActionMessage cmd)

◆ setLogger()

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().

◆ setOptionFlag()

void helics::FederateState::setOptionFlag ( int  optionFlag,
bool  value 
)

set an option Flag on the federate

Referenced by helics::CommonCore::registerFederate().

◆ setParent()

void helics::FederateState::setParent ( CommonCore coreObject)
inline

set the CommonCore object that is managing this Federate

Referenced by helics::CommonCore::registerFederate().

◆ setProperties()

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().

◆ setProperty() [1/2]

void helics::FederateState::setProperty ( int  intProperty,
int  propertyVal 
)

set an integral property on the federate

◆ setProperty() [2/2]

void helics::FederateState::setProperty ( int  timeProperty,
Time  propertyVal 
)

set a timeProperty on the federate

◆ setQueryCallback()

void helics::FederateState::setQueryCallback ( std::function< std::string(std::string_view)>  queryCallbackFunction,
int  order 
)
inline

set the query callback function

function must have signature std::string(const std::string &query)

Referenced by helics::CommonCore::setQueryCallback().

◆ setTag()

void helics::FederateState::setTag ( std::string_view  tag,
std::string_view  value 
)

set a tag (key-value pair)

◆ sleeplock()

void helics::FederateState::sleeplock ( ) const
inline

locks the processing with a sleep loop

Referenced by lock().

◆ spinlock()

void helics::FederateState::spinlock ( ) const
inline

locks the processing with a busy loop

◆ tagCount()

auto helics::FederateState::tagCount ( ) const
inline

get the number of tags associated with an interface

◆ try_lock()

bool helics::FederateState::try_lock ( ) const
inline

tries to lock the processing return true if successful and false if not

◆ unlock()

void helics::FederateState::unlock ( ) const
inline

unlocks the processing

◆ waitCommand()

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().

◆ waitSetup()

IterationResult helics::FederateState::waitSetup ( )

process until the federate has verified its membership and assigned a global id number

Member Data Documentation

◆ init_transmitted

std::atomic<bool> helics::FederateState::init_transmitted {false}

the initialization request has been transmitted

Referenced by reset().

◆ initRequested

std::atomic<bool> helics::FederateState::initRequested {false}

atomic flag indicating this federate has requested entry to initialization

Referenced by helics::CommonCore::enterInitializingMode(), and reset().


The documentation for this class was generated from the following files: