\hypertarget{connman-list-services_8c-example}{}\section{connman-\/list-\/services.\+c}
Client to list networks/services from connman.


\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{// gcc -o connman-list-services connman-list-services.c `pkg-config --cflags --libs eldbus ecore`}

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

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
on\_services\_get(\textcolor{keywordtype}{void} *data \hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}, \textcolor{keyword}{const} \hyperlink{group__Eldbus__Core_ga14e8c4d4b96af5fb8bb5c66dc315593a}{Eldbus\_Message} *msg, 
      \hyperlink{group__Eldbus__Core_ga7a5d4dc070bd925034de6e52c4260be7}{Eldbus\_Pending} *pending EINA\_UNUSED)
\{
   \hyperlink{group__Eldbus__Core_ga08a70c6651064414e56d75fba2232925}{Eldbus\_Message\_Iter} *array, *entry;
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *errname, *errmsg;

   \textcolor{keywordflow}{if} (\hyperlink{group__Eldbus__Message_ga3aeec7d275bef2bb244ed9a045540921}{eldbus\_message\_error\_get}(msg, &errname, &errmsg))
     \{
        fprintf(stderr, \textcolor{stringliteral}{"Error: %s %s\(\backslash\)n"}, errname, errmsg);
        \textcolor{keywordflow}{return};
     \}

   \textcolor{keywordflow}{if} (!\hyperlink{group__Eldbus__Message_ga7aec6beec8e8a73982c7f43bd1322df8}{eldbus\_message\_arguments\_get}(msg, \textcolor{stringliteral}{"a(oa\{sv\})"}, &array))
     \{
        fprintf(stderr, \textcolor{stringliteral}{"Error: could not get array\(\backslash\)n"});
        \textcolor{keywordflow}{return};
     \}

   \textcolor{keywordflow}{while} (\hyperlink{group__Eldbus__Message__Iter_ga45c7d707ee830ae5be39c17df05af615}{eldbus\_message\_iter\_get\_and\_next}(array, \textcolor{charliteral}{'r'}, &entry))
     \{
        \hyperlink{group__Eldbus__Core_ga08a70c6651064414e56d75fba2232925}{Eldbus\_Message\_Iter} *properties, *dict\_entry;
        \textcolor{keyword}{const} \textcolor{keywordtype}{char} *path;

        \textcolor{keywordflow}{if} (!\hyperlink{group__Eldbus__Message__Iter_gae44918ce0b571a30546219d1d5040da0}{eldbus\_message\_iter\_arguments\_get}(entry, \textcolor{stringliteral}{"oa\{sv\}"}, &path, &
      properties))
          \{
             fprintf(stderr, \textcolor{stringliteral}{"Error: could not get entry contents\(\backslash\)n"});
             \textcolor{keywordflow}{return};
          \}

        printf(\textcolor{stringliteral}{"service: %s\(\backslash\)n"}, path);

        \textcolor{keywordflow}{while} (\hyperlink{group__Eldbus__Message__Iter_ga45c7d707ee830ae5be39c17df05af615}{eldbus\_message\_iter\_get\_and\_next}(properties, \textcolor{charliteral}{'e'}, &
      dict\_entry))
          \{
             \hyperlink{group__Eldbus__Core_ga08a70c6651064414e56d75fba2232925}{Eldbus\_Message\_Iter} *variant;
             \textcolor{keyword}{const} \textcolor{keywordtype}{char} *key;

             \textcolor{keywordflow}{if} (!\hyperlink{group__Eldbus__Message__Iter_gae44918ce0b571a30546219d1d5040da0}{eldbus\_message\_iter\_arguments\_get}(dict\_entry, \textcolor{stringliteral}{"sv"}, &key
      ,
                                                      &variant))
               \{
                  fprintf(stderr,
                          \textcolor{stringliteral}{"Error: could not get property contents\(\backslash\)n"});
                  \textcolor{keywordflow}{return};
               \}

             printf(\textcolor{stringliteral}{"\(\backslash\)t%s: type %s\(\backslash\)n"}, key,
                    \hyperlink{group__Eldbus__Message__Iter_gab0201e1d78d70477ba337d0aa2977802}{eldbus\_message\_iter\_signature\_get}(variant));

             \textcolor{comment}{/* TODO: get the value from variant */}
          \}
     \}
\}

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{void})
\{
   \hyperlink{group__Eldbus_ga1de8233c3e9240291bb952776810c831}{Eldbus\_Connection} *conn;
   \hyperlink{group__Eldbus_gab374430ed25089e7c5213767cc637191}{Eldbus\_Object} *obj;
   Eldbus\_Proxy *manager;
   \hyperlink{group__Eldbus__Core_ga7a5d4dc070bd925034de6e52c4260be7}{Eldbus\_Pending} *pending;

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

   conn = \hyperlink{group__Eldbus__Conneciton_ga203ec794fc0c7e1bddce4eb18b628c04}{eldbus\_connection\_get}(ELDBUS\_CONNECTION\_TYPE\_SYSTEM);
   \textcolor{keywordflow}{if} (!conn)
     \{
        fprintf(stderr, \textcolor{stringliteral}{"Error: could not get system bus\(\backslash\)n"});
        \textcolor{keywordflow}{return} EXIT\_FAILURE;
     \}

   obj = \hyperlink{group__Eldbus__Object__Mapper_ga067d5c8eba2590fb58e7dc39de87d203}{eldbus\_object\_get}(conn, \textcolor{stringliteral}{"net.connman"}, \textcolor{stringliteral}{"/"});
   \textcolor{keywordflow}{if} (!obj)
     \{
        fprintf(stderr, \textcolor{stringliteral}{"Error: could not get object\(\backslash\)n"});
        \textcolor{keywordflow}{return} EXIT\_FAILURE;
     \}

   manager = \hyperlink{group__Eldbus__Proxy_ga58b8d61188435800e1e866ab3fdc7090}{eldbus\_proxy\_get}(obj, \textcolor{stringliteral}{"net.connman.Manager"});
   \textcolor{keywordflow}{if} (!manager)
     \{
        fprintf(stderr, \textcolor{stringliteral}{"Error: could not get proxy\(\backslash\)n"});
        \textcolor{keywordflow}{return} EXIT\_FAILURE;
     \}

   pending = \hyperlink{group__Eldbus__Proxy_ga0eaac8e928bd7605855bf61d97eea37c}{eldbus\_proxy\_call}(manager, \textcolor{stringliteral}{"GetServices"}, on\_services\_get, NULL,
                              -1, \textcolor{stringliteral}{""});

   \textcolor{keywordflow}{if} (!pending)
     \{
        fprintf(stderr, \textcolor{stringliteral}{"Error: could not call\(\backslash\)n"});
        \textcolor{keywordflow}{return} EXIT\_FAILURE;
     \}

   \hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}();

   \hyperlink{group__Eldbus__Proxy_gab8b43f9e377544b987d2e0151c660aa7}{eldbus\_proxy\_unref}(manager);
   \hyperlink{group__Eldbus__Object__Mapper_gabf9de9a1f28df4a8b0b3b2cd416d647e}{eldbus\_object\_unref}(obj);
   \hyperlink{group__Eldbus__Conneciton_ga1c035aac8b601b416bba11d0d68f80ae}{eldbus\_connection\_unref}(conn);

   \hyperlink{group__Eldbus__Core_ga255ee3e090da6704d009ee74ba9d8a79}{eldbus\_shutdown}();
   \hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}();
   \textcolor{keywordflow}{return} 0;
\}

\end{DoxyCodeInclude}
 