coral
A C++ library for distributed co-simulation
Classes | Functions
coral::protocol::execution Namespace Reference

Functions for constructing and parsing messages sent between execution participants. More...

Classes

class  RemoteErrorException
 Exception which signifies that the remote end sent a DENIED or ERROR message. More...
 

Functions

void CreateHelloMessage (std::vector< zmq::message_t > &message, uint16_t protocolVersion)
 Fills message with a body-less HELLO message that requests the given protocol version. More...
 
void CreateHelloMessage (std::vector< zmq::message_t > &message, uint16_t protocolVersion, const google::protobuf::MessageLite &body)
 Fills message with a HELLO message that requests the given protocol version. More...
 
void CreateDeniedMessage (std::vector< zmq::message_t > &message, const std::string &reason=std::string())
 Fills 'message' with a DENIED message with the given reason string. More...
 
void CreateMessage (std::vector< zmq::message_t > &message, coralproto::execution::MessageType type)
 Fills message with a body-less message of the given type. More...
 
void CreateMessage (std::vector< zmq::message_t > &message, coralproto::execution::MessageType type, const google::protobuf::MessageLite &body)
 Fills message with a body-less message of the given type. More...
 
void CreateErrorMessage (std::vector< zmq::message_t > &message, coralproto::execution::ErrorInfo::Code code, const std::string &details=std::string())
 Fills message with an ERROR message. More...
 
void CreateFatalErrorMessage (std::vector< zmq::message_t > &message, coralproto::execution::ErrorInfo::Code code, const std::string &details=std::string())
 Fills message with a FATAL_ERROR message. More...
 
uint16_t ParseMessageType (const zmq::message_t &header)
 Parses the first two bytes of header as an uint16_t. More...
 
uint16_t NonErrorMessageType (const std::vector< zmq::message_t > &message)
 Parses the first two bytes of the message as an uint16_t, and throws an exception if it is an ERROR message. More...
 
uint16_t ParseHelloMessage (const std::vector< zmq::message_t > &message)
 Parses HELLO or DENIED messages. More...
 

Detailed Description

Functions for constructing and parsing messages sent between execution participants.

Function Documentation

void coral::protocol::execution::CreateDeniedMessage ( std::vector< zmq::message_t > &  message,
const std::string reason = std::string() 
)

Fills 'message' with a DENIED message with the given reason string.

Any pre-existing contents of message will be replaced.

void coral::protocol::execution::CreateErrorMessage ( std::vector< zmq::message_t > &  message,
coralproto::execution::ErrorInfo::Code  code,
const std::string details = std::string() 
)

Fills message with an ERROR message.

Any pre-existing contents of message will be replaced.

void coral::protocol::execution::CreateFatalErrorMessage ( std::vector< zmq::message_t > &  message,
coralproto::execution::ErrorInfo::Code  code,
const std::string details = std::string() 
)

Fills message with a FATAL_ERROR message.

Any pre-existing contents of message will be replaced.

void coral::protocol::execution::CreateHelloMessage ( std::vector< zmq::message_t > &  message,
uint16_t  protocolVersion 
)

Fills message with a body-less HELLO message that requests the given protocol version.

Any pre-existing contents of message will be replaced.

void coral::protocol::execution::CreateHelloMessage ( std::vector< zmq::message_t > &  message,
uint16_t  protocolVersion,
const google::protobuf::MessageLite &  body 
)

Fills message with a HELLO message that requests the given protocol version.

Any pre-existing contents of message will be replaced.

void coral::protocol::execution::CreateMessage ( std::vector< zmq::message_t > &  message,
coralproto::execution::MessageType  type 
)

Fills message with a body-less message of the given type.

Any pre-existing contents of message will be replaced.

void coral::protocol::execution::CreateMessage ( std::vector< zmq::message_t > &  message,
coralproto::execution::MessageType  type,
const google::protobuf::MessageLite &  body 
)

Fills message with a body-less message of the given type.

Any pre-existing contents of message will be replaced.

uint16_t coral::protocol::execution::NonErrorMessageType ( const std::vector< zmq::message_t > &  message)

Parses the first two bytes of the message as an uint16_t, and throws an exception if it is an ERROR message.

Exceptions
RemoteErrorExceptionif message is an ERROR message.
std::invalid_argumentif message is empty.
uint16_t coral::protocol::execution::ParseHelloMessage ( const std::vector< zmq::message_t > &  message)

Parses HELLO or DENIED messages.

If message is a HELLO message, this function will parse it and return the protocol version. Otherwise, if it is a DENIED message, a RemoteErrorException will be thrown. If the message is neither of these types, a ProtocolViolationException will be thrown.

Exceptions
std::logic_errorif message is empty.
RemoteErrorExceptionif message is a DENIED message.
coral::error::ProtocolViolationExceptionif message is not a HELLO or DENIED message.
uint16_t coral::protocol::execution::ParseMessageType ( const zmq::message_t &  header)

Parses the first two bytes of header as an uint16_t.

This function does not check whether the returned number is a valid message type.

Exceptions
coral::error::ProtocolViolationExceptionif header is shorter than two bytes.