193 lines
22 KiB
HTML
193 lines
22 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>esignal: Ewol signal interface: Tutorial</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">esignal: Ewol signal interface 0.5.0</a>
|
|
</div>
|
|
<div id="navbar" class="navbar-collapse collapse">
|
|
<ul class="nav navbar-nav">
|
|
<li><a href="index.html">Main Page</a></li>
|
|
<li><a href="pages.html">Related 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">Tutorial </div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<div class="toc"><h3>Table of Contents</h3>
|
|
<ul><li class="level1"><a href="#esignal_declare">Declare a Signal: </a></li>
|
|
<li class="level1"><a href="#esignal_connection">Connecting on a signal </a><ul><li class="level2"><a href="#esignal_connection_base">Connection and basic emition </a></li>
|
|
<li class="level2"><a href="#esignal_connection_class">Connection on class member function </a></li>
|
|
<li class="level2"><a href="#esignal_connection_shared">Connection on ememory::SharedPtr<class> member function </a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="level1"><a href="#esignal_create">Create new Signal </a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="textblock"><h1><a class="anchor" id="esignal_declare"></a>
|
|
Declare a Signal: </h1>
|
|
<p>Declaring a signal is really simple, just include the esignal file:</p>
|
|
<div class="fragment"><div class="line"><span class="preprocessor">#include <esignal/Signal.hpp></span></div></div><!-- fragment --><p> You can now declare your signals. We have basicly declare some basic signal type:</p><ul>
|
|
<li>void</li>
|
|
<li>bool</li>
|
|
<li>std::string / std::u32string</li>
|
|
<li>int8_t / int16_t / int32_t / int64_t</li>
|
|
<li>uint8_t / uint16_t / uint32_t / uint64_t</li>
|
|
<li>float / double</li>
|
|
<li>vec2 / bvec2 / ivec2 / uivec2</li>
|
|
<li>vec3 / bvec3 / ivec3 / uivec3</li>
|
|
<li>etk::Color<unsigned char,4></li>
|
|
<li>etk::Color<unsigned char,3></li>
|
|
<li>etk::Color<float,4></li>
|
|
<li>etk::Color<float,3></li>
|
|
</ul>
|
|
<p>To declare a signal with 'void' type: </p><div class="fragment"><div class="line"> esignal::Signal<> signalVoid;</div></div><!-- fragment --><p> To declare a signal with 'int32_t' type: </p><div class="fragment"><div class="line"> esignal::Signal<int32_t> signalInt;</div></div><!-- fragment --><p> To declare a signal with 'string' type: </p><div class="fragment"><div class="line"> esignal::Signal<std::string> signalString;</div></div><!-- fragment --><h1><a class="anchor" id="esignal_connection"></a>
|
|
Connecting on a signal </h1>
|
|
<p>We have some way to connect on a signals depending on where we do the connection.</p>
|
|
<h2><a class="anchor" id="esignal_connection_base"></a>
|
|
Connection and basic emition </h2>
|
|
<p>Declare the signal: </p><div class="fragment"><div class="line"> esignal::Signal<int32_t> signalValue;</div></div><!-- fragment --><p> Declare a generic fuction: </p><div class="fragment"><div class="line"><span class="keywordtype">void</span> localCallBack(int32_t _val) {</div><div class="line"> TEST_PRINT(<span class="stringliteral">"Callback Local the value is : "</span> << _val);</div><div class="line">}</div></div><!-- fragment --><p> Connect a generic function: </p><div class="fragment"><div class="line"> esignal::Connection con1 = signalValue.connect(&localCallBack);</div></div><!-- fragment --><p> Or simply connect a lambda function: </p><div class="fragment"><div class="line"> esignal::Connection con2 = signalValue.connect(</div><div class="line"> [](int32_t _val) {</div><div class="line"> TEST_PRINT(<span class="stringliteral">"Callback 1 the value is : "</span> << _val);</div><div class="line"> });</div></div><!-- fragment --><p> And now, we can emit a simple signal: </p><div class="fragment"><div class="line"> signalValue.emit(1001001);</div></div><!-- fragment --><p> You can see that all connection return a esignal::Connection value. This is an handle that can not be copiable, but only movable, While this handle is alive, the connection is allive too. The to remove a connection, we only need to remive the handle or call the esignal::Connection::disconnect fucntion.</p>
|
|
<p>To disconnect a signal, it is very simple: </p><div class="fragment"><div class="line"> con1.disconnect();</div></div><!-- fragment --><p>This Will generate this simple sample code: </p><div class="fragment"><div class="line"><span class="keywordtype">void</span> localCallBack(int32_t _val) {</div><div class="line"> TEST_PRINT(<span class="stringliteral">"Callback Local the value is : "</span> << _val);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> basicConnection() {</div><div class="line"> <span class="comment">// Create the signal</span></div><div class="line"><span class="comment"></span> esignal::Signal<int32_t> signalValue;</div><div class="line"> <span class="comment">// Connect the signal function</span></div><div class="line"><span class="comment"></span> esignal::Connection con1 = signalValue.connect(&localCallBack);</div><div class="line"> <span class="comment">// Connect the signal Lambda</span></div><div class="line"><span class="comment"></span> esignal::Connection con2 = signalValue.connect(</div><div class="line"> [](int32_t _val) {</div><div class="line"> TEST_PRINT(<span class="stringliteral">"Callback 1 the value is : "</span> << _val);</div><div class="line"> });</div><div class="line"> <span class="comment">// Emit the signal</span></div><div class="line"><span class="comment"></span> signalValue.emit(1001001);</div><div class="line"> <span class="comment">// Disconnect the connection n°1</span></div><div class="line"><span class="comment"></span> con1.disconnect();</div><div class="line"> <span class="comment">// Second emit to check disconnection</span></div><div class="line"> signalValue.emit(2002002);</div><div class="line">}</div></div><!-- fragment --><h2><a class="anchor" id="esignal_connection_class"></a>
|
|
Connection on class member function </h2>
|
|
<p>Declare class fuction: </p><div class="fragment"><div class="line"><span class="keyword">class </span>TmpClass {</div><div class="line"> <span class="keyword">public</span>:</div><div class="line"> <span class="keywordtype">void</span> localCallBack(<span class="keyword">const</span> int32_t& _val) {</div><div class="line"> TEST_PRINT(<span class="stringliteral">"Callback Local the value is : "</span> << _val);</div><div class="line"> }</div><div class="line"> <span class="keywordtype">void</span> localCallBackSecond(<span class="keyword">const</span> int32_t& _val, <span class="keyword">const</span> std::string& _otherValue) {</div><div class="line"> TEST_PRINT(<span class="stringliteral">"Callback 2 Local the value is : "</span> << _val << <span class="stringliteral">" with perso: '"</span> << _otherValue << <span class="stringliteral">"'"</span>);</div><div class="line"> }</div><div class="line">};</div></div><!-- fragment --><p> For direct connection, you need to have a 'const ref' on the parameter (internal helper design) to bind on the signal</p>
|
|
<p>Now you can nonnect the functions: </p><div class="fragment"><div class="line"> esignal::Connection con1 = signalValue.connect(&myClass, &TmpClass::localCallBack);</div><div class="line"> esignal::Connection con2 = signalValue.connect(&myClass, &TmpClass::localCallBackSecond, <span class="stringliteral">"Hello, HowAreYou"</span>);</div></div><!-- fragment --><p> This Will generate this simple sample code: </p><div class="fragment"><div class="line"><span class="keyword">class </span>TmpClass {</div><div class="line"> <span class="keyword">public</span>:</div><div class="line"> <span class="keywordtype">void</span> localCallBack(<span class="keyword">const</span> int32_t& _val) {</div><div class="line"> TEST_PRINT(<span class="stringliteral">"Callback Local the value is : "</span> << _val);</div><div class="line"> }</div><div class="line"> <span class="keywordtype">void</span> localCallBackSecond(<span class="keyword">const</span> int32_t& _val, <span class="keyword">const</span> std::string& _otherValue) {</div><div class="line"> TEST_PRINT(<span class="stringliteral">"Callback 2 Local the value is : "</span> << _val << <span class="stringliteral">" with perso: '"</span> << _otherValue << <span class="stringliteral">"'"</span>);</div><div class="line"> }</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> classConnection() {</div><div class="line"> <span class="comment">// Create the signal</span></div><div class="line"> esignal::Signal<int32_t> signalValue;</div><div class="line"> <span class="comment">// Declare the class</span></div><div class="line"> TmpClass myClass;</div><div class="line"> <span class="comment">// Connect signals</span></div><div class="line"><span class="comment"></span> esignal::Connection con1 = signalValue.connect(&myClass, &TmpClass::localCallBack);</div><div class="line"> esignal::Connection con2 = signalValue.connect(&myClass, &TmpClass::localCallBackSecond, <span class="stringliteral">"Hello, HowAreYou"</span>);</div><div class="line"> <span class="comment">// Emit sample signals</span></div><div class="line"> signalValue.emit(4004004);</div><div class="line">}</div><div class="line"></div></div><!-- fragment --> <h2><a class="anchor" id="esignal_connection_shared"></a>
|
|
Connection on ememory::SharedPtr<class> member function </h2>
|
|
<p><a class="elRef" 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">ememory::SharedPtr</a> have intrinsec knowledge of alive pointer, then, if you do not need to remove connection while the <a class="elRef" 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">ememory::SharedPtr</a> is alive, just connect it like: </p><div class="fragment"><div class="line"></div><div class="line"><span class="keywordtype">void</span> sharedConnection() {</div><div class="line"> <span class="comment">// Create the signal</span></div><div class="line"> esignal::Signal<int32_t> signalValue;</div><div class="line"> <span class="comment">// Declare the class</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">ememory::SharedPtr<TmpClass></a> myClassShared = ememory::makeShared<TmpClass>();</div><div class="line"> <span class="comment">// Connect signals</span></div><div class="line"> signalValue.connect(myClassShared, &TmpClass::localCallBack);</div><div class="line"> <span class="comment">// Emit sample signals</span></div><div class="line"> signalValue.emit(7007007);</div><div class="line">}</div></div><!-- fragment --> <h1><a class="anchor" id="esignal_create"></a>
|
|
Create new Signal </h1>
|
|
<p>If the signal is not in the list: <a class="el" href="esignal_tutorial.html#esignal_declare">Declare a Signal: </a>, you need to declare it yourself. This is due to optimise the compilation time, in C++ when we inserte many template with all the implementation, the compilation time increase, the we decide to optimise the build time.</p>
|
|
<p>Create a new custum signal: </p><div class="fragment"><div class="line"> esignal::Signal<int32_t, std::string> signalCustum;</div></div><!-- fragment --><p> Connect on the Signal: </p><div class="fragment"><div class="line"> esignal::Connection con2 = signalCustum.connect(</div><div class="line"> [](int32_t _val, std::string _val2) {</div><div class="line"> TEST_PRINT(<span class="stringliteral">"lambda callback: "</span> << _val << <span class="stringliteral">" vel2="</span> << _val2);</div><div class="line"> });</div></div><!-- fragment --><p> Emit a Signal: </p><div class="fragment"><div class="line"> signalCustum.emit(1001001, <span class="stringliteral">"plop"</span>);</div></div><!-- fragment --><p> This might work good, but at this point the compilation is OK, but not the linking ==> we need to declare the implementation of the signal: </p><div class="fragment"><div class="line"><span class="preprocessor">#include <esignal/details/Signal.hxx></span></div><div class="line">ESIGNAL_DECLARE_SIGNAL(int32_t, std::string);</div></div><!-- fragment --><p>This Will generate this simple sample code: </p><div class="fragment"><div class="line"></div><div class="line"><span class="keywordtype">void</span> newSignal() {</div><div class="line"> <span class="comment">// Declare new signal</span></div><div class="line"><span class="comment"></span> esignal::Signal<int32_t, std::string> signalCustum;</div><div class="line"> <span class="comment">// Connect a lambda</span></div><div class="line"><span class="comment"></span> esignal::Connection con2 = signalCustum.connect(</div><div class="line"> [](int32_t _val, std::string _val2) {</div><div class="line"> TEST_PRINT(<span class="stringliteral">"lambda callback: "</span> << _val << <span class="stringliteral">" vel2="</span> << _val2);</div><div class="line"> });</div><div class="line"> <span class="comment">// Example emit</span></div><div class="line"><span class="comment"></span> signalCustum.emit(1001001, <span class="stringliteral">"plop"</span>);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">// do it in a single C++: Implementation of signal</span></div><div class="line"><span class="comment"></span><span class="preprocessor">#include <esignal/details/Signal.hxx></span></div><div class="line">ESIGNAL_DECLARE_SIGNAL(int32_t, std::string);</div><div class="line"></div></div><!-- fragment --></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:50 for esignal: Ewol signal interface by  <a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
|
</a> 1.8.12
|
|
</small></address>
|
|
</body>
|
|
</html>
|