FairMQ  1.4.14
C++ Message Queuing Library and Framework
Public Types | 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 Types

enum  Event {
  INIT_DEVICE, internal_DEVICE_READY, INIT_TASK, internal_READY,
  RUN, STOP, RESET_TASK, RESET_DEVICE,
  internal_IDLE, END, ERROR_FOUND
}
 
enum  State {
  OK, Error, IDLE, INITIALIZING_DEVICE,
  DEVICE_READY, INITIALIZING_TASK, READY, RUNNING,
  RESETTING_TASK, RESETTING_DEVICE, EXITING
}
 

Public Member Functions

 FairMQDevice ()
 Default constructor.
 
 FairMQDevice (fair::mq::ProgOptions &config)
 Constructor with external fair::mq::ProgOptions.
 
 FairMQDevice (const fair::mq::tools::Version version)
 Constructor that sets the version.
 
 FairMQDevice (fair::mq::ProgOptions &config, const fair::mq::tools::Version version)
 Constructor that sets the version and external fair::mq::ProgOptions.
 
 FairMQDevice (const FairMQDevice &)=delete
 Copy constructor (disabled)
 
FairMQDevice operator= (const FairMQDevice &)=delete
 Assignment operator (disabled)
 
virtual ~FairMQDevice ()
 Default destructor.
 
virtual void LogSocketRates ()
 Outputs the socket transfer rates.
 
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 &channel, const int index=0, int sndTimeoutInMs=-1)
 
int Receive (FairMQMessagePtr &msg, const std::string &channel, const int index=0, int rcvTimeoutInMs=-1)
 
int64_t Send (FairMQParts &parts, const std::string &channel, const int index=0, int sndTimeoutInMs=-1)
 
int64_t Receive (FairMQParts &parts, const std::string &channel, const int index=0, int rcvTimeoutInMs=-1)
 
auto Transport () const -> FairMQTransportFactory *
 Getter for default transport factory.
 
template<typename... Args>
FairMQMessagePtr NewMessage (Args &&... args)
 
template<typename... Args>
FairMQMessagePtr NewMessageFor (const std::string &channel, int index, Args &&... args)
 
template<typename T >
FairMQMessagePtr NewStaticMessage (const T &data)
 
template<typename T >
FairMQMessagePtr NewStaticMessageFor (const std::string &channel, int index, const T &data)
 
template<typename T >
FairMQMessagePtr NewSimpleMessage (const T &data)
 
template<typename T >
FairMQMessagePtr NewSimpleMessageFor (const std::string &channel, int index, const T &data)
 
FairMQUnmanagedRegionPtr NewUnmanagedRegion (const size_t size, FairMQRegionCallback callback=nullptr, const std::string &path="", int flags=0)
 
FairMQUnmanagedRegionPtr NewUnmanagedRegion (const size_t size, const int64_t userFlags, FairMQRegionCallback callback=nullptr, const std::string &path="", int flags=0)
 
FairMQUnmanagedRegionPtr NewUnmanagedRegionFor (const std::string &channel, int index, const size_t size, FairMQRegionCallback callback=nullptr, const std::string &path="", int flags=0)
 
FairMQUnmanagedRegionPtr NewUnmanagedRegionFor (const std::string &channel, int index, const size_t size, const int64_t userFlags, FairMQRegionCallback callback=nullptr, const std::string &path="", int flags=0)
 
template<typename ... Ts>
FairMQPollerPtr NewPoller (const Ts &... inputs)
 
FairMQPollerPtr NewPoller (const std::vector< FairMQChannel *> &channels)
 
std::shared_ptr< FairMQTransportFactoryAddTransport (const fair::mq::Transport transport)
 
void SetConfig (fair::mq::ProgOptions &config)
 Assigns config to the device.
 
fair::mq::ProgOptionsGetConfig () const
 Get pointer to the config.
 
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)
 
FairMQChannelGetChannel (const std::string &channelName, const int index=0)
 
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 SetNetworkInterface (const std::string &networkInterface)
 
std::string GetNetworkInterface () const
 
void SetDefaultTransport (const std::string &name)
 
std::string GetDefaultTransport () const
 
void SetInitTimeoutInS (int initTimeoutInS)
 
int GetInitTimeoutInS () const
 
void SetTransport (const std::string &transport)
 
std::string GetTransportName () const
 Gets the default transport name.
 
void SetRawCmdLineArgs (const std::vector< std::string > &args)
 
std::vector< std::string > GetRawCmdLineArgs () const
 
void RunStateMachine ()
 
template<typename Rep , typename Period >
bool WaitFor (std::chrono::duration< Rep, Period > const &duration)
 
void AddChannel (const std::string &name, FairMQChannel &&channel)
 

Public Attributes

std::unordered_map< std::string, std::vector< FairMQChannel > > fChannels
 Device channels.
 
std::unique_ptr< fair::mq::ProgOptionsfInternalConfig
 Internal program options configuration.
 
fair::mq::ProgOptionsfConfig
 Pointer to config (internal or external)
 

Protected Member Functions

virtual void Init ()
 Additional user initialization (can be overloaded in child classes). Prefer to use InitTask().
 
virtual void Bind ()
 
virtual void Connect ()
 
virtual void InitTask ()
 Task initialization (can be overloaded in child classes)
 
virtual void Run ()
 Runs the device (to be overloaded in child classes)
 
virtual void PreRun ()
 Called in the RUNNING state once before executing the Run()/ConditionalRun() method.
 
virtual bool ConditionalRun ()
 Called during RUNNING state repeatedly until it returns false or device state changes.
 
virtual void PostRun ()
 Called in the RUNNING state once after executing the Run()/ConditionalRun() method.
 
virtual void Pause () __attribute__((deprecated("PAUSE state is removed. This method is never called. To pause Run
 

Protected Attributes

std::shared_ptr< FairMQTransportFactoryfTransportFactory
 Default transport factory.
 
std::unordered_map< fair::mq::Transport, std::shared_ptr< FairMQTransportFactory > > fTransports
 Container for transports.
 
std::string fId
 Device ID.
 
virtual void go to READY with STOP transition and back to RUNNING with RUN to resume
 

Friends

class FairMQChannel
 

Member Function Documentation

◆ AddTransport()

shared_ptr< FairMQTransportFactory > FairMQDevice::AddTransport ( const fair::mq::Transport  transport)

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

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

◆ Receive() [1/2]

int FairMQDevice::Receive ( FairMQMessagePtr &  msg,
const std::string &  channel,
const int  index = 0,
int  rcvTimeoutInMs = -1 
)
inline

Shorthand method to receive msg on chan at index i

Parameters
msgmessage reference
chanchannel name
ichannel index
rcvTimeoutInMsreceive timeout in ms, -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
Returns
Number of bytes that have been received. -2 if reading from the queue was not possible or timed out. -1 if there was an error.

◆ Receive() [2/2]

int64_t FairMQDevice::Receive ( FairMQParts parts,
const std::string &  channel,
const int  index = 0,
int  rcvTimeoutInMs = -1 
)
inline

Shorthand method to receive FairMQParts on chan at index i

Parameters
partsparts reference
chanchannel name
ichannel index
rcvTimeoutInMsreceive timeout in ms, -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
Returns
Number of bytes that have been received. -2 if reading from the queue was not possible or timed out. -1 if there was an error.

◆ Send() [1/2]

int FairMQDevice::Send ( FairMQMessagePtr &  msg,
const std::string &  channel,
const int  index = 0,
int  sndTimeoutInMs = -1 
)
inline

Shorthand method to send msg on chan at index i

Parameters
msgmessage reference
chanchannel name
ichannel index
sndTimeoutInMssend timeout in ms, -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
Returns
Number of bytes that have been queued. -2 If queueing was not possible or timed out. -1 if there was an error.

◆ Send() [2/2]

int64_t FairMQDevice::Send ( FairMQParts parts,
const std::string &  channel,
const int  index = 0,
int  sndTimeoutInMs = -1 
)
inline

Shorthand method to send FairMQParts on chan at index i

Parameters
partsparts reference
chanchannel name
ichannel index
sndTimeoutInMssend timeout in ms, -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
Returns
Number of bytes that have been queued. -2 If queueing was not possible or timed out. -1 if there was an error.

◆ SetTransport()

void FairMQDevice::SetTransport ( const std::string &  transport)
inline

Sets the default transport for the device

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

◆ WaitFor()

template<typename Rep , typename Period >
bool FairMQDevice::WaitFor ( std::chrono::duration< Rep, Period > const &  duration)
inline

Wait for the supplied amount of time or for interruption. If interrupted, returns false, otherwise true.

Parameters
durationwait duration

Member Data Documentation

◆ resume

virtual void go to READY with STOP transition and back to RUNNING with RUN to FairMQDevice::resume
protected
Initial value:
{}
virtual void ResetTask() {}
virtual void Reset() {}
public:
bool ChangeState(const fair::mq::Transition transition) { return fStateMachine.ChangeState(transition); }
bool ChangeState(const std::string& transition) { return fStateMachine.ChangeState(fair::mq::GetTransition(transition)); }
bool ChangeState(const int transition) __attribute__((deprecated("Use ChangeState(const fair::mq::Transition transition).")))

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

privacy