Qpid Proton C++  0.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
message.hpp
1 #ifndef PROTON_CPP_MESSAGE_H
2 #define PROTON_CPP_MESSAGE_H
3 
4 /*
5  *
6  * Licensed to the Apache Software Foundation (ASF) under one
7  * or more contributor license agreements. See the NOTICE file
8  * distributed with this work for additional information
9  * regarding copyright ownership. The ASF licenses this file
10  * to you under the Apache License, Version 2.0 (the
11  * "License"); you may not use this file except in compliance
12  * with the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing,
17  * software distributed under the License is distributed on an
18  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19  * KIND, either express or implied. See the License for the
20  * specific language governing permissions and limitations
21  * under the License.
22  *
23  */
24 
25 #include "proton/export.hpp"
26 #include "proton/message_id.hpp"
27 #include "proton/annotation_key.hpp"
28 #include "proton/pn_unique_ptr.hpp"
29 #include "proton/value.hpp"
30 #include "proton/duration.hpp"
31 
32 #include <string>
33 #include <vector>
34 #include <utility>
35 
36 struct pn_message_t;
37 
38 namespace proton {
39 
40 class link;
41 class delivery;
42 class message_id;
43 class annotation_key;
44 
48 class message {
49  public:
51  typedef std::map<std::string, scalar> property_map;
52 
54  typedef std::map<annotation_key, value> annotation_map;
55 
57  PN_CPP_EXTERN message();
58 
60  PN_CPP_EXTERN message(const message&);
61 
62 #if PN_HAS_CPP11
63  PN_CPP_EXTERN message(message&&);
64 #endif
65 
68  template <class T> message(const T& x) : pn_msg_(0) { body() = x; }
69 
70  PN_CPP_EXTERN ~message();
71 
73  PN_CPP_EXTERN message& operator=(const message&);
74 
77 
79  PN_CPP_EXTERN void clear();
80 
81  PN_CPP_EXTERN void id(const message_id& id);
82  PN_CPP_EXTERN message_id id() const;
83 
87  PN_CPP_EXTERN void user_id(const std::string &user);
88  PN_CPP_EXTERN std::string user_id() const;
90 
93  PN_CPP_EXTERN void encode(std::vector<char> &bytes) const;
94 
96  PN_CPP_EXTERN std::vector<char> encode() const;
97 
99  PN_CPP_EXTERN void decode(const std::vector<char> &bytes);
100 
105  PN_CPP_EXTERN void decode(proton::link, proton::delivery);
107 
109 
112 
113  PN_CPP_EXTERN void address(const std::string &addr);
114  PN_CPP_EXTERN std::string address() const;
115 
116  PN_CPP_EXTERN void reply_to(const std::string &addr);
117  PN_CPP_EXTERN std::string reply_to() const;
118 
119  PN_CPP_EXTERN void correlation_id(const message_id&);
120  PN_CPP_EXTERN message_id correlation_id() const;
121 
123 
126 
128  template<class T> void body(const T& v) { body() = v; }
129 
131  PN_CPP_EXTERN const value& body() const;
132 
134  PN_CPP_EXTERN value& body();
135 
136  PN_CPP_EXTERN void subject(const std::string &s);
137  PN_CPP_EXTERN std::string subject() const;
138 
139  PN_CPP_EXTERN void content_type(const std::string &s);
140  PN_CPP_EXTERN std::string content_type() const;
141 
142  PN_CPP_EXTERN void content_encoding(const std::string &s);
143  PN_CPP_EXTERN std::string content_encoding() const;
144 
145  PN_CPP_EXTERN void expiry_time(amqp_timestamp t);
146  PN_CPP_EXTERN amqp_timestamp expiry_time() const;
147 
148  PN_CPP_EXTERN void creation_time(amqp_timestamp t);
149  PN_CPP_EXTERN amqp_timestamp creation_time() const;
150 
160  PN_CPP_EXTERN bool inferred() const;
162  PN_CPP_EXTERN void inferred(bool);
163 
165 
168 
175  PN_CPP_EXTERN bool durable() const;
177  PN_CPP_EXTERN void durable(bool);
178 
186  PN_CPP_EXTERN duration ttl() const;
187 
189  PN_CPP_EXTERN void ttl(duration);
190 
196  PN_CPP_EXTERN uint8_t priority() const;
197 
199  PN_CPP_EXTERN void priority(uint8_t);
200 
209  PN_CPP_EXTERN bool first_acquirer() const;
210 
212  PN_CPP_EXTERN void first_acquirer(bool);
213 
218  PN_CPP_EXTERN uint32_t delivery_count() const;
219 
221  PN_CPP_EXTERN void delivery_count(uint32_t);
222 
224 
227 
228  PN_CPP_EXTERN void group_id(const std::string &s);
229  PN_CPP_EXTERN std::string group_id() const;
230 
231  PN_CPP_EXTERN void reply_to_group_id(const std::string &s);
232  PN_CPP_EXTERN std::string reply_to_group_id() const;
233 
239  PN_CPP_EXTERN int32_t group_sequence() const;
241  PN_CPP_EXTERN void group_sequence(int32_t);
242 
244 
247 
249  PN_CPP_EXTERN property_map& application_properties();
250  PN_CPP_EXTERN const property_map& application_properties() const;
251 
253  PN_CPP_EXTERN annotation_map& message_annotations();
254  PN_CPP_EXTERN const annotation_map& message_annotations() const;
255 
257  PN_CPP_EXTERN annotation_map& delivery_annotations();
258  PN_CPP_EXTERN const annotation_map& delivery_annotations() const;
259 
261 
262  private:
263  pn_message_t *pn_msg() const;
264 
265  mutable pn_message_t *pn_msg_;
266  mutable value body_;
267  mutable property_map application_properties_;
268  mutable annotation_map message_annotations_;
269  mutable annotation_map delivery_annotations_;
270 
273  friend PN_CPP_EXTERN void swap(message&, message&);
275 };
276 
277 }
278 
279 #endif // PROTON_CPP_MESSAGE_H
duration ttl() const
Get the TTL for a message.
An AMQP message.
Definition: message.hpp:48
std::map< std::string, scalar > property_map
A map of string keys and AMQP scalar values.
Definition: message.hpp:51
A span of time in milliseconds.
Definition: duration.hpp:32
void decode(const std::vector< char > &bytes)
Decode from string data into the message.
annotation_map & message_annotations()
Message annotations map, can be modified in place.
annotation_map & delivery_annotations()
Delivery annotations map, can be modified in place.
property_map & application_properties()
Application properties map, can be modified in place.
A message transfer.
Definition: delivery.hpp:36
uint32_t delivery_count() const
Get the delivery count for a message.
bool durable() const
Get the durable flag for a message.
A holder for an AMQP value.
Definition: value.hpp:33
message & operator=(const message &)
Copy a message.
void clear()
Clear the message content and properties.
uint8_t priority() const
Get the priority for a message.
bool inferred() const
Get the inferred flag for a message.
int32_t group_sequence() const
Get the group sequence for a message.
message(const T &x)
Create a message with its body set from any value that can be assigned to a proton::value.
Definition: message.hpp:68
void body(const T &v)
Set the body, equivalent to body() = v.
Definition: message.hpp:128
std::vector< char > encode() const
Return encoded message as a byte vector.
std::map< annotation_key, value > annotation_map
A map of AMQP annotation keys and AMQP values.
Definition: message.hpp:54
bool first_acquirer() const
Get the first acquirer flag for a message.
const value & body() const
Get the body.
An AMQP message ID.
Definition: message_id.hpp:39
message()
Create an empty message.