blob: 2b4a9e4df300e59032c5987f409c071eb995d0e6 [file] [log] [blame]
<!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"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Qpid Proton C++ API: helloworld.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>
<script type="text/javascript">
$(document).ready(initResizable);
</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">
$(document).ready(function() { init_search(); });
</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
&#160;<span id="projectnumber">0.25.0</span>
</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
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.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</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">
$(document).ready(function(){initNavTree('helloworld_8cpp-example.html','');});
</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">helloworld.cpp</div> </div>
</div><!--header-->
<div class="contents">
<p>Connects to a broker on 127.0.0.1:5672, establishes a subscription from the 'examples' node, and creates a sending link to the same node. Sends one message and receives it back.</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"> * &quot;License&quot;); 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"> * &quot;AS IS&quot; 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 &lt;<a class="code" href="connection_8hpp.html">proton/connection.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="container_8hpp.html">proton/container.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="delivery_8hpp.html">proton/delivery.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="message_8hpp.html">proton/message.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="messaging__handler_8hpp.html">proton/messaging_handler.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="tracker_8hpp.html">proton/tracker.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;fake_cpp11.hpp&quot;</span></div><div class="line"></div><div class="line"><span class="keyword">class </span>hello_world : <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"> std::string conn_url_;</div><div class="line"> std::string addr_;</div><div class="line"></div><div class="line"> <span class="keyword">public</span>:</div><div class="line"> hello_world(<span class="keyword">const</span> std::string&amp; u, <span class="keyword">const</span> std::string&amp; a) :</div><div class="line"> conn_url_(u), addr_(a) {}</div><div class="line"></div><div class="line"> <span class="keywordtype">void</span> <a name="a1"></a><a class="code" href="classproton_1_1messaging__handler.html#a9188622c33638e076d2214080129c824">on_container_start</a>(<a name="_a2"></a><a class="code" href="classproton_1_1container.html">proton::container</a>&amp; c) OVERRIDE {</div><div class="line"> c.<a name="a3"></a><a class="code" href="classproton_1_1container.html#adbd9ed231804512a47cca3c81f00cdf1">connect</a>(conn_url_);</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordtype">void</span> <a name="a4"></a><a class="code" href="classproton_1_1messaging__handler.html#a41277abe0e33a3df2764b08dcc12d768">on_connection_open</a>(<a name="_a5"></a><a class="code" href="classproton_1_1connection.html">proton::connection</a>&amp; c) OVERRIDE {</div><div class="line"> c.<a name="a6"></a><a class="code" href="classproton_1_1connection.html#aad60d14592ee9d34caca4c61214ecd27">open_receiver</a>(addr_);</div><div class="line"> c.<a name="a7"></a><a class="code" href="classproton_1_1connection.html#ae8eece4fd4b9e1a2531ca12d2ab57a32">open_sender</a>(addr_);</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#a86c9509ba3ce1925150c5b7a9a937c94">on_sendable</a>(<a name="_a9"></a><a class="code" href="classproton_1_1sender.html">proton::sender</a> &amp;s) OVERRIDE {</div><div class="line"> <a name="_a10"></a><a class="code" href="classproton_1_1message.html">proton::message</a> m(<span class="stringliteral">&quot;Hello World!&quot;</span>);</div><div class="line"> s.<a name="a11"></a><a class="code" href="classproton_1_1sender.html#a214eb30b24e6831d016a47b9dddda830">send</a>(m);</div><div class="line"> s.<a name="a12"></a><a class="code" href="classproton_1_1link.html#a5ae591df94fc66ccb85cbb6565368bca">close</a>();</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordtype">void</span> <a name="a13"></a><a class="code" href="classproton_1_1messaging__handler.html#a584c9daeadf4322801f58e054017fecb">on_message</a>(<a name="_a14"></a><a class="code" href="classproton_1_1delivery.html">proton::delivery</a> &amp;d, <a class="code" href="classproton_1_1message.html">proton::message</a> &amp;m) OVERRIDE {</div><div class="line"> std::cout &lt;&lt; m.<a name="a15"></a><a class="code" href="classproton_1_1message.html#ae9af642f154a68ec0eb8e715ecaf95ae">body</a>() &lt;&lt; std::endl;</div><div class="line"> d.<a name="a16"></a><a class="code" href="classproton_1_1transfer.html#aff302bb6016f2ae29f01bb4e07389a52">connection</a>().<a name="a17"></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"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv) {</div><div class="line"> <span class="keywordflow">try</span> {</div><div class="line"> std::string conn_url = argc &gt; 1 ? argv[1] : <span class="stringliteral">&quot;//127.0.0.1:5672&quot;</span>;</div><div class="line"> std::string addr = argc &gt; 2 ? argv[2] : <span class="stringliteral">&quot;examples&quot;</span>;</div><div class="line"></div><div class="line"> hello_world hw(conn_url, addr);</div><div class="line"> <a class="code" href="classproton_1_1container.html">proton::container</a>(hw).<a name="a18"></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> std::exception&amp; e) {</div><div class="line"> std::cerr &lt;&lt; e.what() &lt;&lt; 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 -->
<!-- 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.png" alt="doxygen"/></a> 1.8.13 </li>
</ul>
</div>
</body>
</html>