Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cellframe/libdap
1 result
Show changes
Commits on Source (6)
Showing
with 846 additions and 608 deletions
...@@ -89,7 +89,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); ...@@ -89,7 +89,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
<div class="title">dap_common.h</div> </div> <div class="title">dap_common.h</div> </div>
</div><!--header--> </div><!--header-->
<div class="contents"> <div class="contents">
<a href="dap__common_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;<span class="comment">/*</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span>&#160;<span class="comment"> * Authors:</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span>&#160;<span class="comment"> * Dmitriy A. Gearasimov &lt;kahovski@gmail.com&gt;</span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span>&#160;<span class="comment"> * DeM Labs Inc. https://demlabs.net</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span>&#160;<span class="comment"> * DeM Labs Open source community https://github.com/demlabsinc</span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span>&#160;<span class="comment"> * Copyright (c) 2017-2018</span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span>&#160;<span class="comment"> * All rights reserved.</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span>&#160;<span class="comment"> This file is part of DAP (Deus Applications Prototypes) the open source project</span></div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span>&#160;<span class="comment"> DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span>&#160;<span class="comment"> it under the terms of the GNU General Public License as published by</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span>&#160;<span class="comment"> the Free Software Foundation, either version 3 of the License, or</span></div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span>&#160;<span class="comment"> (at your option) any later version.</span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span>&#160;<span class="comment"> DAP is distributed in the hope that it will be useful,</span></div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span>&#160;<span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span>&#160;<span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span>&#160;<span class="comment"> GNU General Public License for more details.</span></div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span>&#160;<span class="comment"> You should have received a copy of the GNU General Public License</span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span>&#160;<span class="comment"> along with any DAP based project. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span>&#160;<span class="comment">*/</span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span>&#160;<span class="preprocessor">#pragma once</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span>&#160;<span class="preprocessor">#include &lt;stdarg.h&gt;</span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span>&#160;<span class="preprocessor">#include &lt;stddef.h&gt;</span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span>&#160;<span class="preprocessor">#include &lt;stdlib.h&gt;</span></div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span>&#160;<span class="preprocessor">#include &lt;time.h&gt;</span></div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span>&#160;</div><div class="line"><a name="l00030"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a74a9d9e85c7cc12c155f147d9a971cad"> 30</a></span>&#160;<span class="preprocessor">#define DAP_NEW(a) ( (a*) malloc(sizeof(a)))</span></div><div class="line"><a name="l00031"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a80373ba28489011c16cd76f6d0ba5b53"> 31</a></span>&#160;<span class="preprocessor">#define DAP_NEW_SIZE(a,b) ( (a*) malloc(b))</span></div><div class="line"><a name="l00032"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a9270d1341aa00be475591ecfa8985c08"> 32</a></span>&#160;<span class="preprocessor">#define DAP_NEW_Z(a) ( (a*) calloc(1,sizeof(a)))</span></div><div class="line"><a name="l00033"></a><span class="lineno"><a class="line" href="dap__common_8h.html#ad0f1f3c74154c73a5dfd33598dfd375b"> 33</a></span>&#160;<span class="preprocessor">#define DAP_NEW_Z_SIZE(a,b) ( (a*) calloc(1,b))</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span>&#160;</div><div class="line"><a name="l00035"></a><span class="lineno"><a class="line" href="dap__common_8h.html#abc94d3603906f97d0ce7368f44eebf8b"> 35</a></span>&#160;<span class="preprocessor">#define DAP_DELETE(a) free(a)</span></div><div class="line"><a name="l00036"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a7303c16a9766b284e07bd6790d65b59e"> 36</a></span>&#160;<span class="preprocessor">#define DAP_DUP(a) (__typeof(a) ret = memcpy(ret,a,sizeof(*a)) )</span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span>&#160;</div><div class="line"><a name="l00038"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a9757f0cc77df1fd0759b1b91a9f63ff0"> 38</a></span>&#160;<span class="preprocessor">#define DAP_PROTOCOL_VERSION 21</span></div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span>&#160;</div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span>&#160;<span class="preprocessor">#if defined(__GNUC__) ||defined (__clang__)</span></div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span>&#160;<span class="preprocessor">#define DAP_ALIGN_PACKED __attribute__((aligned(1),packed))</span></div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>&#160;</div><div class="line"><a name="l00047"></a><span class="lineno"><a class="line" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e"> 47</a></span>&#160;<span class="keyword">enum</span> <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a>{<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748ead95cd234638314479dea217167c37e4a">L_CRITICAL</a>=5,<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748ea5aa6d01f59e4b628af96f650fc5ecc15">L_ERROR</a>=4, <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748ea83e54d43eb3fd145052377ecd43932a1">L_WARNING</a>=3,<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748eac0e398e95a19b2d3e23eb0620e91a515">L_NOTICE</a>=2,<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748eae580867d0ddde34905fea2f8669839b7">L_INFO</a>=1,<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748eabef96148470abb1ed19980e5b5c40ad4">L_DEBUG</a>=0};</div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>&#160;</div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>&#160;<span class="preprocessor">#ifdef __cplusplus</span></div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>&#160;<span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span> {</div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>&#160;</div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>&#160;<span class="keywordtype">int</span> <a class="code" href="dap__common_8h.html#aff6dc9e558a255f56618643f5be92b08">dap_common_init</a>( <span class="keyword">const</span> <span class="keywordtype">char</span> * a_log_file );</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#ab96d7e843bc09468220a7d264295cf69">dap_common_deinit</a>(<span class="keywordtype">void</span>);</div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>&#160;</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#acbe3239b788dc1105a094596354a7e42">_log_it</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * log_tag, <span class="keyword">enum</span> <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a>, <span class="keyword">const</span> <span class="keywordtype">char</span> * format,...);</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#ab3ae03011f7dfbbf40dce01f7bdd4157">_vlog_it</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * log_tag, <span class="keyword">enum</span> <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a>, <span class="keyword">const</span> <span class="keywordtype">char</span> * format, va_list ap );</div><div class="line"><a name="l00058"></a><span class="lineno"><a class="line" href="dap__common_8h.html#acd8f4f3ce595157ca36ce6b61ca4195e"> 58</a></span>&#160;<span class="preprocessor">#define log_it(_log_level,...) _log_it(LOG_TAG,_log_level,##__VA_ARGS__)</span></div><div class="line"><a name="l00059"></a><span class="lineno"><a class="line" href="dap__common_8h.html#ab53061ef6723b1e4a233022ef9f33c76"> 59</a></span>&#160;<span class="preprocessor">#define vlog_it(a_log_level,a_format,a_ap) _vlog_it(LOG_TAG,a_log_level,a_format,a_ap)</span></div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>&#160;</div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span>&#160;<span class="keyword">const</span> <span class="keywordtype">char</span> * <a class="code" href="dap__common_8h.html#aa76592df3b155b21f4d05cbd042db5f7">log_error</a>(<span class="keywordtype">void</span>);</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#a98de0fce0a8fb5c3b0cfe80bebe8f691">set_log_level</a>(<span class="keyword">enum</span> <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a> ll);</div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#ac8d0df7015664c720b27ee4f6e660479">dap_set_log_tag_width</a>(<span class="keywordtype">size_t</span> width);</div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>&#160;</div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>&#160;<span class="preprocessor">#ifdef __GNUC__</span></div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span>&#160;<span class="keywordtype">char</span> *<a class="code" href="dap__common_8c.html#a9c7174a7bbe81eedbd86ded2e247eee7">itoa</a>(<span class="keywordtype">int</span> i);</div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>&#160;</div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>&#160;</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>&#160;<span class="preprocessor">#elif _MSC_VER</span></div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>&#160;<span class="keywordtype">char</span> *strndup(<span class="keyword">const</span> <span class="keywordtype">char</span> *s, <span class="keywordtype">size_t</span> n);</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>&#160;<span class="keywordtype">int</span> <a class="code" href="dap__common_8h.html#a6ab10606e8ac33dd93a0526933b192c8">time_to_rfc822</a>(<span class="keywordtype">char</span> * out, <span class="keywordtype">size_t</span> out_size_max, time_t t);</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>&#160;</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span>&#160;<span class="keywordtype">int</span> <a class="code" href="dap__common_8h.html#ab027eeb728bcf25f75bc592fc627e4fe">get_select_breaker</a>(<span class="keywordtype">void</span>);</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>&#160;<span class="keywordtype">int</span> <a class="code" href="dap__common_8h.html#aa3c5a3515672b9ecc8d114af678cb0a4">send_select_break</a>(<span class="keywordtype">void</span>);</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>&#160;<span class="keywordtype">char</span> * <a class="code" href="dap__common_8h.html#a00992fd7732b0ff40ce020728f84bc3a">exec_with_ret</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * a_cmd);</div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>&#160;<span class="keywordtype">char</span> * <a class="code" href="dap__common_8h.html#aa4a4c13332f14e44630f5e269048249a">exec_with_ret_multistring</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * a_cmd);</div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>&#160;<span class="keywordtype">char</span> * <a class="code" href="dap__common_8h.html#aabbc0306fee1c3a56540b1604bbb516c">dap_random_string_create_alloc</a>(<span class="keywordtype">size_t</span> a_length);</div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#a3fa34950395c0139c5c95510de7119a8">dap_random_string_fill</a>(<span class="keywordtype">char</span> *str, <span class="keywordtype">size_t</span> length);</div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>&#160;</div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>&#160;<span class="preprocessor">#ifdef __cplusplus</span></div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>&#160;}</div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>&#160;<span class="preprocessor">#endif</span></div><div class="ttc" id="dap__common_8h_html_ac91d55174d383848b976a34de843748eabef96148470abb1ed19980e5b5c40ad4"><div class="ttname"><a href="dap__common_8h.html#ac91d55174d383848b976a34de843748eabef96148470abb1ed19980e5b5c40ad4">L_DEBUG</a></div><div class="ttdef"><b>Definition:</b> dap_common.h:47</div></div> <a href="dap__common_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;<span class="comment">/*</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span>&#160;<span class="comment"> * Authors:</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span>&#160;<span class="comment"> * Dmitriy A. Gearasimov &lt;kahovski@gmail.com&gt;</span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span>&#160;<span class="comment"> * DeM Labs Inc. https://demlabs.net</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span>&#160;<span class="comment"> * DeM Labs Open source community https://gitlab.demlabs.net/cellframe</span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span>&#160;<span class="comment"> * Copyright (c) 2017-2018</span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span>&#160;<span class="comment"> * All rights reserved.</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span>&#160;<span class="comment"> This file is part of DAP (Deus Applications Prototypes) the open source project</span></div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span>&#160;<span class="comment"> DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span>&#160;<span class="comment"> it under the terms of the GNU General Public License as published by</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span>&#160;<span class="comment"> the Free Software Foundation, either version 3 of the License, or</span></div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span>&#160;<span class="comment"> (at your option) any later version.</span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span>&#160;<span class="comment"> DAP is distributed in the hope that it will be useful,</span></div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span>&#160;<span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span>&#160;<span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span>&#160;<span class="comment"> GNU General Public License for more details.</span></div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span>&#160;<span class="comment"> You should have received a copy of the GNU General Public License</span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span>&#160;<span class="comment"> along with any DAP based project. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span>&#160;<span class="comment">*/</span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span>&#160;<span class="preprocessor">#pragma once</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span>&#160;<span class="preprocessor">#include &lt;stdarg.h&gt;</span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span>&#160;<span class="preprocessor">#include &lt;stddef.h&gt;</span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span>&#160;<span class="preprocessor">#include &lt;stdlib.h&gt;</span></div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span>&#160;<span class="preprocessor">#include &lt;time.h&gt;</span></div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span>&#160;</div><div class="line"><a name="l00030"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a74a9d9e85c7cc12c155f147d9a971cad"> 30</a></span>&#160;<span class="preprocessor">#define DAP_NEW(a) ( (a*) malloc(sizeof(a)))</span></div><div class="line"><a name="l00031"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a80373ba28489011c16cd76f6d0ba5b53"> 31</a></span>&#160;<span class="preprocessor">#define DAP_NEW_SIZE(a,b) ( (a*) malloc(b))</span></div><div class="line"><a name="l00032"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a9270d1341aa00be475591ecfa8985c08"> 32</a></span>&#160;<span class="preprocessor">#define DAP_NEW_Z(a) ( (a*) calloc(1,sizeof(a)))</span></div><div class="line"><a name="l00033"></a><span class="lineno"><a class="line" href="dap__common_8h.html#ad0f1f3c74154c73a5dfd33598dfd375b"> 33</a></span>&#160;<span class="preprocessor">#define DAP_NEW_Z_SIZE(a,b) ( (a*) calloc(1,b))</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span>&#160;</div><div class="line"><a name="l00035"></a><span class="lineno"><a class="line" href="dap__common_8h.html#abc94d3603906f97d0ce7368f44eebf8b"> 35</a></span>&#160;<span class="preprocessor">#define DAP_DELETE(a) free(a)</span></div><div class="line"><a name="l00036"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a7303c16a9766b284e07bd6790d65b59e"> 36</a></span>&#160;<span class="preprocessor">#define DAP_DUP(a) (__typeof(a) ret = memcpy(ret,a,sizeof(*a)) )</span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span>&#160;</div><div class="line"><a name="l00038"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a9757f0cc77df1fd0759b1b91a9f63ff0"> 38</a></span>&#160;<span class="preprocessor">#define DAP_PROTOCOL_VERSION 21</span></div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span>&#160;</div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span>&#160;<span class="preprocessor">#if defined(__GNUC__) ||defined (__clang__)</span></div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span>&#160;<span class="preprocessor">#define DAP_ALIGN_PACKED __attribute__((aligned(1),packed))</span></div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>&#160;</div><div class="line"><a name="l00047"></a><span class="lineno"><a class="line" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e"> 47</a></span>&#160;<span class="keyword">enum</span> <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a>{<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748ead95cd234638314479dea217167c37e4a">L_CRITICAL</a>=5,<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748ea5aa6d01f59e4b628af96f650fc5ecc15">L_ERROR</a>=4, <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748ea83e54d43eb3fd145052377ecd43932a1">L_WARNING</a>=3,<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748eac0e398e95a19b2d3e23eb0620e91a515">L_NOTICE</a>=2,<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748eae580867d0ddde34905fea2f8669839b7">L_INFO</a>=1,<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748eabef96148470abb1ed19980e5b5c40ad4">L_DEBUG</a>=0};</div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>&#160;</div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>&#160;<span class="preprocessor">#ifdef __cplusplus</span></div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>&#160;<span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span> {</div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>&#160;</div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>&#160;<span class="keywordtype">int</span> <a class="code" href="dap__common_8h.html#aff6dc9e558a255f56618643f5be92b08">dap_common_init</a>( <span class="keyword">const</span> <span class="keywordtype">char</span> * a_log_file );</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#ab96d7e843bc09468220a7d264295cf69">dap_common_deinit</a>(<span class="keywordtype">void</span>);</div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>&#160;</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#acbe3239b788dc1105a094596354a7e42">_log_it</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * log_tag, <span class="keyword">enum</span> <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a>, <span class="keyword">const</span> <span class="keywordtype">char</span> * format,...);</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#ab3ae03011f7dfbbf40dce01f7bdd4157">_vlog_it</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * log_tag, <span class="keyword">enum</span> <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a>, <span class="keyword">const</span> <span class="keywordtype">char</span> * format, va_list ap );</div><div class="line"><a name="l00058"></a><span class="lineno"><a class="line" href="dap__common_8h.html#acd8f4f3ce595157ca36ce6b61ca4195e"> 58</a></span>&#160;<span class="preprocessor">#define log_it(_log_level,...) _log_it(LOG_TAG,_log_level,##__VA_ARGS__)</span></div><div class="line"><a name="l00059"></a><span class="lineno"><a class="line" href="dap__common_8h.html#ab53061ef6723b1e4a233022ef9f33c76"> 59</a></span>&#160;<span class="preprocessor">#define vlog_it(a_log_level,a_format,a_ap) _vlog_it(LOG_TAG,a_log_level,a_format,a_ap)</span></div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>&#160;</div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span>&#160;<span class="keyword">const</span> <span class="keywordtype">char</span> * <a class="code" href="dap__common_8h.html#aa76592df3b155b21f4d05cbd042db5f7">log_error</a>(<span class="keywordtype">void</span>);</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#a98de0fce0a8fb5c3b0cfe80bebe8f691">set_log_level</a>(<span class="keyword">enum</span> <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a> ll);</div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#ac8d0df7015664c720b27ee4f6e660479">dap_set_log_tag_width</a>(<span class="keywordtype">size_t</span> width);</div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>&#160;</div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>&#160;<span class="preprocessor">#ifdef __GNUC__</span></div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span>&#160;<span class="keywordtype">char</span> *<a class="code" href="dap__common_8c.html#a9c7174a7bbe81eedbd86ded2e247eee7">itoa</a>(<span class="keywordtype">int</span> i);</div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>&#160;</div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>&#160;</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>&#160;<span class="preprocessor">#elif _MSC_VER</span></div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>&#160;<span class="keywordtype">char</span> *strndup(<span class="keyword">const</span> <span class="keywordtype">char</span> *s, <span class="keywordtype">size_t</span> n);</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>&#160;<span class="keywordtype">int</span> <a class="code" href="dap__common_8h.html#a6ab10606e8ac33dd93a0526933b192c8">time_to_rfc822</a>(<span class="keywordtype">char</span> * out, <span class="keywordtype">size_t</span> out_size_max, time_t t);</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>&#160;</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span>&#160;<span class="keywordtype">int</span> <a class="code" href="dap__common_8h.html#ab027eeb728bcf25f75bc592fc627e4fe">get_select_breaker</a>(<span class="keywordtype">void</span>);</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>&#160;<span class="keywordtype">int</span> <a class="code" href="dap__common_8h.html#aa3c5a3515672b9ecc8d114af678cb0a4">send_select_break</a>(<span class="keywordtype">void</span>);</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>&#160;<span class="keywordtype">char</span> * <a class="code" href="dap__common_8h.html#a00992fd7732b0ff40ce020728f84bc3a">exec_with_ret</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * a_cmd);</div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>&#160;<span class="keywordtype">char</span> * <a class="code" href="dap__common_8h.html#aa4a4c13332f14e44630f5e269048249a">exec_with_ret_multistring</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * a_cmd);</div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>&#160;<span class="keywordtype">char</span> * <a class="code" href="dap__common_8h.html#aabbc0306fee1c3a56540b1604bbb516c">dap_random_string_create_alloc</a>(<span class="keywordtype">size_t</span> a_length);</div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#a3fa34950395c0139c5c95510de7119a8">dap_random_string_fill</a>(<span class="keywordtype">char</span> *str, <span class="keywordtype">size_t</span> length);</div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>&#160;</div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>&#160;<span class="preprocessor">#ifdef __cplusplus</span></div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>&#160;}</div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>&#160;<span class="preprocessor">#endif</span></div><div class="ttc" id="dap__common_8h_html_ac91d55174d383848b976a34de843748eabef96148470abb1ed19980e5b5c40ad4"><div class="ttname"><a href="dap__common_8h.html#ac91d55174d383848b976a34de843748eabef96148470abb1ed19980e5b5c40ad4">L_DEBUG</a></div><div class="ttdef"><b>Definition:</b> dap_common.h:47</div></div>
<div class="ttc" id="dap__common_8h_html_ac8d0df7015664c720b27ee4f6e660479"><div class="ttname"><a href="dap__common_8h.html#ac8d0df7015664c720b27ee4f6e660479">dap_set_log_tag_width</a></div><div class="ttdeci">void dap_set_log_tag_width(size_t width)</div><div class="ttdoc">dap_set_log_tag_width Sets the length of the label </div><div class="ttdef"><b>Definition:</b> dap_common.c:77</div></div> <div class="ttc" id="dap__common_8h_html_ac8d0df7015664c720b27ee4f6e660479"><div class="ttname"><a href="dap__common_8h.html#ac8d0df7015664c720b27ee4f6e660479">dap_set_log_tag_width</a></div><div class="ttdeci">void dap_set_log_tag_width(size_t width)</div><div class="ttdoc">dap_set_log_tag_width Sets the length of the label </div><div class="ttdef"><b>Definition:</b> dap_common.c:77</div></div>
<div class="ttc" id="dap__common_8h_html_ac91d55174d383848b976a34de843748ea5aa6d01f59e4b628af96f650fc5ecc15"><div class="ttname"><a href="dap__common_8h.html#ac91d55174d383848b976a34de843748ea5aa6d01f59e4b628af96f650fc5ecc15">L_ERROR</a></div><div class="ttdef"><b>Definition:</b> dap_common.h:47</div></div> <div class="ttc" id="dap__common_8h_html_ac91d55174d383848b976a34de843748ea5aa6d01f59e4b628af96f650fc5ecc15"><div class="ttname"><a href="dap__common_8h.html#ac91d55174d383848b976a34de843748ea5aa6d01f59e4b628af96f650fc5ecc15">L_ERROR</a></div><div class="ttdef"><b>Definition:</b> dap_common.h:47</div></div>
<div class="ttc" id="dap__common_8h_html_ac91d55174d383848b976a34de843748e"><div class="ttname"><a href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a></div><div class="ttdeci">log_level</div><div class="ttdoc">The log_level enum. </div><div class="ttdef"><b>Definition:</b> dap_common.h:47</div></div> <div class="ttc" id="dap__common_8h_html_ac91d55174d383848b976a34de843748e"><div class="ttname"><a href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a></div><div class="ttdeci">log_level</div><div class="ttdoc">The log_level enum. </div><div class="ttdef"><b>Definition:</b> dap_common.h:47</div></div>
......
/* /*
* Authors: * Authors:
* Dmitriy A. Gearasimov <kahovski@gmail.com> * Dmitriy A. Gearasimov <kahovski@gmail.com>
* Anatolii Kurotych <akurotych@gmail.com> * Anatolii Kurotych <akurotych@gmail.com>
* DeM Labs Inc. https://demlabs.net * DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://github.com/demlabsinc * DeM Labs Open source community https://github.com/demlabsinc
* Copyright (c) 2017-2019 * Copyright (c) 2017-2019
* All rights reserved. * All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
DAP is distributed in the hope that it will be useful, DAP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include "portable_endian.h" #include "portable_endian.h"
#if defined(__GNUC__) ||defined (__clang__) #if defined(__GNUC__) ||defined (__clang__)
#define DAP_ALIGN_PACKED __attribute__((aligned(1),packed)) #define DAP_ALIGN_PACKED __attribute__((aligned(1),packed))
#else #else
#define DAP_ALIGN_PACKED __attribute__((aligned(1),packed)) #define DAP_ALIGN_PACKED __attribute__((aligned(1),packed))
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
#define DAP_STATIC_INLINE static __forceinline #define DAP_STATIC_INLINE static __forceinline
#define DAP_INLINE __forceinline #define DAP_INLINE __forceinline
#define DAP_ALIGNED(x) __declspec( align(x) ) #define DAP_ALIGNED(x) __declspec( align(x) )
#else #else
#define DAP_STATIC_INLINE static __attribute__((always_inline)) inline #define DAP_STATIC_INLINE static __attribute__((always_inline)) inline
#define DAP_INLINE __attribute__((always_inline)) inline #define DAP_INLINE __attribute__((always_inline)) inline
#define DAP_ALIGNED(x) __attribute__ ((aligned (x))) #define DAP_ALIGNED(x) __attribute__ ((aligned (x)))
#endif #endif
#ifndef TRUE #ifndef TRUE
#define TRUE true #define TRUE true
#define FALSE false #define FALSE false
#endif #endif
#ifndef ROUNDUP #ifndef ROUNDUP
#define ROUNDUP(n,width) (((n) + (width) - 1) & ~unsigned((width) - 1)) #define ROUNDUP(n,width) (((n) + (width) - 1) & ~(unsigned)((width) - 1))
#endif #endif
#if DAP_USE_RPMALLOC #if DAP_USE_RPMALLOC
#include "rpmalloc.h" #include "rpmalloc.h"
#define DAP_MALLOC(a) rpmalloc(a) #define DAP_MALLOC(a) rpmalloc(a)
#define DAP_FREE(a) rpfree(a) #define DAP_FREE(a) rpfree(a)
#define DAP_CALLOC(a, b) rpcalloc(a, b) #define DAP_CALLOC(a, b) rpcalloc(a, b)
#define DAP_ALMALLOC(a, b) rpaligned_alloc(a, b) #define DAP_ALMALLOC(a, b) rpaligned_alloc(a, b)
#define DAP_ALREALLOC(a,b,c) rpaligned_realloc(a, b, c, 0, 0) #define DAP_ALREALLOC(a,b,c) rpaligned_realloc(a, b, c, 0, 0)
#define DAP_ALFREE(a) rpfree(a) #define DAP_ALFREE(a) rpfree(a)
#define DAP_NEW(a) ((a*) rpmalloc(sizeof(a))) #define DAP_NEW(a) ((a*) rpmalloc(sizeof(a)))
#define DAP_NEW_SIZE(a, b) ((a*) rpmalloc(b)) #define DAP_NEW_SIZE(a, b) ((a*) rpmalloc(b))
#define DAP_NEW_Z(a) ((a*) rpcalloc(1,sizeof(a))) #define DAP_NEW_Z(a) ((a*) rpcalloc(1,sizeof(a)))
#define DAP_NEW_Z_SIZE(a, b) ((a*) rpcalloc(1,b)) #define DAP_NEW_Z_SIZE(a, b) ((a*) rpcalloc(1,b))
#define DAP_REALLOC(a, b) rprealloc(a,b) #define DAP_REALLOC(a, b) rprealloc(a,b)
#define DAP_DELETE(a) rpfree(a) #define DAP_DELETE(a) rpfree(a)
#define DAP_DUP(a) ( __typeof(a) ret = memcpy(ret,a,sizeof(*a)) ) #define DAP_DUP(a) ( __typeof(a) ret = memcpy(ret,a,sizeof(*a)) )
#else #else
#define DAP_MALLOC(a) malloc(a) #define DAP_MALLOC(a) malloc(a)
#define DAP_FREE(a) free(a) #define DAP_FREE(a) free(a)
#define DAP_CALLOC(a, b) calloc(a, b) #define DAP_CALLOC(a, b) calloc(a, b)
#define DAP_ALMALLOC(a, b) _dap_aligned_alloc(a, b) #define DAP_ALMALLOC(a, b) _dap_aligned_alloc(a, b)
#define DAP_ALREALLOC(a, b) _dap_aligned_realloc(a, b) #define DAP_ALREALLOC(a, b) _dap_aligned_realloc(a, b)
#define DAP_ALFREE(a) _dap_aligned_free(a, b) #define DAP_ALFREE(a) _dap_aligned_free(a, b)
#define DAP_NEW( a ) ((a*) malloc(sizeof(a))) #define DAP_NEW( a ) ((a*) malloc(sizeof(a)))
#define DAP_NEW_SIZE(a, b) ((a*) malloc(b) ) #define DAP_NEW_SIZE(a, b) ((a*) malloc(b) )
#define DAP_NEW_Z( a ) ((a*) calloc(1,sizeof(a))) #define DAP_NEW_Z( a ) ((a*) calloc(1,sizeof(a)))
#define DAP_NEW_Z_SIZE(a, b) ((a*) calloc(1,b)) #define DAP_NEW_Z_SIZE(a, b) ((a*) calloc(1,b))
#define DAP_REALLOC(a, b) realloc(a,b) #define DAP_REALLOC(a, b) realloc(a,b)
#define DAP_DELETE(a) free(a) #define DAP_DELETE(a) free(a)
#define DAP_DUP(a) ( __typeof(a) ret = memcpy(ret,a,sizeof(*a)) ) #define DAP_DUP(a) ( __typeof(a) ret = memcpy(ret,a,sizeof(*a)) )
#endif #endif
DAP_STATIC_INLINE void *_dap_aligned_alloc( uintptr_t alignment, uintptr_t size ) DAP_STATIC_INLINE void *_dap_aligned_alloc( uintptr_t alignment, uintptr_t size )
{ {
uintptr_t ptr = (uintptr_t) DAP_MALLOC( size + (alignment * 2) + sizeof(void *) ); uintptr_t ptr = (uintptr_t) DAP_MALLOC( size + (alignment * 2) + sizeof(void *) );
if ( !ptr ) if ( !ptr )
return (void *)ptr; return (void *)ptr;
uintptr_t al_ptr = ( ptr + sizeof(void *) + alignment) & ~(alignment - 1 ); uintptr_t al_ptr = ( ptr + sizeof(void *) + alignment) & ~(alignment - 1 );
((uintptr_t *)al_ptr)[-1] = ptr; ((uintptr_t *)al_ptr)[-1] = ptr;
return (void *)al_ptr; return (void *)al_ptr;
} }
DAP_STATIC_INLINE void *_dap_aligned_realloc( uintptr_t alignment, void *bptr, uintptr_t size ) DAP_STATIC_INLINE void *_dap_aligned_realloc( uintptr_t alignment, void *bptr, uintptr_t size )
{ {
uintptr_t ptr = (uintptr_t) DAP_REALLOC( bptr, size + (alignment * 2) + sizeof(void *) ); uintptr_t ptr = (uintptr_t) DAP_REALLOC( bptr, size + (alignment * 2) + sizeof(void *) );
if ( !ptr ) if ( !ptr )
return (void *)ptr; return (void *)ptr;
uintptr_t al_ptr = ( ptr + sizeof(void *) + alignment) & ~(alignment - 1 ); uintptr_t al_ptr = ( ptr + sizeof(void *) + alignment) & ~(alignment - 1 );
((uintptr_t *)al_ptr)[-1] = ptr; ((uintptr_t *)al_ptr)[-1] = ptr;
return (void *)al_ptr; return (void *)al_ptr;
} }
DAP_STATIC_INLINE void _dap_aligned_free( void *ptr ) DAP_STATIC_INLINE void _dap_aligned_free( void *ptr )
{ {
if ( !ptr ) if ( !ptr )
return; return;
void *base_ptr = (void *)((uintptr_t *)ptr)[-1]; void *base_ptr = (void *)((uintptr_t *)ptr)[-1];
DAP_FREE( base_ptr ); DAP_FREE( base_ptr );
} }
#define DAP_PROTOCOL_VERSION 22 #define DAP_PROTOCOL_VERSION 22
#ifndef MAX #ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif #endif
#ifndef MIN #ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif #endif
#ifndef min #ifndef min
#define min MIN #define min MIN
#endif #endif
#ifndef max #ifndef max
#define max MAX #define max MAX
#endif #endif
#ifndef LOWORD #ifndef LOWORD
#define LOWORD( l ) ((uint16_t) (((uintptr_t) (l)) & 0xFFFF)) #define LOWORD( l ) ((uint16_t) (((uintptr_t) (l)) & 0xFFFF))
#define HIWORD( l ) ((uint16_t) ((((uintptr_t) (l)) >> 16) & 0xFFFF)) #define HIWORD( l ) ((uint16_t) ((((uintptr_t) (l)) >> 16) & 0xFFFF))
#define LOBYTE( w ) ((uint8_t) (((uintptr_t) (w)) & 0xFF)) #define LOBYTE( w ) ((uint8_t) (((uintptr_t) (w)) & 0xFF))
#define HIBYTE( w ) ((uint8_t) ((((uintptr_t) (w)) >> 8) & 0xFF)) #define HIBYTE( w ) ((uint8_t) ((((uintptr_t) (w)) >> 8) & 0xFF))
#endif #endif
#ifndef RGB #ifndef RGB
#define RGB(r,g,b) ((uint32_t)(((uint8_t)(r)|((uint16_t)((uint8_t)(g))<<8))|(((uint32_t)(uint8_t)(b))<<16))) #define RGB(r,g,b) ((uint32_t)(((uint8_t)(r)|((uint16_t)((uint8_t)(g))<<8))|(((uint32_t)(uint8_t)(b))<<16)))
#define RGBA(r, g, b, a) ((uint32_t) ((uint32_t)RGB(r,g,b) | (uint32_t)(a) << 24)) #define RGBA(r, g, b, a) ((uint32_t) ((uint32_t)RGB(r,g,b) | (uint32_t)(a) << 24))
#define GetRValue(rgb) (LOBYTE(rgb)) #define GetRValue(rgb) (LOBYTE(rgb))
#define GetGValue(rgb) (LOBYTE(((uint16_t)(rgb)) >> 8)) #define GetGValue(rgb) (LOBYTE(((uint16_t)(rgb)) >> 8))
#define GetBValue(rgb) (LOBYTE((rgb)>>16)) #define GetBValue(rgb) (LOBYTE((rgb)>>16))
#define GetAValue(rgb) (LOBYTE((rgb)>>24)) #define GetAValue(rgb) (LOBYTE((rgb)>>24))
#endif #endif
#define QBYTE RGBA #define QBYTE RGBA
#define DAP_LOG_HISTORY_STR_SIZE 128 #define DAP_LOG_HISTORY 1
#define DAP_LOG_HISTORY_MAX_STRINGS 4096
#define DAP_LOG_HISTORY_BUFFER_SIZE (DAP_LOG_HISTORY_STR_SIZE * DAP_LOG_HISTORY_MAX_STRINGS) #define DAP_LOG_HISTORY_STR_SIZE 128
#define DAP_LOG_HISTORY_M (DAP_LOG_HISTORY_MAX_STRINGS - 1) #define DAP_LOG_HISTORY_MAX_STRINGS 4096
#define DAP_LOG_HISTORY_BUFFER_SIZE (DAP_LOG_HISTORY_STR_SIZE * DAP_LOG_HISTORY_MAX_STRINGS)
#ifdef _WIN32 #define DAP_LOG_HISTORY_M (DAP_LOG_HISTORY_MAX_STRINGS - 1)
#define dap_sscanf __mingw_sscanf
#define dap_vsscanf __mingw_vsscanf #ifdef _WIN32
#define dap_scanf __mingw_scanf #define dap_sscanf __mingw_sscanf
#define dap_vscanf __mingw_vscanf #define dap_vsscanf __mingw_vsscanf
#define dap_fscanf __mingw_fscanf #define dap_scanf __mingw_scanf
#define dap_vfscanf __mingw_vfscanf #define dap_vscanf __mingw_vscanf
#define dap_sprintf __mingw_sprintf #define dap_fscanf __mingw_fscanf
#define dap_snprintf __mingw_snprintf #define dap_vfscanf __mingw_vfscanf
#define dap_printf __mingw_printf #define dap_sprintf __mingw_sprintf
#define dap_vprintf __mingw_vprintf #define dap_snprintf __mingw_snprintf
#define dap_fprintf __mingw_fprintf #define dap_printf __mingw_printf
#define dap_vfprintf __mingw_vfprintf #define dap_vprintf __mingw_vprintf
#define dap_vsprintf __mingw_vsprintf #define dap_fprintf __mingw_fprintf
#define dap_vsnprintf __mingw_vsnprintf #define dap_vfprintf __mingw_vfprintf
#define dap_asprintf __mingw_asprintf #define dap_vsprintf __mingw_vsprintf
#define dap_vasprintf __mingw_vasprintf #define dap_vsnprintf __mingw_vsnprintf
#else #define dap_asprintf __mingw_asprintf
#define dap_sscanf sscanf #define dap_vasprintf __mingw_vasprintf
#define dap_vsscanf vsscanf #else
#define dap_scanf scanf #define dap_sscanf sscanf
#define dap_vscanf vscanf #define dap_vsscanf vsscanf
#define dap_fscanf fscanf #define dap_scanf scanf
#define dap_vfscanf vfscanf #define dap_vscanf vscanf
#define dap_sprintf sprintf #define dap_fscanf fscanf
#define dap_snprintf snprintf #define dap_vfscanf vfscanf
#define dap_printf printf #define dap_sprintf sprintf
#define dap_vprintf vprintf #define dap_snprintf snprintf
#define dap_fprintf fprintf #define dap_printf printf
#define dap_vfprintf vfprintf #define dap_vprintf vprintf
#define dap_vsprintf vsprintf #define dap_fprintf fprintf
#define dap_vsnprintf vsnprintf #define dap_vfprintf vfprintf
#define dap_asprintf asprintf #define dap_vsprintf vsprintf
#define dap_vasprintf vasprintf #define dap_vsnprintf vsnprintf
#endif #define dap_asprintf asprintf
#define dap_vasprintf vasprintf
#endif
/**
* @brief The log_level enum typedef int DAP_SpinLock;
*/
/**
typedef enum dap_log_level { * @brief The log_level enum
*/
L_DEBUG = 0,
L_INFO = 1, typedef enum dap_log_level {
L_NOTICE = 2,
L_MSG = 3, L_DEBUG = 0,
L_DAP = 4, L_INFO = 1,
L_WARNING = 5, L_NOTICE = 2,
L_ATT = 6, L_MSG = 3,
L_ERROR = 7, L_DAP = 4,
L_CRITICAL = 8, L_WARNING = 5,
L_TOTAL, L_ATT = 6,
L_ERROR = 7,
} dap_log_level_t; L_CRITICAL = 8,
L_TOTAL,
typedef struct dap_log_str_s {
} dap_log_level_t;
time_t t;
uint8_t *str; typedef struct dap_log_history_str_s {
uint32_t len;
time_t t;
} dap_log_str_t; uint8_t *str;
uint32_t len;
#ifdef __cplusplus
extern "C" { } dap_log_history_str_t;
#endif
#ifdef __cplusplus
extern uint16_t htoa_lut256[ 256 ]; extern "C" {
#endif
#define dap_htoa64( out, in, len ) \
{\ extern uint16_t htoa_lut256[ 256 ];
uintptr_t _len = len; \
uint16_t *__restrict _out = (uint16_t *__restrict)out; \ #define dap_htoa64( out, in, len ) \
uint64_t *__restrict _in = (uint64_t *__restrict)in;\ {\
\ uintptr_t _len = len; \
while ( _len ) {\ uint16_t *__restrict _out = (uint16_t *__restrict)out; \
uint64_t _val = *_in ++;\ uint64_t *__restrict _in = (uint64_t *__restrict)in;\
_out[0] = htoa_lut256[ _val & 0x00000000000000FF ];\ \
_out[1] = htoa_lut256[ (_val & 0x000000000000FF00) >> 8 ];\ while ( _len ) {\
_out[2] = htoa_lut256[ (_val & 0x0000000000FF0000) >> 16 ];\ uint64_t _val = *_in ++;\
_out[3] = htoa_lut256[ (_val & 0x00000000FF000000) >> 24 ];\ _out[0] = htoa_lut256[ _val & 0x00000000000000FF ];\
_out[4] = htoa_lut256[ (_val & 0x000000FF00000000) >> 32 ];\ _out[1] = htoa_lut256[ (_val & 0x000000000000FF00) >> 8 ];\
_out[5] = htoa_lut256[ (_val & 0x0000FF0000000000) >> 40 ];\ _out[2] = htoa_lut256[ (_val & 0x0000000000FF0000) >> 16 ];\
_out[6] = htoa_lut256[ (_val & 0x00FF000000000000) >> 48 ];\ _out[3] = htoa_lut256[ (_val & 0x00000000FF000000) >> 24 ];\
_out[7] = htoa_lut256[ (_val & 0xFF00000000000000) >> 56 ];\ _out[4] = htoa_lut256[ (_val & 0x000000FF00000000) >> 32 ];\
_out += 8;\ _out[5] = htoa_lut256[ (_val & 0x0000FF0000000000) >> 40 ];\
_len -= 8;\ _out[6] = htoa_lut256[ (_val & 0x00FF000000000000) >> 48 ];\
}\ _out[7] = htoa_lut256[ (_val & 0xFF00000000000000) >> 56 ];\
} _out += 8;\
_len -= 8;\
typedef enum { }\
DAP_ASCII_ALNUM = 1 << 0, }
DAP_ASCII_ALPHA = 1 << 1,
DAP_ASCII_CNTRL = 1 << 2, typedef enum {
DAP_ASCII_DIGIT = 1 << 3, DAP_ASCII_ALNUM = 1 << 0,
DAP_ASCII_GRAPH = 1 << 4, DAP_ASCII_ALPHA = 1 << 1,
DAP_ASCII_LOWER = 1 << 5, DAP_ASCII_CNTRL = 1 << 2,
DAP_ASCII_PRINT = 1 << 6, DAP_ASCII_DIGIT = 1 << 3,
DAP_ASCII_PUNCT = 1 << 7, DAP_ASCII_GRAPH = 1 << 4,
DAP_ASCII_SPACE = 1 << 8, DAP_ASCII_LOWER = 1 << 5,
DAP_ASCII_UPPER = 1 << 9, DAP_ASCII_PRINT = 1 << 6,
DAP_ASCII_XDIGIT = 1 << 10 DAP_ASCII_PUNCT = 1 << 7,
} DapAsciiType; DAP_ASCII_SPACE = 1 << 8,
DAP_ASCII_UPPER = 1 << 9,
static const uint16_t s_ascii_table_data[256] = { DAP_ASCII_XDIGIT = 1 << 10
0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, } DapAsciiType;
0x004, 0x104, 0x104, 0x004, 0x104, 0x104, 0x004, 0x004,
0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, static const uint16_t s_ascii_table_data[256] = {
0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004,
0x140, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x004, 0x104, 0x104, 0x004, 0x104, 0x104, 0x004, 0x004,
0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004,
0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004,
0x459, 0x459, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x140, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0,
0x0d0, 0x653, 0x653, 0x653, 0x653, 0x653, 0x653, 0x253, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0,
0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459,
0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x459, 0x459, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0,
0x253, 0x253, 0x253, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x653, 0x653, 0x653, 0x653, 0x653, 0x653, 0x253,
0x0d0, 0x473, 0x473, 0x473, 0x473, 0x473, 0x473, 0x073, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253,
0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253,
0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x253, 0x253, 0x253, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x0d0,
0x073, 0x073, 0x073, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x004 0x0d0, 0x473, 0x473, 0x473, 0x473, 0x473, 0x473, 0x073,
/* the upper 128 are all zeroes */ 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073,
}; 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073,
0x073, 0x073, 0x073, 0x0d0, 0x0d0, 0x0d0, 0x0d0, 0x004
//const uint16_t * const c_dap_ascii_table = s_ascii_table_data; /* the upper 128 are all zeroes */
};
#define dap_ascii_isspace(c) (s_ascii_table_data[(unsigned char) (c)] & DAP_ASCII_SPACE) != 0
#define dap_ascii_isalpha(c) (s_ascii_table_data[(unsigned char) (c)] & DAP_ASCII_ALPHA) != 0 //const uint16_t * const c_dap_ascii_table = s_ascii_table_data;
//int dap_common_init( const char * a_log_file ); #define dap_ascii_isspace(c) (s_ascii_table_data[(unsigned char) (c)] & DAP_ASCII_SPACE) != 0
int dap_common_init( const char *console_title, const char *a_log_file ); #define dap_ascii_isalpha(c) (s_ascii_table_data[(unsigned char) (c)] & DAP_ASCII_ALPHA) != 0
void dap_common_deinit(void); void DAP_Sleep( uint32_t ms );
// set max items in log list DAP_STATIC_INLINE bool DAP_AtomicTryLock( DAP_SpinLock *lock )
void dap_log_set_max_item(unsigned int a_max); {
// get logs from list return (__sync_lock_test_and_set(lock, 1) == 0);
char *dap_log_get_item(time_t a_start_time, int a_limit); }
DAP_STATIC_INLINE void DAP_AtomicLock( DAP_SpinLock *lock )
void _log_it( const char * log_tag, enum dap_log_level, const char * format,... ); {
void _vlog_it( const char * log_tag, enum dap_log_level, const char * format, va_list ap ); while ( !DAP_AtomicTryLock(lock) ) {
DAP_Sleep( 0 );
#define log_it(_log_level,...) _log_it( LOG_TAG, _log_level, ##__VA_ARGS__) }
#define vlog_it( a_log_level, a_format, a_ap ) _vlog_it( LOG_TAG, a_log_level, a_format, a_ap ) }
const char * log_error(void); DAP_STATIC_INLINE void DAP_AtomicUnlock( DAP_SpinLock *lock )
void dap_log_level_set(enum dap_log_level ll); {
enum dap_log_level dap_log_level_get(void); __sync_lock_release( lock );
}
void dap_set_log_tag_width(size_t width);
//int dap_common_init( const char * a_log_file );
char *dap_itoa(int i); int dap_common_init( const char *console_title, const char *a_log_file );
int dap_time_to_str_rfc822(char * out, size_t out_size_max, time_t t); void dap_common_deinit(void);
int get_select_breaker(void); // set max items in log list
int send_select_break(void); void dap_log_set_max_item(unsigned int a_max);
char * exec_with_ret(const char * a_cmd); // get logs from list
char * exec_with_ret_multistring(const char * a_cmd); char *dap_log_get_item(time_t a_start_time, int a_limit);
char * dap_random_string_create_alloc(size_t a_length);
void dap_random_string_fill(char *str, size_t length); void _log_it( const char * log_tag, uint32_t taglen, enum dap_log_level, const char * format,... );
void dap_dump_hex(const void* data, size_t size); void _vlog_it( const char * log_tag, uint32_t taglen, enum dap_log_level, const char * format, va_list ap );
size_t dap_hex2bin(uint8_t *a_out, const char *a_in, size_t a_len); #define log_it( _log_level, ...) _log_it( LOG_TAG, sizeof(LOG_TAG)-1,_log_level, ##__VA_ARGS__)
size_t dap_bin2hex(char *a_out, const void *a_in, size_t a_len); #define vlog_it( a_log_level, a_format, a_ap ) _vlog_it( LOG_TAG, sizeof(LOG_TAG)-1, a_log_level, a_format, a_ap )
void dap_digit_from_string(const char *num_str, uint8_t *raw, size_t raw_len);
void dap_digit_from_string2(const char *num_str, uint8_t *raw, size_t raw_len); const char * log_error(void);
void dap_log_level_set(enum dap_log_level ll);
enum dap_log_level dap_log_level_get(void);
#ifdef __MINGW32__
int exec_silent(const char *a_cmd); void dap_set_log_tag_width(size_t width);
#endif
char *dap_itoa(int i);
#ifdef __cplusplus
} int dap_time_to_str_rfc822(char * out, size_t out_size_max, time_t t);
#endif
int get_select_breaker(void);
int send_select_break(void);
char * exec_with_ret(const char * a_cmd);
char * exec_with_ret_multistring(const char * a_cmd);
char * dap_random_string_create_alloc(size_t a_length);
void dap_random_string_fill(char *str, size_t length);
void dap_dump_hex(const void* data, size_t size);
size_t dap_hex2bin(uint8_t *a_out, const char *a_in, size_t a_len);
size_t dap_bin2hex(char *a_out, const void *a_in, size_t a_len);
void dap_digit_from_string(const char *num_str, uint8_t *raw, size_t raw_len);
void dap_digit_from_string2(const char *num_str, uint8_t *raw, size_t raw_len);
#ifdef __MINGW32__
int exec_silent(const char *a_cmd);
#endif
#ifdef __cplusplus
}
#endif
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Dmitriy A. Gearasimov <kahovski@gmail.com> * Dmitriy A. Gearasimov <kahovski@gmail.com>
* Anatolii Kurotych <akurotych@gmail.com> * Anatolii Kurotych <akurotych@gmail.com>
* DeM Labs Inc. https://demlabs.net * DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://github.com/demlabsinc * DeM Labs Open source community https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2019 * Copyright (c) 2017-2019
* All rights reserved. * All rights reserved.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Authors: * Authors:
* Aleksandr Lysikov <alexander.lysikov@demlabs.net> * Aleksandr Lysikov <alexander.lysikov@demlabs.net>
* DeM Labs Inc. https://demlabs.net * DeM Labs Inc. https://demlabs.net
* Kelvin Project https://github.com/kelvinblockchain * Kelvin Project https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2019 * Copyright (c) 2017-2019
* All rights reserved. * All rights reserved.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Authors: * Authors:
* Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net> * Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net>
* DeM Labs Inc. https://demlabs.net * DeM Labs Inc. https://demlabs.net
* Kelvin Project https://github.com/kelvinblockchain * Kelvin Project https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2018 * Copyright (c) 2017-2018
* All rights reserved. * All rights reserved.
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#include <assert.h> #include <assert.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#ifdef DAP_OS_ANDROID #ifdef DAP_OS_ANDROID
#include <android/log.h> #include <android/log.h>
#endif #endif
...@@ -62,93 +64,138 @@ ...@@ -62,93 +64,138 @@
#include "dap_lut.h" #include "dap_lut.h"
#define LAST_ERROR_MAX 255 #define DAP_LOG_USE_SPINLOCK 1
#define DAP_LOG_HISTORY 1
#define LAST_ERROR_MAX 255
#define LOG_TAG "dap_common" #define LOG_TAG "dap_common"
const char *log_level_tag[ 16 ] = {
" [DBG] [ ", // L_DEBUG = 0
" [INF] [ ", // L_INFO = 1,
" [ * ] [ ", // L_NOTICE = 2,
" [MSG] [ ", // L_MESSAGE = 3,
" [DAP] [ ", // L_DAP = 4,
" [WRN] [ ", // L_WARNING = 5,
" [ATT] [ ", // L_ATT = 6,
" [ERR] [ ", // L_ERROR = 7,
" [ ! ] [ ", // L_CRITICAL = 8,
" [---] [ ", // = 9
" [---] [ ", // = 10
" [---] [ ", // = 11
" [---] [ ", // = 12
" [---] [ ", // = 13
" [---] [ ", // = 14
" [---] [ ", // = 15
};
const char *ansi_seq_color[ 16 ] = {
"\x1b[0;37;40m", // L_DEBUG = 0
"\x1b[1;32;40m", // L_INFO = 2,
"\x1b[0;32;40m", // L_NOTICE = 1,
"\x1b[1;33;40m", // L_MESSAGE = 3,
"\x1b[0;36;40m", // L_DAP = 4,
"\x1b[1;35;40m", // L_WARNING = 5,
"\x1b[1;36;40m", // L_ATT = 6,
"\x1b[1;31;40m", // L_ERROR = 7,
"\x1b[1;37;41m", // L_CRITICAL = 8,
"", // = 9
"", // = 10
"", // = 11
"", // = 12
"", // = 13
"", // = 14
"", // = 15
};
#ifdef _WIN32
OSVERSIONINFO win32_osvi;
bool bUseANSIEscapeSequences = false;
HANDLE hWin32ConOut = INVALID_HANDLE_VALUE;
WORD log_level_colors[ 16 ] = {
7, // L_DEBUG
10, // L_INFO
2, // L_NOTICE
11, // L_MESSAGE
9, // L_DAP
13, // L_WARNING
14, // L_ATT
12, // L_ERROR
(12 << 4) + 15, // L_CRITICAL
7,
7,
7,
7,
7,
7,
7
};
#endif
uint32_t ansi_seq_color_len[ 16 ];
static char s_last_error[LAST_ERROR_MAX] = {0}; static char s_last_error[LAST_ERROR_MAX] = {0};
static enum dap_log_level dap_log_level = L_DEBUG; static enum dap_log_level dap_log_level = L_DEBUG;
static FILE *s_log_file = NULL; static FILE *s_log_file = NULL;
static char log_tag_fmt_str[10]; static char log_tag_fmt_str[10];
#ifdef DAP_LOG_HISTORY
static pthread_mutex_t s_list_logs_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t s_list_logs_mutex = PTHREAD_MUTEX_INITIALIZER;
static uint32_t logh_total = 0; // log history size static uint32_t logh_total = 0; // log history size
static uint32_t logh_outindex = 0; static uint32_t logh_outindex = 0;
static uint8_t *log_buffer = NULL; static uint8_t *logh_buffer = NULL;
static uint8_t *temp_buffer = NULL; static uint8_t *temp_buffer = NULL;
static uint8_t *end_of_log_buffer = NULL; static uint8_t *end_of_logh_buffer = NULL;
static dap_log_str_t *log_history = NULL; static dap_log_history_str_t *log_history = NULL;
static time_t g_start_time = 0; #endif
const char *log_level_tag[ 16 ] = { #if DAP_LOG_USE_SPINLOCK
DAP_SpinLock log_spinlock;
#else
static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
" [DBG] [ ", // L_DEBUG = 0 typedef struct dap_log_str_s {
" [INF] [ ", // L_INFO = 1,
" [ * ] [ ", // L_NOTICE = 2,
" [MSG] [ ", // L_MESSAGE = 3,
" [DAP] [ ", // L_DAP = 4,
" [WRN] [ ", // L_WARNING = 5,
" [ATT] [ ", // L_ATT = 6,
" [ERR] [ ", // L_ERROR = 7,
" [ ! ] [ ", // L_CRITICAL = 8,
" [---] [ ", // = 9
" [---] [ ", // = 10
" [---] [ ", // = 11
" [---] [ ", // = 12
" [---] [ ", // = 13
" [---] [ ", // = 14
" [---] [ ", // = 15
};
const char *ansi_seq_color[ 16 ] = { time_t t;
uint8_t *str;
uint32_t len;
uint8_t tag;
"\x1b[0;37;40m", // L_DEBUG = 0 } dap_log_str_t;
"\x1b[1;32;40m", // L_INFO = 2,
"\x1b[0;32;40m", // L_NOTICE = 1,
"\x1b[1;33;40m", // L_MESSAGE = 3,
"\x1b[0;36;40m", // L_DAP = 4,
"\x1b[1;35;40m", // L_WARNING = 5,
"\x1b[1;36;40m", // L_ATT = 6,
"\x1b[1;31;40m", // L_ERROR = 7,
"\x1b[1;37;41m", // L_CRITICAL = 8,
"", // = 9
"", // = 10
"", // = 11
"", // = 12
"", // = 13
"", // = 14
"", // = 15
};
#ifdef _WIN32 #define DAP_LOG_STR_SIZE 128
#define DAP_LOG_MAX_STRINGS 32768
#define DAP_LOG_BUFFER_SIZE (DAP_LOG_STR_SIZE * DAP_LOG_MAX_STRINGS)
OSVERSIONINFO win32_osvi; static uint32_t log_outindex = 0;
bool bUseANSIEscapeSequences = false; static uint8_t *log_buffer = NULL;
HANDLE hWin32ConOut = INVALID_HANDLE_VALUE; static dap_log_str_t *log_strs = NULL;
WORD log_level_colors[ 16 ] = {
7, // L_DEBUG
10, // L_INFO
2, // L_NOTICE
11, // L_MESSAGE
9, // L_DAP
13, // L_WARNING
14, // L_ATT
12, // L_ERROR
(12 << 4) + 15, // L_CRITICAL
7,
7,
7,
7,
7,
7,
7
};
#endif static pthread_t log_thread;
static bool log_term_signal = false;
static uint32_t log_page = 0;
uint32_t ansi_seq_color_len[ 16 ]; static time_t g_start_time = 0;
static volatile time_t g_time;
static bool bOverflow = false;
static DAP_ALIGNED(32) uint8_t cdatatime[ 64 ];
static void *log_thread_proc( void *arg );
DAP_STATIC_INLINE DAP_UpdateLogTime( uint32_t lp )
{
time_t t = time( NULL );
struct tm *tmptime = localtime( &t );
strftime( (char *)&cdatatime[lp*32], 32, "[%x-%X]", tmptime );
// printf("Time updated %s page %u\n", (char *)&cdatatime[lp*32], log_page );
}
/** /**
* @brief set_log_level Sets the logging level * @brief set_log_level Sets the logging level
...@@ -168,16 +215,16 @@ enum dap_log_level dap_log_level_get( void ) { ...@@ -168,16 +215,16 @@ enum dap_log_level dap_log_level_get( void ) {
*/ */
void dap_set_log_tag_width(size_t width) { void dap_set_log_tag_width(size_t width) {
if (width > 99) { if (width > 99) {
dap_fprintf(stderr,"Can't set width %zd", width); dap_fprintf(stderr,"Can't set width %zd", width);
return; return;
} }
// construct new log_tag_fmt_str // construct new log_tag_fmt_str
strcpy( log_tag_fmt_str, "[%" ); strcpy( log_tag_fmt_str, "[%" );
strcat( log_tag_fmt_str, dap_itoa((int)width) ); strcat( log_tag_fmt_str, dap_itoa((int)width) );
// strcat( log_tag_fmt_str, itoa((int)width) ); // strcat( log_tag_fmt_str, itoa((int)width) );
strcat( log_tag_fmt_str, "s]\t" ); strcat( log_tag_fmt_str, "s]\t" );
} }
/** /**
...@@ -187,71 +234,93 @@ void dap_set_log_tag_width(size_t width) { ...@@ -187,71 +234,93 @@ void dap_set_log_tag_width(size_t width) {
*/ */
int dap_common_init( const char *console_title, const char *a_log_file ) int dap_common_init( const char *console_title, const char *a_log_file )
{ {
srand( (unsigned int)time(NULL) ); srand( (unsigned int)time(NULL) );
#ifdef _WIN32 #ifdef _WIN32
SetupConsole( console_title, L"Lucida Console", 12, 20 ); SetupConsole( console_title, L"Lucida Console", 12, 20 );
#endif #endif
g_start_time = time( NULL ); g_start_time = time( NULL );
// init default log tag 8 width // init default log tag 8 width
strcpy( log_tag_fmt_str, "[%8s]\t"); strcpy( log_tag_fmt_str, "[%8s]\t");
log_buffer = (uint8_t *)malloc( DAP_LOG_HISTORY_BUFFER_SIZE + 65536 ); #if DAP_LOG_HISTORY
if ( !log_buffer ) logh_buffer = (uint8_t *)DAP_MALLOC( DAP_LOG_HISTORY_BUFFER_SIZE );
goto err; if ( !logh_buffer )
goto err;
temp_buffer = log_buffer + 65536; end_of_logh_buffer = logh_buffer + DAP_LOG_HISTORY_BUFFER_SIZE;
end_of_log_buffer = log_buffer + DAP_LOG_HISTORY_BUFFER_SIZE;
log_history = (dap_log_str_t *)malloc( DAP_LOG_HISTORY_MAX_STRINGS * sizeof(dap_log_str_t) ); log_history = (dap_log_history_str_t *)DAP_MALLOC( DAP_LOG_HISTORY_MAX_STRINGS * sizeof(dap_log_history_str_t) );
if ( !log_history ) if ( !log_history )
goto err; goto err;
for ( uint32_t i = 0; i < DAP_LOG_HISTORY_MAX_STRINGS; ++ i ) { for ( uint32_t i = 0; i < DAP_LOG_HISTORY_MAX_STRINGS; ++ i ) {
log_history[ i ].t = 0; log_history[ i ].t = 0;
log_history[ i ].str = log_buffer + DAP_LOG_HISTORY_STR_SIZE * i; log_history[ i ].str = logh_buffer + DAP_LOG_HISTORY_STR_SIZE * i;
} }
#endif
for ( uint32_t i = 0; i < 16; ++ i ) log_buffer = (uint8_t *)DAP_MALLOC( DAP_LOG_BUFFER_SIZE * 2 );
ansi_seq_color_len[ i ] = strlen( ansi_seq_color[i] ); if ( !log_buffer )
goto err;
#ifdef _WIN32 log_strs = (dap_log_str_t *)DAP_MALLOC( DAP_LOG_MAX_STRINGS * sizeof(dap_log_str_t) * 2 );
if ( !log_history )
goto err;
for ( uint32_t i = 0; i < DAP_LOG_MAX_STRINGS * 2; ++ i ) {
log_strs[ i ].str = log_buffer + DAP_LOG_STR_SIZE * i;
}
memset( &win32_osvi, 0, sizeof(OSVERSIONINFO) ); temp_buffer = (uint8_t *)DAP_MALLOC( 65536 );
if ( !logh_buffer )
goto err;
win32_osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ); for ( uint32_t i = 0; i < 16; ++ i )
GetVersionEx( (OSVERSIONINFO *)&win32_osvi ); ansi_seq_color_len[ i ] = strlen( ansi_seq_color[i] );
bUseANSIEscapeSequences = (win32_osvi.dwMajorVersion >= 10); #ifdef _WIN32
//if ( !bUseANSIEscapeSequences ) memset( &win32_osvi, 0, sizeof(OSVERSIONINFO) );
hWin32ConOut = GetStdHandle( STD_OUTPUT_HANDLE );
#if 0 win32_osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
printf( "Windows version %u.%u platformID %u \n", GetVersionEx( (OSVERSIONINFO *)&win32_osvi );
win32_osvi.dwMajorVersion,
win32_osvi.dwMinorVersion, bUseANSIEscapeSequences = (win32_osvi.dwMajorVersion >= 10);
win32_osvi.dwPlatformId ); //if ( !bUseANSIEscapeSequences )
hWin32ConOut = GetStdHandle( STD_OUTPUT_HANDLE );
#if 0
printf( "Windows version %u.%u platformID %u \n",
win32_osvi.dwMajorVersion,
win32_osvi.dwMinorVersion,
win32_osvi.dwPlatformId );
#endif
#endif #endif
#endif
if ( !a_log_file ) if ( !a_log_file )
return 0; return 0;
s_log_file = fopen( a_log_file , "a" ); s_log_file = fopen( a_log_file , "a" );
if( s_log_file == NULL ) { if ( s_log_file == NULL ) {
dap_fprintf( stderr, "Can't open log file %s to append\n", a_log_file ); dap_fprintf( stderr, "Can't open log file %s to append\n", a_log_file );
return -1; return -1;
} }
return 0; log_page = 0;
log_outindex = 0;
DAP_UpdateLogTime( 0 );
log_term_signal = false;
pthread_create( &log_thread, NULL, log_thread_proc, NULL );
return 0;
err: err:
printf( "Fatal Error: Out of memory!\n" ); printf( "Fatal Error: Out of memory!\n" );
dap_common_deinit( ); dap_common_deinit( );
return -1; return -1;
} }
/** /**
...@@ -259,55 +328,68 @@ err: ...@@ -259,55 +328,68 @@ err:
*/ */
void dap_common_deinit( ) void dap_common_deinit( )
{ {
printf("dap_common_deinit( )\n"); printf("dap_common_deinit( )\n");
if ( s_log_file ) log_term_signal = true;
fclose( s_log_file ); pthread_join( log_thread, NULL );
if ( s_log_file )
fclose( s_log_file );
if ( temp_buffer )
DAP_FREE( temp_buffer );
if ( log_strs )
DAP_FREE( log_strs );
if ( log_buffer )
DAP_FREE( log_buffer );
if( log_history ) #if DAP_LOG_HISTORY
free( log_history ); if ( log_history )
DAP_FREE( log_history );
if( log_buffer ) if ( logh_buffer )
free( log_buffer ); DAP_FREE( logh_buffer );
#endif
} }
#if DAP_LOG_HISTORY
void log_log( char *str, uint32_t len, time_t t ) void log_log( char *str, uint32_t len, time_t t )
{ {
pthread_mutex_lock( &s_list_logs_mutex ); pthread_mutex_lock( &s_list_logs_mutex );
// printf("log_log with time = %llu\n", t );
while( len ) { while( len ) {
uint8_t *out = log_history[ logh_outindex ].str; uint8_t *out = log_history[ logh_outindex ].str;
uint32_t ilen = len; uint32_t ilen = len;
if ( out + len >= end_of_log_buffer ) if ( out + len >= end_of_logh_buffer )
ilen = end_of_log_buffer - out; ilen = end_of_logh_buffer - out;
memcpy( out, str, ilen ); memcpy( out, str, ilen );
len -= ilen; len -= ilen;
do { do {
log_history[ logh_outindex ].t = t; log_history[ logh_outindex ].t = t;
if ( ilen >= DAP_LOG_HISTORY_STR_SIZE ) { if ( ilen >= DAP_LOG_HISTORY_STR_SIZE ) {
log_history[ logh_outindex ].len = DAP_LOG_HISTORY_STR_SIZE; log_history[ logh_outindex ].len = DAP_LOG_HISTORY_STR_SIZE;
ilen -= DAP_LOG_HISTORY_STR_SIZE; ilen -= DAP_LOG_HISTORY_STR_SIZE;
} }
else { else {
log_history[ logh_outindex ].len = ilen; log_history[ logh_outindex ].len = ilen;
ilen = 0; ilen = 0;
} }
++ logh_outindex; ++ logh_outindex;
logh_outindex &= DAP_LOG_HISTORY_M; logh_outindex &= DAP_LOG_HISTORY_M;
if ( logh_total < DAP_LOG_HISTORY_MAX_STRINGS ) if ( logh_total < DAP_LOG_HISTORY_MAX_STRINGS )
++ logh_total; ++ logh_total;
} while( ilen ); } while( ilen );
} }
pthread_mutex_unlock( &s_list_logs_mutex ); pthread_mutex_unlock( &s_list_logs_mutex );
return; return;
...@@ -315,28 +397,28 @@ void log_log( char *str, uint32_t len, time_t t ) ...@@ -315,28 +397,28 @@ void log_log( char *str, uint32_t len, time_t t )
uint32_t logh_since( time_t t ) uint32_t logh_since( time_t t )
{ {
uint32_t bi = 0; uint32_t bi = 0;
uint32_t si = logh_total >> 1; uint32_t si = logh_total >> 1;
uint32_t li = (logh_outindex - 1) & DAP_LOG_HISTORY_M; uint32_t li = (logh_outindex - 1) & DAP_LOG_HISTORY_M;
if ( log_history[li].t < t ) // no new logs if ( log_history[li].t < t ) // no new logs
return 0xFFFFFFFF; return 0xFFFFFFFF;
if (logh_total >= DAP_LOG_HISTORY_MAX_STRINGS ) if (logh_total >= DAP_LOG_HISTORY_MAX_STRINGS )
bi = logh_outindex; bi = logh_outindex;
if ( log_history[bi].t >= t ) // all logs is new if ( log_history[bi].t >= t ) // all logs is new
return bi; return bi;
while( si ) { while( si ) {
if ( log_history[(bi + si) & DAP_LOG_HISTORY_M].t < t ) if ( log_history[(bi + si) & DAP_LOG_HISTORY_M].t < t )
bi += si; bi += si;
si >>= 1; si >>= 1;
} }
return (bi + si + 1) & DAP_LOG_HISTORY_M; return (bi + si + 1) & DAP_LOG_HISTORY_M;
} }
/** /**
...@@ -370,122 +452,233 @@ uint32_t logh_since( time_t t ) ...@@ -370,122 +452,233 @@ uint32_t logh_since( time_t t )
return (si + 1) & DAP_LOG_HISTORY_M; return (si + 1) & DAP_LOG_HISTORY_M;
} }
**/ **/
#endif
/* /*
* Get logs from list * Get logs from list
*/ */
char *dap_log_get_item( time_t a_time, int a_limit ) char *dap_log_get_item( time_t a_time, int a_limit )
{ {
uint32_t l_count; #if !DAP_LOG_HISTORY
uint32_t si;
char *res, *out;
time_t a_start_time;
a_start_time = time( NULL ); char *res = (char *)DAP_MALLOC( 64 );
if ( !res )
return res;
if ( a_time > a_start_time ) strcpy( res, "DAP_LOG_HISTORY is disabled" );
a_start_time = 0; return res;
else
a_start_time -= a_time;
pthread_mutex_lock( &s_list_logs_mutex ); #else
uint32_t l_count;
uint32_t si;
char *res, *out;
time_t a_start_time;
// printf("dap_log_get_item() a_start_time = %llu, a_limit = %u\n", a_start_time, a_limit ); a_start_time = time( NULL );
l_count = logh_total; if ( a_time > a_start_time )
a_start_time = 0;
else
a_start_time -= a_time;
if ( l_count > (uint32_t)a_limit ) pthread_mutex_lock( &s_list_logs_mutex );
l_count = a_limit;
if ( !l_count ) { l_count = logh_total;
pthread_mutex_unlock( &s_list_logs_mutex );
return NULL;
}
si = logh_since( a_start_time ); if ( l_count > (uint32_t)a_limit )
if ( si == 0xFFFFFFFF || log_history[ si ].t < a_start_time ) {// no new logs l_count = a_limit;
pthread_mutex_unlock( &s_list_logs_mutex );
return NULL;
}
out = res = (char *)malloc( l_count * DAP_LOG_HISTORY_STR_SIZE + 1 ); if ( !l_count ) {
if ( !res ) { pthread_mutex_unlock( &s_list_logs_mutex );
pthread_mutex_unlock( &s_list_logs_mutex ); return NULL;
return NULL; }
}
do { si = logh_since( a_start_time );
if ( si == 0xFFFFFFFF || log_history[ si ].t < a_start_time ) {// no new logs
pthread_mutex_unlock( &s_list_logs_mutex );
return NULL;
}
memcpy( out, log_history[ si ].str, log_history[ si ].len ); out = res = (char *)DAP_MALLOC( l_count * DAP_LOG_HISTORY_STR_SIZE + 1 );
out += log_history[ si ].len; if ( !res ) {
pthread_mutex_unlock( &s_list_logs_mutex );
return NULL;
}
si = (si + 1) & DAP_LOG_HISTORY_M; do {
if ( si == logh_outindex || log_history[ si ].t < a_start_time )
break;
} while ( --l_count ); memcpy( out, log_history[ si ].str, log_history[ si ].len );
out += log_history[ si ].len;
*out = 0; si = (si + 1) & DAP_LOG_HISTORY_M;
pthread_mutex_unlock( &s_list_logs_mutex ); if ( si == logh_outindex || log_history[ si ].t < a_start_time )
break;
} while ( --l_count );
*out = 0;
pthread_mutex_unlock( &s_list_logs_mutex );
return res; return res;
#endif
} }
#if 0 static void *log_thread_proc( void *arg )
// save log to list
static void log_add_to_list(time_t a_t, const char *a_time_str, const char * a_log_tag, enum dap_log_level a_ll,
const char * a_format, va_list a_ap)
{ {
// pthread_mutex_lock(&s_list_logs_mutex); int32_t outlogstrs = 0, tmp, n;
// dap_string_t *l_string = dap_string_new(""); dap_log_str_t *logstr;
//
// dap_string_append_printf(l_string, "[%s]\t", a_time_str); while ( !log_term_signal ) {
DAP_UpdateLogTime( log_page^1 );
#if DAP_LOG_USE_SPINLOCK
DAP_AtomicLock( &log_spinlock );
#else
pthread_mutex_lock( &log_mutex );
#endif
if ( !log_outindex ) {
log_page ^= 1;
#if DAP_LOG_USE_SPINLOCK
DAP_AtomicUnlock( &log_spinlock );
#else
pthread_mutex_unlock( &log_mutex );
#endif
// printf("log_thread_proc: nothing to log. Sleeping...\n" );
DAP_Sleep( 10 );
continue;
}
// l_string = dap_string_append(l_string, log_level_tag[a_ll] ); n = outlogstrs = log_outindex;
log_outindex = 0;
logstr = &log_strs[ log_page * DAP_LOG_MAX_STRINGS ];
log_page ^= 1;
/** #if DAP_LOG_USE_SPINLOCK
if(a_ll == L_DEBUG) { DAP_AtomicUnlock( &log_spinlock );
l_string = dap_string_append(l_string, "[DBG]\t"); #else
} else if(a_ll == L_INFO) { pthread_mutex_unlock( &log_mutex );
l_string = dap_string_append(l_string, "[INF]\t"); #endif
} else if(a_ll == L_NOTICE) {
l_string = dap_string_append(l_string, "[ * ]\t");
} else if(a_ll == L_WARNING) {
l_string = dap_string_append(l_string, "[WRN]\t");
} else if(a_ll == L_ERROR) {
l_string = dap_string_append(l_string, "[ERR]\t");
} else if(a_ll == L_CRITICAL) {
l_string = dap_string_append(l_string, "[!!!]\t");
}
**/
/** // printf("log_thread_proc: outlogstrs: %u\n", outlogstrs );
do {
if(a_log_tag != NULL) { #ifdef DAP_OS_ANDROID
dap_string_append_printf(l_string, log_tag_fmt_str, a_log_tag); buf2[ len ] = 0;
__android_log_write( ANDROID_LOG_INFO, DAP_BRAND, buf0 + msg_offset );
#endif
#if 1
#ifdef _WIN32
// if ( !bUseANSIEscapeSequences )
SetConsoleTextAttribute( hWin32ConOut, log_level_colors[logstr->tag] );
// WriteConsole( hWin32ConOut, buf0 + time_offset, len - time_offset, &tmp, NULL );
// fwrite( buf0 + time_offset, len - time_offset, 1, stdout );
WriteFile( hWin32ConOut, logstr->str, logstr->len, (LPDWORD)&tmp, NULL );
#else
fwrite( ansi_seq_color[logstr->tag], 10, 1, stdout );
fwrite( logstr->str, logstr->len, 1, stdout );
#endif
#endif
if ( s_log_file )
fwrite( logstr->str, logstr->len, 1, s_log_file );
// fwrite( "1234567890", 5, 1, stdout );
uint32_t al = ROUNDUP(logstr->len, 128 ) >> 7;
logstr += al;
n -= al;
} while ( n > 0 );
if ( outlogstrs < 1024 ) {
DAP_Sleep( 10 );
}
} }
dap_string_append_vprintf(l_string, a_format, a_ap);
dap_list_logs_item_t *l_item = DAP_NEW(dap_list_logs_item_t); // printf("log_thread_proc Finished! Overflows? = %u\n", bOverflow );
l_item->t = a_t;
return NULL;
}
DAP_STATIC_INLINE void _log_enqueue( const char *log_tag, uint32_t taglen, uint8_t *msg, uint32_t len , uint32_t ll )
{
uint32_t total_len = len + 19 + 8 + taglen + 3;
uint32_t al = ROUNDUP( total_len, 128 ) >> 7;
if ( !al )
return;
//[07/27/19-03:22:45] [INF] [db_cdb]
l_item->str = dap_string_free(l_string, false); #if DAP_LOG_USE_SPINLOCK
s_list_logs = dap_list_append(s_list_logs, l_item); DAP_AtomicLock( &log_spinlock );
#else
pthread_mutex_lock( &log_mutex );
#endif
// remove old items if ( log_outindex + (al-1) >= DAP_LOG_MAX_STRINGS ) {
unsigned int l_count = dap_list_length(s_list_logs); if ( !bOverflow ) {
if(l_count > s_max_items) { bOverflow = true;
// remove items from the beginning printf("Overflow!!!\n");
for(unsigned int i = 0; i < l_count - s_max_items; i++) {
s_list_logs = dap_list_remove(s_list_logs, s_list_logs->data);
} }
#if DAP_LOG_USE_SPINLOCK
DAP_AtomicUnlock( &log_spinlock );
#else
pthread_mutex_unlock( &log_mutex );
#endif
return;
} }
pthread_mutex_unlock(&s_list_logs_mutex); dap_log_str_t *logstr = &log_strs[ log_page * DAP_LOG_MAX_STRINGS + log_outindex ];
**/ uint8_t *out = logstr->str;
memcpy( out, &cdatatime[log_page*32], 19 );
out += 19;
memcpy( out, log_level_tag[ll], 8 );
out += 8;
memcpy( out, log_tag, taglen );
out += taglen;
*out ++ = ']';
*out ++ = ' ';
memcpy( out, msg, len );
out += len;
*out = 10;
logstr->t = g_time;
logstr->len = total_len;
logstr->tag = ll;
log_outindex += al;
#if DAP_LOG_USE_SPINLOCK
DAP_AtomicUnlock( &log_spinlock );
#else
pthread_mutex_unlock( &log_mutex );
#endif
} }
#endif
void _log_it( const char *log_tag, uint32_t taglen, enum dap_log_level ll, const char *fmt,... )
{
DAP_ALIGNED(32) uint8_t buf0[ 16384 ];
uint32_t len;
if ( ll < dap_log_level || ll >= 16 || !log_tag )
return;
va_list va;
va_start( va, fmt );
len = dap_vsprintf( (char *)&buf0[0], fmt, va );
va_end( va );
_log_enqueue( log_tag, taglen, &buf0[0], len, ll );
return;
}
/** /**
* @brief _log_it Writes information to the log * @brief _log_it Writes information to the log
...@@ -494,7 +687,7 @@ static void log_add_to_list(time_t a_t, const char *a_time_str, const char * a_l ...@@ -494,7 +687,7 @@ static void log_add_to_list(time_t a_t, const char *a_time_str, const char * a_l
* @param[in] format * @param[in] format
*/ */
void _log_it( const char *log_tag, enum dap_log_level ll, const char *fmt,... ) void _log_it2( const char *log_tag, enum dap_log_level ll, const char *fmt,... )
{ {
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
uint8_t *buf0 = temp_buffer; uint8_t *buf0 = temp_buffer;
...@@ -550,6 +743,7 @@ void _log_it( const char *log_tag, enum dap_log_level ll, const char *fmt,... ) ...@@ -550,6 +743,7 @@ void _log_it( const char *log_tag, enum dap_log_level ll, const char *fmt,... )
// buf0[ len++ ] = 0; // buf0[ len++ ] = 0;
log_log( (char *)(buf0 + time_offset), len - time_offset, t ); log_log( (char *)(buf0 + time_offset), len - time_offset, t );
#if 0
#ifdef _WIN32 #ifdef _WIN32
// if ( !bUseANSIEscapeSequences ) // if ( !bUseANSIEscapeSequences )
SetConsoleTextAttribute( hWin32ConOut, log_level_colors[ll] ); SetConsoleTextAttribute( hWin32ConOut, log_level_colors[ll] );
...@@ -559,12 +753,33 @@ void _log_it( const char *log_tag, enum dap_log_level ll, const char *fmt,... ) ...@@ -559,12 +753,33 @@ void _log_it( const char *log_tag, enum dap_log_level ll, const char *fmt,... )
#else #else
fwrite( buf0, len, 1, stdout ); fwrite( buf0, len, 1, stdout );
#endif #endif
#endif
// printf("\x1b[0m\n"); // printf("\x1b[0m\n");
pthread_mutex_unlock( &mutex ); pthread_mutex_unlock( &mutex );
} }
void DAP_Sleep( uint32_t ms )
{
#ifdef _WIN32
Sleep( ms );
#else
int was_error;
struct timespec elapsed, tv;
elapsed.tv_sec = ms / 1000;
elapsed.tv_nsec = (ms % 1000) * 1000000;
do {
errno = 0;
tv.tv_sec = elapsed.tv_sec;
tv.tv_nsec = elapsed.tv_nsec;
was_error = nanosleep( &tv, &elapsed );
} while( was_error && (errno == EINTR) );
#endif
}
/** /**
* @brief log_error Error log * @brief log_error Error log
* @return * @return
......
...@@ -486,6 +486,8 @@ char** dap_config_get_array_str(dap_config_t * a_config, const char * a_section_ ...@@ -486,6 +486,8 @@ char** dap_config_get_array_str(dap_config_t * a_config, const char * a_section_
const char * a_item_name, uint16_t * array_length) { const char * a_item_name, uint16_t * array_length) {
dap_config_item_t * item = dap_config_get_item(a_config, a_section_path, a_item_name); dap_config_item_t * item = dap_config_get_item(a_config, a_section_path, a_item_name);
if (item == NULL){ if (item == NULL){
if(array_length != NULL)
*array_length = 0;
return NULL; return NULL;
} }
if (array_length != NULL) if (array_length != NULL)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Authors: * Authors:
* Aleksandr Lysikov <alexander.lysikov@demlabs.net> * Aleksandr Lysikov <alexander.lysikov@demlabs.net>
* DeM Labs Inc. https://demlabs.net * DeM Labs Inc. https://demlabs.net
* Kelvin Project https://github.com/kelvinblockchain * Kelvin Project https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2018 * Copyright (c) 2017-2018
* All rights reserved. * All rights reserved.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Authors: * Authors:
* Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net> * Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net>
* DeM Labs Inc. https://demlabs.net * DeM Labs Inc. https://demlabs.net
* Kelvin Project https://github.com/kelvinblockchain * Kelvin Project https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2018 * Copyright (c) 2017-2018
* All rights reserved. * All rights reserved.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Authors: * Authors:
* Anton Isaikin <anton.isaikin@demlabs.net> * Anton Isaikin <anton.isaikin@demlabs.net>
* DeM Labs Inc. https://demlabs.net * DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://github.com/demlabsinc * DeM Labs Open source community https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2019 * Copyright (c) 2017-2019
* All rights reserved. * All rights reserved.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Authors: * Authors:
* Anatolii Kurotych <akurotych@gmail.com> * Anatolii Kurotych <akurotych@gmail.com>
* DeM Labs Inc. https://demlabs.net * DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://github.com/demlabsinc * DeM Labs Open source community https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2019 * Copyright (c) 2017-2019
* All rights reserved. * All rights reserved.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Authors: * Authors:
* Anatolii Kurotych <akurotych@gmail.com> * Anatolii Kurotych <akurotych@gmail.com>
* DeM Labs Inc. https://demlabs.net * DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://github.com/demlabsinc * DeM Labs Open source community https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2019 * Copyright (c) 2017-2019
* All rights reserved. * All rights reserved.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Authors: * Authors:
* Anatolii Kurotych <akurotych@gmail.com> * Anatolii Kurotych <akurotych@gmail.com>
* DeM Labs Inc. https://demlabs.net * DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://github.com/demlabsinc * DeM Labs Open source community https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2019 * Copyright (c) 2017-2019
* All rights reserved. * All rights reserved.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Authors: * Authors:
* Anatolii Kurotych <akurotych@gmail.com> * Anatolii Kurotych <akurotych@gmail.com>
* DeM Labs Inc. https://demlabs.net * DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://github.com/demlabsinc * DeM Labs Open source community https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2019 * Copyright (c) 2017-2019
* All rights reserved. * All rights reserved.
......
/* /*
Copyright (c) 2017-2019 (c) Project "DeM Labs Inc" https://github.com/demlabsinc Copyright (c) 2017-2019 (c) Project "DeM Labs Inc" https://gitlab.demlabs.net/cellframe
All rights reserved. All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project This file is part of DAP (Deus Applications Prototypes) the open source project
......
/* /*
Copyright (c) 2017-2019 (c) Project "DeM Labs Inc" https://github.com/demlabsinc Copyright (c) 2017-2019 (c) Project "DeM Labs Inc" https://gitlab.demlabs.net/cellframe
All rights reserved. All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project This file is part of DAP (Deus Applications Prototypes) the open source project
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Authors: * Authors:
* Anatolii Kurotych <akurotych@gmail.com> * Anatolii Kurotych <akurotych@gmail.com>
* DeM Labs Inc. https://demlabs.net * DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://github.com/demlabsinc * DeM Labs Open source community https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2019 * Copyright (c) 2017-2019
* All rights reserved. * All rights reserved.
......
/* /*
Copyright (c) 2017-2019 (c) Project "DeM Labs Inc" https://github.com/demlabsinc Copyright (c) 2017-2019 (c) Project "DeM Labs Inc" https://gitlab.demlabs.net/cellframe
All rights reserved. All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project This file is part of DAP (Deus Applications Prototypes) the open source project
......
/* /*
Copyright (c) 2017-2019 (c) Project "DeM Labs Inc" https://github.com/demlabsinc Copyright (c) 2017-2019 (c) Project "DeM Labs Inc" https://gitlab.demlabs.net/cellframe
All rights reserved. All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project This file is part of DAP (Deus Applications Prototypes) the open source project
......