helics  2.8.1
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 ()
 
void reInit ()
 
const std::string & getIdentifier () const
 
federate_state getState () const
 
InterfaceInfointerfaces ()
 
const InterfaceInfointerfaces () const
 
uint64_t getQueueSize (interface_handle id) const
 
uint64_t getQueueSize () const
 
int32_t getCurrentIteration () const
 
std::unique_ptr< Messagereceive (interface_handle id)
 
std::unique_ptr< MessagereceiveAny (interface_handle &id)
 
const std::shared_ptr< const data_block > & getValue (interface_handle handle, uint32_t *inputIndex)
 
const std::vector< std::shared_ptr< const data_block > > & getAllValues (interface_handle 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 (interface_handle 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
 
Time grantedTime () const
 
Time nextAllowedSendTime () const
 
const std::vector< interface_handle > & getEvents () const
 
std::vector< global_federate_idgetDependencies () const
 
std::vector< global_federate_idgetDependents () const
 
const std::string & lastErrorString () const
 
int lastErrorCode () const noexcept
 
void setCoreObject (CommonCore *parent)
 
iteration_result waitSetup ()
 
iteration_result enterInitializingMode ()
 
iteration_result enterExecutingMode (iteration_request iterate, bool sendRequest=false)
 
iteration_time requestTime (Time nextTime, iteration_request iterate, bool sendRequest=false)
 
std::vector< global_handlegetSubscribers (interface_handle handle)
 
iteration_result genericUnspecifiedQueueProcess ()
 
void finalize ()
 
void addAction (const ActionMessage &action)
 
void addAction (ActionMessage &&action)
 
opt< ActionMessageprocessPostTerminationAction (const ActionMessage &action)
 
void logMessage (int level, const std::string &logMessageSource, const std::string &message) const
 
void setLogger (std::function< void(int, const std::string &, const std::string &)> logFunction)
 
void setQueryCallback (std::function< std::string(const std::string &)> queryCallbackFunction)
 
std::string processQuery (const std::string &query, bool force_ordering=false) const
 
bool checkAndSetValue (interface_handle pub_id, const char *data, uint64_t len)
 
void routeMessage (const ActionMessage &msg)
 
void createInterface (handle_type htype, interface_handle handle, const std::string &key, const std::string &type, const std::string &units)
 
void closeInterface (interface_handle handle, handle_type type)
 

Public Attributes

local_federate_id local_id
 id code for the local federate descriptor
 
std::atomic< global_federate_idglobal_id
 global id code, default to invalid
 
std::atomic< bool > init_transmitted {false}
 the initialization request has been transmitted
 
std::atomic< bool > init_requested
 this federate has requested entry to initialization More...
 
std::atomic< bool > requestingMode {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 ( interface_handle  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(), and data.

◆ closeInterface()

void helics::FederateState::closeInterface ( interface_handle  handle,
handle_type  type 
)

◆ createInterface()

void helics::FederateState::createInterface ( handle_type  htype,
interface_handle  handle,
const std::string &  key,
const std::string &  type,
const std::string &  units 
)

create an interface

References checkActionFlag(), and required_flag.

◆ endpointCount()

int helics::FederateState::endpointCount ( ) const

get the number of endpoints

◆ enterExecutingMode()

iteration_result helics::FederateState::enterExecutingMode ( iteration_request  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

References error, helics::HELICS_ERROR, helics::HELICS_FINISHED, indicator_flag, helics::initializationTime, setActionFlag(), helics::setIterationFlags(), helics::ActionMessage::source_id, and helics::timeZero.

◆ enterInitializingMode()

iteration_result helics::FederateState::enterInitializingMode ( )

process until the initialization state has been entered or there is a failure

References error, helics::HELICS_ERROR, and helics::HELICS_FINISHED.

◆ finalize()

void helics::FederateState::finalize ( )

function to process the queue until a disconnect_fed_ack is received

References error, helics::HELICS_ERROR, and helics::HELICS_FINISHED.

◆ genericUnspecifiedQueueProcess()

iteration_result helics::FederateState::genericUnspecifiedQueueProcess ( )

function to process the queue in a generic fashion used to just process messages with no specific end in mind

◆ getAllValues()

const std::vector< std::shared_ptr< const data_block > > & helics::FederateState::getAllValues ( interface_handle  handle)

Return all the available data for the specified handle or the latest input

References interfaces.

◆ 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

◆ getDependencies()

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

get a vector of the federates this one depends on

◆ getDependents()

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

get a vector to the global ids of dependent federates

◆ getEvents()

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

get a reference to the handles of subscriptions with value updates

◆ getHandleOption()

int32_t helics::FederateState::getHandleOption ( interface_handle  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

◆ getIntegerProperty()

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

get an option flag value

◆ getInterfaceFlags()

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

get the currently active interface flags

◆ getOptionFlag()

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

get an option flag value

◆ 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 ( interface_handle  id) const

get the size of a message queue for a specific endpoint or filter handle

References helics::EndpointInfo::availableMessages().

◆ getState()

federate_state helics::FederateState::getState ( ) const

get the current state of the federate

◆ getSubscribers()

std::vector< global_handle > helics::FederateState::getSubscribers ( interface_handle  handle)

get a list of current subscribers to a publication

Parameters
handlethe publication handle to use

◆ getTimeProperty()

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

get a time Property

◆ getValue()

const std::shared_ptr< const data_block > & helics::FederateState::getValue ( interface_handle  handle,
uint32_t *  inputIndex 
)

Return the data for the specified handle or the latest input

References interfaces.

◆ grantedTime()

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

get the granted time of a federate

◆ 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

◆ interfaces() [2/2]

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

const version of the interface info retrieval function

◆ lastErrorCode()

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

get the last error code

◆ lastErrorString()

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

get the last error string

◆ 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
inline

get the current logging level

◆ logMessage()

void helics::FederateState::logMessage ( int  level,
const std::string &  logMessageSource,
const std::string &  message 
) 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

◆ nextAllowedSendTime()

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

get allowable message time

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

◆ processPostTerminationAction()

stx::optional< ActionMessage > helics::FederateState::processPostTerminationAction ( const ActionMessage action)

sometime a message comes in after a federate has terminated and may require a response

◆ processQuery()

std::string helics::FederateState::processQuery ( const std::string &  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

◆ publicationCount()

int helics::FederateState::publicationCount ( ) const

get the number of publications

◆ receive()

std::unique_ptr< Message > helics::FederateState::receive ( interface_handle  id)

get the next available message for an endpoint

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

◆ receiveAny()

std::unique_ptr< Message > helics::FederateState::receiveAny ( interface_handle id)

get any message ready for reception

Parameters
[out]idthe endpoint related to the message

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

◆ reInit()

void helics::FederateState::reInit ( )

reset the federate to the initializing state

References helics::HELICS_INITIALIZING.

◆ requestTime()

iteration_time helics::FederateState::requestTime ( Time  nextTime,
iteration_request  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 convergence state

◆ reset()

void helics::FederateState::reset ( )

reset the federate to created state

References global_id, local_id, and helics::InterfaceInfo::setGlobalId().

◆ routeMessage()

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

◆ setCoreObject()

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

set the managing core object

◆ setInterfaceProperty()

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

set a property on a specific interface

References checkActionFlag(), and indicator_flag.

◆ setLogger()

void helics::FederateState::setLogger ( std::function< void(int, const std::string &, const std::string &)>  logFunction)
inline

set the logging function

function must have signature void(int level, const std::string &sourceName, const std::string &message)

◆ setOptionFlag()

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

set an option Flag for a the coordinator

◆ setParent()

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

set the CommonCore object that is managing this Federate

◆ 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

◆ setProperty() [1/2]

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

set a timeProperty for a the coordinator

◆ setProperty() [2/2]

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

set a timeProperty for a the coordinator

◆ setQueryCallback()

void helics::FederateState::setQueryCallback ( std::function< std::string(const std::string &)>  queryCallbackFunction)
inline

set the query callback function

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

◆ 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

◆ 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

◆ waitSetup()

iteration_result helics::FederateState::waitSetup ( )

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

Member Data Documentation

◆ init_requested

std::atomic<bool> helics::FederateState::init_requested
Initial value:
{
false}

this federate has requested entry to initialization


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