helics  2.8.1
Public Member Functions | Protected Member Functions | List of all members
helics::MessageFederate Class Reference

#include <MessageFederate.hpp>

+ Inheritance diagram for helics::MessageFederate:

Public Member Functions

 MessageFederate (const std::string &fedName, const FederateInfo &fi)
 
 MessageFederate (const std::string &fedName, const std::shared_ptr< Core > &core, const FederateInfo &fi=FederateInfo{})
 
 MessageFederate (const std::string &fedName, CoreApp &core, const FederateInfo &fi=FederateInfo{})
 
 MessageFederate (const std::string &name, const std::string &configString)
 
 MessageFederate (const std::string &configString)
 
 MessageFederate (const char *configString)
 
 MessageFederate (MessageFederate &&mFed) noexcept
 
 MessageFederate (const MessageFederate &mFed)=delete
 
 MessageFederate ()
 
 MessageFederate (bool res)
 
virtual ~MessageFederate ()
 
MessageFederateoperator= (MessageFederate &&mFed) noexcept
 
MessageFederateoperator= (const MessageFederate &mFed)=delete
 
EndpointregisterEndpoint (const std::string &eptName=std::string(), const std::string &type=std::string())
 
EndpointregisterGlobalEndpoint (const std::string &eptName, const std::string &type=std::string())
 
EndpointregisterIndexedEndpoint (const std::string &eptName, int index1, const std::string &type=std::string())
 
virtual void registerInterfaces (const std::string &configString) override
 
void registerMessageInterfaces (const std::string &configString)
 
void registerKnownCommunicationPath (const Endpoint &localEndpoint, const std::string &remoteEndpoint)
 
void subscribe (const Endpoint &ept, const std::string &key)
 
bool hasMessage () const
 
bool hasMessage (const Endpoint &ept) const
 
uint64_t pendingMessages (const Endpoint &ept) const
 
uint64_t pendingMessages () const
 
std::unique_ptr< MessagegetMessage (const Endpoint &ept)
 
std::unique_ptr< MessagegetMessage ()
 
void sendMessage (const Endpoint &source, const std::string &dest, const char *data, size_t dataLength)
 
void sendMessage (const Endpoint &source, const std::string &dest, const data_view &message)
 
void sendMessage (const Endpoint &source, const std::string &dest, const char *data, size_t dataLength, Time sendTime)
 
void sendMessage (const Endpoint &source, const std::string &dest, const data_view &message, Time sendTime)
 
void sendMessage (const Endpoint &source, std::unique_ptr< Message > message)
 
void sendMessage (const Endpoint &source, const Message &message)
 
EndpointgetEndpoint (const std::string &name) const
 
EndpointgetEndpoint (int index) const
 
void setMessageNotificationCallback (const std::function< void(Endpoint &, Time)> &callback)
 
void setMessageNotificationCallback (const Endpoint &ept, const std::function< void(Endpoint &, Time)> &callback)
 
void addSourceFilter (const Endpoint &ept, const std::string &filterName)
 
void addDestinationFilter (const Endpoint &ept, const std::string &filterName)
 
virtual void disconnect () override
 
int getEndpointCount () const
 
- Public Member Functions inherited from helics::Federate
 Federate (const std::string &fedname, const FederateInfo &fi)
 
 Federate (const std::string &fedname, const std::shared_ptr< Core > &core, const FederateInfo &fi=FederateInfo{})
 
 Federate (const std::string &fedname, CoreApp &core, const FederateInfo &fi=FederateInfo{})
 
 Federate (const std::string &configString)
 
 Federate (const std::string &fedname, const std::string &configString)
 
 Federate () noexcept
 
 Federate (Federate &&fed) noexcept
 
 Federate (const Federate &fed)=delete
 
virtual ~Federate ()
 
Federateoperator= (Federate &&fed) noexcept
 
Federateoperator= (const Federate &fed)=delete
 
void enterInitializingMode ()
 
void enterInitializingModeAsync ()
 
bool isAsyncOperationCompleted () const
 
void enterInitializingModeComplete ()
 
iteration_result enterExecutingMode (iteration_request iterate=iteration_request::no_iterations)
 
void enterExecutingModeAsync (iteration_request iterate=iteration_request::no_iterations)
 
iteration_result enterExecutingModeComplete ()
 
void finalize ()
 
void finalizeAsync ()
 
void finalizeComplete ()
 
void error (int errorcode)
 
void error (int errorcode, const std::string &message)
 
void localError (int errorcode, const std::string &message)
 
void globalError (int errorcode, const std::string &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, iteration_request iterate)
 
void requestTimeAsync (Time nextInternalTimeStep)
 
void requestTimeIterativeAsync (Time nextInternalTimeStep, iteration_request iterate)
 
Time requestTimeComplete ()
 
iteration_time requestTimeIterativeComplete ()
 
void setProperty (int32_t option, double timeValue)
 
void setProperty (int32_t option, Time timeValue)
 
virtual void setFlagOption (int flag, bool flagValue=true)
 
void setProperty (int32_t option, int32_t optionValue)
 
Time getTimeProperty (int32_t option) const
 
virtual bool getFlagOption (int flag) const
 
int getIntegerProperty (int32_t option) const
 
void setLoggingCallback (const std::function< void(int, const std::string &, const std::string &)> &logFunction)
 
std::string query (const std::string &target, const std::string &queryStr, helics_sequencing_mode mode=helics_sequencing_mode_fast)
 
std::string query (const std::string &queryStr, helics_sequencing_mode mode=helics_sequencing_mode_fast)
 
query_id_t queryAsync (const std::string &target, const std::string &queryStr, helics_sequencing_mode mode=helics_sequencing_mode_fast)
 
query_id_t queryAsync (const std::string &queryStr, helics_sequencing_mode mode=helics_sequencing_mode_fast)
 
std::string queryComplete (query_id_t queryIndex)
 
bool isQueryCompleted (query_id_t queryIndex) const
 
void setQueryCallback (const std::function< std::string(const std::string &)> &queryFunction)
 
void setGlobal (const std::string &valueName, const std::string &value)
 
void addDependency (const std::string &fedName)
 
FilterregisterGlobalFilter (const std::string &filterName, const std::string &inputType=std::string(), const std::string &outputType=std::string())
 
CloningFilterregisterGlobalCloningFilter (const std::string &filterName, const std::string &inputType=std::string(), const std::string &outputType=std::string())
 
FilterregisterFilter (const std::string &filterName, const std::string &inputType=std::string(), const std::string &outputType=std::string())
 
CloningFilterregisterCloningFilter (const std::string &filterName, const std::string &inputType=std::string(), const std::string &outputType=std::string())
 
FilterregisterFilter ()
 
CloningFilterregisterCloningFilter ()
 
void addSourceTarget (const Filter &filt, const std::string &targetEndpoint)
 
void addDestinationTarget (const Filter &filt, const std::string &targetEndpoint)
 
const std::string & getInterfaceName (interface_handle handle) const
 
const FiltergetFilter (const std::string &filterName) const
 
const FiltergetFilter (int index) const
 
FiltergetFilter (const std::string &filterName)
 
FiltergetFilter (int index)
 
void setFilterOperator (const Filter &filt, std::shared_ptr< FilterOperator > op)
 register a operator for the specified filter More...
 
int getFilterCount () const
 
void registerFilterInterfaces (const std::string &configString)
 
void closeInterface (interface_handle handle)
 
auto getID () const noexcept
 
modes getCurrentMode () const
 
Time getCurrentTime () const
 
const std::string & getName () const
 
const std::shared_ptr< Core > & getCorePointer ()
 
int filterCount () const
 
void setInfo (interface_handle handle, const std::string &info)
 
const std::string & getInfo (interface_handle handle)
 
void setInterfaceOption (interface_handle handle, int32_t option, int32_t option_value=1)
 
int32_t getInterfaceOption (interface_handle handle, int32_t option)
 
const std::string & getInjectionType (interface_handle handle) const
 
const std::string & getExtractionType (interface_handle handle) const
 
const std::string & getInjectionUnits (interface_handle handle) const
 
const std::string & getExtractionUnits (interface_handle handle) const
 
const std::string & getInterfaceUnits (interface_handle handle) const
 
void logMessage (int level, const std::string &message) const
 
void logErrorMessage (const std::string &message) const
 
void logWarningMessage (const std::string &message) const
 
void logInfoMessage (const std::string &message) const
 
void logDebugMessage (const std::string &message) const
 
void completeOperation ()
 

Protected Member Functions

virtual void startupToInitializeStateTransition () override
 
virtual void initializeToExecuteStateTransition (iteration_result result) override
 
virtual void updateTime (Time newTime, Time oldTime) override
 
virtual std::string localQuery (const std::string &queryStr) const override
 

Additional Inherited Members

- Public Types inherited from helics::Federate
enum  modes : char {
  modes::startup = 0, modes::initializing = 1, modes::executing = 2, modes::finalize,
  modes::error = 4, modes::pending_init = 5, modes::pending_exec = 6, modes::pending_time = 7,
  modes::pending_iterative_time, modes::pending_finalize = 9, modes::finished = 10
}
 
- Protected Attributes inherited from helics::Federate
std::atomic< modescurrentMode {modes::startup}
 the current state of the simulation
 
char nameSegmentSeparator = '/'
 the separator between automatically prependend names
 
bool strictConfigChecking {true}
 
bool useJsonSerialization {false}
 
std::shared_ptr< CorecoreObject
 reference to the core simulation API
 
Time currentTime = Time::minVal()
 the current simulation time
 

Detailed Description

class defining the block communication based interface

Constructor & Destructor Documentation

◆ MessageFederate() [1/10]

helics::MessageFederate::MessageFederate ( const std::string &  fedName,
const FederateInfo fi 
)

constructor taking a federate information structure and using the default core

Parameters
fedNamethe name of the messageFederate, can be left empty to use a default or one from fi
fia federate information structure

References helics::Federate::coreObject, and helics::Federate::getID().

◆ MessageFederate() [2/10]

helics::MessageFederate::MessageFederate ( const std::string &  fedName,
const std::shared_ptr< Core > &  core,
const FederateInfo fi = FederateInfo{} 
)

constructor taking a core and a federate information structure, core information in fi is ignored

Parameters
fedNamethe name of the messageFederate, can be left empty to use a default or one from fi
corea shared ptr to a core to join
fia federate information structure

References helics::Federate::coreObject, and helics::Federate::getID().

◆ MessageFederate() [3/10]

helics::MessageFederate::MessageFederate ( const std::string &  fedName,
CoreApp core,
const FederateInfo fi = FederateInfo{} 
)

constructor taking a core and a federate information structure, core information in fi is ignored

Parameters
fedNamethe name of the messageFederate, can be left empty to use a default or one from fi
corea CoreApp object representing the core to connect to
fia federate information structure

References helics::Federate::coreObject, and helics::Federate::getID().

◆ MessageFederate() [4/10]

helics::MessageFederate::MessageFederate ( const std::string &  name,
const std::string &  configString 
)

constructor taking a string with the required information

Parameters
namethe name of the federate, can be empty to get name from config
configStringcan be either a JSON file, TOML file or a string containing JSON code

References helics::Federate::coreObject, helics::Federate::getID(), and registerInterfaces().

◆ MessageFederate() [5/10]

helics::MessageFederate::MessageFederate ( const std::string &  configString)
explicit

constructor taking a string with the required information

Parameters
configStringcan be either a JSON file, TOML file or a string containing JSON code, or command line arguments it can also be just the federate name

◆ MessageFederate() [6/10]

helics::MessageFederate::MessageFederate ( const char *  configString)
explicit

constructor taking a string as const char * with the required information

; this constructor is to deconflict with the bool overload which can be triggered if a string literal is passed on some platforms

Parameters
configStringcan be either a JSON file, TOML file or a string containing JSON code, or command line arguments it can also be just the federate name

◆ MessageFederate() [7/10]

helics::MessageFederate::MessageFederate ( MessageFederate &&  mFed)
defaultnoexcept

move constructor

◆ MessageFederate() [8/10]

helics::MessageFederate::MessageFederate ( const MessageFederate mFed)
delete

delete copy constructor

◆ MessageFederate() [9/10]

helics::MessageFederate::MessageFederate ( )

default constructor

◆ MessageFederate() [10/10]

helics::MessageFederate::MessageFederate ( bool  res)
explicit

special constructor should only be used by child classes in constructor due to virtual inheritance

References helics::Federate::coreObject, and helics::Federate::getID().

◆ ~MessageFederate()

helics::MessageFederate::~MessageFederate ( )
virtualdefault

destructor

Member Function Documentation

◆ addDestinationFilter()

void helics::MessageFederate::addDestinationFilter ( const Endpoint ept,
const std::string &  filterName 
)

add a named filter to an endpoint for all message going to the endpoint

◆ addSourceFilter()

void helics::MessageFederate::addSourceFilter ( const Endpoint ept,
const std::string &  filterName 
)

add a named filter to an endpoint for all message coming from the endpoint

◆ disconnect()

void helics::MessageFederate::disconnect ( )
overridevirtual

disconnect a simulation from the core (will also call finalize before disconnecting if necessary)

Reimplemented from helics::Federate.

Reimplemented in helics::CombinationFederate.

References helics::Federate::disconnect().

Referenced by helics::CombinationFederate::disconnect().

◆ getEndpoint() [1/2]

Endpoint & helics::MessageFederate::getEndpoint ( const std::string &  name) const

get an endpoint by its name

Parameters
namethe Endpoint
Returns
an Endpoint

References helics::Federate::getName(), and helics::Federate::nameSegmentSeparator.

◆ getEndpoint() [2/2]

Endpoint & helics::MessageFederate::getEndpoint ( int  index) const

get an Endpoint from an index

Parameters
indexthe index of the endpoint to retrieve index is 0 based
Returns
an Endpoint

◆ getEndpointCount()

int helics::MessageFederate::getEndpointCount ( ) const

get the number of registered endpoints

get a count of the number endpoints registered

◆ getMessage() [1/2]

std::unique_ptr< Message > helics::MessageFederate::getMessage ( )

receive a communication message for any endpoint in the federate

the return order will be in order of endpoint creation then order of arrival all messages for the first endpoint, then all for the second, and so on

Returns
a unique_ptr to a Message object containing the message data

References helics::Federate::currentMode, and helics::Federate::initializing.

◆ getMessage() [2/2]

std::unique_ptr< Message > helics::MessageFederate::getMessage ( const Endpoint ept)

receive a packet from a particular endpoint

Parameters
eptthe identifier for the endpoint
Returns
a message object

References helics::Federate::currentMode, and helics::Federate::initializing.

◆ hasMessage()

bool helics::MessageFederate::hasMessage ( ) const

check if the federate has any outstanding messages

References helics::Federate::currentMode, and helics::Federate::initializing.

◆ initializeToExecuteStateTransition()

void helics::MessageFederate::initializeToExecuteStateTransition ( iteration_result  iterate)
overrideprotectedvirtual

function to deal with any operations that need to occur on the transition from startup to initialize

Reimplemented from helics::Federate.

Reimplemented in helics::CombinationFederate.

Referenced by helics::CombinationFederate::initializeToExecuteStateTransition().

◆ localQuery()

std::string helics::MessageFederate::localQuery ( const std::string &  queryStr) const
overrideprotectedvirtual

function to generate results for a local Query

should return an empty string if the query is not recognized

Reimplemented from helics::Federate.

Reimplemented in helics::CombinationFederate.

Referenced by helics::CombinationFederate::localQuery().

◆ operator=() [1/2]

MessageFederate& helics::MessageFederate::operator= ( const MessageFederate mFed)
delete

delete copy assignment

◆ operator=() [2/2]

MessageFederate & helics::MessageFederate::operator= ( MessageFederate &&  mFed)
noexcept

move assignment

References helics::Federate::operator=().

◆ pendingMessages() [1/2]

uint64_t helics::MessageFederate::pendingMessages ( ) const

Returns the number of pending receives for all endpoints.

References helics::Federate::currentMode, and helics::Federate::initializing.

◆ pendingMessages() [2/2]

uint64_t helics::MessageFederate::pendingMessages ( const Endpoint ept) const

Returns the number of pending receives for the specified destination endpoint.

References helics::Federate::currentMode, and helics::Federate::initializing.

◆ registerEndpoint()

Endpoint & helics::MessageFederate::registerEndpoint ( const std::string &  eptName = std::string(),
const std::string &  type = std::string() 
)

register an endpoint

call is only valid in startup mode

Parameters
eptNamethe name of the endpoint
typethe defined type of the interface for endpoint checking if requested

References helics::Federate::getName(), and helics::Federate::nameSegmentSeparator.

◆ registerGlobalEndpoint()

Endpoint & helics::MessageFederate::registerGlobalEndpoint ( const std::string &  eptName,
const std::string &  type = std::string() 
)

register an endpoint directly without prepending the federate name

call is only valid in startup mode

Parameters
eptNamethe name of the endpoint
typethe defined type of the interface for endpoint checking if requested
Returns
a Reference to an Endpoint Object

◆ registerIndexedEndpoint()

Endpoint& helics::MessageFederate::registerIndexedEndpoint ( const std::string &  eptName,
int  index1,
const std::string &  type = std::string() 
)
inline

register an indexed Endpoint

register a global endpoint as part of a 1D array of endpoints

Parameters
eptNamethe name of the endpoint array
index1the index into a 1 dimensional array of endpoints
typethe optional type on the endpoint

◆ registerInterfaces()

void helics::MessageFederate::registerInterfaces ( const std::string &  configString)
overridevirtual

register a set of interfaces defined in a file

call is only valid in startup mode

Parameters
configStringthe location of the file or config String to load to generate the interfaces

Reimplemented from helics::Federate.

Reimplemented in helics::CombinationFederate.

References helics::Federate::registerFilterInterfaces(), and registerMessageInterfaces().

Referenced by MessageFederate().

◆ registerKnownCommunicationPath()

void helics::MessageFederate::registerKnownCommunicationPath ( const Endpoint localEndpoint,
const std::string &  remoteEndpoint 
)

give the core a hint for known communication paths

the function will generate an error in the core if a communication path is not present once the simulation is initialized

Parameters
localEndpointthe local endpoint of a known communication pair
remoteEndpointof a communication pair

◆ registerMessageInterfaces()

void helics::MessageFederate::registerMessageInterfaces ( const std::string &  configString)

register a set Message interfaces

call is only valid in startup mode it is a protected call to add an

Parameters
configStringthe location of the file(TOML or JSON) or JSON String to load to generate the interfaces

Referenced by helics::CombinationFederate::registerInterfaces(), and registerInterfaces().

◆ sendMessage() [1/6]

void helics::MessageFederate::sendMessage ( const Endpoint source,
const Message message 
)

send an event message at a particular time

send a message to a specific destination

Parameters
sourcethe source endpoint
messagea message object

References helics::Federate::currentMode, helics::Federate::executing, and helics::Federate::initializing.

◆ sendMessage() [2/6]

void helics::MessageFederate::sendMessage ( const Endpoint source,
const std::string &  dest,
const char *  data,
size_t  dataLength 
)
inline

send a message

send a message to a specific destination

Parameters
sourcethe source endpoint
desta string naming the destination
dataa buffer containing the data
dataLengththe length of the data buffer

References data.

◆ sendMessage() [3/6]

void helics::MessageFederate::sendMessage ( const Endpoint source,
const std::string &  dest,
const char *  data,
size_t  dataLength,
Time  sendTime 
)
inline

send an event message at a particular time

send a message to a specific destination

Parameters
sourcethe source endpoint
desta string naming the destination
dataa buffer containing the data
dataLengththe length of the data buffer
sendTimethe time the message should be sent

References data.

◆ sendMessage() [4/6]

void helics::MessageFederate::sendMessage ( const Endpoint source,
const std::string &  dest,
const data_view message 
)

send a message

send a message to a specific destination

Parameters
sourcethe source endpoint
desta string naming the destination
messagea data_view of the message

References helics::Federate::currentMode, helics::Federate::executing, and helics::Federate::initializing.

◆ sendMessage() [5/6]

void helics::MessageFederate::sendMessage ( const Endpoint source,
const std::string &  dest,
const data_view message,
Time  sendTime 
)

send an event message at a particular time

send a message to a specific destination

Parameters
sourcethe source endpoint
desta string naming the destination
messagea data_view of the message data to send
sendTimethe time the message should be sent

References helics::Federate::currentMode, helics::Federate::executing, and helics::Federate::initializing.

◆ sendMessage() [6/6]

void helics::MessageFederate::sendMessage ( const Endpoint source,
std::unique_ptr< Message message 
)

send an event message at a particular time

send a message to a specific destination

Parameters
sourcethe source endpoint
messagea pointer to the message

References helics::Federate::currentMode, helics::Federate::executing, and helics::Federate::initializing.

◆ setMessageNotificationCallback() [1/2]

void helics::MessageFederate::setMessageNotificationCallback ( const Endpoint ept,
const std::function< void(Endpoint &, Time)> &  callback 
)

register a callback for a specific endpoint

Parameters
eptthe endpoint to associate with the specified callback
callbackthe function to execute upon receipt of a message for the given endpoint

◆ setMessageNotificationCallback() [2/2]

void helics::MessageFederate::setMessageNotificationCallback ( const std::function< void(Endpoint &, Time)> &  callback)

register a callback for all endpoints

Parameters
callbackthe function to execute upon receipt of a message for any endpoint

◆ startupToInitializeStateTransition()

void helics::MessageFederate::startupToInitializeStateTransition ( )
overrideprotectedvirtual

function to deal with any operations that need to occur on the transition from startup to initialize

Reimplemented from helics::Federate.

Reimplemented in helics::CombinationFederate.

Referenced by helics::CombinationFederate::startupToInitializeStateTransition().

◆ subscribe()

void helics::MessageFederate::subscribe ( const Endpoint ept,
const std::string &  key 
)

subscribe to valueFederate publication to be delivered as Messages to the given endpoint

Parameters
eptthe specified endpoint to deliver the values
keythe name of the publication to subscribe

◆ updateTime()

void helics::MessageFederate::updateTime ( Time  newTime,
Time  oldTime 
)
overrideprotectedvirtual

function to deal with any operations that need to occur on a time update

Reimplemented from helics::Federate.

Reimplemented in helics::CombinationFederate.

Referenced by helics::CombinationFederate::updateTime().


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