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


\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{// gcc -o simple-signal-emit simple-signal-emit.c `pkg-config --cflags --libs eldbus`}

\textcolor{preprocessor}{#include <Eldbus.h>}

\textcolor{keyword}{enum} \{
   TEST\_SIGNAL\_ALIVE,
   TEST\_SIGNAL\_PROP,
   TEST\_SIGNAL\_NAME,
\};

\textcolor{keyword}{static} \textcolor{keyword}{const} \hyperlink{struct__Eldbus__Signal}{Eldbus\_Signal} test\_signals[] = \{
   [TEST\_SIGNAL\_ALIVE] = \{ \textcolor{stringliteral}{"Alive"} \},
   [TEST\_SIGNAL\_PROP] = \{ \textcolor{stringliteral}{"Properties"}, \hyperlink{group__Eldbus__Service_gab77338df786b5ad2a9f86693432f23a4}{ELDBUS\_ARGS}(\{ \textcolor{stringliteral}{"a\{ss\}"}, \textcolor{stringliteral}{"properties"}\}) \},
   [TEST\_SIGNAL\_NAME] = \{ \textcolor{stringliteral}{"Name"}, \hyperlink{group__Eldbus__Service_gab77338df786b5ad2a9f86693432f23a4}{ELDBUS\_ARGS}(\{ \textcolor{stringliteral}{"s"}, \textcolor{stringliteral}{"name"}\}) \},
   \{ \}
\};

\textcolor{comment}{/* signal with complex arguments (a dict) */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void} emit\_properties(Eldbus\_Service\_Interface *iface)
\{
   \hyperlink{group__Eldbus__Core_ga14e8c4d4b96af5fb8bb5c66dc315593a}{Eldbus\_Message} *alive2;
   \hyperlink{group__Eldbus__Core_ga08a70c6651064414e56d75fba2232925}{Eldbus\_Message\_Iter} *iter, *dict;
   \textcolor{keyword}{struct }keyval \{
      \textcolor{keyword}{const} \textcolor{keywordtype}{char} *key;
      \textcolor{keyword}{const} \textcolor{keywordtype}{char} *val;
   \} keyval[] = \{
      \{ \textcolor{stringliteral}{"key1"}, \textcolor{stringliteral}{"val1"} \},
      \{ \textcolor{stringliteral}{"key2"}, \textcolor{stringliteral}{"val2"} \},
      \{ \}
   \};
   \textcolor{keyword}{struct }keyval *k;

   alive2 = \hyperlink{group__Eldbus__Service_ga6448c01e341163b5ce9593416e4e75f3}{eldbus\_service\_signal\_new}(iface, TEST\_SIGNAL\_PROP);
   iter = \hyperlink{group__Eldbus__Message__Iter_ga7ca2412ef3cf3c8f77e3782413820814}{eldbus\_message\_iter\_get}(alive2);
   dict = \hyperlink{group__Eldbus__Message__Iter_gac053452551e924020d2105d87e73521e}{eldbus\_message\_iter\_container\_new}(iter, \textcolor{charliteral}{'a'}, \textcolor{stringliteral}{"\{ss\}"});

   \textcolor{keywordflow}{for} (k = keyval; k && k->key; k++)
     \{
        \hyperlink{group__Eldbus__Core_ga08a70c6651064414e56d75fba2232925}{Eldbus\_Message\_Iter} *entry = 
      \hyperlink{group__Eldbus__Message__Iter_gac053452551e924020d2105d87e73521e}{eldbus\_message\_iter\_container\_new}(dict, \textcolor{charliteral}{'e'},
                                                                     NULL);
        \hyperlink{group__Eldbus__Message__Iter_gae00cddea6435838b7189bcf5ca816332}{eldbus\_message\_iter\_arguments\_append}(entry, \textcolor{stringliteral}{"ss"}, k->key, k->
      val);
        \hyperlink{group__Eldbus__Message__Iter_ga01840f4c9fb71cbf1c8081cf4e84189c}{eldbus\_message\_iter\_container\_close}(dict, entry);
     \}

   \hyperlink{group__Eldbus__Message__Iter_ga01840f4c9fb71cbf1c8081cf4e84189c}{eldbus\_message\_iter\_container\_close}(iter, dict);
   \hyperlink{group__Eldbus__Service_gabcd4af078093c616f025bc05a95c04a7}{eldbus\_service\_signal\_send}(iface, alive2);
\}

\textcolor{comment}{/* signal with basic args */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void} emit\_name(Eldbus\_Service\_Interface *iface)
\{
   \hyperlink{group__Eldbus__Service_ga710a0428a3bb8d0f436a030272c9f82b}{eldbus\_service\_signal\_emit}(iface, TEST\_SIGNAL\_NAME, \textcolor{stringliteral}{"TEST"});
\}

\textcolor{comment}{/* simple signal example */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void} emit\_alive(Eldbus\_Service\_Interface *iface)
\{
   \hyperlink{group__Eldbus__Service_ga710a0428a3bb8d0f436a030272c9f82b}{eldbus\_service\_signal\_emit}(iface, TEST\_SIGNAL\_ALIVE);
\}

\textcolor{keyword}{static} \textcolor{keyword}{const} \hyperlink{struct__Eldbus__Service__Interface__Desc}{Eldbus\_Service\_Interface\_Desc} iface\_desc = \{
   \textcolor{stringliteral}{"org.enlightenment.Test"}, NULL, test\_signals
\};

\textcolor{keywordtype}{int} main(\textcolor{keywordtype}{void})
\{
   \hyperlink{group__Eldbus__Core_ga5f0557a7e65ed263fcc1678874b8f7e7}{Eldbus\_Connection} *conn;
   Eldbus\_Service\_Interface *iface;

   \hyperlink{group__Eldbus__Core_gadd7c8b8a43b5dd590f7fd06166288754}{eldbus\_init}();

   conn = \hyperlink{group__Eldbus__Conneciton_ga203ec794fc0c7e1bddce4eb18b628c04}{eldbus\_connection\_get}(ELDBUS\_CONNECTION\_TYPE\_SESSION);
   iface = \hyperlink{group__Eldbus__Service_ga5e48c24176e0d4e845eaa24be5a89c5b}{eldbus\_service\_interface\_register}(conn, \textcolor{stringliteral}{"/org/enlightenment"},
                                            &iface\_desc);

   emit\_alive(iface);
   emit\_name(iface);
   emit\_properties(iface);

   \hyperlink{group__Eldbus__Conneciton_ga1c035aac8b601b416bba11d0d68f80ae}{eldbus\_connection\_unref}(conn);

   \hyperlink{group__Eldbus__Core_ga255ee3e090da6704d009ee74ba9d8a79}{eldbus\_shutdown}();

   \textcolor{keywordflow}{return} 0;
\}
\end{DoxyCodeInclude}
 