Qpid Proton C++  0.14.0
message.hpp
1 #ifndef PROTON_MESSAGE_HPP
2 #define PROTON_MESSAGE_HPP
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 "./annotation_key.hpp"
26 #include "./codec/map.hpp"
27 #include "./duration.hpp"
28 #include "./internal/export.hpp"
29 #include "./message_id.hpp"
30 #include "./value.hpp"
31 
32 #include "./internal/cached_map.hpp"
33 #include "./internal/pn_unique_ptr.hpp"
34 
35 #include <string>
36 #include <vector>
37 #include <utility>
38 
39 struct pn_message_t;
40 
41 namespace proton {
42 
43 class delivery;
44 class message_id;
45 class annotation_key;
46 
51 class message {
52  public:
55  class property_map : public internal::cached_map<std::string, scalar> {};
56 
59  class annotation_map : public internal::cached_map<annotation_key, value> {};
60 
62  PN_CPP_EXTERN message();
63 
65  PN_CPP_EXTERN message(const message&);
66 
68  PN_CPP_EXTERN message& operator=(const message&);
69 
70 #if PN_CPP_HAS_RVALUE_REFERENCES
71  PN_CPP_EXTERN message(message&&);
73 
75  PN_CPP_EXTERN message& operator=(message&&);
76 #endif
77 
80  PN_CPP_EXTERN message(const value& x);
81 
82  PN_CPP_EXTERN ~message();
83 
86 
88  PN_CPP_EXTERN void clear();
89 
94  PN_CPP_EXTERN void id(const message_id& id);
95 
97  PN_CPP_EXTERN message_id id() const;
98 
100  PN_CPP_EXTERN void user(const std::string &user);
101 
103  PN_CPP_EXTERN std::string user() const;
104 
107  PN_CPP_EXTERN void encode(std::vector<char> &bytes) const;
108 
110  PN_CPP_EXTERN std::vector<char> encode() const;
111 
113  PN_CPP_EXTERN void decode(const std::vector<char> &bytes);
114 
116 
119 
121  PN_CPP_EXTERN void to(const std::string &addr);
122 
124  PN_CPP_EXTERN std::string to() const;
125 
128  PN_CPP_EXTERN void address(const std::string &addr);
129  PN_CPP_EXTERN std::string address() const;
131 
133  PN_CPP_EXTERN void reply_to(const std::string &addr);
134 
136  PN_CPP_EXTERN std::string reply_to() const;
137 
139  PN_CPP_EXTERN void correlation_id(const message_id&);
140 
142  PN_CPP_EXTERN message_id correlation_id() const;
143 
145 
148 
150  PN_CPP_EXTERN void body(const value& x);
151 
153  PN_CPP_EXTERN const value& body() const;
154 
156  PN_CPP_EXTERN value& body();
157 
159  PN_CPP_EXTERN void subject(const std::string &s);
160 
162  PN_CPP_EXTERN std::string subject() const;
163 
165  PN_CPP_EXTERN void content_type(const std::string &s);
166 
168  PN_CPP_EXTERN std::string content_type() const;
169 
171  PN_CPP_EXTERN void content_encoding(const std::string &s);
172 
174  PN_CPP_EXTERN std::string content_encoding() const;
175 
177  PN_CPP_EXTERN void expiry_time(timestamp t);
178 
180  PN_CPP_EXTERN timestamp expiry_time() const;
181 
183  PN_CPP_EXTERN void creation_time(timestamp t);
184 
186  PN_CPP_EXTERN timestamp creation_time() const;
187 
197  PN_CPP_EXTERN bool inferred() const;
198 
200  PN_CPP_EXTERN void inferred(bool);
201 
203 
206 
211  PN_CPP_EXTERN bool durable() const;
212 
214  PN_CPP_EXTERN void durable(bool);
215 
223  PN_CPP_EXTERN duration ttl() const;
224 
226  PN_CPP_EXTERN void ttl(duration);
227 
233  PN_CPP_EXTERN uint8_t priority() const;
234 
236  PN_CPP_EXTERN void priority(uint8_t);
237 
246 
247  // XXX The triple-not in the last sentence above is confusing.
248 
249  PN_CPP_EXTERN bool first_acquirer() const;
250 
252  PN_CPP_EXTERN void first_acquirer(bool);
253 
258  PN_CPP_EXTERN uint32_t delivery_count() const;
259 
261  PN_CPP_EXTERN void delivery_count(uint32_t);
262 
264 
267 
269  PN_CPP_EXTERN void group_id(const std::string &s);
270 
272  PN_CPP_EXTERN std::string group_id() const;
273 
275  PN_CPP_EXTERN void reply_to_group_id(const std::string &s);
276 
278  PN_CPP_EXTERN std::string reply_to_group_id() const;
279 
285  PN_CPP_EXTERN int32_t group_sequence() const;
286 
288  PN_CPP_EXTERN void group_sequence(int32_t);
289 
291 
294 
297  PN_CPP_EXTERN property_map& properties();
298 
301  PN_CPP_EXTERN const property_map& properties() const;
302 
305  PN_CPP_EXTERN annotation_map& message_annotations();
306 
309  PN_CPP_EXTERN const annotation_map& message_annotations() const;
310 
313  PN_CPP_EXTERN annotation_map& delivery_annotations();
314 
317  PN_CPP_EXTERN const annotation_map& delivery_annotations() const;
318 
320 
322  private:
323  pn_message_t *pn_msg() const;
324 
325  mutable pn_message_t *pn_msg_;
326  mutable internal::value_ref body_;
327  mutable property_map application_properties_;
328  mutable annotation_map message_annotations_;
329  mutable annotation_map delivery_annotations_;
330 
332  void decode(proton::delivery);
333 
334  PN_CPP_EXTERN friend void swap(message&, message&);
335  friend class messaging_adapter;
337 };
338 
339 } // proton
340 
341 #endif // PROTON_MESSAGE_HPP
duration ttl() const
Get the TTL.
An AMQP message.
Definition: message.hpp:51
message_id id() const
Get the message ID.
std::string to() const
Get the destination address.
std::string subject() const
Get the subject.
std::string user() const
Get the user name or ID.
A span of time in milliseconds.
Definition: duration.hpp:34
message_id correlation_id() const
Get the ID for matching related messages.
Experimental - A map of AMQP annotation keys and AMQP values.
Definition: message.hpp:59
void decode(const std::vector< char > &bytes)
Decode from string data into the message.
timestamp expiry_time() const
Get the expiration time.
annotation_map & message_annotations()
Experimental - Get the message annotations map.
annotation_map & delivery_annotations()
Experimental - Get the delivery annotations map.
A received message.
Definition: delivery.hpp:40
Experimental - A map of string keys and AMQP scalar values.
Definition: message.hpp:55
uint32_t delivery_count() const
Get the delivery count.
std::string reply_to_group_id() const
Get the reply-to group ID.
timestamp creation_time() const
Get the creation time.
std::string reply_to() const
Get the address for replies.
A 64-bit timestamp in milliseconds since the Unix epoch.
Definition: timestamp.hpp:30
bool durable() const
Get the durable flag.
A holder for any AMQP value, simple or complex.
Definition: value.hpp:60
message & operator=(const message &)
Copy a message.
void clear()
Clear the message content and properties.
uint8_t priority() const
Get the priority.
bool inferred() const
Get the inferred flag.
std::string content_encoding() const
Get the content encoding of the body.
int32_t group_sequence() const
Get the group sequence.
std::string group_id() const
Get the message group ID.
property_map & properties()
Experimental - Get the application properties map.
std::vector< char > encode() const
Return encoded message as a byte vector.
bool first_acquirer() const
Get the first acquirer flag.
Type traits for mapping between AMQP and C++ types.
Definition: annotation_key.hpp:28
const value & body() const
Get the body.
An AMQP message ID.
Definition: message_id.hpp:42
std::string content_type() const
Get the content type of the body.
message()
Create an empty message.