\hypertarget{simple-signal-emit_8c-example}{}\doxysection{simple-\/signal-\/emit.\+c}
Server that registers a service interface and emits simple signals.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{comment}{//Compile with:}}
\DoxyCodeLine{\textcolor{comment}{// gcc -\/o simple-\/signal-\/emit simple-\/signal-\/emit.c `pkg-\/config -\/-\/cflags -\/-\/libs eldbus`}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <Eldbus.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{enum} \{}
\DoxyCodeLine{   TEST\_SIGNAL\_ALIVE,}
\DoxyCodeLine{   TEST\_SIGNAL\_PROP,}
\DoxyCodeLine{   TEST\_SIGNAL\_NAME,}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keyword}{const} \mbox{\hyperlink{struct__Eldbus__Signal}{Eldbus\_Signal}} test\_signals[] = \{}
\DoxyCodeLine{   [TEST\_SIGNAL\_ALIVE] = \{ \textcolor{stringliteral}{"{}Alive"{}} \},}
\DoxyCodeLine{   [TEST\_SIGNAL\_PROP] = \{ \textcolor{stringliteral}{"{}Properties"{}}, \mbox{\hyperlink{group__Eldbus__Service_gab77338df786b5ad2a9f86693432f23a4}{ELDBUS\_ARGS}}(\{ \textcolor{stringliteral}{"{}a\{ss\}"{}}, \textcolor{stringliteral}{"{}properties"{}}\}) \},}
\DoxyCodeLine{   [TEST\_SIGNAL\_NAME] = \{ \textcolor{stringliteral}{"{}Name"{}}, \mbox{\hyperlink{group__Eldbus__Service_gab77338df786b5ad2a9f86693432f23a4}{ELDBUS\_ARGS}}(\{ \textcolor{stringliteral}{"{}s"{}}, \textcolor{stringliteral}{"{}name"{}}\}) \},}
\DoxyCodeLine{   \{ \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{/* signal with complex arguments (a dict) */}}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void} emit\_properties(Eldbus\_Service\_Interface *iface)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eldbus__Core_ga14e8c4d4b96af5fb8bb5c66dc315593a}{Eldbus\_Message}} *alive2;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eldbus__Core_ga08a70c6651064414e56d75fba2232925}{Eldbus\_Message\_Iter}} *iter, *dict;}
\DoxyCodeLine{   \textcolor{keyword}{struct }keyval \{}
\DoxyCodeLine{      \textcolor{keyword}{const} \textcolor{keywordtype}{char} *key;}
\DoxyCodeLine{      \textcolor{keyword}{const} \textcolor{keywordtype}{char} *val;}
\DoxyCodeLine{   \} keyval[] = \{}
\DoxyCodeLine{      \{ \textcolor{stringliteral}{"{}key1"{}}, \textcolor{stringliteral}{"{}val1"{}} \},}
\DoxyCodeLine{      \{ \textcolor{stringliteral}{"{}key2"{}}, \textcolor{stringliteral}{"{}val2"{}} \},}
\DoxyCodeLine{      \{ \}}
\DoxyCodeLine{   \};}
\DoxyCodeLine{   \textcolor{keyword}{struct }keyval *k;}
\DoxyCodeLine{}
\DoxyCodeLine{   alive2 = \mbox{\hyperlink{group__Eldbus__Service_ga6448c01e341163b5ce9593416e4e75f3}{eldbus\_service\_signal\_new}}(iface, TEST\_SIGNAL\_PROP);}
\DoxyCodeLine{   iter = \mbox{\hyperlink{group__Eldbus__Message__Iter_ga7ca2412ef3cf3c8f77e3782413820814}{eldbus\_message\_iter\_get}}(alive2);}
\DoxyCodeLine{   dict = \mbox{\hyperlink{group__Eldbus__Message__Iter_gac053452551e924020d2105d87e73521e}{eldbus\_message\_iter\_container\_new}}(iter, \textcolor{charliteral}{'a'}, \textcolor{stringliteral}{"{}\{ss\}"{}});}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{for} (k = keyval; k \&\& k-\/>key; k++)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \mbox{\hyperlink{group__Eldbus__Core_ga08a70c6651064414e56d75fba2232925}{Eldbus\_Message\_Iter}} *entry = \mbox{\hyperlink{group__Eldbus__Message__Iter_gac053452551e924020d2105d87e73521e}{eldbus\_message\_iter\_container\_new}}(dict, \textcolor{charliteral}{'e'},}
\DoxyCodeLine{                                                                     NULL);}
\DoxyCodeLine{        \mbox{\hyperlink{group__Eldbus__Message__Iter_gae00cddea6435838b7189bcf5ca816332}{eldbus\_message\_iter\_arguments\_append}}(entry, \textcolor{stringliteral}{"{}ss"{}}, k-\/>key, k-\/>val);}
\DoxyCodeLine{        \mbox{\hyperlink{group__Eldbus__Message__Iter_ga01840f4c9fb71cbf1c8081cf4e84189c}{eldbus\_message\_iter\_container\_close}}(dict, entry);}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eldbus__Message__Iter_ga01840f4c9fb71cbf1c8081cf4e84189c}{eldbus\_message\_iter\_container\_close}}(iter, dict);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eldbus__Service_gabcd4af078093c616f025bc05a95c04a7}{eldbus\_service\_signal\_send}}(iface, alive2);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{/* signal with basic args */}}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void} emit\_name(Eldbus\_Service\_Interface *iface)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eldbus__Service_ga710a0428a3bb8d0f436a030272c9f82b}{eldbus\_service\_signal\_emit}}(iface, TEST\_SIGNAL\_NAME, \textcolor{stringliteral}{"{}TEST"{}});}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{/* simple signal example */}}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void} emit\_alive(Eldbus\_Service\_Interface *iface)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eldbus__Service_ga710a0428a3bb8d0f436a030272c9f82b}{eldbus\_service\_signal\_emit}}(iface, TEST\_SIGNAL\_ALIVE);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keyword}{const} \mbox{\hyperlink{struct__Eldbus__Service__Interface__Desc}{Eldbus\_Service\_Interface\_Desc}} iface\_desc = \{}
\DoxyCodeLine{   \textcolor{stringliteral}{"{}org.enlightenment.Test"{}}, NULL, test\_signals}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int} main(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eldbus_ga1de8233c3e9240291bb952776810c831}{Eldbus\_Connection}} *conn;}
\DoxyCodeLine{   Eldbus\_Service\_Interface *iface;}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eldbus__Core_gadd7c8b8a43b5dd590f7fd06166288754}{eldbus\_init}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   conn = \mbox{\hyperlink{group__Eldbus__Connection_ga203ec794fc0c7e1bddce4eb18b628c04}{eldbus\_connection\_get}}(ELDBUS\_CONNECTION\_TYPE\_SESSION);}
\DoxyCodeLine{   iface = \mbox{\hyperlink{group__Eldbus__Service_ga5e48c24176e0d4e845eaa24be5a89c5b}{eldbus\_service\_interface\_register}}(conn, \textcolor{stringliteral}{"{}/org/enlightenment"{}},}
\DoxyCodeLine{                                            \&iface\_desc);}
\DoxyCodeLine{}
\DoxyCodeLine{   emit\_alive(iface);}
\DoxyCodeLine{   emit\_name(iface);}
\DoxyCodeLine{   emit\_properties(iface);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eldbus__Connection_ga1c035aac8b601b416bba11d0d68f80ae}{eldbus\_connection\_unref}}(conn);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eldbus__Core_ga255ee3e090da6704d009ee74ba9d8a79}{eldbus\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} 0;}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 