mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 17:41:45 +00:00
Enable new callback API
- OnData() channel data handler. - ConditionalRun() for devices without incoming data. - Header file with common main(), to be extended with getDevice/addCustomOptions. - Update examples (MQ/Tutorial3) to use the new API and config. - NewSimpleMessage() for simpler creation of small messages (additional copy). - Replace SetProperty/GetProperty with fConfig access. - Runtime configurable channel names for common devices. - Configurable logging interval per channel. - FairMQMultiplier for distributing same data to multiple outputs. - Cleanup state machine messages. - Cmd option to toggle signal handling. - Simpler API for send/receive timeouts. - Enable --log-to-file. - Fix coverity issues, warnings. - Various code cleanup and minor tweaks.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <memory> // unique_ptr
|
||||
#include <atomic>
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
|
||||
@@ -61,57 +62,73 @@ class FairMQChannel
|
||||
/// Get socket type
|
||||
/// @return Returns socket type (push/pull/pub/sub/spub/xsub/pair/req/rep/dealer/router/)
|
||||
std::string GetType() const;
|
||||
|
||||
/// Get socket method
|
||||
/// @return Returns socket method (bind/connect)
|
||||
std::string GetMethod() const;
|
||||
|
||||
/// Get socket address (e.g. "tcp://127.0.0.1:5555" or "ipc://abc")
|
||||
/// @return Returns socket type (e.g. "tcp://127.0.0.1:5555" or "ipc://abc")
|
||||
std::string GetAddress() const;
|
||||
|
||||
/// Get channel property (custom property)
|
||||
/// @return Returns property value
|
||||
std::string GetProperty() const;
|
||||
|
||||
/// Get socket send buffer size (in number of messages)
|
||||
/// @return Returns socket send buffer size (in number of messages)
|
||||
int GetSndBufSize() const;
|
||||
|
||||
/// Get socket receive buffer size (in number of messages)
|
||||
/// @return Returns socket receive buffer size (in number of messages)
|
||||
int GetRcvBufSize() const;
|
||||
|
||||
/// Get socket kernel transmit send buffer size (in bytes)
|
||||
/// @return Returns socket kernel transmit send buffer size (in bytes)
|
||||
int GetSndKernelSize() const;
|
||||
|
||||
/// Get socket kernel transmit receive buffer size (in bytes)
|
||||
/// @return Returns socket kernel transmit receive buffer size (in bytes)
|
||||
int GetRcvKernelSize() const;
|
||||
/// Get socket rate logging setting (1/0)
|
||||
/// @return Returns socket rate logging setting (1/0)
|
||||
|
||||
/// Get socket rate logging interval (in seconds)
|
||||
/// @return Returns socket rate logging interval (in seconds)
|
||||
int GetRateLogging() const;
|
||||
|
||||
/// Set socket type
|
||||
/// @param type Socket type (push/pull/pub/sub/spub/xsub/pair/req/rep/dealer/router/)
|
||||
void UpdateType(const std::string& type);
|
||||
|
||||
/// Set socket method
|
||||
/// @param method Socket method (bind/connect)
|
||||
void UpdateMethod(const std::string& method);
|
||||
|
||||
/// Set socket address
|
||||
/// @param address Socket address (e.g. "tcp://127.0.0.1:5555" or "ipc://abc")
|
||||
void UpdateAddress(const std::string& address);
|
||||
|
||||
/// Set custom channel property
|
||||
/// @param property Channel property
|
||||
void UpdateProperty(const std::string& property);
|
||||
|
||||
/// Set socket send buffer size
|
||||
/// @param sndBufSize Socket send buffer size (in number of messages)
|
||||
void UpdateSndBufSize(const int sndBufSize);
|
||||
|
||||
/// Set socket receive buffer size
|
||||
/// @param rcvBufSize Socket receive buffer size (in number of messages)
|
||||
void UpdateRcvBufSize(const int rcvBufSize);
|
||||
|
||||
/// Set socket kernel transmit send buffer size (in bytes)
|
||||
/// @param sndKernelSize Socket send buffer size (in bytes)
|
||||
void UpdateSndKernelSize(const int sndKernelSize);
|
||||
|
||||
/// Set socket kernel transmit receive buffer size (in bytes)
|
||||
/// @param rcvKernelSize Socket receive buffer size (in bytes)
|
||||
void UpdateRcvKernelSize(const int rcvKernelSize);
|
||||
/// Set socket rate logging setting
|
||||
/// @param rateLogging Socket rate logging setting (1/0)
|
||||
|
||||
/// Set socket rate logging interval (in seconds)
|
||||
/// @param rateLogging Socket rate logging interval (in seconds)
|
||||
void UpdateRateLogging(const int rateLogging);
|
||||
|
||||
/// Checks if the configured channel settings are valid (checks the validity parameter, without running full validation (as oposed to ValidateChannel()))
|
||||
@@ -135,7 +152,7 @@ class FairMQChannel
|
||||
/// @param msg Constant reference of unique_ptr to a FairMQMessage
|
||||
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out.
|
||||
/// In case of errors, returns -1.
|
||||
int Send(const std::unique_ptr<FairMQMessage>& msg) const;
|
||||
int Send(const std::unique_ptr<FairMQMessage>& msg, int sndTimeoutInMs = -1) const;
|
||||
|
||||
/// Sends a message in non-blocking mode.
|
||||
/// @details SendAsync method attempts to send a message without blocking by
|
||||
@@ -179,7 +196,7 @@ class FairMQChannel
|
||||
/// @param msgVec message vector reference
|
||||
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out.
|
||||
/// In case of errors, returns -1.
|
||||
int64_t Send(const std::vector<std::unique_ptr<FairMQMessage>>& msgVec) const;
|
||||
int64_t Send(const std::vector<std::unique_ptr<FairMQMessage>>& msgVec, int sndTimeoutInMs = -1) const;
|
||||
|
||||
/// Sends a vector of message in non-blocking mode.
|
||||
/// @details SendAsync method attempts to send a vector of messages without blocking by
|
||||
@@ -200,7 +217,7 @@ class FairMQChannel
|
||||
/// @param msg Constant reference of unique_ptr to a FairMQMessage
|
||||
/// @return 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.
|
||||
int Receive(const std::unique_ptr<FairMQMessage>& msg) const;
|
||||
int Receive(const std::unique_ptr<FairMQMessage>& msg, int rcvTimeoutInMs = -1) const;
|
||||
|
||||
/// Receives a message in non-blocking mode.
|
||||
///
|
||||
@@ -217,7 +234,7 @@ class FairMQChannel
|
||||
/// @param msgVec message vector reference
|
||||
/// @return 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.
|
||||
int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) const;
|
||||
int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, int rcvTimeoutInMs = -1) const;
|
||||
|
||||
/// Receives a vector of messages in non-blocking mode.
|
||||
///
|
||||
@@ -229,44 +246,16 @@ class FairMQChannel
|
||||
return fSocket->Receive(msgVec, fNoBlockFlag);
|
||||
}
|
||||
|
||||
// DEPRECATED socket method wrappers with raw pointers and flag checks
|
||||
int Send(FairMQMessage* msg, const std::string& flag = "") const;
|
||||
int Send(FairMQMessage* msg, const int flags) const;
|
||||
int Receive(FairMQMessage* msg, const std::string& flag = "") const;
|
||||
int Receive(FairMQMessage* msg, const int flags) const;
|
||||
|
||||
/// Sets a timeout on the (blocking) Send method
|
||||
/// @param timeout timeout value in milliseconds
|
||||
inline void SetSendTimeout(const int timeout)
|
||||
{
|
||||
fSndTimeoutInMs = timeout;
|
||||
}
|
||||
|
||||
/// Gets the current value of the timeout on the (blocking) Send method
|
||||
/// @return Timeout value in milliseconds. -1 for no timeout.
|
||||
inline int GetSendTimeout() const
|
||||
{
|
||||
return fSndTimeoutInMs;
|
||||
}
|
||||
|
||||
/// Sets a timeout on the (blocking) Receive method
|
||||
/// @param timeout timeout value in milliseconds
|
||||
inline void SetReceiveTimeout(const int timeout)
|
||||
{
|
||||
fRcvTimeoutInMs = timeout;
|
||||
}
|
||||
|
||||
/// Gets the current value of the timeout on the (blocking) Receive method
|
||||
/// @return Timeout value in milliseconds. -1 for no timeout.
|
||||
inline int GetReceiveTimeout() const
|
||||
{
|
||||
return fRcvTimeoutInMs;
|
||||
}
|
||||
|
||||
/// Checks if the socket is expecting to receive another part of a multipart message.
|
||||
/// @return Return true if the socket expects another part of a multipart message and false otherwise.
|
||||
bool ExpectsAnotherPart() const;
|
||||
|
||||
// DEPRECATED socket method wrappers with raw pointers and flag checks
|
||||
int Send(FairMQMessage* msg, const std::string& flag = "", int sndTimeoutInMs = -1) const;
|
||||
int Send(FairMQMessage* msg, const int flags, int sndTimeoutInMs = -1) const;
|
||||
int Receive(FairMQMessage* msg, const std::string& flag = "", int rcvTimeoutInMs = -1) const;
|
||||
int Receive(FairMQMessage* msg, const int flags, int rcvTimeoutInMs = -1) const;
|
||||
|
||||
private:
|
||||
std::string fType;
|
||||
std::string fMethod;
|
||||
@@ -279,7 +268,7 @@ class FairMQChannel
|
||||
int fRateLogging;
|
||||
|
||||
std::string fChannelName;
|
||||
bool fIsValid;
|
||||
std::atomic<bool> fIsValid;
|
||||
|
||||
FairMQPoller* fPoller;
|
||||
FairMQSocket* fCmdSocket;
|
||||
@@ -289,9 +278,6 @@ class FairMQChannel
|
||||
int fNoBlockFlag;
|
||||
int fSndMoreFlag;
|
||||
|
||||
int fSndTimeoutInMs;
|
||||
int fRcvTimeoutInMs;
|
||||
|
||||
bool InitCommandInterface(FairMQTransportFactory* factory, int numIoThreads);
|
||||
|
||||
bool HandleUnblock() const;
|
||||
@@ -301,6 +287,8 @@ class FairMQChannel
|
||||
// this does not hurt much, because mutex is used only during initialization with very low contention
|
||||
// possible TODO: improve this
|
||||
static boost::mutex fChannelMutex;
|
||||
|
||||
static std::atomic<bool> fInterrupted;
|
||||
};
|
||||
|
||||
#endif /* FAIRMQCHANNEL_H_ */
|
||||
|
Reference in New Issue
Block a user