ewol/ewol_tutorial_object_message.html

185 lines
17 KiB
HTML

<!-- HTML header for doxygen 1.8.8-->
<!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="X-UA-Compatible" content="IE=edge">
<!-- For Mobile Devices -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta name="generator" content="Doxygen 1.8.12"/>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<title>Ewol: Ewol Widget in OpenGl: EWOL: Object message</title>
<!--<link href="tabs.css" rel="stylesheet" type="text/css"/>-->
<script type="text/javascript" src="dynsections.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>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="doxy-boot.js"></script>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand">Ewol: Ewol Widget in OpenGl 0.10.0</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="index.html">Main&nbsp;Page</a></li>
<li><a href="pages.html">Related&nbsp;Pages</a></li>
<li><a href="namespaces.html">Namespaces</a></li>
<li><a href="annotated.html">Classes</a></li>
<li><a href="files.html">Files</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Link-libs<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="http://HeeroYui.github.io/lutin">lutin</a></li>
<li><a href="http://atria-soft.github.io/ewol">ewol</a></li>
<li><a href="http://atria-soft.github.io/echrono">echrono</a></li>
<li><a href="http://atria-soft.github.io/etk">etk</a></li>
<li><a href="http://atria-soft.github.io/ejson">ejson</a></li>
<li><a href="http://atria-soft.github.io/exml">exml</a></li>
<li><a href="http://atria-soft.github.io/esvg">esvg</a></li>
<li><a href="http://atria-soft.github.io/egami">egami</a></li>
<li><a href="http://atria-soft.github.io/gale">gale</a></li>
<li><a href="http://atria-soft.github.io/ege">ege</a></li>
<li><a href="http://atria-soft.github.io/elog">elog</a></li>
<li><a href="http://atria-soft.github.io/ememory">ememory</a></li>
<li><a href="http://atria-soft.github.io/enet">enet</a></li>
<li><a href="http://atria-soft.github.io/eproperty">eproperty</a></li>
<li><a href="http://atria-soft.github.io/esignal">esignal</a></li>
<li><a href="http://atria-soft.github.io/etranslate">etranslate</a></li>
<li><a href="http://atria-soft.github.io/zeus">zeus</a></li>
<li><a href="http://musicdsp.github.io/audio-ess">audio-ess</a></li>
<li><a href="http://musicdsp.github.io/audio">audio</a></li>
<li><a href="http://musicdsp.github.io/audio-drain">audio-drain</a></li>
<li><a href="http://musicdsp.github.io/audio-orchestra">audio-orchestra</a></li>
<li><a href="http://musicdsp.github.io/audio-river">audio-river</a></li>
</ul>
</li>
</ul>
<div id="search-box" class="input-group">
<div class="input-group-btn">
<button aria-expanded="false" type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-search"></span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#">All</a></li>
<li><a href="#">Classes</a></li>
<li><a href="#">Namespaces</a></li>
<li><a href="#">Files</a></li>
<li><a href="#">Functions</a></li>
<li><a href="#">Variables</a></li>
<li><a href="#">Typedefs</a></li>
<li><a href="#">Enumerations</a></li>
<li><a href="#">Enumerator</a></li>
<li><a href="#">Friends</a></li>
<li><a href="#">Macros</a></li>
<li><a href="#">Pages</a></li>
</ul>
</div>
<button id="search-close" type="button" class="close" aria-label="Close">
<span aria-hidden="true"></span>
</button>
<input id="search-field" class="form-control" accesskey="S" onkeydown="searchBox.OnSearchFieldChange(event);" placeholder="Search ..." type="text">
</div>
</div><!--/.nav-collapse -->
</div>
</nav>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div class="content" id="content">
<div class="container">
<div class="row">
<div class="col-sm-12 panel panel-default" style="padding-bottom: 15px;">
<div style="margin-bottom: 15px;margin-top: 60px;">
<!-- end header part -->
<!-- Generated by Doxygen 1.8.12 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- 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><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">EWOL: Object message </div> </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#ewol_tutorial_object_message_objectifs">Objectifs: </a></li>
<li class="level1"><a href="#ewol_tutorial_object_message_system">Message system </a></li>
<li class="level1"><a href="#ewol_tutorial_object_message_from_object">Receive signals from other object </a></li>
<li class="level1"><a href="#ewol_tutorial_object_message_declare">Declare Signal: </a></li>
<li class="level1"><a href="#ewol_tutorial_object_message_conclusion">Conclusion: </a></li>
</ul>
</div>
<div class="textblock"><p>Constructor MyObj() { // nothing to do.. } void <a class="elRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/namespaceetk.html#aa87d94d7a27bd41c9982fe0ba83d6f88">init()</a> { ewol::Object::init(); m_button = <a class="el" href="message_8hpp.html#abc42ae0f5f36d369f8e81d14741c2a48" title="Create a simple pop-up message on the screen for application error. ">ewol::widget::Button::create()</a>; if (m_button == nullptr) { APPL_ERROR("Can not create button..."); return; } m_button-&gt;propertyToggle.set(true); // We connect signals here: (permanent connection) m_button-&gt;signalUp.connect(sharedFromThis(), &amp;appl::MyObj::onCallbackUp); m_button-&gt;signalValue.connect(sharedFromThis(), &amp;appl::MyObj::onCallbackValue); } public: //!</p>
<h1><a class="anchor" id="ewol_tutorial_object_message_objectifs"></a>
Objectifs: </h1>
<ul>
<li>Understand base of <a href="http://atria-soft.github.io/esignal">e-signal</a> Messaging system</li>
<li>Create extern message and receive Object message</li>
</ul>
<h1><a class="anchor" id="ewol_tutorial_object_message_system"></a>
Message system </h1>
<p>esignal base his signal on landa functions</p>
<p>It permit to an object to generate some **'signals'**</p>
<p>All signal are synchronous *(asynchronous is not implemented yet)*</p>
<h1><a class="anchor" id="ewol_tutorial_object_message_from_object"></a>
Receive signals from other object </h1>
<p>Register on the 'up' and 'value' signal of a button:</p>
<p>Button header : </p><div class="fragment"><div class="line">...</div><div class="line">public:</div><div class="line"> esignal::Signal&lt;&gt; signalDown;</div><div class="line"> esignal::Signal&lt;&gt; signalUp;</div><div class="line"> ...</div><div class="line"> esignal::Signal&lt;bool&gt; signalValue;</div><div class="line">...</div></div><!-- fragment --><h2>simple signal connection: </h2>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="_object_8hpp.html">ewol/object/Object.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="_button_8hpp.html">ewol/widget/Button.hpp</a>&gt;</span></div><div class="line"><span class="keyword">namespace </span>appl {</div><div class="line"> <span class="keyword">class </span>MyObj : <span class="keyword">public</span> <a class="code" href="classewol_1_1_object.html">ewol::Object</a> {</div><div class="line"> <span class="keyword">private</span>:</div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/ememory.tag:http://atria-soft.github.io/ememory/" href="http://atria-soft.github.io/ememory/classememory_1_1_shared_ptr.html">ewol::widget::ButtonShared</a> m_button;</div><div class="line"> esignal::Connection m_connect;</div><div class="line"> <span class="keyword">protected</span>:</div><div class="line"> <span class="keyword">virtual</span> ~MyObj() { }</div><div class="line"> DECLARE_FACTORY(MyObj);</div><div class="line"> <span class="keyword">private</span>:</div><div class="line"> <span class="keywordtype">void</span> onCallbackUp() {</div><div class="line"> APPL_INFO(<span class="stringliteral">&quot;button pressed: UP&quot;</span>);</div><div class="line"> }</div><div class="line"> <span class="keywordtype">void</span> onCallbackDown() {</div><div class="line"> APPL_INFO(<span class="stringliteral">&quot;button pressed: DOWN&quot;</span>);</div><div class="line"> }</div><div class="line"> <span class="keywordtype">void</span> onCallbackValue(<span class="keyword">const</span> <span class="keywordtype">bool</span>&amp; _value) {</div><div class="line"> APPL_INFO(<span class="stringliteral">&quot;button value: &quot;</span> &lt;&lt; _value);</div><div class="line"> <span class="keywordflow">if</span> (_value == <span class="keyword">true</span>) {</div><div class="line"> <span class="comment">// We connect signals here: (removable connection)</span></div><div class="line"> m_connect = m_button-&gt;signalDown.connect(<span class="keyword">this</span>, &amp;appl::MyObj::onCallbackDown);</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> <span class="comment">// we disconnect the previous connection</span></div><div class="line"> m_connect.disconnect();</div><div class="line"> }</div><div class="line"> }</div><div class="line"> }</div><div class="line">}</div></div><!-- fragment --><p><b>Note:</b></p>
<div class="fragment"><div class="line">The connection with SharedPtr are static. they keep in internal a WeakPtr to remove connection if the object is removed.</div></div><!-- fragment --><p><b>Note:</b></p>
<div class="fragment"><div class="line">The connection that return a esignal::Connection are volatil, if you don&#39;t keep the connection handle, the connection is automaticly removed.</div></div><!-- fragment --><h1><a class="anchor" id="ewol_tutorial_object_message_declare"></a>
Declare Signal: </h1>
<h2>source </h2>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="_object_8hpp.html">ewol/object/Object.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="_button_8hpp.html">ewol/widget/Button.hpp</a>&gt;</span></div><div class="line"><span class="keyword">namespace </span>appl {</div><div class="line"> <span class="keyword">class </span>MyObj : <span class="keyword">public</span> <a class="code" href="classewol_1_1_object.html">ewol::Object</a> {</div><div class="line"> <span class="keyword">public</span>:</div><div class="line"> ewol::object::Signal&lt;&gt; signalEmpty;</div><div class="line"> ewol::object::Signal&lt;bool&gt; signalBoolean;</div><div class="line"> ewol::object::Signal&lt;std::string&gt; signalString;</div><div class="line"> <span class="keyword">protected</span>:</div><div class="line"> MyObj() :</div><div class="line"> signalEmpty(this, <span class="stringliteral">&quot;empty&quot;</span>),</div><div class="line"> signalBoolean(this, <span class="stringliteral">&quot;boolean&quot;</span>),</div><div class="line"> signalString(this, <span class="stringliteral">&quot;string&quot;</span>) {</div><div class="line"> <span class="comment">// nothing to do..</span></div><div class="line"> }</div><div class="line"> <span class="keyword">public</span>:</div><div class="line"> <span class="keyword">virtual</span> ~MyObj() { }</div><div class="line"> DECLARE_FACTORY(MyObj);</div><div class="line"> <span class="keyword">private</span>:</div><div class="line"> <span class="keywordtype">void</span> process() {</div><div class="line"> signalEmpty.emit();</div><div class="line"> signalBoolean.emit(<span class="keyword">false</span>);</div><div class="line"> signalString.emit(<span class="stringliteral">&quot;plop... plop&quot;</span>);</div><div class="line"> }</div><div class="line"> }</div><div class="line">}</div></div><!-- fragment --><h1><a class="anchor" id="ewol_tutorial_object_message_conclusion"></a>
Conclusion: </h1>
<p>You will now able to reise signals between objects...</p>
<p>For more information see <a href="http://atria-soft.github.io/esignal">e-signal</a> </p>
</div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.8-->
<!-- start footer part -->
</div>
</div>
</div>
</div>
</div>
<hr class="footer"/><address class="footer"><small>
Generated on Mon Oct 24 2016 15:35:52 for Ewol: Ewol Widget in OpenGl by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.12
</small></address>
</body>
</html>