Apama  10.1.0.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
message.hpp
Go to the documentation of this file.
1 /*
2  * Title: bits/message.hpp
3  * Description: C++ header-only wrapper for C-ABI data_t type
4  * $Copyright (c) 2015-2017 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.$
5  * Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG
6  * @Version: $Id: message.hpp 302187 2017-02-15 10:49:57Z rit $
7  */
8 
15 #ifndef _DATAT_BITS_INCLUDE_TAG
16 #error Must only be included from sag_connectivity_cpp.hpp, use that instead
17 #endif
18 
27 class Message: protected sag_underlying_message_t
28 {
29 public:
34  typedef data_t payload_t;
36  Message();
37 
41  explicit Message(payload_t &&_payload);
42 
46  Message(payload_t &&_payload, metadata_t &&_metadata);
50  Message(payload_t &&_payload, map_t &&_metadata);
51 
53  ~Message();
54 
58  Message(Message &&other);
59 
64  {
65  Message tmp;
66  swap(std::move(tmp));
67  swap(std::move(other));
68  return *this;
69  }
71  const payload_t &getPayload() const;
75  const metadata_t &getMetadata() const { return reinterpret_cast<const metadata_t&>(metadata); }
76 
78  payload_t &getPayload() { return static_cast<payload_t&>(payload); }
82  metadata_t &getMetadata() { return reinterpret_cast<metadata_t&>(metadata); }
84  map_t &getMetadataMap() { return static_cast<map_t&>(metadata); }
86  const map_t &getMetadataMap() const { return static_cast<const map_t&>(metadata); }
87 
91  void setPayload(payload_t &&_payload);
95  void setMetadata(metadata_t &&_metadata);
99  void setMetadata(map_t &&_metadata);
100 
102  void swap(Message &&other);
103 
105  Message copy() const
106  {
107  return Message(getPayload().copy(), getMetadata().copy());
108  }
109 
111  static const char *HOST_MESSAGE_TYPE() {
112  return "sag.type";
113  }
114 
116  static const char *CHANNEL() {
117  return "sag.channel";
118  }
119 
133  static const char *CONTROL_TYPE() {
134  return "sag.control.type";
135  }
136 
152  static const char* MESSAGE_ID() {
153  return "sag.messageId";
154  }
155 
165  static const char* REQUEST_ID() {
166  return "sag.requestId";
167  }
168 
180  static const char* CONTROL_TYPE_FLUSH() {
181  return "Flush";
182  }
183 
194  static const char* CONTROL_TYPE_FLUSH_ACK() {
195  return "FlushAck";
196  }
197 
209  static const char* CONTROL_TYPE_ACK_REQUIRED() {
210  return "AckRequired";
211  }
212 
224  static const char* CONTROL_TYPE_ACK_UPTO() {
225  return "AckUpTo";
226  }
227 
235  Message &putMetadataValue(const char *key, const char *value);
236 
241  Message &putMetadataValue(data_t &&key, data_t &&value);
242 
246  Message &putMetadataValue(const std::string &key, const std::string &value) { return putMetadataValue(key.c_str(), value.c_str()); }
247 private:
249  Message(const Message &other) { abort(); }
251  Message &operator=(const Message &other) { abort(); }
252 };
253 
254 
Message copy() const
Return a deep copy of this message, payload and metadata.
Definition: message.hpp:105
void setPayload(payload_t &&_payload)
Set the payload.
A container for an payload and associated metadata.
Definition: message.hpp:27
static const char * CONTROL_TYPE_ACK_UPTO()
Name of the AckUpTo control message, a towards-transport control message in response to AckRequired...
Definition: message.hpp:224
Message & putMetadataValue(const char *key, const char *value)
Sets a value in the metadata.
A map class which implements many of the functions on std::map.
Definition: sag_connectivity_cpp.hpp:39
payload_t & getPayload()
Return a reference to the payload.
Definition: message.hpp:78
const map_t & getMetadataMap() const
Return a view on the metadata which can contain non-string values.
Definition: message.hpp:86
~Message()
Free the underlying payload and metadata.
const payload_t & getPayload() const
Return a reference to the payload.
void setMetadata(metadata_t &&_metadata)
Set the metadata as metadata_t.
static const char * CONTROL_TYPE()
The metadata key indicating that a message is a control message, and what its type is...
Definition: message.hpp:133
A map class which implements many of the functions on std::map.
Definition: sag_connectivity_cpp.hpp:37
Message & operator=(Message &&other)
Move assignment from another message.
Definition: message.hpp:63
static const char * CHANNEL()
Returns the metadata key used by the host for identifying the channel of the message - "sag...
Definition: message.hpp:116
Message()
Construct an empty message.
Message & putMetadataValue(const std::string &key, const std::string &value)
Sets a value in the metadata.
Definition: message.hpp:246
com::softwareag::connectivity::metadata_t metadata_t
The type of a message metadata.
Definition: message.hpp:31
data_t payload_t
The type of a message payload.
Definition: message.hpp:34
static const char * MESSAGE_ID()
The metadata key used for unique identification of towards-host messages.
Definition: message.hpp:152
map_t & getMetadataMap()
Return a view on the metadata which can contain non-string values.
Definition: message.hpp:84
A variant type which can be one of the following:
Definition: data_t.hpp:42
static const char * CONTROL_TYPE_FLUSH()
Name of the Flush control message, a towards-transport control message.
Definition: message.hpp:180
void swap(Message &&other)
Swap the contents of this message with another.
static const char * REQUEST_ID()
The metadata key used for unique identification of towards-transport control messages, with a value of type int64_t.
Definition: message.hpp:165
static const char * HOST_MESSAGE_TYPE()
Returns the metadata key used by the host for identifying the type of the message - "sag...
Definition: message.hpp:111
const metadata_t & getMetadata() const
Definition: message.hpp:75
static const char * CONTROL_TYPE_FLUSH_ACK()
Name of the FlushAck control message, a towards-host control message in response to Flush...
Definition: message.hpp:194
static const char * CONTROL_TYPE_ACK_REQUIRED()
Name of the AckRequired control message, a towards-host control message.
Definition: message.hpp:209
metadata_t & getMetadata()
Definition: message.hpp:82