| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head> |
| <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> |
| <title>mqttpp: mqtt/message.h Source File</title> |
| <link href="tabs.css" rel="stylesheet" type="text/css"/> |
| <link href="doxygen.css" rel="stylesheet" type="text/css"/> |
| </head> |
| <body> |
| <!-- Generated by Doxygen 1.6.1 --> |
| <div class="navigation" id="top"> |
| <div class="tabs"> |
| <ul> |
| <li><a href="main.html"><span>Main Page</span></a></li> |
| <li><a href="annotated.html"><span>Classes</span></a></li> |
| <li class="current"><a href="files.html"><span>Files</span></a></li> |
| </ul> |
| </div> |
| <div class="tabs"> |
| <ul> |
| <li><a href="files.html"><span>File List</span></a></li> |
| </ul> |
| </div> |
| <h1>mqtt/message.h</h1><a href="message_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 |
| <a name="l00002"></a>00002 |
| <a name="l00003"></a>00003 |
| <a name="l00004"></a>00004 |
| <a name="l00005"></a>00005 |
| <a name="l00006"></a>00006 |
| <a name="l00007"></a>00007 |
| <a name="l00008"></a>00008 <span class="comment">/*******************************************************************************</span> |
| <a name="l00009"></a>00009 <span class="comment"> * Copyright (c) 2013 Frank Pagliughi <fpagliughi@mindspring.com></span> |
| <a name="l00010"></a>00010 <span class="comment"> *</span> |
| <a name="l00011"></a>00011 <span class="comment"> * All rights reserved. This program and the accompanying materials</span> |
| <a name="l00012"></a>00012 <span class="comment"> * are made available under the terms of the Eclipse Public License v1.0</span> |
| <a name="l00013"></a>00013 <span class="comment"> * and Eclipse Distribution License v1.0 which accompany this distribution. </span> |
| <a name="l00014"></a>00014 <span class="comment"> *</span> |
| <a name="l00015"></a>00015 <span class="comment"> * The Eclipse Public License is available at </span> |
| <a name="l00016"></a>00016 <span class="comment"> * http://www.eclipse.org/legal/epl-v10.html</span> |
| <a name="l00017"></a>00017 <span class="comment"> * and the Eclipse Distribution License is available at </span> |
| <a name="l00018"></a>00018 <span class="comment"> * http://www.eclipse.org/org/documents/edl-v10.php.</span> |
| <a name="l00019"></a>00019 <span class="comment"> *</span> |
| <a name="l00020"></a>00020 <span class="comment"> * Contributors:</span> |
| <a name="l00021"></a>00021 <span class="comment"> * Frank Pagliughi - initial implementation and documentation</span> |
| <a name="l00022"></a>00022 <span class="comment"> *******************************************************************************/</span> |
| <a name="l00023"></a>00023 |
| <a name="l00024"></a>00024 <span class="preprocessor">#ifndef __mqtt_message_h</span> |
| <a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#define __mqtt_message_h</span> |
| <a name="l00026"></a>00026 <span class="preprocessor"></span> |
| <a name="l00027"></a>00027 <span class="keyword">extern</span> <span class="stringliteral">"C"</span> { |
| <a name="l00028"></a>00028 <span class="preprocessor"> #include "MQTTAsync.h"</span> |
| <a name="l00029"></a>00029 } |
| <a name="l00030"></a>00030 |
| <a name="l00031"></a>00031 <span class="preprocessor">#include <string></span> |
| <a name="l00032"></a>00032 <span class="preprocessor">#include <memory></span> |
| <a name="l00033"></a>00033 <span class="preprocessor">#include <stdexcept></span> |
| <a name="l00034"></a>00034 |
| <a name="l00035"></a>00035 <span class="keyword">namespace </span>mqtt { |
| <a name="l00036"></a>00036 |
| <a name="l00038"></a>00038 |
| <a name="l00044"></a><a class="code" href="classmqtt_1_1message.html">00044</a> <span class="keyword">class </span><a class="code" href="classmqtt_1_1message.html" title="An MQTT message holds the application payload and options specifying how the message...">message</a> |
| <a name="l00045"></a>00045 { |
| <a name="l00047"></a>00047 MQTTAsync_message msg_; |
| <a name="l00048"></a>00048 |
| <a name="l00050"></a><a class="code" href="classmqtt_1_1message.html#ac39954340d8b15edaa883af1bcfcf7ae">00050</a> <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classmqtt_1_1async__client.html" title="Lightweight client for talking to an MQTT server using non-blocking methods that...">async_client</a>; |
| <a name="l00051"></a>00051 |
| <a name="l00056"></a>00056 <span class="keywordtype">void</span> set_duplicate(<span class="keywordtype">bool</span> dup) { msg_.dup = (dup) ? (!0) : 0; } |
| <a name="l00062"></a>00062 <span class="keywordtype">void</span> copy_payload(<span class="keyword">const</span> <span class="keywordtype">void</span>* payload, <span class="keywordtype">size_t</span> len); |
| <a name="l00063"></a>00063 |
| <a name="l00064"></a>00064 <span class="keyword">public</span>: |
| <a name="l00068"></a><a class="code" href="classmqtt_1_1message.html#ab310ab7859aa48dc0a6489fa331f41fc">00068</a> <span class="keyword">typedef</span> std::shared_ptr<message> <a class="code" href="classmqtt_1_1message.html#ab310ab7859aa48dc0a6489fa331f41fc" title="Smart/shared pointer to this class.">ptr_t</a>; |
| <a name="l00073"></a>00073 <a class="code" href="classmqtt_1_1message.html#a3c82927ad233c393b30f28f376b9d1b0" title="Constructs a message with an empty payload, and all other values set to defaults...">message</a>(); |
| <a name="l00078"></a>00078 <a class="code" href="classmqtt_1_1message.html#a3c82927ad233c393b30f28f376b9d1b0" title="Constructs a message with an empty payload, and all other values set to defaults...">message</a>(<span class="keyword">const</span> <span class="keywordtype">void</span>* payload, <span class="keywordtype">size_t</span> len); |
| <a name="l00083"></a>00083 <a class="code" href="classmqtt_1_1message.html#a3c82927ad233c393b30f28f376b9d1b0" title="Constructs a message with an empty payload, and all other values set to defaults...">message</a>(<span class="keyword">const</span> std::string& payload); |
| <a name="l00087"></a>00087 <a class="code" href="classmqtt_1_1message.html#a3c82927ad233c393b30f28f376b9d1b0" title="Constructs a message with an empty payload, and all other values set to defaults...">message</a>(<span class="keyword">const</span> MQTTAsync_message& msg); |
| <a name="l00091"></a>00091 <a class="code" href="classmqtt_1_1message.html#a3c82927ad233c393b30f28f376b9d1b0" title="Constructs a message with an empty payload, and all other values set to defaults...">message</a>(<span class="keyword">const</span> <a class="code" href="classmqtt_1_1message.html" title="An MQTT message holds the application payload and options specifying how the message...">message</a>& other); |
| <a name="l00095"></a>00095 <a class="code" href="classmqtt_1_1message.html#a3c82927ad233c393b30f28f376b9d1b0" title="Constructs a message with an empty payload, and all other values set to defaults...">message</a>(<a class="code" href="classmqtt_1_1message.html" title="An MQTT message holds the application payload and options specifying how the message...">message</a>&& other); |
| <a name="l00099"></a>00099 <a class="code" href="classmqtt_1_1message.html#ad66d97679cdd8c1f7b22446801295f51" title="Destroys a message and frees all associated resources.">~message</a>(); |
| <a name="l00105"></a>00105 <a class="code" href="classmqtt_1_1message.html" title="An MQTT message holds the application payload and options specifying how the message...">message</a>& <a class="code" href="classmqtt_1_1message.html#ae40dd6ffa3596bcef33b81f8a3995f3f" title="Copies another message to this one.">operator=</a>(<span class="keyword">const</span> <a class="code" href="classmqtt_1_1message.html" title="An MQTT message holds the application payload and options specifying how the message...">message</a>& rhs); |
| <a name="l00111"></a>00111 <a class="code" href="classmqtt_1_1message.html" title="An MQTT message holds the application payload and options specifying how the message...">message</a>& <a class="code" href="classmqtt_1_1message.html#ae40dd6ffa3596bcef33b81f8a3995f3f" title="Copies another message to this one.">operator=</a>(<a class="code" href="classmqtt_1_1message.html" title="An MQTT message holds the application payload and options specifying how the message...">message</a>&& rhs); |
| <a name="l00115"></a>00115 <span class="keywordtype">void</span> <a class="code" href="classmqtt_1_1message.html#a74ab9515b7f84a9023c61a942a2b2459" title="Clears the payload, resetting it to be empty.">clear_payload</a>(); |
| <a name="l00119"></a>00119 std::string <a class="code" href="classmqtt_1_1message.html#aba72487cdf0852e11eb94895cddbeb51" title="Gets the payload.">get_payload</a>() <span class="keyword">const</span>; |
| <a name="l00124"></a><a class="code" href="classmqtt_1_1message.html#aacab31d78f9ac17f962d89f9405c0c38">00124</a> <span class="keywordtype">int</span> <a class="code" href="classmqtt_1_1message.html#aacab31d78f9ac17f962d89f9405c0c38" title="Returns the quality of service for this message.">get_qos</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> msg_.qos; } |
| <a name="l00130"></a><a class="code" href="classmqtt_1_1message.html#ad05a411b58f9b7aad271c2dee0c937f8">00130</a> <span class="keywordtype">bool</span> <a class="code" href="classmqtt_1_1message.html#ad05a411b58f9b7aad271c2dee0c937f8" title="Returns whether or not this message might be a duplicate of one which has already...">is_duplicate</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> msg_.dup != 0; } |
| <a name="l00136"></a><a class="code" href="classmqtt_1_1message.html#aa845a148b73a9be79c4e5d09910d36b7">00136</a> <span class="keywordtype">bool</span> <a class="code" href="classmqtt_1_1message.html#aa845a148b73a9be79c4e5d09910d36b7" title="Returns whether or not this message should be/was retained by the server.">is_retained</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> msg_.retained != 0; } |
| <a name="l00140"></a>00140 <span class="keywordtype">void</span> <a class="code" href="classmqtt_1_1message.html#ae784b5150baacfaaca319c0ce84ddcb2" title="Sets the payload of this message to be the specified byte array.">set_payload</a>(<span class="keyword">const</span> <span class="keywordtype">void</span>* payload, <span class="keywordtype">size_t</span> n); |
| <a name="l00144"></a>00144 <span class="keywordtype">void</span> <a class="code" href="classmqtt_1_1message.html#ae784b5150baacfaaca319c0ce84ddcb2" title="Sets the payload of this message to be the specified byte array.">set_payload</a>(<span class="keyword">const</span> std::string& payload); |
| <a name="l00150"></a><a class="code" href="classmqtt_1_1message.html#af666e57c7e68f43e5331f09a843b4262">00150</a> <span class="keywordtype">void</span> <a class="code" href="classmqtt_1_1message.html#af666e57c7e68f43e5331f09a843b4262" title="Sets the quality of service for this message.">set_qos</a>(<span class="keywordtype">int</span> qos) <span class="keywordflow">throw</span>(std::invalid_argument) { |
| <a name="l00151"></a>00151 <a class="code" href="classmqtt_1_1message.html#a5da9f7a3c9c437069e32f05a933a62aa" title="Determines if the QOS value is a valid one.">validate_qos</a>(qos); |
| <a name="l00152"></a>00152 msg_.qos = qos; |
| <a name="l00153"></a>00153 } |
| <a name="l00159"></a><a class="code" href="classmqtt_1_1message.html#a51c7f7cfe89ebcc17d1686ec025193d2">00159</a> <span class="keywordtype">void</span> <a class="code" href="classmqtt_1_1message.html#a51c7f7cfe89ebcc17d1686ec025193d2" title="Whether or not the publish message should be retained by the messaging engine.">set_retained</a>(<span class="keywordtype">bool</span> retained) { msg_.retained = (retained) ? (!0) : 0; } |
| <a name="l00164"></a><a class="code" href="classmqtt_1_1message.html#a0f89f7c1ae58dc8b3ceaae6c86781e22">00164</a> std::string <a class="code" href="classmqtt_1_1message.html#a0f89f7c1ae58dc8b3ceaae6c86781e22" title="Returns a string representation of this messages payload.">to_str</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classmqtt_1_1message.html#aba72487cdf0852e11eb94895cddbeb51" title="Gets the payload.">get_payload</a>(); } |
| <a name="l00170"></a><a class="code" href="classmqtt_1_1message.html#a5da9f7a3c9c437069e32f05a933a62aa">00170</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classmqtt_1_1message.html#a5da9f7a3c9c437069e32f05a933a62aa" title="Determines if the QOS value is a valid one.">validate_qos</a>(<span class="keywordtype">int</span> qos) <span class="keywordflow">throw</span>(std::invalid_argument) { |
| <a name="l00171"></a>00171 <span class="keywordflow">if</span> (qos < 0 || qos > 2) |
| <a name="l00172"></a>00172 <span class="keywordflow">throw</span> std::invalid_argument(<span class="stringliteral">"QOS invalid"</span>); |
| <a name="l00173"></a>00173 } |
| <a name="l00174"></a>00174 }; |
| <a name="l00175"></a>00175 |
| <a name="l00176"></a>00176 <span class="keyword">typedef</span> <a class="code" href="classmqtt_1_1message.html#ab310ab7859aa48dc0a6489fa331f41fc" title="Smart/shared pointer to this class.">message::ptr_t</a> message_ptr; |
| <a name="l00177"></a>00177 |
| <a name="l00179"></a>00179 <span class="comment">// end namespace mqtt</span> |
| <a name="l00180"></a>00180 } |
| <a name="l00181"></a>00181 |
| <a name="l00182"></a>00182 <span class="preprocessor">#endif // __mqtt_message_h</span> |
| <a name="l00183"></a>00183 <span class="preprocessor"></span> |
| </pre></div></div> |
| <hr size="1"/><address style="text-align: right;"><small>Generated on 30 Apr 2014 for mqttpp by |
| <a href="http://www.doxygen.org/index.html"> |
| <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address> |
| </body> |
| </html> |