Common API Reference#

The OdinData namespace is shared between all odin-data applications.

IpcChannel#

class IpcChannel#

Public Functions

IpcChannel(int type)#

Construct an IpcChannel object

This constructor creates an IpcChannel object, initialising an underlying ZeroMQ socket of the specified type. If the requested type is DEALER, the socket identity is set using a UUID-like syntax.

Parameters:

type[in] - ZeroMQ socket type

IpcChannel(int type, const std::string identity)#

Construct an IpcChannel object

This constructor creates an IpcChannel object, initialising an underlying ZeroMQ socket of the specified type. If the requested type is DEALER, the socket identity is set using identity string passed as an argument.

Parameters:
  • type[in] - ZeroMQ socket type

  • identity[in] - identity string to use for DEALER sockets

~IpcChannel()#

IpcChannel destructor

void bind(const char *endpoint)#

Bind the IpcChannel to an endpoint

This method binds the IpcChannel to the endpoint specified in the argument in ZeroMQ URI syntax. Bound endpoints are stored to allow them to be unbound cleanly if necessary.

Parameters:

endpoint[in] - endpoint URI

void bind(std::string &endpoint)#

Bind the IpcChannel to an endpoint

This method binds the IpcChannel to the endpoint specified in the argument in ZeroMQ URI syntax. Bound endpoints are stored to allow them to be unbound cleanly if necessary.

Parameters:

endpoint[in] - endpoint URI

void unbind(const char *endpoint)#

Unbind the IpcChannel from an endpoint

This method unbinds the IpcChannel from the endpoint specified in the argument in ZeroMQ URI syntax.

Parameters:

endpoint[in] - endpoint URI

void unbind(const std::string &endpoint)#

Unbind the IpcChannel from an endpoint

This method unbinds the IpcChannel from the endpoint specified in the argument in ZeroMQ URI syntax.

Parameters:

endpoint[in] - endpoint URI

void connect(const char *endpoint)#

Connect the IpcChannel to an endpoint

This method connects the IpcChannel to an endpoint specified in the argument in ZeroMQ URI syntax.

Parameters:

endpoint[in] - endpoint URI

void connect(std::string &endpoint)#

Connect the IpcChannel to an endpoint

This method connects the IpcChannel to an endpoint specified in the argument in ZeroMQ URI syntax.

Parameters:

endpoint[in] - endpoint URI

bool has_bound_endpoint(const std::string &endpoint)#

Check if the IpcChannel is bound to an endpoint

This method checks if the IpcChannel is currently bound to the endpoint specified in the argument.

Parameters:

endpoint[in] - endpoint URI

Returns:

- boolean indicating if endpoint bound

void subscribe(const char *topic)#

Subscribe the IpcChannel to a topic

This method subscribes the IpcChannel to a topic string specified in the argument. This is applicable to ZMQ_SUB type channels used in publish and subscribe patterns.

Parameters:

topic[in] - topic to subscribe to

void send(std::string &message_str, int flags = 0, const std::string &identity_str = std::string())#

Send a message on the IpcChannel

This method sends the specified message on the IpcChannel, copying the message string into a ZeroMQ message buffer first. The optional flags argument specifies any ZeroMQ flags to use (e.g. ZMQ_DONTWAIT, ZMQ_SNDMORE). The optional identity_str argument is used to identify the destination identity when using DEALER-ROUTER channels.

Parameters:
  • message_str[in] - message string to send

  • flags[in] - ZeroMQ message send flags (default value 0)

  • identity_str[in] - identity of the destination endpoint to use for ROUTER sockets

void send(const char *message, int flags = 0, const std::string &identity_str = std::string())#

Send a message on the IpcChannel

This method sends the specified message on the IpcChannel, copying the null-terminated message string into a ZeroMQ message buffer first. The optional flags argument specifies any ZeroMQ flags to use (e.g. ZMQ_DONTWAIT, ZMQ_SNDMORE). The optional identity_str argument is used to identify the destination identity when using DEALER-ROUTER channels.

Parameters:
  • message[in] - pointer to null-terminated message string to send

  • flags[in] - ZeroMQ message send flags (default value 0)

  • identity_str[in] - identity of the destination endpoint to use for ROUTER sockets

void send(size_t msg_size, void *message, int flags = 0, const std::string &identity_str = std::string())#

Send a message on the IpcChannel

This method sends the specified message on the IpcChannel, copying the message from the specified buffer into a ZeroMQ message buffer first. The optional flags argument specifies any ZeroMQ flags to use (e.g. ZMQ_DONTWAIT, ZMQ_SNDMORE). The optional identity_str argument is used to identify the destination identity when using DEALER-ROUTER channels.

Parameters:
  • msg_size[in] - size of message to send

  • message[in] - pointer to location of message to send

  • flags[in] - ZeroMQ message send flags (default value 0)

  • identity_str[in] - identity of the destination endpoint to use for ROUTER sockets

const std::string recv(std::string *identity_str = 0)#

Receive a message on the channel

This method receives and returns a string-like message on the IpcChannel. For ROUTER-type channels, the string pointer argument has the incoming message identity copied into it. If the argument is NULL, the identity will not be copied.

Parameters:

identity_str[out] - pointer to string to receive identity on ROUTER sockets

Returns:

string containing the message

const std::size_t recv_raw(void *msg_buf, std::string *identity_str = 0)#

Receive a raw message on the channel

This method receives a raw message on the channel, copying it into the buffer specified in the argument and returning the size of the message received. For ROUTER-type channels, the string pointer argument has the incoming message identity copied into it. If this argument is NULL, the identity will not be copied.

Parameters:
  • msg_buf[out] - pointer to buffer where message should be copied

  • identity_str[out] - pointer to string to receive identity on ROUTER sockets

Returns:

size of the received message

void setsockopt(int option, const void *option_value, std::size_t option_len)#

Set an option on the channel socket

This method sets a ZeroMQ option on the socket underlying the IpcChannel.

Parameters:
  • option[in] - ZeroMQ option to set

  • option_value[in] - pointer to option value to use

  • option_len[in] - length of option value to use in bytes

void getsockopt(int option, void *option_value, std::size_t *option_len)#

Get an option from the channel socket

This method gets a ZeroMQ option from the socket underlying the IpcChannel.

Parameters:
  • option[in] - ZeroMQ option to get

  • option_value[out] - pointer to option value to use

  • option_len[inout] - length of option value to use in bytes

bool eom(void)#

Determine if the end-of-message has been reached on a channel.

This methods determines if the end-of-message has been reached on a channel, i.e. there are no more parts of a multipart message to be received.

Returns:

boolean true if end-of-message reached

bool poll(long timeout_ms = -1)#

Poll the channel for incoming messages

This method uses the ZeroMQ poll I/O multiplexing to to a timed poll on a channel. This is primarily intended for testing, as normally IpcChannels are multiplexed into an IpcReactor event loop.

Parameters:

timeout_ms[in] - poll timeout in milliseconds

Returns:

boolean true if there is incoming data ready on the socket

void close(void)#

Close the IpcChannel socket

This method closes the IpcChannel socket. Note that any subsequent attempt to use the channel without re-initialisation will generate errors.

Private Functions

void router_send_identity(const std::string &identity_str)#

Send an identity message part on ROUTER channels

This private method is used by ROUTER channels to send the identity of the destination endpoint as the first part of a multi-part ZeroMQ message. This is necessary to ensure that the sent message is routed to the correct destination (e.g. a remote DEALER channel).

Parameters:

identity_str[in] - destination identity

Private Members

IpcContext &context_#
zmq::socket_t socket_#
int socket_type_#
std::map<std::string, std::string> bound_endpoints_#

Friends

friend class IpcReactor

IpcContext#

class IpcContext#

Public Functions

zmq::context_t &get(void)#

Retrieve the underlying ZeroMQ context from the IpcContext instance

This method is used by IpcChannel instances to access the underlying ZeroMQ context during socket initialisation

Public Static Functions

static IpcContext &Instance(unsigned int io_threads = 1)#

Retrieve the single IpcContext instance.

This static method retrieves the singleton IpcContext instance used by call IpcChannels in an application.

Private Functions

IpcContext(unsigned int io_threads = 1)#

Constructor for the IpcContext class

This private constructor initialises the IpcConext instance. It should not be called directly, rather via the Instance() singleton static method. The underlying IpcContext is initialised with the specified number of IO thread.

Parameters:

io_threads[in] - number of IO threads to create.

IpcContext(const IpcContext&)#
IpcContext &operator=(const IpcContext&)#

Private Members

zmq::context_t zmq_context_#

IpcMessage#

class IpcMessage#

IpcMessage - inter-process communication JSON message format class.

Public Types

enum MsgType#

Type attribute of IPC message.

Values:

enumerator MsgTypeIllegal#

Illegal message.

enumerator MsgTypeCmd#

Command.

enumerator MsgTypeAck#

Message acknowledgement.

enumerator MsgTypeNack#

Message no-ackonowledgement.

enumerator MsgTypeNotify#

Notify message.

enum MsgVal#

Value attribute of IPC message.

Values:

enumerator MsgValIllegal#

Illegal value.

enumerator MsgValCmdReset#

Reset command message.

enumerator MsgValCmdStatus#

Status command message.

enumerator MsgValCmdConfigure#

Configure command message.

enumerator MsgValCmdRequestConfiguration#

Request configuration command message.

enumerator MsgValCmdExecute#

Execute a command message.

enumerator MsgValCmdRequestCommands#

Request available commands message.

enumerator MsgValCmdRequestVersion#

Request version information message.

enumerator MsgValCmdBufferConfigRequest#

Buffer configuration request.

enumerator MsgValCmdBufferPrechargeRequest#

Buffer precharge request.

enumerator MsgValCmdResetStatistics#

Reset statistics command.

enumerator MsgValCmdShutdown#

Process shutdown request.

enumerator MsgValNotifyIdentity#

Identity notification message.

enumerator MsgValNotifyFrameReady#

Frame ready notification message.

enumerator MsgValNotifyFrameRelease#

Frame release notification message.

enumerator MsgValNotifyBufferConfig#

Buffer configuration notification.

enumerator MsgValNotifyBufferPrecharge#

Buffer precharge notification.

enumerator MsgValNotifyStatus#

Status notification.

typedef boost::bimap<std::string, MsgType> MsgTypeMap#

Internal bi-directional mapping of message type from string to enumerated MsgType.

typedef MsgTypeMap::value_type MsgTypeMapEntry#

Internal bi-directional mapping of message type from string to enumerated MsgType.

typedef boost::bimap<std::string, MsgVal> MsgValMap#

Internal bi-directional mapping of message value from string to enumerated MsgVal.

typedef MsgValMap::value_type MsgValMapEntry#

Internal bi-directional mapping of message value from string to enumerated MsgVal.

Public Functions

IpcMessage(MsgType msg_type = MsgTypeIllegal, MsgVal msg_val = MsgValIllegal, bool strict_validation = true)#

Default constructor - initialises all attributes.

This consructs an empty IPC message object with initialised, but invalid, attributes and an empty parameter block. The message can be subsequently populated with valid contents through calls to the various setter methods provided.

Parameters:
  • msg_type – - MsgType enumerated message type (default: MsgTypeIllegal)

  • msg_val – - MsgVal enumerated message value (default: MsgValIllegal)

  • strict_validation – - Enforces strict validation of the message contents during subsequent setter calls (default: True)

IpcMessage(const char *json_msg, bool strict_validation = true)#

Constructor taking JSON-formatted text message as argument.

This constructor takes a JSON-formatted string as an argument to construct a message based on its contents. If the string is not valid JSON syntax, an IpcMessageException will be thrown. If strict validation is enabled, an IpcMessgeException will be thrown if any of the message attributes do not have valid values.

Parameters:
  • json_msg – - JSON-formatted string containing the message to parse

  • strict_validation – - Enforces strict validation of the message contents during subsequent setter calls (default: True)

IpcMessage(const rapidjson::Value &value, MsgType msg_type = MsgTypeIllegal, MsgVal msg_val = MsgValIllegal, bool strict_validation = true)#

Constructor taking rapidJSON value as argument.

This constructor takes a rapidJSON value as an argument to construct a message based on its contents.

Parameters:
  • value – - rapidJSON value to set as the parameters

  • msg_type – - MsgType enumerated message type (default: MsgTypeIllegal)

  • msg_val – - MsgVal enumerated message value (default: MsgValIllegal)

  • strict_validation – - Enforces strict validation of the message contents during subsequent setter calls (default: True)

void update(const IpcMessage &other)#

Updates parameters from another IPCMessage.

Updates parameters from another IPCMessage.

This will iterate the parameters in the given IPCMessage and set them on this instance.

Parameters:

other – - IPCMessage to take parameters from

void update(const rapidjson::Value &param_val, std::string param_prefix = "")#

Updates parameters from a rapidJSON object.

Updates parameters from a rapidJSON object.

This method will update the parameters in message with the contents of the specified JSON object.

Parameters:
  • param_val – - RapidJSON value object of parameters

  • param_prefix – - string prefix for parameter path to set

template<typename T>
inline T get_param(std::string const &param_name) const#

Gets the value of a named parameter in the message.

This template method returns the value of the specified parameter stored in the params block of the message. If the block or parameter is missing, an exception of type IpcMessageException is thrown.

Parameters:

param_name – - string name of the parameter to return

Returns:

The value of the parameter if present, otherwise an exception is thrown

template<typename T>
inline T get_param(std::string const &param_name, T const &default_value)#

Gets the value of a named parameter in the message.

This template method returns the value of the specified parameter stored in the params block of the message. if the block or parameter is missing, the specified default value is returned in its place.

Parameters:
  • param_name – - string name of the parameter to return

  • default_value – - default value to return if parameter not present in message

Returns:

The value of the parameter if present, otherwise the specified default value

std::vector<std::string> get_param_names() const#

Returns a vector of all parameter names contained in the message.

Returns:

A vector of all parameter names in this message

bool has_param(const std::string &param_name) const#

Returns true if the parameter is found within the message.

Searches for the named parameter in the message.

This method returns true if the parameter is found in the message, or false if the block or parameter is missing

Parameters:

param_name – - string name of the parameter to return

Returns:

true if the parameter is present, otherwise false

template<typename T>
inline void set_param(const std::string &param_name, T const &param_value)#

Sets the value of a named parameter in the message.

This template method sets the value of a named parameter in the message, creating that block and/orparameter if necessary. Complex names can be supplied to generate complex parameter structures.

Parameters:
  • param_name – - string name of the parameter to set

  • param_value – - value of parameter to set

void set_nack(const std::string &reason)#

Sets the nack message type with a reason parameter.

Sets the message type to not acknowledged and sets an appropriate rejection message

This method can be used to set this IpcMessage up as a rejection (nack) message. A reason is supplied and set as a parameter called ‘error’

Returns:

void

bool is_valid(void)#

Indicates if message has necessary attributes with legal values.

Indicates if message has necessary attributes with legal values.

This method indicates if the message is valid, i.e. that all required attributes have legal values and that a parameter block is present

Returns:

bool value, true if the emssage is valid, false otherwise

const MsgType get_msg_type(void) const#

Returns type attribute of message.

Returns type attribute of message.

This method returns the “msg_type” type attribute of the message.

Returns:

MsgType enumerated message type attribute

const MsgVal get_msg_val(void) const#

Returns value attribute of message.

Returns value attribute of message.

This method returns the “msg_val” value attribute of the message.

Returns:

MsgVal enumerated message value attribute

const unsigned int get_msg_id(void) const#

Returns id attribute of message.

Returns id attribute of message.

This method returns the “id” attribute of the message.

Returns:

unsigned int message id

const std::string get_msg_timestamp(void) const#

Returns message timestamp as a string in ISO8601 extended format.

Returns message timestamp as a string in ISO8601 extended format.

This method returns the message timestamp (generated either at message creation or from the parsed content of a JSON message). The message is returned as a string in ISO8601 extended format

Returns:

std::string message timestamp in ISO8601 extended format

const struct tm get_msg_datetime(void) const#

Returns message timstamp as tm structure.

Returns message timstamp as tm structure.

This method returns a standard tm struture derived from the message timestamp.

Returns:

tm struct containing the message timestamp

void set_msg_type(MsgType const msg_type)#

Sets the message type attribute.

Sets the message type attribute.

This method sets the type attribute of the message. If strict validation is enabled an IpcMessageException will be thrown if the type is illegal.

Parameters:

msg_type – - MsgType enumerated message type

void set_msg_val(MsgVal const msg_val)#

Sets the message value attribute.

Sets the message type attribute.

This method sets the value attribute of the message. If strict validation is enabled an IpcMessageException will be thrown if the value is illegal.

Parameters:

msg_val – - MsgVal enumerated message value

void set_msg_id(unsigned int msg_id)#

Sets the message id attribute.

Sets the message id attribute.

This method sets the id attribute of the message.

Parameters:

msg_id – - Message id

const char *encode(void)#

Returns a JSON-encoded string of the message.

Returns a JSON-encoded string of the message.

This method returns a JSON-encoded string version of the message, intended for transmission across an IPC message channel.

Returns:

JSON encoded message as a null-terminated, string character array

const char *encode_params(const std::string &param_path = std::string())#

Returns a JSON-encoded string of the message parameters at a specified path.

Returns a JSON-encoded string of the message parameters at a specified path

This method returns a JSON-encoded string version of the parameters associated with the message, or a subset of those at a specified slash-delimited path.

Parameters:

param_path – - JSON pointer-like slash delimited path into the parameter block

Returns:

JSON encoded parameters as a null-terminated, string character array

void copy_params(rapidjson::Value &param_obj, const std::string &param_path = std::string())#

Copies parameters at a specified into the specified JSON value object.

Copies parameters at a specified into the specified JSON value object

This method copies the message parameters at the specified path into a JSON value object.

Parameters:
  • param_obj – - reference to JSON value object to receive the parameters

  • param_path – - path of parameters in the message to copy

Private Functions

template<typename T>
inline void internal_set_param(std::string const &param_name, T const &param_value)#

Sets the value of a named parameter in the message.

This template method sets the value of a named parameter in the message, creating that block and/orparameter if necessary.

Parameters:
  • param_name – - string name of the parameter to set

  • param_value – - value of parameter to set

template<typename T>
inline T get_attribute(std::string const &attr_name)#

Gets the value of a message attribute.

This private template method returns the value of a message attribute. If the attribute is mssing, an IpcMessageException is thrown

Parameters:

attr_name – - name of the attribte to return

Returns:

value of the attribute if present, otherwise an exception is thrown

template<typename T>
inline T get_attribute(std::string const &attr_name, T const &default_value)#

Gets the value of a message attribute.

This private template method returns the value of a message attribute. If the attribute is mssing, the default value specified in the arguments is returned.

Parameters:
  • attr_name – - name of the attribute to return

  • default_value – - default value to return if attribute missing

Returns:

value of the attribute if present, otherwise an exception is thrown

template<typename T>
inline void set_attribute(std::string const &attr_name, T const &attr_value)#

Sets the value of a message attribute.

The private template method sets the value of a message attribute, creating the attribute if not already present in the message.

Parameters:
  • attr_name – - name of the attribute to set

  • attr_value – - value to set

template<typename T>
T get_value(rapidjson::Value::ConstMemberIterator &itr) const#

Gets the value of a message attribute.

This private template method gets the value of a message attribute referenced by the iterator provided as an argument. Explicit specializations of this method are provided, mapping each of the RapidJSON attribute types onto the appropriate return value.

Parameters:

itr – - RapidJSON const member iterator referencing the attribute to access

Returns:

- value of the attribute, with the appropriate type

template<typename T>
void set_value(rapidjson::Value &value_obj, T const &value)#

Sets the value of a message attribute.

This private template method sets the value of a message attribute referenced by the RapidJSON value object passed as an argument. Explicit specialisations of this method are provided below, mapping the value type specified onto each of the RapidJSON atttribute types.

Parameters:
  • value_obj – - RapidJSON value object to set value of

  • value – - value to set

void msg_type_map_init()#

Initialise the internal message type bidirectional map.

Initialise the internal message type bidirectional map.

This function initialises the interal message type bi-directional map for use in the valid_msg_type methods.

MsgType valid_msg_type(std::string msg_type_name)#

Maps a message type string to a valid enumerated MsgType.

Maps a message type string to a valid enumerated MsgType.

This private method maps a string message type to an valid enumerated MsgType. If the string is not valid, MsgTypeIllegal is returned

Parameters:

msg_type_name – - string message type

Returns:

MsgType value, MsgTypeIllegal if string is not a valid message type

std::string valid_msg_type(MsgType msg_type)#

Maps an enumerated MsgType message type to the equivalent string.

Maps an enumerated MsgType message type to the equivalent string.

This private method maps an enumnerated MsgType message type to the equivalent string. If the type is no valid, “illegal” is returned.

Parameters:

msg_type – - enumerated MsgType message type

Returns:

string containing the message type

void msg_val_map_init()#

Initialise the internal message value bidirectional map.

Initialise the internal message value bidirectional map.

This function initialises the interal message value bi-directional map for use in the valid_msg_val methods.

MsgVal valid_msg_val(std::string msg_val_name)#

Maps a message value string to a valid enumerated MsgVal.

Maps a message value string to a valid enumerated MsgVal.

This private method maps a string message value to an valid enumerated MsgVal. If the string is not valid, MsgValIllegal is returned.

Parameters:

msg_val_name – - string message value

Returns:

MsgVal value, MsgValIllegal if string is not a valid message value

std::string valid_msg_val(MsgVal msg_val)#

Maps an enumerated MsgVal message value to the equivalent string.

Maps an enumerated MsgVal message value to the equivalent string.

This private method maps an enumnerated MsgVal message value to the equivalent string. If the value is no valid, “illegal” is returned.

Parameters:

msg_val – - enumerated MsgVal message value

Returns:

string containing the message value

boost::posix_time::ptime valid_msg_timestamp(std::string msg_timestamp_text)#

Maps a message timestamp onto a the internal timestamp representation.

Maps a message timestamp onto a the internal timestamp representation.

This private method maps a valid, ISO8601 extended format timestamp string to the internal representation. If the string is not valid, the timestamp returned is set to the boost::posix::not_a_date_time value.

Parameters:

msg_timestamp_text – message timestamp string in ISO8601 extneded format

Returns:

boost::posix::ptime internal timestamp representation

std::string valid_msg_timestamp(boost::posix_time::ptime msg_timestamp)#

Maps an internal message timestamp representation to an ISO8601 extended format string.

Maps an internal message timestamp representation to an ISO8601 extended format string.

This private method maps the internal boost::posix_time::ptime timestamp representation to an ISO8601 extended format string, as used in the encoded JSON message.

Parameters:

msg_timestamp – - internal boost::posix_time::ptime timestamp representation return ISO8601 extended format timestamp string

bool has_params(void) const#

Indicates if the message has a params block.

Indicates if the message has a params block.

This private method indicates if the message has a valid params block, which may be empty but is required for valid message syntax.

Returns:

boolean value, true if message has valid params block

template<>
int get_value(rapidjson::Value::ConstMemberIterator &itr) const#
template<>
void set_value(rapidjson::Value &value_obj, int const &value)#

Sets the value of a message attribute.

This explicit specialisation of the private template method sets the value of a message attribute referenced by the RapidJSON value object passed as an argument.

Parameters:
  • value_obj – - RapidJSON value object to set value of

  • value – - integer value to set

template<>
void set_value(rapidjson::Value &value_obj, bool const &value)#

Sets the value of a message attribute.

This explicit specialisation of the private template method sets the value of a message attribute referenced by the RapidJSON value object passed as an argument.

Parameters:
  • value_obj – - RapidJSON value object to set value of

  • value – - boolean value to set

template<>
void set_value(rapidjson::Value &value_obj, unsigned int const &value)#

Sets the value of a message attribute.

This explicit specialisation of the private template method sets the value of a message attribute referenced by the RapidJSON value object passed as an argument.

Parameters:
  • value_obj – - RapidJSON value object to set value of

  • value – - unsigned integer value to set

template<>
void set_value(rapidjson::Value &value_obj, int64_t const &value)#

Sets the value of a message attribute.

This explicit specialisation of the private template method sets the value of a message attribute referenced by the RapidJSON value object passed as an argument.

Parameters:
  • value_obj – - RapidJSON value object to set value of

  • value – - int64_t value to set

template<>
void set_value(rapidjson::Value &value_obj, uint64_t const &value)#

Sets the value of a message attribute.

This explicit specialisation of the private template method sets the value of a message attribute referenced by the RapidJSON value object passed as an argument.

Parameters:
  • value_obj – - RapidJSON value object to set value of

  • value – - uint64_t value to set

template<>
void set_value(rapidjson::Value &value_obj, double const &value)#

Sets the value of a message attribute.

This explicit specialisation of the private template method sets the value of a message attribute referenced by the RapidJSON value object passed as an argument.

Parameters:
  • value_obj – - RapidJSON value object to set value of

  • value – - double value to set

template<>
void set_value(rapidjson::Value &value_obj, std::string const &value)#

Sets the value of a message attribute.

This explicit specialisation of the private template method sets the value of a message attribute referenced by the RapidJSON value object passed as an argument.

Parameters:
  • value_obj – - RapidJSON value object to set value of

  • value – - string value to set

template<>
void set_value(rapidjson::Value &value_obj, rapidjson::Value const &value)#

Sets the value of a message attribute.

This explicit specialisation of the private template method sets the value of a message attribute referenced by the RapidJSON value object passed as an argument.

Parameters:
  • value_obj – - RapidJSON value object to set value of

  • value – - RapidJSON value to set

Private Members

bool strict_validation_#

Strict validation enabled flag.

rapidjson::Document doc_#

RapidJSON document object.

MsgType msg_type_#

Message type attribute.

MsgVal msg_val_#

Message value attribute.

boost::posix_time::ptime msg_timestamp_#

Message timestamp (internal representation)

unsigned int msg_id_#

Message id attribute.

rapidjson::StringBuffer encode_buffer_#

Encoding buffer used to encode message to JSON string.

Private Static Attributes

static MsgTypeMap msg_type_map_#

Bi-directional message type map.

static MsgValMap msg_val_map_#

Bi-directional message value map.

Friends

friend bool operator==(IpcMessage const &lhs_msg, IpcMessage const &rhs_msg)#

Overloaded equality relational operator.

Overloaded equality relational operator.

This function overloads the equality relational operator, allowing two messages to be compared for the same content. All fields in the messages are compared and tested for equality

Parameters:
  • lhs_msg – - left-hand side message for comparison

  • rhs_msg – - right-hand side message for comparison

Returns:

boolean indicating equality

friend bool operator!=(IpcMessage const &lhs_msg, IpcMessage const &rhs_msg)#

Overloaded inequality relational operator.

Overloaded inequality relational operator.

This function overloads the inequality relational operator, allowing two messages to be compared for the different content. All fields in the messages are compared and tested for inequality.

Parameters:
  • lhs_msg – - left-hand side message for comparison

  • rhs_msg – - righ-hand side message for comparison

Returns:

boolean indicating inequality

friend std::ostream &operator<<(std::ostream &os, IpcMessage &the_msg)#

Overloaded stream insertion operator.

Overloaded stream insertion operator.

This function overloads the ostream insertion operator, allowing a message to be inserted into a ostream as a JSON-formatted string.

Parameters:
  • os – - std::ostream to insert string into

  • the_msg – - reference to the IpcMessage object to insert

IpcReactor#

class IpcReactor#

Public Functions

IpcReactor(void)#

Constructor

This constructs an IpcReactor object ready for use

~IpcReactor()#

Destructor

This destroys an IpcReactor object

void register_channel(IpcChannel &channel, ReactorCallback callback)#

Adds an IPC channel and associated callback to the reactor.

Adds an IPC channel and associated callback to the reactor

This method adds an IPC channel and associated callback method with the appropriate signature to the reactor.

Parameters:
  • channelIpcChannel to add to reactor

  • callback – function reference to callback method

void remove_channel(IpcChannel &channel)#

Removes an IPC chanel from the reactor.

Removes an IPC chanel from the reactor

This method removes an IPC channel and its associated callback method from the reactor.

Parameters:

channelIpcChannel to remove from the reactor

void register_socket(int socket_fd, ReactorCallback callback)#
void remove_socket(int socket_fd)#
int register_timer(size_t delay_ms, size_t times, ReactorCallback callback)#

Adds a timer to the reactor.

Adds a timer to the reactor

This method adds a timer to the reactor. The periodic delay of the timer, the number of times it should fire and the callback method to be called on firing are specified.

Parameters:
  • delay_ms – periodic timer delay in milliseconds

  • times – number of times the timer should fire (0=indefinite)

  • callback – function reference to callback method

Returns:

integer unique timer ID, which can be used by the caller to delete it subsequently

void remove_timer(int timer_id)#

Removes a timer from the reactor.

Removes a timer from the reactor

This method removes a timer from the reactor, based on the timer ID

Parameters:

timer_id – integer unique timer ID that was returned by the add_timer() method

int run(void)#

Runs the reactor polling loop.

Runs the reactor polling loop

This method runs the reactor polling loop, handling any callbacks to registered channels and timers. The loop runs indefinitely until an error occurs or the stop() method is called. The loop uses a tickless timeout based on the currently registered timers.

Returns:

integer return code, 0 = OK, -1 = error

void stop(void)#

Signals that the reactor polling loop should stop gracefully.

Signals that the reactor polling loop should stop gracefully

This method is used to signal that the reactor polling loop should stop gracefully.

Private Functions

void rebuild_pollitems(void)#

Rebuilds the internal list of polling items.

Rebuilds the internal list of polling item

This private method rebuilds the internal list of items to poll in the reactor loop. This is done when the rebuild_flag is set, i.e. after adding or deleting channels.

long calculate_timeout(void)#

Calculates the next poll timeout based on the tickless pattern.

Calculates the next poll timeout based on the tickless pattern

This private method calculates the next reactor poll timeout based on the ‘tickless’ idiom in the CZMQ zloop implementation. The timeout is set to match the next timer due to fire.

Returns:

long timeout value in milliseconds

Private Members

bool terminate_reactor_#

Indicates that the reactor loop should terminate.

ChannelMap channels_#

Map of channels associated with the reactor.

SocketMap sockets_#
TimerMap timers_#

Map of timers associated with the reactor.

zmq::pollitem_t *pollitems_#

Ptr to array of pollitems to use in poll call.

ReactorCallback *callbacks_#

Ptr to matched array of callbacks.

std::size_t pollsize_#

Number if active items to poll.

bool needs_rebuild_#

Indicates that the poll item list needs rebuilding.

boost::mutex mutex_#

Mutex used to make some calls in this class thread safe.

IpcReactorTimer#

class IpcReactorTimer#

IpcReactorTimer - timer objects for use in the IpcReactor class.

Public Functions

IpcReactorTimer(size_t delay_ms, size_t times, TimerCallback callback)#

Constructor - instantiates an IpcReactorTimer object

This instantiates and IpcReactorTimer object for use in an IpcReactor. The timer is not responsible for firing itself; rather it is a tracking object with the real work being performed by the IpcReactor event loop. The timer runs periodically, either forever or for a fixed number of times.

Parameters:
  • delay_ms – Timer delay in milliseconds for

  • times – Number of times the timer should fire, a value of 0 indicates forever

  • callback – Callback function signature to be called when the timer fires

~IpcReactorTimer()#

Destructor - destroys an IpcReactorTimer object.

int get_id(void)#

get_id - returns the unique ID of the timer instance

Returns the unique ID of the timer instance

This method returns the unique ID of the timer, which can be used to track and remove the timer from the reactor as necessary

Returns:

int unique timer id

void do_callback(void)#

Executes the registered callback method of the timer.

Executes the registered callback method of the timer

This method executes the registered callback method of the timer and then evaluates if the timer should fire again. If so, the time of the next firing is updated according to the specified delay

bool has_fired(void)#

Indicates if the timer has fired (e.g. is due for handling)

Indicates if the timer has fired (e.g. is due for handling)

This method indicates if the timer has fired, i.e. is due for handling by the controlling object.

Returns:

boolean value, true if timer has fired

bool has_expired(void)#

Indicates if the timer has expired, i.e. reached its maximum times fired.

Indicates if the timer has expired, i.e. reached its maximum times fired

This method indicates if the timer has expired, i.e. reached its maximum number of times fired and is no longer active. It is up to the controlling object to delete the timer as appropriate.

Returns:

boolean value, true if the timer has fired

TimeMs when(void)#

Indicates when (in absolute monotonic time) the timer is due to fire.

Indicates when (in absolute monotonic time) the timer is due to fire

this method indicates when a timer is next due to fire, in absolute monotonic time in milliseconds

Returns:

TimeMs value indicating when the timer is next due to fire

Public Static Functions

static TimeMs clock_mono_ms(void)#

Returns the current monotonic clock time in milliseconds (static method)

Returns the current monotonic clock time in milliseconds (static method)

This static method returns the current monotonic system clock time to millisecond precision. The monotonic clock is used rather than the local real time, since the latter can be reset by clock operations on the host system, which would disrupt the periodic operation of any timers

Returns:

TimeMs value of the current monotonic time in milliseconds

Private Members

int timer_id_#

Unique ID for the timer.

size_t delay_ms_#

Timer delay in milliseconds.

size_t times_#

Number of times the timer has left to fire.

TimerCallback callback_#

Callback method to be called when the timer fires.

TimeMs when_#

Time when the timer is next due to fire.

bool expired_#

Indicates timers has expired.

Private Static Attributes

static int last_timer_id_ = 0#

Class variable of last timer ID assigned.

IVersionedObject#

class IVersionedObject#

Interface to provide version information for any odin-data object.

All FrameReceiver and FrameProcessor plugins will subclass this interface which enforces the retrieval of version information regarding the plugin to be implemented. This information will be available through the odin-control interface.

Subclassed by FrameProcessor::FrameProcessorPlugin, FrameReceiver::FrameDecoder, FrameSimulator::FrameSimulatorPlugin

Public Functions

inline IVersionedObject()#
inline virtual ~IVersionedObject()#
virtual int get_version_major() = 0#
virtual int get_version_minor() = 0#
virtual int get_version_patch() = 0#
virtual std::string get_version_short() = 0#
virtual std::string get_version_long() = 0#

JsonDict#

class JsonDict#

Public Functions

JsonDict()#
template<typename T>
inline void add(const std::string &key, T value)#

Add a scalar value to the underlying rapidjson::Document

Parameters:
  • key[in] - The key of the item to add

  • value[in] - The value of the item to add

void add(const std::string &key, const std::string &json_value)#
template<typename T>
inline void add(const std::string &key, std::vector<T> value)#

Add a vector value to the underlying rapidjson::Document

Parameters:
  • key[in] - The key of the item to add

  • value[in] - The value of the item to add

std::string str() const#

Return a json representation of the dictionary

Generate a string from the rapidjson::Document

Returns:

- The string

Private Functions

void add(const std::string &key, rapidjson::Value &json_value)#

Add a key value pair to the underlying rapidjson::Document

Parameters:
  • key[in] - The key of the item to add

  • value[in] - The value of the item to add

Private Members

rapidjson::Document document_#