Change set/unset cb to add/remove cb, and add device_state_changed cb
[platform/core/multimedia/libmm-sound.git] / mm_sound_proxy.c
1 #include <stdint.h>
2 #include <glib.h>
3
4 #include <mm_error.h>
5 #include <mm_debug.h>
6
7 #include "include/mm_sound_proxy.h"
8 #include "include/mm_sound_common.h"
9 #include "include/mm_sound_dbus.h"
10 #include "include/mm_sound_intf.h"
11
12 struct callback_data {
13         void *user_cb;
14         void *user_data;
15         mm_sound_proxy_userdata_free free_func;
16         uint32_t subs_id;
17 };
18
19 #define CB_DATA_NEW(_cb_data, _func, _userdata, _freefunc) \
20         do { \
21                 _cb_data = (struct callback_data*) g_malloc0(sizeof(struct callback_data)); \
22                 _cb_data->user_cb = _func; \
23                 _cb_data->user_data = _userdata; \
24                 _cb_data->free_func = _freefunc; \
25                 _cb_data->subs_id = 0; \
26         } while (0)
27
28 /* subscribe is true when add callback,
29  * false when remove callback */
30 static int _notify_subscription(audio_event_t event, uint32_t subs_id, gboolean subscribe)
31 {
32         int ret = MM_ERROR_NONE;
33         GVariant *params = NULL;
34         const char *event_name = NULL;
35
36         debug_fenter();
37
38         if ((ret = mm_sound_dbus_get_event_name(event, &event_name) != MM_ERROR_NONE)) {
39                 debug_error("Failed to get event name");
40                 return MM_ERROR_SOUND_INTERNAL;
41         }
42
43         if (!(params = g_variant_new("(sub)", event_name, subs_id, subscribe))) {
44                 debug_error("Construct Param failed");
45                 return MM_ERROR_SOUND_INTERNAL;
46         }
47
48         if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_CLIENT_SUBSCRIBED, params))) {
49                 debug_error("dbus send signal for client subscribed failed");
50         }
51
52         debug_fleave();
53         return ret;
54 }
55
56 static int _notify_signal_handled(audio_event_t event, uint32_t event_id, uint32_t subs_id, GVariant *signal_params)
57 {
58         int ret = MM_ERROR_NONE;
59         GVariant *params = NULL;
60         const char *event_name = NULL;
61
62         debug_fenter();
63
64         if ((ret = mm_sound_dbus_get_event_name(event, &event_name) != MM_ERROR_NONE)) {
65                 debug_error("Failed to get event name");
66                 return MM_ERROR_SOUND_INTERNAL;
67         }
68
69         if (!(params = g_variant_new("(usuv)", event_id, event_name, subs_id, signal_params))) {
70                 debug_error("Construct Param failed");
71                 return MM_ERROR_SOUND_INTERNAL;
72         }
73
74         if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_CLIENT_HANDLED, params))) {
75                 debug_error("dbus send signal for client handled failed");
76         }
77
78         debug_fleave();
79         return ret;
80 }
81
82 /* This callback unmarshall general-formed paramters to subject specific parameters,
83  * and call proper callback */
84 static void dbus_callback(audio_event_t event, GVariant *params, void *userdata)
85 {
86         struct callback_data *cb_data  = (struct callback_data*) userdata;
87         uint32_t event_id;
88
89         if (event == AUDIO_EVENT_VOLUME_CHANGED) {
90                 char *volume_type_str = NULL, *direction = NULL;
91                 unsigned volume_level;
92
93                 g_variant_get(params, "(&s&su)", &direction, &volume_type_str, &volume_level);
94                 ((mm_sound_volume_changed_wrapper_cb)(cb_data->user_cb))(direction, volume_type_str, volume_level, cb_data->user_data);
95         } else if (event == AUDIO_EVENT_DEVICE_CONNECTED) {
96                 const char *name = NULL, *device_type = NULL;
97                 gboolean is_connected = FALSE;
98                 int device_id, io_direction, state;
99
100                 g_variant_get(params, "(u(i&sii&s)b)", &event_id, &device_id, &device_type, &io_direction,
101                                         &state, &name, &is_connected);
102                 ((mm_sound_device_connected_wrapper_cb)(cb_data->user_cb))(device_id, device_type, io_direction,
103                         state, name, is_connected, cb_data->user_data);
104                 _notify_signal_handled(event, event_id, cb_data->subs_id, g_variant_new("(ib)", device_id, is_connected));
105         } else if (event == AUDIO_EVENT_DEVICE_INFO_CHANGED) {
106                 const char *name = NULL, *device_type = NULL;
107                 int changed_device_info_type = 0;
108                 int device_id, io_direction, state;
109
110                 g_variant_get(params, "(u(i&sii&s)i)", &event_id, &device_id, &device_type, &io_direction,
111                                         &state, &name, &changed_device_info_type);
112                 ((mm_sound_device_info_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, io_direction,
113                         state, name, changed_device_info_type, cb_data->user_data);
114         } else if (event == AUDIO_EVENT_DEVICE_STATE_CHANGED) {
115                 const char *name = NULL, *device_type = NULL;
116                 int device_id, io_direction, state;
117
118                 g_variant_get(params, "(u(i&sii&s))", &event_id, &device_id, &device_type, &io_direction,
119                                         &state, &name);
120                 ((mm_sound_device_state_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, io_direction,
121                         state, name, cb_data->user_data);
122         } else if (event == AUDIO_EVENT_FOCUS_CHANGED) {
123         } else if (event == AUDIO_EVENT_FOCUS_WATCH) {
124         } else if (event == AUDIO_EVENT_TEST) {
125                 int test_var = 0;
126                 g_variant_get(params, "(i)", &test_var);
127                 ((mm_sound_test_cb)(cb_data->user_cb))(test_var, cb_data->user_data);
128         } else if (event == AUDIO_EVENT_PLAY_FILE_END) {
129                 int ended_handle = 0;
130                 g_variant_get(params, "(i)", &ended_handle);
131                 ((mm_sound_stop_callback_wrapper_func)(cb_data->user_cb))(ended_handle, cb_data->user_data);
132         }
133 }
134
135 static void simple_callback_data_free_func(void *data)
136 {
137         struct callback_data *cb_data = (struct callback_data*) data;
138
139         if (cb_data) {
140                 if (cb_data->free_func)
141                         cb_data->free_func(cb_data->user_data);
142                 g_free(cb_data);
143         }
144 }
145
146 int mm_sound_proxy_add_test_callback(mm_sound_test_cb func, void *userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
147 {
148         int ret = MM_ERROR_NONE;
149         struct callback_data *cb_data;
150
151         debug_fenter();
152
153         CB_DATA_NEW(cb_data, func, userdata, freefunc);
154
155         if ((ret = mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_EVENT_TEST, dbus_callback, cb_data, simple_callback_data_free_func, &cb_data->subs_id)) != MM_ERROR_NONE)
156                 debug_error("add test callback failed");
157         else
158                 *subs_id = cb_data->subs_id;
159
160         debug_fleave();
161         return ret;
162 }
163
164 int mm_sound_proxy_remove_test_callback(unsigned subs_id)
165 {
166         int ret = MM_ERROR_NONE;
167         debug_fenter();
168
169         if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
170                 debug_error("remove test callback failed");
171         }
172
173         debug_fleave();
174         return ret;
175 }
176
177 int mm_sound_proxy_test(int a, int b, int *get)
178 {
179         int ret = MM_ERROR_NONE;
180         int reply = 0;
181         GVariant *params = NULL, *result = NULL;
182
183         debug_fenter();
184
185         params = g_variant_new("(ii)", a, b);
186         if (params) {
187                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_TEST, params, &result)) != MM_ERROR_NONE) {
188                         debug_error("dbus test call failed");
189                         goto cleanup;
190                 }
191         } else {
192                 debug_error("Construct Param for method call failed");
193                 return MM_ERROR_SOUND_INTERNAL;
194         }
195
196         if (result) {
197                 g_variant_get(result, "(i)",  &reply);
198                 debug_log("reply : %d", reply);
199                 *get = reply;
200         } else {
201                 debug_error("reply null");
202         }
203
204 cleanup:
205         if (result)
206                 g_variant_unref(result);
207
208         debug_fleave();
209         return ret;
210 }
211
212 int mm_sound_proxy_get_current_connected_device_list(int device_flags, GList** device_list)
213 {
214         int ret = MM_ERROR_NONE;
215         GVariant *result = NULL, *child = NULL;
216         GVariant *params = NULL;
217         GVariantIter iter;
218         mm_sound_device_t* device_item;
219         const gchar *device_name_tmp = NULL, *device_type_tmp = NULL;
220
221         debug_fenter();
222
223         if (!device_list) {
224                 debug_error("Invalid Parameter, device_list null");
225                 ret = MM_ERROR_INVALID_ARGUMENT;
226                 goto cleanup;
227         }
228
229         params = g_variant_new("(i)", device_flags);
230
231         if (params) {
232                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_GET_CONNECTED_DEVICE_LIST, params, &result)) != MM_ERROR_NONE) {
233                         debug_error("Get current connected device list failed");
234                         goto cleanup;
235                 }
236         } else {
237                 debug_error("Construct Param for get current connected device failed");
238                 return MM_ERROR_SOUND_INTERNAL;
239         }
240
241         child = g_variant_get_child_value(result, 0);
242         g_variant_iter_init(&iter, child);
243         while (1) {
244                 device_item = g_malloc0(sizeof(mm_sound_device_t));
245                 if (device_item && g_variant_iter_loop(&iter, "(i&sii&s)",
246                                         &device_item->id, &device_type_tmp, &device_item->io_direction, &device_item->state,
247                                         &device_name_tmp)) {
248                         MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM);
249                         MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN);
250                         *device_list = g_list_append(*device_list, device_item);
251                         debug_log("Added device id(%d) type(%17s) direction(%d) state(%d) name(%s)",
252                                         device_item->id, device_item->type,device_item->io_direction, device_item->state,
253                                         device_item->name);
254                 } else {
255                         if (device_item)
256                                 g_free(device_item);
257                         break;
258                 }
259         }
260
261 cleanup:
262         if (result)
263                 g_variant_unref(result);
264
265         debug_fleave();
266         return ret;
267 }
268
269 int mm_sound_proxy_add_device_connected_callback(int device_flags, mm_sound_device_connected_wrapper_cb func, void *userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
270 {
271         int ret = MM_ERROR_NONE;
272         struct callback_data *cb_data;
273
274         debug_fenter();
275
276         CB_DATA_NEW(cb_data, func, userdata, freefunc);
277
278         if ((ret = mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_EVENT_DEVICE_CONNECTED, dbus_callback, cb_data, simple_callback_data_free_func, &cb_data->subs_id)) != MM_ERROR_NONE) {
279                 debug_error("add device connected callback failed");
280                 goto finish;
281         }
282
283         if ((ret = _notify_subscription(AUDIO_EVENT_DEVICE_CONNECTED, cb_data->subs_id, TRUE)) != MM_ERROR_NONE) {
284                 debug_error("failed to notify subscription of device connected event");
285                 goto finish;
286         }
287
288         *subs_id = cb_data->subs_id;
289
290 finish:
291         debug_fleave();
292         return ret;
293 }
294
295 int mm_sound_proxy_remove_device_connected_callback(unsigned subs_id)
296 {
297         int ret = MM_ERROR_NONE;
298         debug_fenter();
299
300         if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
301                 debug_error("remove device connected callback failed");
302                 goto finish;
303         }
304
305         if ((ret = _notify_subscription(AUDIO_EVENT_DEVICE_CONNECTED, subs_id, FALSE)) != MM_ERROR_NONE)
306                 debug_error("failed to notify unsubscription of device connected event");
307
308 finish:
309         debug_fleave();
310         return ret;
311 }
312
313 int mm_sound_proxy_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_wrapper_cb func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
314 {
315         int ret = MM_ERROR_NONE;
316         struct callback_data *cb_data;
317
318         debug_fenter();
319
320         CB_DATA_NEW(cb_data, func, userdata, freefunc);
321
322         if ((ret = mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_EVENT_DEVICE_INFO_CHANGED, dbus_callback, cb_data, simple_callback_data_free_func, &cb_data->subs_id)) != MM_ERROR_NONE)
323                 debug_error("Add device info changed callback failed");
324         else
325                 *subs_id = cb_data->subs_id;
326
327         debug_fleave();
328         return ret;
329 }
330
331 int mm_sound_proxy_remove_device_info_changed_callback(unsigned subs_id)
332 {
333         int ret = MM_ERROR_NONE;
334         debug_fenter();
335
336         if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
337                 debug_error("remove device info changed callback failed");
338         }
339
340         debug_fleave();
341         return ret;
342 }
343
344 int mm_sound_proxy_add_device_state_changed_callback(int device_flags, mm_sound_device_state_changed_wrapper_cb func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
345 {
346         int ret = MM_ERROR_NONE;
347         struct callback_data *cb_data;
348
349         debug_fenter();
350
351         CB_DATA_NEW(cb_data, func, userdata, freefunc);
352
353         if ((ret = mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_EVENT_DEVICE_STATE_CHANGED, dbus_callback, cb_data, simple_callback_data_free_func, &cb_data->subs_id)) != MM_ERROR_NONE)
354                 debug_error("Add device state changed callback failed");
355         else
356                 *subs_id = cb_data->subs_id;
357
358         debug_fleave();
359         return ret;
360 }
361
362 int mm_sound_proxy_remove_device_state_changed_callback(unsigned subs_id)
363 {
364         int ret = MM_ERROR_NONE;
365         debug_fenter();
366
367         if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
368                 debug_error("remove device state changed callback failed");
369         }
370
371         debug_fleave();
372         return ret;
373 }
374
375 int mm_sound_proxy_set_volume_by_type(const char *volume_type, const unsigned volume_level)
376 {
377         int ret = MM_ERROR_NONE;
378         char *reply = NULL, *direction = "out";
379         GVariant *params = NULL, *result = NULL;
380
381         debug_fenter();
382
383         params = g_variant_new("(ssu)", direction, volume_type, volume_level);
384         if (params) {
385                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_SET_VOLUME_LEVEL, params, &result)) != MM_ERROR_NONE) {
386                         debug_error("dbus set volume by type failed");
387                         goto cleanup;
388                 }
389         } else {
390                 debug_error("Construct Param for method call failed");
391                 return MM_ERROR_SOUND_INTERNAL;
392         }
393
394         if (result) {
395                 g_variant_get(result, "(&s)",  &reply);
396                 debug_log("reply : %s", reply);
397                 if (!strcmp(reply, "STREAM_MANAGER_RETURN_ERROR"))
398                         ret = MM_ERROR_SOUND_INTERNAL;
399         } else {
400                 debug_error("reply null");
401         }
402
403 cleanup:
404         if (result)
405                 g_variant_unref(result);
406
407         debug_fleave();
408         return ret;
409 }
410
411 int mm_sound_proxy_add_volume_changed_callback(mm_sound_volume_changed_wrapper_cb func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
412 {
413         int ret = MM_ERROR_NONE;
414         struct callback_data *cb_data;
415
416         debug_fenter();
417
418         CB_DATA_NEW(cb_data, func, userdata, freefunc);
419
420         if ((ret = mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_EVENT_VOLUME_CHANGED, dbus_callback, cb_data, simple_callback_data_free_func, &cb_data->subs_id)) != MM_ERROR_NONE)
421                 debug_error("Add Volume changed callback failed");
422         else
423                 *subs_id = cb_data->subs_id;
424
425
426         debug_fleave();
427
428         return ret;
429 }
430
431 int mm_sound_proxy_remove_volume_changed_callback(unsigned subs_id)
432 {
433         int ret = MM_ERROR_NONE;
434         debug_fenter();
435
436         if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
437                 debug_error("Remove Volume changed callback failed");
438         }
439
440         debug_fleave();
441         return ret;
442 }
443
444 int mm_sound_proxy_play_tone(int tone, int repeat, int volume, int volume_config,
445                            int session_type, int session_options, int client_pid,
446                            bool enable_session, int *codechandle, char *stream_type, int stream_index)
447 {
448         int ret = MM_ERROR_NONE;
449         int handle = 0;
450         GVariant *params = NULL, *result = NULL;
451         gboolean _enable_session = enable_session;
452
453         if (!codechandle) {
454                 debug_error("Param for play is null");
455                 return MM_ERROR_INVALID_ARGUMENT;
456         }
457
458         debug_fenter();
459
460         params = g_variant_new("(iiiiiiibsi)", tone, repeat, volume,
461                       volume_config, session_type, session_options, client_pid , _enable_session, stream_type, stream_index);
462         if (params) {
463                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_DTMF, params, &result)) != MM_ERROR_NONE) {
464                         debug_error("dbus play tone failed");
465                         goto cleanup;
466                 }
467         } else {
468                 debug_error("Construct Param for method call failed");
469         }
470
471         if (result) {
472                 g_variant_get(result, "(i)",  &handle);
473                 debug_log("handle : %d", handle);
474                 *codechandle = handle;
475         } else {
476                 debug_error("reply null");
477         }
478
479 cleanup:
480         if (result)
481                 g_variant_unref(result);
482
483         debug_fleave();
484         return ret;
485 }
486
487 int mm_sound_proxy_play_tone_with_stream_info(int client_pid, int tone, char *stream_type, int stream_index, int volume, int repeat, int *codechandle)
488 {
489         int ret = MM_ERROR_NONE;
490         int handle = 0;
491         GVariant *params = NULL, *result = NULL;
492
493         debug_fenter();
494
495         if (!codechandle) {
496                 debug_error("Param for play is null");
497                 return MM_ERROR_INVALID_ARGUMENT;
498         }
499
500         params = g_variant_new("(iiiisi)", tone, repeat, volume, client_pid, stream_type, stream_index);
501         if (params) {
502                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_DTMF_WITH_STREAM_INFO, params, &result)) != MM_ERROR_NONE) {
503                         debug_error("dbus play tone failed");
504                         goto cleanup;
505                 }
506         } else {
507                 debug_error("Construct Param for method call failed");
508         }
509
510         if (result) {
511                 g_variant_get(result, "(i)",  &handle);
512                 debug_log("handle : %d", handle);
513                 *codechandle = handle;
514         } else {
515                 debug_error("reply null");
516         }
517
518 cleanup:
519         if (result)
520                 g_variant_unref(result);
521
522         debug_fleave();
523         return ret;
524 }
525
526 int mm_sound_proxy_play_sound(const char* filename, int tone, int repeat, int volume, int volume_config,
527                            int priority, int session_type, int session_options, int client_pid, int handle_route,
528                            bool enable_session, int *codechandle, char *stream_type, int stream_index)
529 {
530         int ret = MM_ERROR_NONE;
531         int handle = 0;
532         GVariant *params = NULL, *result = NULL;
533         gboolean _enable_session = enable_session;
534
535         if (!filename || !codechandle) {
536                 debug_error("Param for play is null");
537                 return MM_ERROR_INVALID_ARGUMENT;
538         }
539
540         debug_fenter();
541
542         params = g_variant_new("(siiiiiiiiibsi)", filename, tone, repeat, volume,
543                       volume_config, priority, session_type, session_options, client_pid, handle_route, _enable_session, stream_type, stream_index);
544         if (params) {
545                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_FILE_START, params, &result)) != MM_ERROR_NONE) {
546                         debug_error("dbus play file failed");
547                         goto cleanup;
548                 }
549         } else {
550                 debug_error("Construct Param for method call failed");
551         }
552
553         if (result) {
554                 g_variant_get(result, "(i)",  &handle);
555                 debug_log("handle : %d", handle);
556                 *codechandle = handle;
557         } else {
558                 debug_error("reply null");
559         }
560
561 cleanup:
562         if (result)
563                 g_variant_unref(result);
564
565         debug_fleave();
566         return ret;
567 }
568
569 int mm_sound_proxy_play_sound_with_stream_info(const char* filename, int repeat, int volume,
570                                 int priority, int client_pid, int handle_route, int *codechandle, char *stream_type, int stream_index)
571 {
572         int ret = MM_ERROR_NONE;
573         int handle = 0;
574         GVariant *params = NULL, *result = NULL;
575
576         if (!filename || !codechandle) {
577                 debug_error("Param for play is null");
578                 return MM_ERROR_INVALID_ARGUMENT;
579         }
580
581         debug_fenter();
582
583         params = g_variant_new("(siiiiisi)", filename, repeat, volume,
584                         priority, client_pid, handle_route, stream_type, stream_index);
585         if (params) {
586                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_FILE_START_WITH_STREAM_INFO, params, &result)) != MM_ERROR_NONE) {
587                         debug_error("dbus play file failed");
588                         goto cleanup;
589                 }
590         } else {
591                 debug_error("Construct Param for method call failed");
592         }
593
594         if (result) {
595                 g_variant_get(result, "(i)",  &handle);
596                 debug_log("handle : %d", handle);
597                 *codechandle = handle;
598         } else {
599                 debug_error("reply null");
600         }
601
602 cleanup:
603         if (result)
604                 g_variant_unref(result);
605
606         debug_fleave();
607         return ret;
608
609
610 }
611
612 int mm_sound_proxy_stop_sound(int handle)
613 {
614         int ret = MM_ERROR_NONE;
615         GVariant *result = NULL;
616
617         debug_fenter();
618
619         if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_FILE_STOP, g_variant_new("(i)", handle), &result)) != MM_ERROR_NONE) {
620                 debug_error("dbus stop file playing failed");
621                 goto cleanup;
622         }
623
624 cleanup:
625         if (result)
626                 g_variant_unref(result);
627
628         debug_fleave();
629         return ret;
630 }
631
632 int mm_sound_proxy_clear_focus(int pid)
633 {
634         int ret = MM_ERROR_NONE;
635         GVariant *result = NULL;
636
637         debug_fenter();
638
639         if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_CLEAR_FOCUS, g_variant_new("(i)", pid), &result)) != MM_ERROR_NONE) {
640                 debug_error("dbus clear focus failed");
641         }
642
643         if (result)
644                 g_variant_unref(result);
645
646         debug_fleave();
647         return ret;
648 }
649
650 int mm_sound_proxy_add_play_sound_end_callback(mm_sound_stop_callback_wrapper_func func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
651 {
652         int ret = MM_ERROR_NONE;
653         struct callback_data *cb_data;
654
655         debug_fenter();
656
657         CB_DATA_NEW(cb_data, func, userdata, freefunc);
658
659         if ((ret = mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_EVENT_PLAY_FILE_END, dbus_callback, cb_data, simple_callback_data_free_func, &cb_data->subs_id)) != MM_ERROR_NONE)
660                 debug_error("add play sound end callback failed");
661         else
662                 *subs_id = cb_data->subs_id;
663
664         debug_fleave();
665
666         return ret;
667 }
668
669 int mm_sound_proxy_remove_play_sound_end_callback(unsigned subs_id)
670 {
671         int ret = MM_ERROR_NONE;
672         debug_fenter();
673
674         if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
675                 debug_error("Remove Play File End callback failed");
676         }
677
678         debug_fleave();
679         return ret;
680 }
681
682 int mm_sound_proxy_emergent_exit(int exit_pid)
683 {
684         int ret = MM_ERROR_NONE;
685         GVariant *params = NULL;
686
687         debug_fenter();
688
689         params = g_variant_new("(i)", exit_pid);
690         if (params) {
691                 if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_EMERGENT_EXIT, params)) != MM_ERROR_NONE) {
692                         debug_error("dbus emergent exit failed");
693                         goto cleanup;
694                 }
695         } else {
696                 debug_error("Construct Param for emergent exit signal failed");
697                 ret = MM_ERROR_SOUND_INTERNAL;
698         }
699
700 cleanup:
701
702         debug_fleave();
703         return ret;
704 }
705
706 /*------------------------------------------ FOCUS --------------------------------------------------*/
707 #ifdef USE_FOCUS
708
709 int mm_sound_proxy_get_unique_id(int *id)
710 {
711         int ret = MM_ERROR_NONE;
712         int res = 0;
713         GVariant *result = NULL;
714
715         debug_fenter();
716
717         if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_GET_UNIQUE_ID, NULL, &result)) != MM_ERROR_NONE) {
718                 debug_error("dbus get unique id failed");
719         }
720
721         if (result) {
722                 g_variant_get(result, "(i)", &res);
723                 *id = res;
724                 debug_msg("got unique id(%d)", *id);
725                 g_variant_unref(result);
726         }
727
728         debug_fleave();
729
730         return ret;
731 }
732
733 int mm_sound_proxy_register_focus(int id, int instance, const char *stream_type, mm_sound_focus_changed_cb callback, bool is_for_session, void* userdata)
734 {
735         int ret = MM_ERROR_NONE;
736         GVariant *params = NULL, *result = NULL;
737
738         debug_fenter();
739
740         params = g_variant_new("(iisb)", instance, id, stream_type, is_for_session);
741         if (params) {
742                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_REGISTER_FOCUS, params, &result)) != MM_ERROR_NONE) {
743                         debug_error("dbus register focus failed");
744                 }
745         } else {
746                 debug_error("Construct Param for method call failed");
747         }
748
749         if (ret != MM_ERROR_NONE)
750                 g_variant_get(result, "(i)",  &ret);
751         if (result)
752                 g_variant_unref(result);
753
754         debug_fleave();
755
756         return ret;
757
758 }
759
760 int mm_sound_proxy_unregister_focus(int instance, int id, bool is_for_session)
761 {
762         int ret = MM_ERROR_NONE;
763         GVariant *params = NULL, *result = NULL;
764
765         debug_fenter();
766
767         params = g_variant_new("(iib)", instance, id, is_for_session);
768         if (params) {
769                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_UNREGISTER_FOCUS, params, &result)) != MM_ERROR_NONE) {
770                         debug_error("dbus unregister focus failed");
771                 }
772         } else {
773                 debug_error("Construct Param for method call failed");
774         }
775
776         if (ret != MM_ERROR_NONE)
777                 g_variant_get(result, "(i)",  &ret);
778         if (result)
779                 g_variant_unref(result);
780
781         debug_fleave();
782
783         return ret;
784 }
785
786 int mm_sound_proxy_set_foucs_reacquisition(int instance, int id, bool reacquisition)
787 {
788         int ret = MM_ERROR_NONE;
789         GVariant *params = NULL, *result = NULL;
790
791         debug_fenter();
792
793         params = g_variant_new("(iib)", instance, id, reacquisition);
794         if (params) {
795                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_SET_FOCUS_REACQUISITION, params, &result)) != MM_ERROR_NONE) {
796                         debug_error("dbus set focus reacquisition failed");
797                 }
798         } else {
799                 debug_error("Construct Param for method call failed");
800         }
801
802         if (ret != MM_ERROR_NONE)
803                 g_variant_get(result, "(i)",  &ret);
804         if (result)
805                 g_variant_unref(result);
806
807         debug_fleave();
808         return ret;
809 }
810
811 int mm_sound_proxy_get_acquired_focus_stream_type(int focus_type, char **stream_type, int *option, char **ext_info)
812 {
813         int ret = MM_ERROR_NONE;
814         GVariant *params = NULL, *result = NULL;
815
816         debug_fenter();
817
818         if (!(params = g_variant_new("(i)", focus_type))) {
819                 debug_error("Construct Param for method call failed");
820                 return MM_ERROR_SOUND_INTERNAL;
821         }
822
823         if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_GET_ACQUIRED_FOCUS_STREAM_TYPE, params, &result)) == MM_ERROR_NONE) {
824                 if (result) {
825                         g_variant_get(result, "(sis)", stream_type, option, ext_info);
826                         g_variant_unref(result);
827                 }
828         } else {
829                 debug_error("dbus get stream type of acquired focus failed");
830         }
831
832         debug_fleave();
833         return ret;
834 }
835
836 int mm_sound_proxy_acquire_focus(int instance, int id, mm_sound_focus_type_e type, int option, const char *ext_info, bool is_for_session)
837 {
838         int ret = MM_ERROR_NONE;
839         GVariant *params = NULL, *result = NULL;
840
841         debug_fenter();
842
843         params = g_variant_new("(iiiisb)", instance, id, type, option, ext_info ? ext_info : "", is_for_session);
844         if (params) {
845                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_ACQUIRE_FOCUS, params, &result)) != MM_ERROR_NONE) {
846                         debug_error("dbus acquire focus failed");
847                 }
848         } else {
849                 debug_error("Construct Param for method call failed");
850         }
851
852         if (ret != MM_ERROR_NONE)
853                 g_variant_get(result, "(i)",  &ret);
854         if (result)
855                 g_variant_unref(result);
856
857         debug_fleave();
858         return ret;
859 }
860
861 int mm_sound_proxy_release_focus(int instance, int id, mm_sound_focus_type_e type, int option, const char *ext_info, bool is_for_session)
862 {
863         int ret = MM_ERROR_NONE;
864         GVariant *params = NULL, *result = NULL;
865
866         debug_fenter();
867
868         params = g_variant_new("(iiiisb)", instance, id, type, option, ext_info ? ext_info : "", is_for_session);
869         if (params) {
870                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_RELEASE_FOCUS, params, &result)) != MM_ERROR_NONE) {
871                         debug_error("dbus release focus failed");
872                 }
873         } else {
874                 debug_error("Construct Param for method call failed");
875         }
876
877         if (ret != MM_ERROR_NONE)
878                 g_variant_get(result, "(i)",  &ret);
879         if (result)
880                 g_variant_unref(result);
881
882         debug_fleave();
883         return ret;
884 }
885
886 int mm_sound_proxy_set_focus_watch_callback(int instance, int handle, mm_sound_focus_type_e type, mm_sound_focus_changed_watch_cb callback, bool is_for_session, void* userdata)
887 {
888         int ret = MM_ERROR_NONE;
889         GVariant *params = NULL, *result = NULL;
890
891         debug_fenter();
892
893         params = g_variant_new("(iiib)", instance, handle, type, is_for_session);
894         if (params) {
895                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_WATCH_FOCUS, params, &result)) != MM_ERROR_NONE) {
896                         debug_error("dbus set watch focus failed");
897                 }
898         } else {
899                 debug_error("Construct Param for method call failed");
900         }
901
902         if (ret != MM_ERROR_NONE)
903                 g_variant_get(result, "(i)",  &ret);
904         if (result)
905                 g_variant_unref(result);
906         debug_fleave();
907
908         return ret;
909
910 }
911
912 int mm_sound_proxy_unset_focus_watch_callback(int focus_tid, int handle, bool is_for_session)
913 {
914         int ret = MM_ERROR_NONE;
915         GVariant *params = NULL, *result = NULL;
916
917         debug_fenter();
918
919         params = g_variant_new("(iib)", focus_tid, handle, is_for_session);
920         if (params) {
921                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_UNWATCH_FOCUS, params, &result)) != MM_ERROR_NONE) {
922                         debug_error("dbus unset watch focus failed");
923                 }
924         } else {
925                 debug_error("Construct Param for method call failed");
926         }
927         if (ret != MM_ERROR_NONE)
928                 g_variant_get(result, "(i)",  &ret);
929         if (result)
930                 g_variant_unref(result);
931
932         debug_fleave();
933
934         return ret;
935 }
936
937 #endif /* USE_FOCUS */
938 /*------------------------------------------ FOCUS --------------------------------------------------*/
939
940 int mm_sound_proxy_initialize(void)
941 {
942         int ret = MM_ERROR_NONE;
943
944         debug_fenter();
945         debug_fleave();
946
947         return ret;
948 }
949
950 int mm_sound_proxy_finalize(void)
951 {
952         int ret = MM_ERROR_NONE;
953
954         debug_fenter();
955         debug_fleave();
956
957         return ret;
958 }