\hypertarget{banshee_8c-example}{\section{banshee.\+c}
}
Access Banshee music player and send commands to it.


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

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

\textcolor{preprocessor}{#define BUS "org.bansheeproject.Banshee"}
\textcolor{preprocessor}{#define ENGINE\_PATH "/org/bansheeproject/Banshee/PlayerEngine"}
\textcolor{preprocessor}{#define CONTROLLER\_PATH "/org/bansheeproject/Banshee/PlaybackController"}
\textcolor{preprocessor}{#define MPRIS\_PATH "/org/mpris/MediaPlayer2"}

\textcolor{preprocessor}{#define ENGINE\_IFACE "org.bansheeproject.Banshee.PlayerEngine"}
\textcolor{preprocessor}{#define CONTROLLER\_IFACE "org.bansheeproject.Banshee.PlaybackController"}
\textcolor{preprocessor}{#define MPRIS\_IFACE "org.mpris.MediaPlayer2.Playlists"}

\textcolor{keyword}{static} \hyperlink{group__Eldbus__Core_ga0f4385f3952b6ad56f1966a3ed1b744c}{Eldbus\_Signal\_Handler} *state\_changed2;

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_timeout\_application(\textcolor{keywordtype}{void} *data EINA\_UNUSED)
\{
   printf(\textcolor{stringliteral}{"\(\backslash\)n## ecore\_main\_loop\_quit()\(\backslash\)n"});
   \hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}();
   \textcolor{keywordflow}{return} \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE};
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
on\_get\_playlists(\textcolor{keywordtype}{void} *data 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, *struct\_entry;
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *path, *name, *image;
   \textcolor{keywordtype}{int} i = 0;

   EINA\_SAFETY\_ON\_TRUE\_RETURN(\hyperlink{group__Eldbus__Message_ga3aeec7d275bef2bb244ed9a045540921}{eldbus\_message\_error\_get}(msg, NULL, NULL));

   \textcolor{keywordflow}{if} (!\hyperlink{group__Eldbus__Message_ga7aec6beec8e8a73982c7f43bd1322df8}{eldbus\_message\_arguments\_get}(msg, \textcolor{stringliteral}{"a(oss)"}, &array))
     \{
        fprintf(stderr, \textcolor{stringliteral}{"Error: could not get entry contents\(\backslash\)n"});
        \textcolor{keywordflow}{return};
     \}
   printf(\textcolor{stringliteral}{"on\_get\_playlists() \(\backslash\)n\(\backslash\)n"});
   \textcolor{keywordflow}{while} (\hyperlink{group__Eldbus__Message__Iter_ga45c7d707ee830ae5be39c17df05af615}{eldbus\_message\_iter\_get\_and\_next}(array, \textcolor{charliteral}{'r'}, &struct\_entry))
     \{
        \textcolor{keywordflow}{if} (!\hyperlink{group__Eldbus__Message__Iter_gae44918ce0b571a30546219d1d5040da0}{eldbus\_message\_iter\_arguments\_get}(struct\_entry, \textcolor{stringliteral}{"oss"}, &path,
       &name, &image))
          \{
             printf(\textcolor{stringliteral}{"error on eldbus\_massage\_iterator\_arguments\_get()"});
             \textcolor{keywordflow}{return};
          \}
        i++;
        printf(\textcolor{stringliteral}{"%d - %s | %s | %s\(\backslash\)n"}, i, path, name, image);
     \}
   printf(\textcolor{stringliteral}{"end of on\_get\_playlists()\(\backslash\)n\(\backslash\)n"});
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
iterate\_dict(\textcolor{keywordtype}{void} *data EINA\_UNUSED, \textcolor{keyword}{const} \textcolor{keywordtype}{void} *key, \hyperlink{group__Eldbus__Core_ga08a70c6651064414e56d75fba2232925}{Eldbus\_Message\_Iter} *var)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *skey = key;

   \textcolor{keywordflow}{if} (!strcmp(skey, \textcolor{stringliteral}{"PlaylistCount"}))
     \{
        \textcolor{keywordtype}{unsigned} count;
        \textcolor{keywordflow}{if} (!\hyperlink{group__Eldbus__Message__Iter_gae44918ce0b571a30546219d1d5040da0}{eldbus\_message\_iter\_arguments\_get}(var, \textcolor{stringliteral}{"u"}, &count))
          printf(\textcolor{stringliteral}{"error2\(\backslash\)n"});
        printf(\textcolor{stringliteral}{"PlaylistCount=%u\(\backslash\)n"}, count);
     \}
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (!strcmp(skey, \textcolor{stringliteral}{"Orderings"}))
     \{
        \hyperlink{group__Eldbus__Core_ga08a70c6651064414e56d75fba2232925}{Eldbus\_Message\_Iter} *as;
        \textcolor{keyword}{const} \textcolor{keywordtype}{char} *txt;
        printf(\textcolor{stringliteral}{"- Orderings\(\backslash\)n"});
        \textcolor{keywordflow}{if} (!\hyperlink{group__Eldbus__Message__Iter_gae44918ce0b571a30546219d1d5040da0}{eldbus\_message\_iter\_arguments\_get}(var, \textcolor{stringliteral}{"as"}, &as))
          printf(\textcolor{stringliteral}{"error1\(\backslash\)n"});
        \textcolor{keywordflow}{while} (\hyperlink{group__Eldbus__Message__Iter_ga45c7d707ee830ae5be39c17df05af615}{eldbus\_message\_iter\_get\_and\_next}(as, \textcolor{charliteral}{'s'}, &txt))
          printf(\textcolor{stringliteral}{"\(\backslash\)t%s\(\backslash\)n"}, txt);
     \}
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
playlist\_get\_all\_cb(\textcolor{keywordtype}{void} *data 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;
   EINA\_SAFETY\_ON\_TRUE\_RETURN(\hyperlink{group__Eldbus__Message_ga3aeec7d275bef2bb244ed9a045540921}{eldbus\_message\_error\_get}(msg, NULL, NULL));

   \textcolor{keywordflow}{if} (\hyperlink{group__Eldbus__Message_ga7aec6beec8e8a73982c7f43bd1322df8}{eldbus\_message\_arguments\_get}(msg, \textcolor{stringliteral}{"a\{sv\}"}, &array))
     \hyperlink{group__Eldbus__Message__Helpers_ga2b2a85bdad9a8ce06eacb3fe21392360}{eldbus\_message\_iter\_dict\_iterate}(array, \textcolor{stringliteral}{"sv"}, iterate\_dict, NULL);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
on\_introspect(\textcolor{keywordtype}{void} *data EINA\_UNUSED, \textcolor{keyword}{const} \hyperlink{group__Eldbus__Core_ga14e8c4d4b96af5fb8bb5c66dc315593a}{Eldbus\_Message} *msg, 
      \hyperlink{group__Eldbus__Core_ga7a5d4dc070bd925034de6e52c4260be7}{Eldbus\_Pending} *pending EINA\_UNUSED)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *string;

   EINA\_SAFETY\_ON\_TRUE\_RETURN(\hyperlink{group__Eldbus__Message_ga3aeec7d275bef2bb244ed9a045540921}{eldbus\_message\_error\_get}(msg, NULL, NULL));

   \textcolor{keywordflow}{if} (!\hyperlink{group__Eldbus__Message_ga7aec6beec8e8a73982c7f43bd1322df8}{eldbus\_message\_arguments\_get}(msg, \textcolor{stringliteral}{"s"}, &\textcolor{keywordtype}{string}))
     \{
        fprintf(stderr, \textcolor{stringliteral}{"Error: could not get entry contents\(\backslash\)n"});
        \textcolor{keywordflow}{return};
     \}

   printf(\textcolor{stringliteral}{"on\_introspect() data=\(\backslash\)n%s\(\backslash\)n\(\backslash\)n"}, \textcolor{keywordtype}{string});
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
on\_next\_or\_pause(\textcolor{keywordtype}{void} *data, \textcolor{keyword}{const} \hyperlink{group__Eldbus__Core_ga14e8c4d4b96af5fb8bb5c66dc315593a}{Eldbus\_Message} *msg, 
      \hyperlink{group__Eldbus__Core_ga7a5d4dc070bd925034de6e52c4260be7}{Eldbus\_Pending} *pending EINA\_UNUSED)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *status = data;

   EINA\_SAFETY\_ON\_TRUE\_RETURN(\hyperlink{group__Eldbus__Message_ga3aeec7d275bef2bb244ed9a045540921}{eldbus\_message\_error\_get}(msg, NULL, NULL));

   printf(\textcolor{stringliteral}{"%s\(\backslash\)n"}, status);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
on\_state\_changed(\textcolor{keywordtype}{void} *data EINA\_UNUSED, \textcolor{keyword}{const} \hyperlink{group__Eldbus__Core_ga14e8c4d4b96af5fb8bb5c66dc315593a}{Eldbus\_Message} *msg)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *status;
   EINA\_SAFETY\_ON\_TRUE\_RETURN(\hyperlink{group__Eldbus__Message_ga3aeec7d275bef2bb244ed9a045540921}{eldbus\_message\_error\_get}(msg, NULL, NULL));

   \textcolor{keywordflow}{if} (!\hyperlink{group__Eldbus__Message_ga7aec6beec8e8a73982c7f43bd1322df8}{eldbus\_message\_arguments\_get}(msg, \textcolor{stringliteral}{"s"}, &status))
     \{
        fprintf(stderr, \textcolor{stringliteral}{"Error: could not get entry contents\(\backslash\)n"});
        \textcolor{keywordflow}{return};
     \}

   printf(\textcolor{stringliteral}{"on\_state\_changed = %s\(\backslash\)n"}, status);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
on\_state\_changed2(\textcolor{keywordtype}{void} *data EINA\_UNUSED, \textcolor{keyword}{const} \hyperlink{group__Eldbus__Core_ga14e8c4d4b96af5fb8bb5c66dc315593a}{Eldbus\_Message} *msg)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *status;
   EINA\_SAFETY\_ON\_TRUE\_RETURN(\hyperlink{group__Eldbus__Message_ga3aeec7d275bef2bb244ed9a045540921}{eldbus\_message\_error\_get}(msg, NULL, NULL));

   \textcolor{keywordflow}{if} (!\hyperlink{group__Eldbus__Message_ga7aec6beec8e8a73982c7f43bd1322df8}{eldbus\_message\_arguments\_get}(msg, \textcolor{stringliteral}{"s"}, &status))
     \{
        fprintf(stderr, \textcolor{stringliteral}{"Error: could not get entry contents\(\backslash\)n"});
        \textcolor{keywordflow}{return};
     \}

   printf(\textcolor{stringliteral}{"on\_state\_changed2 = %s\(\backslash\)n"}, status);
   \hyperlink{group__Eldbus__Signal__Handler_ga1b39e54fb712220f3e699d1ca9c6c919}{eldbus\_signal\_handler\_unref}(state\_changed2);
   state\_changed2 = NULL;
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
on\_banshee\_startup(\textcolor{keywordtype}{void} *data EINA\_UNUSED, \textcolor{keyword}{const} \hyperlink{group__Eldbus__Core_ga14e8c4d4b96af5fb8bb5c66dc315593a}{Eldbus\_Message} *msg)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *bus, *older\_id, *new\_id;

   EINA\_SAFETY\_ON\_TRUE\_RETURN(\hyperlink{group__Eldbus__Message_ga3aeec7d275bef2bb244ed9a045540921}{eldbus\_message\_error\_get}(msg, NULL, NULL));
   \textcolor{keywordflow}{if} (!\hyperlink{group__Eldbus__Message_ga7aec6beec8e8a73982c7f43bd1322df8}{eldbus\_message\_arguments\_get}(msg, \textcolor{stringliteral}{"sss"}, &bus, &older\_id, &new\_id))
     \{
        printf(\textcolor{stringliteral}{"Error getting arguments from NameOwnerChanged"});
        \textcolor{keywordflow}{return};
     \}

   printf(\textcolor{stringliteral}{"banshee started on id=%s\(\backslash\)n"}, new\_id);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
on\_name\_owner\_changed(\textcolor{keywordtype}{void} *data EINA\_UNUSED, \textcolor{keyword}{const} \hyperlink{group__Eldbus__Core_ga14e8c4d4b96af5fb8bb5c66dc315593a}{Eldbus\_Message} *msg)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *bus, *older\_id, *new\_id;

   EINA\_SAFETY\_ON\_TRUE\_RETURN(\hyperlink{group__Eldbus__Message_ga3aeec7d275bef2bb244ed9a045540921}{eldbus\_message\_error\_get}(msg, NULL, NULL));
   \textcolor{keywordflow}{if} (!\hyperlink{group__Eldbus__Message_ga7aec6beec8e8a73982c7f43bd1322df8}{eldbus\_message\_arguments\_get}(msg, \textcolor{stringliteral}{"sss"}, &bus, &older\_id, &new\_id))
     \{
        printf(\textcolor{stringliteral}{"Error getting arguments from NameOwnerChanged"});
        \textcolor{keywordflow}{return};
     \}

   printf(\textcolor{stringliteral}{"bus = %s older=%s new=%s\(\backslash\)n\(\backslash\)n"}, bus, older\_id, new\_id);
\}

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{void})
\{
   \hyperlink{group__Eldbus__Core_ga5f0557a7e65ed263fcc1678874b8f7e7}{Eldbus\_Connection} *conn;
   \hyperlink{group__Eldbus__Core_ga49914ed24559a149426b5f2bb8294a06}{Eldbus\_Object} *engine\_obj, *controller\_obj, *mpris\_obj;
   \hyperlink{group__Eldbus__Core_ga5598fdabe4f36f8c13ef7a07dc219a3c}{Eldbus\_Proxy} *engine, *controler, *playlists;
   \hyperlink{group__Eldbus__Core_ga0f4385f3952b6ad56f1966a3ed1b744c}{Eldbus\_Signal\_Handler} *sh;

   \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\_SESSION);

   engine\_obj = \hyperlink{group__Eldbus__Object__Mapper_ga067d5c8eba2590fb58e7dc39de87d203}{eldbus\_object\_get}(conn, BUS, ENGINE\_PATH);
   controller\_obj = \hyperlink{group__Eldbus__Object__Mapper_ga067d5c8eba2590fb58e7dc39de87d203}{eldbus\_object\_get}(conn, BUS, CONTROLLER\_PATH);
   mpris\_obj = \hyperlink{group__Eldbus__Object__Mapper_ga067d5c8eba2590fb58e7dc39de87d203}{eldbus\_object\_get}(conn, BUS, MPRIS\_PATH);

   engine = \hyperlink{group__Eldbus__Proxy_ga58b8d61188435800e1e866ab3fdc7090}{eldbus\_proxy\_get}(engine\_obj, ENGINE\_IFACE);
   EINA\_SAFETY\_ON\_NULL\_GOTO(engine, end);
   controler = \hyperlink{group__Eldbus__Proxy_ga58b8d61188435800e1e866ab3fdc7090}{eldbus\_proxy\_get}(controller\_obj, CONTROLLER\_IFACE);
   EINA\_SAFETY\_ON\_NULL\_GOTO(controler, end);
   playlists = \hyperlink{group__Eldbus__Proxy_ga58b8d61188435800e1e866ab3fdc7090}{eldbus\_proxy\_get}(mpris\_obj, MPRIS\_IFACE);
   EINA\_SAFETY\_ON\_NULL\_GOTO(playlists, end);

   \hyperlink{group__Eldbus__FDO__Introspectable_gae4093f860e01425e9b8b5cc80ea5d203}{eldbus\_object\_introspect}(engine\_obj, on\_introspect, NULL);

   \hyperlink{group__Eldbus__Proxy_ga74be21757ba7ff8d43909652c389cf2c}{eldbus\_proxy\_signal\_handler\_add}(engine, \textcolor{stringliteral}{"StateChanged"}, on\_state\_changed,
       NULL);
   \hyperlink{group__Eldbus__Proxy_ga0eaac8e928bd7605855bf61d97eea37c}{eldbus\_proxy\_call}(engine, \textcolor{stringliteral}{"Pause"}, on\_next\_or\_pause, \textcolor{stringliteral}{"Pause"}, -1, \textcolor{stringliteral}{""});

   \hyperlink{group__Eldbus__Proxy_ga0eaac8e928bd7605855bf61d97eea37c}{eldbus\_proxy\_call}(controler, \textcolor{stringliteral}{"Next"}, on\_next\_or\_pause, \textcolor{stringliteral}{"Next"}, -1, \textcolor{stringliteral}{"b"}, 
      \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE});

   \hyperlink{group__Eldbus__FDO__Properties_ga5652d33e39e864e44e514d6708870ec6}{eldbus\_proxy\_property\_get\_all}(playlists, playlist\_get\_all\_cb, NULL);
   \hyperlink{group__Eldbus__Proxy_ga0eaac8e928bd7605855bf61d97eea37c}{eldbus\_proxy\_call}(playlists, \textcolor{stringliteral}{"GetPlaylists"}, on\_get\_playlists, NULL, -1,
                    \textcolor{stringliteral}{"uusb"}, (\textcolor{keywordtype}{unsigned})0, (\textcolor{keywordtype}{unsigned})30, \textcolor{stringliteral}{"asc"}, \hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE});

   \hyperlink{group__Eldbus__Signal__Handler_ga6613bf801b1bbc92708bedc57e64014c}{eldbus\_signal\_handler\_add}(conn, BUS, ENGINE\_PATH, ENGINE\_IFACE,
                            \textcolor{stringliteral}{"StateChanged"}, on\_state\_changed, NULL);
   state\_changed2 = \hyperlink{group__Eldbus__Signal__Handler_ga6613bf801b1bbc92708bedc57e64014c}{eldbus\_signal\_handler\_add}(conn, BUS, ENGINE\_PATH, ENGINE\_IFACE
      ,
                                             \textcolor{stringliteral}{"StateChanged"}, on\_state\_changed2, NULL);

   sh = \hyperlink{group__Eldbus__Signal__Handler_ga6613bf801b1bbc92708bedc57e64014c}{eldbus\_signal\_handler\_add}(conn, \hyperlink{group__Eldbus__Core_gab97eca2dee4c913fbf5b052be14e9f20}{ELDBUS\_FDO\_BUS}, 
      \hyperlink{group__Eldbus__Core_ga44346df7916869917a3bbb641ba970d2}{ELDBUS\_FDO\_PATH},
                                 \hyperlink{group__Eldbus__Core_gafaf7e367f9a6d5e0e1205e42fed56785}{ELDBUS\_FDO\_INTERFACE}, \textcolor{stringliteral}{"NameOwnerChanged"},
                                 on\_name\_owner\_changed, NULL);
   \hyperlink{group__Eldbus__Signal__Handler_ga04f654be8ad8bd3e94cd3f725f2e04a0}{eldbus\_signal\_handler\_match\_extra\_set}(sh, \textcolor{stringliteral}{"arg0"}, BUS, NULL);

   sh = \hyperlink{group__Eldbus__Signal__Handler_ga6613bf801b1bbc92708bedc57e64014c}{eldbus\_signal\_handler\_add}(conn, \hyperlink{group__Eldbus__Core_gab97eca2dee4c913fbf5b052be14e9f20}{ELDBUS\_FDO\_BUS}, 
      \hyperlink{group__Eldbus__Core_ga44346df7916869917a3bbb641ba970d2}{ELDBUS\_FDO\_PATH},
                                 \hyperlink{group__Eldbus__Core_gafaf7e367f9a6d5e0e1205e42fed56785}{ELDBUS\_FDO\_INTERFACE}, \textcolor{stringliteral}{"NameOwnerChanged"},
                                 on\_banshee\_startup, NULL);
   \hyperlink{group__Eldbus__Signal__Handler_ga04f654be8ad8bd3e94cd3f725f2e04a0}{eldbus\_signal\_handler\_match\_extra\_set}(sh, \textcolor{stringliteral}{"arg0"}, BUS, \textcolor{stringliteral}{"arg1"}, \textcolor{stringliteral}{""}, 
      NULL);

   ecore\_timer\_add(50, \_timeout\_application, NULL);

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

end:
   \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}
 