| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://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"/> |
| <meta http-equiv="X-UA-Compatible" content="IE=9"/> |
| <meta name="generator" content="Doxygen 1.8.20"/> |
| <meta name="viewport" content="width=device-width, initial-scale=1"/> |
| <title>Qpid Proton C++ API: simple_recv.cpp</title> |
| <link href="tabs.css" rel="stylesheet" type="text/css"/> |
| <script type="text/javascript" src="jquery.js"></script> |
| <script type="text/javascript" src="dynsections.js"></script> |
| <link href="navtree.css" rel="stylesheet" type="text/css"/> |
| <script type="text/javascript" src="resize.js"></script> |
| <script type="text/javascript" src="navtreedata.js"></script> |
| <script type="text/javascript" src="navtree.js"></script> |
| <link href="search/search.css" rel="stylesheet" type="text/css"/> |
| <script type="text/javascript" src="search/searchdata.js"></script> |
| <script type="text/javascript" src="search/search.js"></script> |
| <script type="text/javascript"> |
| /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ |
| $(document).ready(function() { init_search(); }); |
| /* @license-end */ |
| </script> |
| <link href="doxygen.css" rel="stylesheet" type="text/css" /> |
| </head> |
| <body> |
| <div id="top"><!-- do not remove this div, it is closed by doxygen! --> |
| <div id="titlearea"> |
| <table cellspacing="0" cellpadding="0"> |
| <tbody> |
| <tr style="height: 56px;"> |
| <td id="projectalign" style="padding-left: 0.5em;"> |
| <div id="projectname">Qpid Proton C++ API |
|  <span id="projectnumber">0.32.0</span> |
| </div> |
| </td> |
| <td> <div id="MSearchBox" class="MSearchBoxInactive"> |
| <span class="left"> |
| <img id="MSearchSelect" src="search/mag_sel.svg" |
| onmouseover="return searchBox.OnSearchSelectShow()" |
| onmouseout="return searchBox.OnSearchSelectHide()" |
| alt=""/> |
| <input type="text" id="MSearchField" value="Search" accesskey="S" |
| onfocus="searchBox.OnSearchFieldFocus(true)" |
| onblur="searchBox.OnSearchFieldFocus(false)" |
| onkeyup="searchBox.OnSearchFieldChange(event)"/> |
| </span><span class="right"> |
| <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a> |
| </span> |
| </div> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <!-- end header part --> |
| <!-- Generated by Doxygen 1.8.20 --> |
| <script type="text/javascript"> |
| /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ |
| var searchBox = new SearchBox("searchBox", "search",false,'Search'); |
| /* @license-end */ |
| </script> |
| </div><!-- top --> |
| <div id="side-nav" class="ui-resizable side-nav-resizable"> |
| <div id="nav-tree"> |
| <div id="nav-tree-contents"> |
| <div id="nav-sync" class="sync"></div> |
| </div> |
| </div> |
| <div id="splitbar" style="-moz-user-select:none;" |
| class="ui-resizable-handle"> |
| </div> |
| </div> |
| <script type="text/javascript"> |
| /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ |
| $(document).ready(function(){initNavTree('simple_recv_8cpp-example.html',''); initResizable(); }); |
| /* @license-end */ |
| </script> |
| <div id="doc-content"> |
| <!-- window showing the filter options --> |
| <div id="MSearchSelectWindow" |
| onmouseover="return searchBox.OnSearchSelectShow()" |
| onmouseout="return searchBox.OnSearchSelectHide()" |
| onkeydown="return searchBox.OnSearchSelectKey(event)"> |
| </div> |
| |
| <!-- iframe showing the search results (closed by default) --> |
| <div id="MSearchResultsWindow"> |
| <iframe src="javascript:void(0)" frameborder="0" |
| name="MSearchResults" id="MSearchResults"> |
| </iframe> |
| </div> |
| |
| <div class="header"> |
| <div class="headertitle"> |
| <div class="title">simple_recv.cpp</div> </div> |
| </div><!--header--> |
| <div class="contents"> |
| <p>Subscribes to the 'examples' node on an intermediary accessible on 127.0.0.1:5672. Simply prints out the body of received messages.</p> |
| <div class="fragment"><div class="line"><span class="comment">/*</span></div> |
| <div class="line"><span class="comment"> *</span></div> |
| <div class="line"><span class="comment"> * Licensed to the Apache Software Foundation (ASF) under one</span></div> |
| <div class="line"><span class="comment"> * or more contributor license agreements. See the NOTICE file</span></div> |
| <div class="line"><span class="comment"> * distributed with this work for additional information</span></div> |
| <div class="line"><span class="comment"> * regarding copyright ownership. The ASF licenses this file</span></div> |
| <div class="line"><span class="comment"> * to you under the Apache License, Version 2.0 (the</span></div> |
| <div class="line"><span class="comment"> * "License"); you may not use this file except in compliance</span></div> |
| <div class="line"><span class="comment"> * with the License. You may obtain a copy of the License at</span></div> |
| <div class="line"><span class="comment"> *</span></div> |
| <div class="line"><span class="comment"> * http://www.apache.org/licenses/LICENSE-2.0</span></div> |
| <div class="line"><span class="comment"> *</span></div> |
| <div class="line"><span class="comment"> * Unless required by applicable law or agreed to in writing,</span></div> |
| <div class="line"><span class="comment"> * software distributed under the License is distributed on an</span></div> |
| <div class="line"><span class="comment"> * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY</span></div> |
| <div class="line"><span class="comment"> * KIND, either express or implied. See the License for the</span></div> |
| <div class="line"><span class="comment"> * specific language governing permissions and limitations</span></div> |
| <div class="line"><span class="comment"> * under the License.</span></div> |
| <div class="line"><span class="comment"> *</span></div> |
| <div class="line"><span class="comment"> */</span></div> |
| <div class="line"> </div> |
| <div class="line"><span class="preprocessor">#include "options.hpp"</span></div> |
| <div class="line"> </div> |
| <div class="line"><span class="preprocessor">#include <<a class="code" href="connection_8hpp.html">proton/connection.hpp</a>></span></div> |
| <div class="line"><span class="preprocessor">#include <<a class="code" href="connection__options_8hpp.html">proton/connection_options.hpp</a>></span></div> |
| <div class="line"><span class="preprocessor">#include <<a class="code" href="container_8hpp.html">proton/container.hpp</a>></span></div> |
| <div class="line"><span class="preprocessor">#include <<a class="code" href="delivery_8hpp.html">proton/delivery.hpp</a>></span></div> |
| <div class="line"><span class="preprocessor">#include <<a class="code" href="link_8hpp.html">proton/link.hpp</a>></span></div> |
| <div class="line"><span class="preprocessor">#include <<a class="code" href="message_8hpp.html">proton/message.hpp</a>></span></div> |
| <div class="line"><span class="preprocessor">#include <<a class="code" href="message__id_8hpp.html">proton/message_id.hpp</a>></span></div> |
| <div class="line"><span class="preprocessor">#include <<a class="code" href="messaging__handler_8hpp.html">proton/messaging_handler.hpp</a>></span></div> |
| <div class="line"><span class="preprocessor">#include <<a class="code" href="value_8hpp.html">proton/value.hpp</a>></span></div> |
| <div class="line"> </div> |
| <div class="line"><span class="preprocessor">#include <iostream></span></div> |
| <div class="line"><span class="preprocessor">#include <map></span></div> |
| <div class="line"> </div> |
| <div class="line"><span class="preprocessor">#include "fake_cpp11.hpp"</span></div> |
| <div class="line"> </div> |
| <div class="line"><span class="keyword">class </span>simple_recv : <span class="keyword">public</span> <a name="_a0"></a><a class="code" href="classproton_1_1messaging__handler.html">proton::messaging_handler</a> {</div> |
| <div class="line"> <span class="keyword">private</span>:</div> |
| <div class="line"> std::string url;</div> |
| <div class="line"> std::string user;</div> |
| <div class="line"> std::string password;</div> |
| <div class="line"> <a name="_a1"></a><a class="code" href="classproton_1_1receiver.html">proton::receiver</a> receiver;</div> |
| <div class="line"> <span class="keywordtype">int</span> expected;</div> |
| <div class="line"> <span class="keywordtype">int</span> received;</div> |
| <div class="line"> </div> |
| <div class="line"> <span class="keyword">public</span>:</div> |
| <div class="line"> simple_recv(<span class="keyword">const</span> std::string &s, <span class="keyword">const</span> std::string &u, <span class="keyword">const</span> std::string &p, <span class="keywordtype">int</span> c) :</div> |
| <div class="line"> url(s), user(u), password(p), expected(c), received(0) {}</div> |
| <div class="line"> </div> |
| <div class="line"> <span class="keywordtype">void</span> <a name="a2"></a><a class="code" href="classproton_1_1messaging__handler.html#a9188622c33638e076d2214080129c824">on_container_start</a>(<a name="_a3"></a><a class="code" href="classproton_1_1container.html">proton::container</a> &c) OVERRIDE {</div> |
| <div class="line"> <a name="_a4"></a><a class="code" href="classproton_1_1connection__options.html">proton::connection_options</a> co;</div> |
| <div class="line"> <span class="keywordflow">if</span> (!user.empty()) co.<a name="a5"></a><a class="code" href="classproton_1_1connection__options.html#a10afa48d580025f71f0a6dd31bd1de24">user</a>(user);</div> |
| <div class="line"> <span class="keywordflow">if</span> (!password.empty()) co.<a name="a6"></a><a class="code" href="classproton_1_1connection__options.html#a78a90a1387cf91915dbe39b888955d75">password</a>(password);</div> |
| <div class="line"> receiver = c.<a name="a7"></a><a class="code" href="classproton_1_1container.html#a15df75d582af4ed83f0ffab9dcce84bf">open_receiver</a>(url, co);</div> |
| <div class="line"> }</div> |
| <div class="line"> </div> |
| <div class="line"> <span class="keywordtype">void</span> <a name="a8"></a><a class="code" href="classproton_1_1messaging__handler.html#a584c9daeadf4322801f58e054017fecb">on_message</a>(<a name="_a9"></a><a class="code" href="classproton_1_1delivery.html">proton::delivery</a> &d, <a name="_a10"></a><a class="code" href="classproton_1_1message.html">proton::message</a> &msg) OVERRIDE {</div> |
| <div class="line"> <span class="keywordflow">if</span> (!msg.<a name="a11"></a><a class="code" href="classproton_1_1message.html#a84811758e758988a802673edca6b77cb">id</a>().empty() && proton::coerce<int>(msg.<a class="code" href="classproton_1_1message.html#a84811758e758988a802673edca6b77cb">id</a>()) < received) {</div> |
| <div class="line"> <span class="keywordflow">return</span>; <span class="comment">// Ignore if no id or duplicate</span></div> |
| <div class="line"> }</div> |
| <div class="line"> </div> |
| <div class="line"> <span class="keywordflow">if</span> (expected == 0 || received < expected) {</div> |
| <div class="line"> std::cout << msg.<a name="a12"></a><a class="code" href="classproton_1_1message.html#ae9af642f154a68ec0eb8e715ecaf95ae">body</a>() << std::endl;</div> |
| <div class="line"> received++;</div> |
| <div class="line"> </div> |
| <div class="line"> <span class="keywordflow">if</span> (received == expected) {</div> |
| <div class="line"> d.<a name="a13"></a><a class="code" href="classproton_1_1delivery.html#aeb4319de46c92afec4ebbb3116d67c39">receiver</a>().<a name="a14"></a><a class="code" href="classproton_1_1link.html#a5ae591df94fc66ccb85cbb6565368bca">close</a>();</div> |
| <div class="line"> d.<a name="a15"></a><a class="code" href="classproton_1_1transfer.html#aff302bb6016f2ae29f01bb4e07389a52">connection</a>().<a name="a16"></a><a class="code" href="classproton_1_1connection.html#a5ae591df94fc66ccb85cbb6565368bca">close</a>();</div> |
| <div class="line"> }</div> |
| <div class="line"> }</div> |
| <div class="line"> }</div> |
| <div class="line">};</div> |
| <div class="line"> </div> |
| <div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv) {</div> |
| <div class="line"> std::string address(<span class="stringliteral">"127.0.0.1:5672/examples"</span>);</div> |
| <div class="line"> std::string user;</div> |
| <div class="line"> std::string password;</div> |
| <div class="line"> <span class="keywordtype">int</span> message_count = 100;</div> |
| <div class="line"> example::options opts(argc, argv);</div> |
| <div class="line"> </div> |
| <div class="line"> opts.add_value(address, <span class="charliteral">'a'</span>, <span class="stringliteral">"address"</span>, <span class="stringliteral">"connect to and receive from URL"</span>, <span class="stringliteral">"URL"</span>);</div> |
| <div class="line"> opts.add_value(message_count, <span class="charliteral">'m'</span>, <span class="stringliteral">"messages"</span>, <span class="stringliteral">"receive COUNT messages"</span>, <span class="stringliteral">"COUNT"</span>);</div> |
| <div class="line"> opts.add_value(user, <span class="charliteral">'u'</span>, <span class="stringliteral">"user"</span>, <span class="stringliteral">"authenticate as USER"</span>, <span class="stringliteral">"USER"</span>);</div> |
| <div class="line"> opts.add_value(password, <span class="charliteral">'p'</span>, <span class="stringliteral">"password"</span>, <span class="stringliteral">"authenticate with PASSWORD"</span>, <span class="stringliteral">"PASSWORD"</span>);</div> |
| <div class="line"> </div> |
| <div class="line"> </div> |
| <div class="line"> <span class="keywordflow">try</span> {</div> |
| <div class="line"> opts.parse();</div> |
| <div class="line"> </div> |
| <div class="line"> simple_recv recv(address, user, password, message_count);</div> |
| <div class="line"> <a class="code" href="classproton_1_1container.html">proton::container</a>(recv).<a name="a17"></a><a class="code" href="classproton_1_1container.html#a13a43e6d814de94978c515cb084873b1">run</a>();</div> |
| <div class="line"> </div> |
| <div class="line"> <span class="keywordflow">return</span> 0;</div> |
| <div class="line"> } <span class="keywordflow">catch</span> (<span class="keyword">const</span> example::bad_option& e) {</div> |
| <div class="line"> std::cout << opts << std::endl << e.what() << std::endl;</div> |
| <div class="line"> } <span class="keywordflow">catch</span> (<span class="keyword">const</span> std::exception& e) {</div> |
| <div class="line"> std::cerr << e.what() << std::endl;</div> |
| <div class="line"> }</div> |
| <div class="line"> </div> |
| <div class="line"> <span class="keywordflow">return</span> 1;</div> |
| <div class="line">}</div> |
| </div><!-- fragment --> </div><!-- contents --> |
| </div><!-- doc-content --> |
| <div class="ttc" id="aclassproton_1_1delivery_html_aeb4319de46c92afec4ebbb3116d67c39"><div class="ttname"><a href="classproton_1_1delivery.html#aeb4319de46c92afec4ebbb3116d67c39">proton::delivery::receiver</a></div><div class="ttdeci">class receiver receiver() const</div><div class="ttdoc">Return the receiver for this delivery.</div></div> |
| <div class="ttc" id="amessaging__handler_8hpp_html"><div class="ttname"><a href="messaging__handler_8hpp.html">messaging_handler.hpp</a></div><div class="ttdoc">Handler for Proton messaging events.</div></div> |
| <div class="ttc" id="amessage_8hpp_html"><div class="ttname"><a href="message_8hpp.html">message.hpp</a></div><div class="ttdoc">An AMQP message.</div></div> |
| <div class="ttc" id="aclassproton_1_1connection__options_html_a78a90a1387cf91915dbe39b888955d75"><div class="ttname"><a href="classproton_1_1connection__options.html#a78a90a1387cf91915dbe39b888955d75">proton::connection_options::password</a></div><div class="ttdeci">connection_options & password(const std::string &)</div><div class="ttdoc">Set the password used to authenticate the connection.</div></div> |
| <div class="ttc" id="aclassproton_1_1container_html"><div class="ttname"><a href="classproton_1_1container.html">proton::container</a></div><div class="ttdoc">A top-level container of connections, sessions, and links.</div><div class="ttdef"><b>Definition:</b> container.hpp:50</div></div> |
| <div class="ttc" id="adelivery_8hpp_html"><div class="ttname"><a href="delivery_8hpp.html">delivery.hpp</a></div><div class="ttdoc">A received message.</div></div> |
| <div class="ttc" id="aclassproton_1_1messaging__handler_html_a9188622c33638e076d2214080129c824"><div class="ttname"><a href="classproton_1_1messaging__handler.html#a9188622c33638e076d2214080129c824">proton::messaging_handler::on_container_start</a></div><div class="ttdeci">virtual void on_container_start(container &)</div><div class="ttdoc">The container event loop is starting.</div></div> |
| <div class="ttc" id="aclassproton_1_1messaging__handler_html_a584c9daeadf4322801f58e054017fecb"><div class="ttname"><a href="classproton_1_1messaging__handler.html#a584c9daeadf4322801f58e054017fecb">proton::messaging_handler::on_message</a></div><div class="ttdeci">virtual void on_message(delivery &, message &)</div><div class="ttdoc">A message is received.</div></div> |
| <div class="ttc" id="aclassproton_1_1receiver_html"><div class="ttname"><a href="classproton_1_1receiver.html">proton::receiver</a></div><div class="ttdoc">A channel for receiving messages.</div><div class="ttdef"><b>Definition:</b> receiver.hpp:41</div></div> |
| <div class="ttc" id="aclassproton_1_1connection__options_html"><div class="ttname"><a href="classproton_1_1connection__options.html">proton::connection_options</a></div><div class="ttdoc">Options for creating a connection.</div><div class="ttdef"><b>Definition:</b> connection_options.hpp:67</div></div> |
| <div class="ttc" id="aclassproton_1_1delivery_html"><div class="ttname"><a href="classproton_1_1delivery.html">proton::delivery</a></div><div class="ttdoc">A received message.</div><div class="ttdef"><b>Definition:</b> delivery.hpp:39</div></div> |
| <div class="ttc" id="aclassproton_1_1connection_html_a5ae591df94fc66ccb85cbb6565368bca"><div class="ttname"><a href="classproton_1_1connection.html#a5ae591df94fc66ccb85cbb6565368bca">proton::connection::close</a></div><div class="ttdeci">void close()</div><div class="ttdoc">Close the connection.</div></div> |
| <div class="ttc" id="aclassproton_1_1connection__options_html_a10afa48d580025f71f0a6dd31bd1de24"><div class="ttname"><a href="classproton_1_1connection__options.html#a10afa48d580025f71f0a6dd31bd1de24">proton::connection_options::user</a></div><div class="ttdeci">connection_options & user(const std::string &)</div><div class="ttdoc">Set the user name used to authenticate the connection.</div></div> |
| <div class="ttc" id="aclassproton_1_1link_html_a5ae591df94fc66ccb85cbb6565368bca"><div class="ttname"><a href="classproton_1_1link.html#a5ae591df94fc66ccb85cbb6565368bca">proton::link::close</a></div><div class="ttdeci">void close()</div><div class="ttdoc">Close the endpoint.</div></div> |
| <div class="ttc" id="aconnection_8hpp_html"><div class="ttname"><a href="connection_8hpp.html">connection.hpp</a></div><div class="ttdoc">A connection to a remote AMQP peer.</div></div> |
| <div class="ttc" id="aclassproton_1_1messaging__handler_html"><div class="ttname"><a href="classproton_1_1messaging__handler.html">proton::messaging_handler</a></div><div class="ttdoc">Handler for Proton messaging events.</div><div class="ttdef"><b>Definition:</b> messaging_handler.hpp:69</div></div> |
| <div class="ttc" id="aconnection__options_8hpp_html"><div class="ttname"><a href="connection__options_8hpp.html">connection_options.hpp</a></div><div class="ttdoc">Options for creating a connection.</div></div> |
| <div class="ttc" id="aclassproton_1_1transfer_html_aff302bb6016f2ae29f01bb4e07389a52"><div class="ttname"><a href="classproton_1_1transfer.html#aff302bb6016f2ae29f01bb4e07389a52">proton::transfer::connection</a></div><div class="ttdeci">class connection connection() const</div><div class="ttdoc">Return the connection for this transfer.</div></div> |
| <div class="ttc" id="avalue_8hpp_html"><div class="ttname"><a href="value_8hpp.html">value.hpp</a></div><div class="ttdoc">A holder for any AMQP value, simple or complex.</div></div> |
| <div class="ttc" id="alink_8hpp_html"><div class="ttname"><a href="link_8hpp.html">link.hpp</a></div><div class="ttdoc">A named channel for sending or receiving messages.</div></div> |
| <div class="ttc" id="aclassproton_1_1message_html_a84811758e758988a802673edca6b77cb"><div class="ttname"><a href="classproton_1_1message.html#a84811758e758988a802673edca6b77cb">proton::message::id</a></div><div class="ttdeci">void id(const message_id &)</div><div class="ttdoc">Set the message ID.</div></div> |
| <div class="ttc" id="amessage__id_8hpp_html"><div class="ttname"><a href="message__id_8hpp.html">message_id.hpp</a></div><div class="ttdoc">An AMQP message ID.</div></div> |
| <div class="ttc" id="aclassproton_1_1message_html_ae9af642f154a68ec0eb8e715ecaf95ae"><div class="ttname"><a href="classproton_1_1message.html#ae9af642f154a68ec0eb8e715ecaf95ae">proton::message::body</a></div><div class="ttdeci">void body(const value &x)</div><div class="ttdoc">Set the body. Equivalent to body() = x.</div></div> |
| <div class="ttc" id="aclassproton_1_1container_html_a13a43e6d814de94978c515cb084873b1"><div class="ttname"><a href="classproton_1_1container.html#a13a43e6d814de94978c515cb084873b1">proton::container::run</a></div><div class="ttdeci">void run()</div><div class="ttdoc">Run the container in the current thread.</div></div> |
| <div class="ttc" id="acontainer_8hpp_html"><div class="ttname"><a href="container_8hpp.html">container.hpp</a></div><div class="ttdoc">A top-level container of connections, sessions, and links.</div></div> |
| <div class="ttc" id="aclassproton_1_1container_html_a15df75d582af4ed83f0ffab9dcce84bf"><div class="ttname"><a href="classproton_1_1container.html#a15df75d582af4ed83f0ffab9dcce84bf">proton::container::open_receiver</a></div><div class="ttdeci">returned< receiver > open_receiver(const std::string &addr_url)</div><div class="ttdoc">Open a connection and receiver for addr_url.</div></div> |
| <div class="ttc" id="aclassproton_1_1message_html"><div class="ttname"><a href="classproton_1_1message.html">proton::message</a></div><div class="ttdoc">An AMQP message.</div><div class="ttdef"><b>Definition:</b> message.hpp:50</div></div> |
| <!-- start footer part --> |
| <div id="nav-path" class="navpath"><!-- id is needed for treeview function! --> |
| <ul> |
| <li class="footer">Generated by <a href="http://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.8.20 </li> |
| </ul> |
| </div> |
| </body> |
| </html> |