summaryrefslogtreecommitdiff
path: root/src/examples/eldbus/banshee.c
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@profusion.mobi>2013-04-23 11:40:05 -0300
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2013-04-23 12:36:29 -0300
commit4e3804041f8e865e007b2a6a0d45a05f39500c3b (patch)
treea493b9c8f8a610d2667651f3ba81819ed16fbe8c /src/examples/eldbus/banshee.c
parent4cf68bf728b5a858ce1c0efac25ded1a49ba8d9d (diff)
Rename edbus->eldbus
git grep -l edbus2 | while read f; do sed -i 's/edbus2/eldbus/g' "$f"; done find . -name '*edbus2*' -exec rename edbus2 eldbus {} \; git grep -l "EDBUS" | while read f; do sed -i 's/EDBUS/ELDBUS/g' "$f"; done git grep -l "EDBus" | while read f; do sed -i 's/EDBus/Eldbus/g' "$f"; done git grep -l "edbus (v2)" | while read f; do sed -i 's/edbus (v2)/eldbus/g' "$f"; done git grep -l "Edbus" | while read f; do sed -i 's/Edbus/Eldbus/g' "$f"; done git grep -l "edbus" | while read f; do sed -i 's/edbus/eldbus/g' "$f"; done find . -name '*edbus*' -exec rename edbus eldbus {} \; find . -name '*EDBus*' -exec rename EDBus Eldbus {} \;
Diffstat (limited to 'src/examples/eldbus/banshee.c')
-rw-r--r--src/examples/eldbus/banshee.c241
1 files changed, 241 insertions, 0 deletions
diff --git a/src/examples/eldbus/banshee.c b/src/examples/eldbus/banshee.c
new file mode 100644
index 0000000000..c9d30b5bf0
--- /dev/null
+++ b/src/examples/eldbus/banshee.c
@@ -0,0 +1,241 @@
1//Compile with:
2// gcc -o banshee banshee.c `pkg-config --cflags --libs eldbus ecore eina`
3
4#include "Eldbus.h"
5#include <Ecore.h>
6
7#define BUS "org.bansheeproject.Banshee"
8#define ENGINE_PATH "/org/bansheeproject/Banshee/PlayerEngine"
9#define CONTROLLER_PATH "/org/bansheeproject/Banshee/PlaybackController"
10#define MPRIS_PATH "/org/mpris/MediaPlayer2"
11
12#define ENGINE_IFACE "org.bansheeproject.Banshee.PlayerEngine"
13#define CONTROLLER_IFACE "org.bansheeproject.Banshee.PlaybackController"
14#define MPRIS_IFACE "org.mpris.MediaPlayer2.Playlists"
15
16static Eldbus_Signal_Handler *state_changed2;
17
18static Eina_Bool
19_timeout_application(void *data EINA_UNUSED)
20{
21 printf("\n## ecore_main_loop_quit()\n");
22 ecore_main_loop_quit();
23 return EINA_TRUE;
24}
25
26static void
27on_get_playlists(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
28{
29 Eldbus_Message_Iter *array, *struct_entry;
30 const char *path, *name, *image;
31 int i = 0;
32
33 EINA_SAFETY_ON_TRUE_RETURN(eldbus_message_error_get(msg, NULL, NULL));
34
35 if (!eldbus_message_arguments_get(msg, "a(oss)", &array))
36 {
37 fprintf(stderr, "Error: could not get entry contents\n");
38 return;
39 }
40 printf("on_get_playlists() \n\n");
41 while (eldbus_message_iter_get_and_next(array, 'r', &struct_entry))
42 {
43 if (!eldbus_message_iter_arguments_get(struct_entry, "oss", &path, &name, &image))
44 {
45 printf("error on eldbus_massage_iterator_arguments_get()");
46 return;
47 }
48 i++;
49 printf("%d - %s | %s | %s\n", i, path, name, image);
50 }
51 printf("end of on_get_playlists()\n\n");
52}
53
54static void
55iterate_dict(void *data EINA_UNUSED, const void *key, Eldbus_Message_Iter *var)
56{
57 const char *skey = key;
58
59 if (!strcmp(skey, "PlaylistCount"))
60 {
61 unsigned count;
62 if (!eldbus_message_iter_arguments_get(var, "u", &count))
63 printf("error2\n");
64 printf("PlaylistCount=%u\n", count);
65 }
66 else if (!strcmp(skey, "Orderings"))
67 {
68 Eldbus_Message_Iter *as;
69 const char *txt;
70 printf("- Orderings\n");
71 if (!eldbus_message_iter_arguments_get(var, "as", &as))
72 printf("error1\n");
73 while (eldbus_message_iter_get_and_next(as, 's', &txt))
74 printf("\t%s\n", txt);
75 }
76}
77
78static void
79playlist_get_all_cb(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
80{
81 Eldbus_Message_Iter *array;
82 EINA_SAFETY_ON_TRUE_RETURN(eldbus_message_error_get(msg, NULL, NULL));
83
84 if (eldbus_message_arguments_get(msg, "a{sv}", &array))
85 eldbus_message_iter_dict_iterate(array, "sv", iterate_dict, NULL);
86}
87
88static void
89on_introspect(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
90{
91 const char *string;
92
93 EINA_SAFETY_ON_TRUE_RETURN(eldbus_message_error_get(msg, NULL, NULL));
94
95 if (!eldbus_message_arguments_get(msg, "s", &string))
96 {
97 fprintf(stderr, "Error: could not get entry contents\n");
98 return;
99 }
100
101 printf("on_introspect() data=\n%s\n\n", string);
102}
103
104static void
105on_next_or_pause(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
106{
107 const char *status = data;
108
109 EINA_SAFETY_ON_TRUE_RETURN(eldbus_message_error_get(msg, NULL, NULL));
110
111 printf("%s\n", status);
112}
113
114static void
115on_state_changed(void *data EINA_UNUSED, const Eldbus_Message *msg)
116{
117 const char *status;
118 EINA_SAFETY_ON_TRUE_RETURN(eldbus_message_error_get(msg, NULL, NULL));
119
120 if (!eldbus_message_arguments_get(msg, "s", &status))
121 {
122 fprintf(stderr, "Error: could not get entry contents\n");
123 return;
124 }
125
126 printf("on_state_changed = %s\n", status);
127}
128
129static void
130on_state_changed2(void *data EINA_UNUSED, const Eldbus_Message *msg)
131{
132 const char *status;
133 EINA_SAFETY_ON_TRUE_RETURN(eldbus_message_error_get(msg, NULL, NULL));
134
135 if (!eldbus_message_arguments_get(msg, "s", &status))
136 {
137 fprintf(stderr, "Error: could not get entry contents\n");
138 return;
139 }
140
141 printf("on_state_changed2 = %s\n", status);
142 eldbus_signal_handler_unref(state_changed2);
143 state_changed2 = NULL;
144}
145
146static void
147on_banshee_startup(void *data EINA_UNUSED, const Eldbus_Message *msg)
148{
149 const char *bus, *older_id, *new_id;
150
151 EINA_SAFETY_ON_TRUE_RETURN(eldbus_message_error_get(msg, NULL, NULL));
152 if (!eldbus_message_arguments_get(msg, "sss", &bus, &older_id, &new_id))
153 {
154 printf("Error getting arguments from NameOwnerChanged");
155 return;
156 }
157
158 printf("banshee started on id=%s\n", new_id);
159}
160
161static void
162on_name_owner_changed(void *data EINA_UNUSED, const Eldbus_Message *msg)
163{
164 const char *bus, *older_id, *new_id;
165
166 EINA_SAFETY_ON_TRUE_RETURN(eldbus_message_error_get(msg, NULL, NULL));
167 if (!eldbus_message_arguments_get(msg, "sss", &bus, &older_id, &new_id))
168 {
169 printf("Error getting arguments from NameOwnerChanged");
170 return;
171 }
172
173 printf("bus = %s older=%s new=%s\n\n", bus, older_id, new_id);
174}
175
176int
177main(void)
178{
179 Eldbus_Connection *conn;
180 Eldbus_Object *engine_obj, *controller_obj, *mpris_obj;
181 Eldbus_Proxy *engine, *controler, *playlists;
182 Eldbus_Signal_Handler *sh;
183
184 ecore_init();
185 eldbus_init();
186
187 conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
188
189 engine_obj = eldbus_object_get(conn, BUS, ENGINE_PATH);
190 controller_obj = eldbus_object_get(conn, BUS, CONTROLLER_PATH);
191 mpris_obj = eldbus_object_get(conn, BUS, MPRIS_PATH);
192
193 engine = eldbus_proxy_get(engine_obj, ENGINE_IFACE);
194 EINA_SAFETY_ON_NULL_GOTO(engine, end);
195 controler = eldbus_proxy_get(controller_obj, CONTROLLER_IFACE);
196 EINA_SAFETY_ON_NULL_GOTO(controler, end);
197 playlists = eldbus_proxy_get(mpris_obj, MPRIS_IFACE);
198 EINA_SAFETY_ON_NULL_GOTO(playlists, end);
199
200 eldbus_object_introspect(engine_obj, on_introspect, NULL);
201
202 eldbus_proxy_signal_handler_add(engine, "StateChanged", on_state_changed, NULL);
203 eldbus_proxy_call(engine, "Pause", on_next_or_pause, "Pause", -1, "");
204
205 eldbus_proxy_call(controler, "Next", on_next_or_pause, "Next", -1, "b", EINA_TRUE);
206
207 eldbus_proxy_property_get_all(playlists, playlist_get_all_cb, NULL);
208 eldbus_proxy_call(playlists, "GetPlaylists", on_get_playlists, NULL, -1,
209 "uusb", (unsigned)0, (unsigned)30, "asc", EINA_FALSE);
210
211 eldbus_signal_handler_add(conn, BUS, ENGINE_PATH, ENGINE_IFACE,
212 "StateChanged", on_state_changed, NULL);
213 state_changed2 = eldbus_signal_handler_add(conn, BUS, ENGINE_PATH, ENGINE_IFACE,
214 "StateChanged", on_state_changed2, NULL);
215
216 sh = eldbus_signal_handler_add(conn, ELDBUS_FDO_BUS, ELDBUS_FDO_PATH,
217 ELDBUS_FDO_INTERFACE, "NameOwnerChanged",
218 on_name_owner_changed, NULL);
219 eldbus_signal_handler_match_extra_set(sh, "arg0", BUS, NULL);
220
221 sh = eldbus_signal_handler_add(conn, ELDBUS_FDO_BUS, ELDBUS_FDO_PATH,
222 ELDBUS_FDO_INTERFACE, "NameOwnerChanged",
223 on_banshee_startup, NULL);
224 eldbus_signal_handler_match_extra_set(sh, "arg0", BUS, "arg1", "", NULL);
225
226 ecore_timer_add(50, _timeout_application, NULL);
227
228 ecore_main_loop_begin();
229
230end:
231 /**
232 * It's not necessary unref all objecs, proxys and signal handlers
233 * When a parent have ref = 0, it will unref all your childrens
234 * before free it self.
235 **/
236 eldbus_connection_unref(conn);
237
238 eldbus_shutdown();
239 ecore_shutdown();
240 return 0;
241}