FairMQ  1.2.0
C++ Message Passing Framework
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
FairMQDevice Class Reference
Inheritance diagram for FairMQDevice:
Inheritance graph
[legend]
Collaboration diagram for FairMQDevice:
Collaboration graph
[legend]

Public Member Functions

 FairMQDevice ()
 Default constructor.
 
 FairMQDevice (const fair::mq::tools::Version version)
 Constructor that sets the version.
 
 FairMQDevice (const FairMQDevice &)=delete
 Copy constructor (disabled)
 
FairMQDevice operator= (const FairMQDevice &)=delete
 Assignment operator (disabled)
 
virtual ~FairMQDevice ()
 Default destructor.
 
void CatchSignals ()
 Catches interrupt signals (SIGINT, SIGTERM)
 
virtual void LogSocketRates ()
 Outputs the socket transfer rates.
 
void SortChannel (const std::string &name, const bool reindex=true)
 
void PrintChannel (const std::string &name)
 
template<typename Serializer , typename DataType , typename... Args>
void Serialize (FairMQMessage &msg, DataType &&data, Args &&... args) const
 
template<typename Deserializer , typename DataType , typename... Args>
void Deserialize (FairMQMessage &msg, DataType &&data, Args &&... args) const
 
int Send (FairMQMessagePtr &msg, const std::string &chan, const int i=0) const
 
int Receive (FairMQMessagePtr &msg, const std::string &chan, const int i=0) const
 
int Send (FairMQMessagePtr &msg, const std::string &chan, const int i, int sndTimeoutInMs) const
 
int Receive (FairMQMessagePtr &msg, const std::string &chan, const int i, int rcvTimeoutInMs) const
 
int SendAsync (FairMQMessagePtr &msg, const std::string &chan, const int i=0) const
 
int ReceiveAsync (FairMQMessagePtr &msg, const std::string &chan, const int i=0) const
 
int64_t Send (FairMQParts &parts, const std::string &chan, const int i=0) const
 
int64_t Receive (FairMQParts &parts, const std::string &chan, const int i=0) const
 
int64_t Send (FairMQParts &parts, const std::string &chan, const int i, int sndTimeoutInMs) const
 
int64_t Receive (FairMQParts &parts, const std::string &chan, const int i, int rcvTimeoutInMs) const
 
int64_t SendAsync (FairMQParts &parts, const std::string &chan, const int i=0) const
 
int64_t ReceiveAsync (FairMQParts &parts, const std::string &chan, const int i=0) const
 
auto Transport () const -> const FairMQTransportFactory *
 Getter for default transport factory.
 
template<typename... Args>
FairMQMessagePtr NewMessage (Args &&... args) const
 
template<typename... Args>
FairMQMessagePtr NewMessageFor (const std::string &channel, int index, Args &&... args) const
 
template<typename T >
FairMQMessagePtr NewStaticMessage (const T &data) const
 
template<typename T >
FairMQMessagePtr NewStaticMessageFor (const std::string &channel, int index, const T &data) const
 
template<typename T >
FairMQMessagePtr NewSimpleMessage (const T &data) const
 
template<typename T >
FairMQMessagePtr NewSimpleMessageFor (const std::string &channel, int index, const T &data) const
 
FairMQUnmanagedRegionPtr NewUnmanagedRegion (const size_t size)
 
FairMQUnmanagedRegionPtr NewUnmanagedRegionFor (const std::string &channel, int index, const size_t size, FairMQRegionCallback callback=nullptr)
 
template<typename ... Ts>
FairMQPollerPtr NewPoller (const Ts &... inputs)
 
FairMQPollerPtr NewPoller (const std::vector< const FairMQChannel *> &channels)
 
void WaitForInitialValidation ()
 Waits for the first initialization run to finish.
 
std::shared_ptr< FairMQTransportFactoryAddTransport (const std::string &transport)
 
void SetTransport (const std::string &transport="zeromq")
 
void SetConfig (FairMQProgOptions &config)
 
const FairMQProgOptionsGetConfig () const
 
template<typename T >
void OnData (const std::string &channelName, bool(T::*memberFunction)(FairMQMessagePtr &msg, int index))
 
void OnData (const std::string &channelName, InputMsgCallback callback)
 
template<typename T >
void OnData (const std::string &channelName, bool(T::*memberFunction)(FairMQParts &parts, int index))
 
void OnData (const std::string &channelName, InputMultipartCallback callback)
 
const FairMQChannelGetChannel (const std::string &channelName, const int index=0) const
 
virtual void RegisterChannelEndpoints ()
 
bool RegisterChannelEndpoint (const std::string &channelName, uint16_t minNumSubChannels=1, uint16_t maxNumSubChannels=1)
 
void PrintRegisteredChannels ()
 
void SetId (const std::string &id)
 
std::string GetId ()
 
const fair::mq::tools::Version GetVersion () const
 
void SetNumIoThreads (int numIoThreads)
 
int GetNumIoThreads () const
 
void SetPortRangeMin (int portRangeMin)
 
int GetPortRangeMin () const
 
void SetPortRangeMax (int portRangeMax)
 
int GetPortRangeMax () const
 
void SetNetworkInterface (const std::string &networkInterface)
 
std::string GetNetworkInterface () const
 
void SetDefaultTransport (const std::string &defaultTransport)
 
std::string GetDefaultTransport () const
 
void SetInitializationTimeoutInS (int initializationTimeoutInS)
 
int GetInitializationTimeoutInS () const
 
- Public Member Functions inherited from FairMQStateMachine
 FairMQStateMachine ()
 
int GetInterfaceVersion () const
 
bool ChangeState (int event)
 
bool ChangeState (const std::string &event)
 
void WaitForEndOfState (int event)
 
void WaitForEndOfState (const std::string &event)
 
bool WaitForEndOfStateForMs (int event, int durationInMs)
 
bool WaitForEndOfStateForMs (const std::string &event, int durationInMs)
 
void SubscribeToStateChange (const std::string &key, std::function< void(const State)> callback)
 
void UnsubscribeFromStateChange (const std::string &key)
 

Static Public Member Functions

static bool SortSocketsByAddress (const FairMQChannel &lhs, const FairMQChannel &rhs)
 

Public Attributes

std::unordered_map< std::string, std::vector< FairMQChannel > > fChannels
 Device channels.
 
FairMQProgOptionsfConfig
 Program options configuration.
 

Protected Member Functions

virtual void Init ()
 
virtual void InitTask ()
 
virtual void Run ()
 
virtual void PreRun ()
 
virtual bool ConditionalRun ()
 
virtual void PostRun ()
 
virtual void Pause ()
 
virtual void ResetTask ()
 
virtual void Reset ()
 

Protected Attributes

std::shared_ptr< FairMQTransportFactoryfTransportFactory
 Transport factory.
 
std::unordered_map< FairMQ::Transport, std::shared_ptr< FairMQTransportFactory > > fTransports
 Container for transports.
 
std::string fId
 Device ID.
 
int fNumIoThreads
 Number of ZeroMQ I/O threads.
 

Friends

class FairMQChannel
 

Additional Inherited Members

- Public Types inherited from FairMQStateMachine
enum  Event {
  INIT_DEVICE, internal_DEVICE_READY, INIT_TASK, internal_READY,
  RUN, PAUSE, STOP, RESET_TASK,
  RESET_DEVICE, internal_IDLE, END, ERROR_FOUND
}
 

Member Function Documentation

◆ AddTransport()

shared_ptr< FairMQTransportFactory > FairMQDevice::AddTransport ( const std::string &  transport)

Adds a transport to the device if it doesn't exist

Parameters
transportTransport string ("zeromq"/"nanomsg"/"shmem")

◆ ConditionalRun()

bool FairMQDevice::ConditionalRun ( )
protectedvirtual

Called during RUNNING state repeatedly until it returns false or device state changes Executed in a worker thread

◆ Init()

void FairMQDevice::Init ( )
protectedvirtual

Additional user initialization (can be overloaded in child classes). Prefer to use InitTask(). Executed in a worker thread

Reimplemented in FairMQShmPrototypeSampler, and FairMQShmPrototypeSink.

◆ InitTask()

void FairMQDevice::InitTask ( )
protectedvirtual

Task initialization (can be overloaded in child classes) Executed in a worker thread

Reimplemented in FairMQBenchmarkSampler, FairMQSink, FairMQMerger, FairMQSplitter, FairMQProxy, and FairMQMultiplier.

◆ Pause()

void FairMQDevice::Pause ( )
protectedvirtual

Handles the PAUSE state Executed in a worker thread

◆ PostRun()

void FairMQDevice::PostRun ( )
protectedvirtual

Called in the RUNNING state once after executing the Run()/ConditionalRun() method Executed in a worker thread

Reimplemented in FairMQBenchmarkSampler.

◆ PreRun()

void FairMQDevice::PreRun ( )
protectedvirtual

Called in the RUNNING state once before executing the Run()/ConditionalRun() method Executed in a worker thread

Reimplemented in FairMQBenchmarkSampler.

◆ PrintChannel()

void FairMQDevice::PrintChannel ( const std::string &  name)

Prints channel configuration

Parameters
nameName of the channel

◆ Receive() [1/2]

int FairMQDevice::Receive ( FairMQMessagePtr &  msg,
const std::string &  chan,
const int  i,
int  rcvTimeoutInMs 
) const
inline

Shorthand method to receive msg on chan at index i

Parameters
msgmessage reference
chanchannel name
ichannel index
Returns
Number of bytes that have been received. -2 If reading from the queue was not possible or timed out. In case of errors, returns -1.

◆ Receive() [2/2]

int64_t FairMQDevice::Receive ( FairMQParts parts,
const std::string &  chan,
const int  i,
int  rcvTimeoutInMs 
) const
inline

Shorthand method to receive FairMQParts on chan at index i

Parameters
partsparts reference
chanchannel name
ichannel index
Returns
Number of bytes that have been received. -2 If reading from the queue was not possible or timed out. In case of errors, returns -1.

◆ ReceiveAsync() [1/2]

int FairMQDevice::ReceiveAsync ( FairMQMessagePtr &  msg,
const std::string &  chan,
const int  i = 0 
) const
inline

Shorthand method to receive msg on chan at index i without blocking

Parameters
msgmessage reference
chanchannel name
ichannel index
Returns
Number of bytes that have been received. -2 If reading from the queue was not possible or timed out. In case of errors, returns -1.

◆ ReceiveAsync() [2/2]

int64_t FairMQDevice::ReceiveAsync ( FairMQParts parts,
const std::string &  chan,
const int  i = 0 
) const
inline

Shorthand method to receive FairMQParts on chan at index i without blocking

Parameters
partsparts reference
chanchannel name
ichannel index
Returns
Number of bytes that have been received. -2 If reading from the queue was not possible or timed out. In case of errors, returns -1.

◆ Reset()

void FairMQDevice::Reset ( )
protectedvirtual

Resets the device (can be overloaded in child classes) Executed in a worker thread

◆ ResetTask()

void FairMQDevice::ResetTask ( )
protectedvirtual

Resets the user task (to be overloaded in child classes) Executed in a worker thread

◆ Run()

void FairMQDevice::Run ( )
protectedvirtual

Runs the device (to be overloaded in child classes) Executed in a worker thread

Reimplemented in FairMQBenchmarkSampler, FairMQSink, FairMQShmPrototypeSampler, FairMQShmPrototypeSink, FairMQMerger, and FairMQProxy.

◆ Send() [1/2]

int FairMQDevice::Send ( FairMQMessagePtr &  msg,
const std::string &  chan,
const int  i,
int  sndTimeoutInMs 
) const
inline

Shorthand method to send msg on chan at index i

Parameters
msgmessage reference
chanchannel name
ichannel index
Returns
Number of bytes that have been queued. -2 If queueing was not possible or timed out. In case of errors, returns -1.

◆ Send() [2/2]

int64_t FairMQDevice::Send ( FairMQParts parts,
const std::string &  chan,
const int  i,
int  sndTimeoutInMs 
) const
inline

Shorthand method to send FairMQParts on chan at index i

Parameters
partsparts reference
chanchannel name
ichannel index
Returns
Number of bytes that have been queued. -2 If queueing was not possible or timed out. In case of errors, returns -1.

◆ SendAsync() [1/2]

int FairMQDevice::SendAsync ( FairMQMessagePtr &  msg,
const std::string &  chan,
const int  i = 0 
) const
inline

Shorthand method to send msg on chan at index i without blocking

Parameters
msgmessage reference
chanchannel name
ichannel index
Returns
Number of bytes that have been queued. -2 If queueing was not possible or timed out. In case of errors, returns -1.

◆ SendAsync() [2/2]

int64_t FairMQDevice::SendAsync ( FairMQParts parts,
const std::string &  chan,
const int  i = 0 
) const
inline

Shorthand method to send FairMQParts on chan at index i without blocking

Parameters
partsparts reference
chanchannel name
ichannel index
Returns
Number of bytes that have been queued. -2 If queueing was not possible or timed out. In case of errors, returns -1.

◆ SetTransport()

void FairMQDevice::SetTransport ( const std::string &  transport = "zeromq")

Sets the default transport for the device

Parameters
transportTransport string ("zeromq"/"nanomsg"/"shmem")

◆ SortChannel()

void FairMQDevice::SortChannel ( const std::string &  name,
const bool  reindex = true 
)

Sorts a channel by address, with optional reindexing of the sorted values

Parameters
nameChannel name
reindexShould reindexing be done

◆ SortSocketsByAddress()

bool FairMQDevice::SortSocketsByAddress ( const FairMQChannel lhs,
const FairMQChannel rhs 
)
static

Implements the sort algorithm used in SortChannel()

Parameters
lhsRight hand side value for comparison
rhsLeft hand side value for comparison

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