fixup! Do not raise() inside signal handler
[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 #include "include/mm_sound_focus_socket.h"
12
13 struct callback_data {
14         void *user_cb;
15         void *user_data;
16         mm_sound_proxy_userdata_free free_func;
17         uint32_t subs_id;
18 };
19
20 #define CB_DATA_NEW(_cb_data, _func, _userdata, _freefunc) \
21         do { \
22                 _cb_data = (struct callback_data*) g_malloc0(sizeof(struct callback_data)); \
23                 _cb_data->user_cb = _func; \
24                 _cb_data->user_data = _userdata; \
25                 _cb_data->free_func = _freefunc; \
26                 _cb_data->subs_id = 0; \
27         } while (0)
28
29 /* subscribe is true when add callback,
30  * false when remove callback */
31 static int _notify_subscription(audio_event_t event, uint32_t subs_id, gboolean subscribe)
32 {
33         int ret = MM_ERROR_NONE;
34         GVariant *params = NULL;
35         const char *event_name = NULL;
36
37         debug_fenter();
38
39         if ((ret = mm_sound_dbus_get_event_name(event, &event_name) != MM_ERROR_NONE)) {
40                 debug_error("Failed to get event name");
41                 return MM_ERROR_SOUND_INTERNAL;
42         }
43
44         if (!(params = g_variant_new("(sub)", event_name, subs_id, subscribe))) {
45                 debug_error("Construct Param failed");
46                 return MM_ERROR_SOUND_INTERNAL;
47         }
48
49         if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_CLIENT_SUBSCRIBED, params)))
50                 debug_error("dbus send signal for client subscribed failed");
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 static int parse_device_variant(GVariant *v, int *device_id, const char **device_type, int *direction, int *state,
83                                                 const char **device_name, int *vendor_id, int *product_id, int *stream_id, int *stream_num)
84 {
85         const char *v_type;
86         GVariant *array_v;
87         GVariantIter iter, array_iter;
88         int i = 0;
89         int ret = MM_ERROR_NONE;
90
91         if (v == NULL) {
92                 debug_error("Variant NULL");
93                 return MM_ERROR_NONE;
94         }
95
96         v_type = g_variant_get_type_string(v);
97         if (g_variant_type_equal(v_type, "(isiisiiai)") == FALSE) {
98                 debug_error("device variant type not matching '%s'", v_type);
99                 return MM_ERROR_NONE;
100         }
101
102         g_variant_iter_init(&iter, v);
103         g_variant_iter_next(&iter, "i", device_id);
104         g_variant_iter_next(&iter, "&s", device_type);
105         g_variant_iter_next(&iter, "i", direction);
106         g_variant_iter_next(&iter, "i", state);
107         g_variant_iter_next(&iter, "&s", device_name);
108         g_variant_iter_next(&iter, "i", vendor_id);
109         g_variant_iter_next(&iter, "i", product_id);
110
111         array_v = g_variant_iter_next_value(&iter);
112         *stream_num = g_variant_iter_init(&array_iter, array_v);
113         if (*stream_num > MAX_STREAM_ON_DEVICE) {
114                 debug_error("too many streams on device %d", *stream_num);
115                 ret = MM_ERROR_SOUND_INTERNAL;
116                 goto finish;
117         }
118
119         while (g_variant_iter_loop(&array_iter, "i", &stream_id[i++])) ;
120 finish:
121         g_variant_unref(array_v);
122
123         return ret;
124 }
125
126 /* This callback unmarshall general-formed paramters to subject specific parameters,
127  * and call proper callback */
128 static void dbus_callback(audio_event_t event, GVariant *params, void *userdata)
129 {
130         struct callback_data *cb_data  = (struct callback_data*) userdata;
131         uint32_t event_id;
132         const char *name = NULL, *device_type = NULL;
133         int device_id, direction, state;
134         const gchar *v_type;
135         GVariantIter iter;
136         GVariant *device_v;
137         int stream_id[MAX_STREAM_ON_DEVICE];
138         int stream_num;
139         int vendor_id, product_id;
140
141         v_type = g_variant_get_type_string(params);
142
143         if (event == AUDIO_EVENT_VOLUME_CHANGED) {
144                 char *volume_type_str = NULL, *direction = NULL;
145                 unsigned volume_level;
146
147                 g_variant_get(params, "(&s&su)", &direction, &volume_type_str, &volume_level);
148                 ((mm_sound_volume_changed_wrapper_cb)(cb_data->user_cb))(direction, volume_type_str, volume_level, cb_data->user_data);
149         } else if (event == AUDIO_EVENT_DEVICE_CONNECTED) {
150                 gboolean is_connected = FALSE;
151
152                 if (g_variant_type_equal(v_type, "(u(isiisiiai)b)") == FALSE) {
153                         debug_error("Device connection changed signature not matching : %s", v_type);
154                         return ;
155                 }
156                 g_variant_iter_init(&iter, params);
157                 g_variant_iter_next(&iter, "u", &event_id);
158                 device_v = g_variant_iter_next_value(&iter);
159                 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
160                                                         &name, &vendor_id, &product_id, stream_id, &stream_num) < 0) {
161                         debug_error("Failed to parse device variant");
162                         return ;
163                 }
164                 g_variant_iter_next(&iter, "b", &is_connected);
165
166                 ((mm_sound_device_connected_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
167                         state, name, vendor_id, product_id, stream_id, stream_num, is_connected, cb_data->user_data);
168                 _notify_signal_handled(event, event_id, cb_data->subs_id, g_variant_new("(ib)", device_id, is_connected));
169         } else if (event == AUDIO_EVENT_DEVICE_INFO_CHANGED) {
170                 int changed_device_info_type = 0;
171
172                 if (g_variant_type_equal(v_type, "(u(isiisiiai)i)") == FALSE) {
173                         debug_error("Device information changed signature not matching : %s", v_type);
174                         return ;
175                 }
176
177                 g_variant_iter_init(&iter, params);
178                 g_variant_iter_next(&iter, "u", &event_id);
179                 device_v = g_variant_iter_next_value(&iter);
180                 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
181                                                         &name, &vendor_id, &product_id, stream_id, &stream_num) < 0) {
182                         debug_error("Failed to parse device variant");
183                         return ;
184                 }
185                 g_variant_iter_next(&iter, "i", &changed_device_info_type);
186
187                 ((mm_sound_device_info_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
188                         state, name, vendor_id, product_id, stream_id, stream_num, changed_device_info_type, cb_data->user_data);
189         } else if (event == AUDIO_EVENT_DEVICE_STATE_CHANGED) {
190
191                 if (g_variant_type_equal(v_type, "(u(isiisiiai))") == FALSE) {
192                         debug_error("Device state changed signature not matching : %s", v_type);
193                         return ;
194                 }
195
196                 g_variant_iter_init(&iter, params);
197                 g_variant_iter_next(&iter, "u", &event_id);
198                 device_v = g_variant_iter_next_value(&iter);
199                 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
200                                                         &name, &vendor_id, &product_id, stream_id, &stream_num) < 0) {
201                         debug_error("Failed to parse device variant");
202                         return ;
203                 }
204
205                 ((mm_sound_device_state_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
206                         state, name, vendor_id, product_id, stream_id, stream_num, cb_data->user_data);
207         } else if (event == AUDIO_EVENT_FOCUS_CHANGED) {
208         } else if (event == AUDIO_EVENT_FOCUS_WATCH) {
209         } else if (event == AUDIO_EVENT_TEST) {
210                 int test_var = 0;
211                 g_variant_get(params, "(i)", &test_var);
212                 ((mm_sound_test_cb)(cb_data->user_cb))(test_var, cb_data->user_data);
213         } else if (event == AUDIO_EVENT_PLAY_FILE_END) {
214                 int ended_handle = 0;
215                 g_variant_get(params, "(i)", &ended_handle);
216                 ((mm_sound_stop_callback_wrapper_func)(cb_data->user_cb))(ended_handle, cb_data->user_data);
217         }
218 }
219
220 static void simple_callback_data_free_func(void *data)
221 {
222         struct callback_data *cb_data = (struct callback_data*) data;
223
224         if (cb_data) {
225                 if (cb_data->free_func)
226                         cb_data->free_func(cb_data->user_data);
227                 g_free(cb_data);
228         }
229 }
230
231 int mm_sound_proxy_add_test_callback(mm_sound_test_cb func, void *userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
232 {
233         int ret = MM_ERROR_NONE;
234         struct callback_data *cb_data;
235
236         debug_fenter();
237
238         CB_DATA_NEW(cb_data, func, userdata, freefunc);
239
240         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)
241                 debug_error("add test callback failed");
242         else
243                 *subs_id = cb_data->subs_id;
244
245         debug_fleave();
246         return ret;
247 }
248
249 int mm_sound_proxy_remove_test_callback(unsigned subs_id)
250 {
251         int ret = MM_ERROR_NONE;
252         debug_fenter();
253
254         if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
255                 debug_error("remove test callback failed");
256
257         debug_fleave();
258         return ret;
259 }
260
261 int mm_sound_proxy_test(int a, int b, int *get)
262 {
263         int ret = MM_ERROR_NONE;
264         int reply = 0;
265         GVariant *params = NULL, *result = NULL;
266
267         debug_fenter();
268
269         params = g_variant_new("(ii)", a, b);
270         if (params) {
271                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_TEST, params, &result)) != MM_ERROR_NONE) {
272                         debug_error("dbus test call failed");
273                         goto cleanup;
274                 }
275         } else {
276                 debug_error("Construct Param for method call failed");
277                 return MM_ERROR_SOUND_INTERNAL;
278         }
279
280         if (result) {
281                 g_variant_get(result, "(i)",  &reply);
282                 debug_log("reply : %d", reply);
283                 *get = reply;
284         } else {
285                 debug_error("reply null");
286         }
287
288 cleanup:
289         if (result)
290                 g_variant_unref(result);
291
292         debug_fleave();
293         return ret;
294 }
295
296 int mm_sound_proxy_is_stream_on_device(int stream_id, int device_id, bool *is_on)
297 {
298         int ret = MM_ERROR_NONE;
299         GVariant *params, *result;
300         gboolean _is_on;
301
302         debug_fenter();
303
304         if (!is_on) {
305                 debug_error("Invalid Parameter, is_on null");
306                 return MM_ERROR_INVALID_ARGUMENT;
307         }
308
309         if ((params = g_variant_new("(ii)", stream_id, device_id)) == NULL) {
310                 debug_error("Construct Param for query is stream on device failed");
311                 return MM_ERROR_SOUND_INTERNAL;
312         }
313
314         if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_IS_STREAM_ON_DEVICE, params, &result)) != MM_ERROR_NONE) {
315                 debug_error("is stream on device failed");
316                 goto cleanup;
317         }
318
319         if (result) {
320                 g_variant_get(result, "(b)",  &_is_on);
321                 debug_log("is_on : %d", _is_on);
322                 *is_on = (bool)_is_on;
323         } else {
324                 debug_error("reply null");
325                 ret = MM_ERROR_SOUND_INTERNAL;
326         }
327
328 cleanup:
329         if (params)
330                 g_variant_unref(params);
331         if (result)
332                 g_variant_unref(result);
333
334         debug_fleave();
335         return ret;
336 }
337
338 int mm_sound_proxy_get_current_connected_device_list(int device_flags, GList** device_list)
339 {
340         int ret = MM_ERROR_NONE;
341         GVariant *result = NULL, *child = NULL;
342         GVariant *params = NULL;
343         GVariantIter iter;
344         mm_sound_device_t* device_item;
345         const gchar *device_name_tmp = NULL, *device_type_tmp = NULL;
346
347         debug_fenter();
348
349         if (!device_list) {
350                 debug_error("Invalid Parameter, device_list null");
351                 ret = MM_ERROR_INVALID_ARGUMENT;
352                 goto cleanup;
353         }
354
355         params = g_variant_new("(i)", device_flags);
356
357         if (params) {
358                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_GET_CONNECTED_DEVICE_LIST, params, &result)) != MM_ERROR_NONE) {
359                         debug_error("Get current connected device list failed");
360                         goto cleanup;
361                 }
362         } else {
363                 debug_error("Construct Param for get current connected device failed");
364                 return MM_ERROR_SOUND_INTERNAL;
365         }
366
367         child = g_variant_get_child_value(result, 0);
368         g_variant_iter_init(&iter, child);
369         while (1) {
370                 device_item = g_malloc0(sizeof(mm_sound_device_t));
371                 if (device_item && g_variant_iter_loop(&iter, "(i&sii&sii)",
372                                         &device_item->id, &device_type_tmp, &device_item->io_direction, &device_item->state,
373                                         &device_name_tmp, &device_item->vendor_id, &device_item->product_id)) {
374                         MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM);
375                         MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN);
376                         *device_list = g_list_append(*device_list, device_item);
377                         debug_log("Added device id(%d) type(%17s) direction(%d) state(%d) name(%s) vendor-id(%04x), product-id(%04x)",
378                                         device_item->id, device_item->type,device_item->io_direction, device_item->state,
379                                         device_item->name, device_item->vendor_id, device_item->product_id);
380                         device_item->stream_num = -1;
381                 } else {
382                         if (device_item)
383                                 g_free(device_item);
384                         break;
385                 }
386         }
387
388 cleanup:
389         if (result)
390                 g_variant_unref(result);
391
392         debug_fleave();
393         return ret;
394 }
395
396 int mm_sound_proxy_get_device_by_id(int device_id, mm_sound_device_t **device)
397 {
398         int ret = MM_ERROR_NONE;
399         GVariant *params = NULL, *result = NULL;
400         mm_sound_device_t* device_item = NULL;
401         const gchar *device_name_tmp = NULL, *device_type_tmp = NULL;
402
403         debug_fenter();
404
405         if (!device || device_id < 1) {
406                 debug_error("Invalid Parameter, device null or improper device id");
407                 return MM_ERROR_INVALID_ARGUMENT;
408         }
409
410         if ((params = g_variant_new("(i)", device_id)) == NULL) {
411                 debug_error("Construct Param for get device by id failed");
412                 return MM_ERROR_SOUND_INTERNAL;
413         }
414
415         if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_GET_DEVICE_BY_ID, params, &result)) != MM_ERROR_NONE) {
416                 debug_error("get device by id failed");
417                 ret = MM_ERROR_SOUND_NO_DATA;
418                 goto cleanup;
419         }
420
421         if (result) {
422                 if ((device_item = g_malloc0(sizeof(mm_sound_device_t))) == NULL) {
423                         debug_error("Alloc device handle failed");
424                         ret = MM_ERROR_SOUND_INTERNAL;
425                         goto cleanup;
426                 }
427
428                 g_variant_get(result, "(i&sii&sii)",
429                                 &device_item->id, &device_type_tmp, &device_item->io_direction,
430                                 &device_item->state, &device_name_tmp,
431                                 &device_item->vendor_id, &device_item->product_id);
432                 MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM);
433                 MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN);
434                 debug_log("Get device id(%d) type(%17s) direction(%d) state(%d) name(%s) vendor-id(%04x) product-id(%04x)",
435                                 device_item->id, device_item->type, device_item->io_direction,
436                                 device_item->state, device_item->name,
437                                 device_item->vendor_id, device_item->product_id);
438                 device_item->stream_num = -1;
439                 *device = device_item;
440         } else {
441                 debug_error("reply null");
442                 ret = MM_ERROR_SOUND_INTERNAL;
443         }
444
445 cleanup:
446         if (result)
447                 g_variant_unref(result);
448
449         debug_fleave();
450         return ret;
451 }
452
453 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)
454 {
455         int ret = MM_ERROR_NONE;
456         struct callback_data *cb_data;
457
458         debug_fenter();
459
460         CB_DATA_NEW(cb_data, func, userdata, freefunc);
461
462         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) {
463                 debug_error("add device connected callback failed");
464                 goto finish;
465         }
466
467         if ((ret = _notify_subscription(AUDIO_EVENT_DEVICE_CONNECTED, cb_data->subs_id, TRUE)) != MM_ERROR_NONE) {
468                 debug_error("failed to notify subscription of device connected event");
469                 goto finish;
470         }
471
472         *subs_id = cb_data->subs_id;
473
474 finish:
475         debug_fleave();
476         return ret;
477 }
478
479 int mm_sound_proxy_remove_device_connected_callback(unsigned subs_id)
480 {
481         int ret = MM_ERROR_NONE;
482         debug_fenter();
483
484         if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
485                 debug_error("remove device connected callback failed");
486                 goto finish;
487         }
488
489         if ((ret = _notify_subscription(AUDIO_EVENT_DEVICE_CONNECTED, subs_id, FALSE)) != MM_ERROR_NONE)
490                 debug_error("failed to notify unsubscription of device connected event");
491
492 finish:
493         debug_fleave();
494         return ret;
495 }
496
497 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)
498 {
499         int ret = MM_ERROR_NONE;
500         struct callback_data *cb_data;
501
502         debug_fenter();
503
504         CB_DATA_NEW(cb_data, func, userdata, freefunc);
505
506         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)
507                 debug_error("Add device info changed callback failed");
508         else
509                 *subs_id = cb_data->subs_id;
510
511         debug_fleave();
512         return ret;
513 }
514
515 int mm_sound_proxy_remove_device_info_changed_callback(unsigned subs_id)
516 {
517         int ret = MM_ERROR_NONE;
518         debug_fenter();
519
520         if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
521                 debug_error("remove device info changed callback failed");
522
523         debug_fleave();
524         return ret;
525 }
526
527 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)
528 {
529         int ret = MM_ERROR_NONE;
530         struct callback_data *cb_data;
531
532         debug_fenter();
533
534         CB_DATA_NEW(cb_data, func, userdata, freefunc);
535
536         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)
537                 debug_error("Add device state changed callback failed");
538         else
539                 *subs_id = cb_data->subs_id;
540
541         debug_fleave();
542         return ret;
543 }
544
545 int mm_sound_proxy_remove_device_state_changed_callback(unsigned subs_id)
546 {
547         int ret = MM_ERROR_NONE;
548         debug_fenter();
549
550         if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
551                 debug_error("remove device state changed callback failed");
552
553         debug_fleave();
554         return ret;
555 }
556
557 int mm_sound_proxy_set_volume_by_type(const char *volume_type, const unsigned volume_level)
558 {
559         int ret = MM_ERROR_NONE;
560         char *reply = NULL, *direction = "out";
561         GVariant *params = NULL, *result = NULL;
562
563         debug_fenter();
564
565         params = g_variant_new("(ssu)", direction, volume_type, volume_level);
566         if (params) {
567                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_SET_VOLUME_LEVEL, params, &result)) != MM_ERROR_NONE) {
568                         debug_error("dbus set volume by type failed");
569                         goto cleanup;
570                 }
571         } else {
572                 debug_error("Construct Param for method call failed");
573                 return MM_ERROR_SOUND_INTERNAL;
574         }
575
576         if (result) {
577                 g_variant_get(result, "(&s)",  &reply);
578                 debug_log("reply : %s", reply);
579                 if (!strcmp(reply, "STREAM_MANAGER_RETURN_ERROR"))
580                         ret = MM_ERROR_SOUND_INTERNAL;
581         } else {
582                 debug_error("reply null");
583         }
584
585 cleanup:
586         if (result)
587                 g_variant_unref(result);
588
589         debug_fleave();
590         return ret;
591 }
592
593 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)
594 {
595         int ret = MM_ERROR_NONE;
596         struct callback_data *cb_data;
597
598         debug_fenter();
599
600         CB_DATA_NEW(cb_data, func, userdata, freefunc);
601
602         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)
603                 debug_error("Add Volume changed callback failed");
604         else
605                 *subs_id = cb_data->subs_id;
606
607
608         debug_fleave();
609
610         return ret;
611 }
612
613 int mm_sound_proxy_remove_volume_changed_callback(unsigned subs_id)
614 {
615         int ret = MM_ERROR_NONE;
616         debug_fenter();
617
618         if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
619                 debug_error("Remove Volume changed callback failed");
620
621         debug_fleave();
622         return ret;
623 }
624
625 int mm_sound_proxy_set_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_parameters, const char *filter_group)
626 {
627         int ret = MM_ERROR_NONE;
628         char *reply = NULL;
629         GVariant *params = NULL, *result = NULL;
630
631         debug_fenter();
632
633         params = g_variant_new("(ssss)", filter_name, filter_parameters, filter_group, stream_type);
634         if (params) {
635                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_SET_FILTER, params, &result)) != MM_ERROR_NONE) {
636                         debug_error("dbus set filter by type failed");
637                         goto cleanup;
638                 }
639         } else {
640                 debug_error("construct param for method call failed");
641                 return MM_ERROR_SOUND_INTERNAL;
642         }
643
644         if (result) {
645                 g_variant_get(result, "(&s)", &reply);
646                 debug_log("reply : %s", reply);
647                 if (!strcmp(reply, "STREAM_MANAGER_RETURN_ERROR"))
648                         ret = MM_ERROR_SOUND_INTERNAL;
649         } else {
650                 debug_error("reply null");
651         }
652
653 cleanup:
654         if (result)
655                 g_variant_unref(result);
656
657         debug_fleave();
658         return ret;
659 }
660
661 int mm_sound_proxy_unset_filter_by_type(const char *stream_type)
662 {
663         int ret = MM_ERROR_NONE;
664         char *reply = NULL;
665         GVariant *params = NULL, *result = NULL;
666
667         debug_fenter();
668
669         params = g_variant_new("(s)", stream_type);
670         if (params) {
671                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_UNSET_FILTER, params, &result)) != MM_ERROR_NONE) {
672                         debug_error("dbus unset filter by type failed");
673                         goto cleanup;
674                 }
675         } else {
676                 debug_error("construct param for method call failed");
677                 return MM_ERROR_SOUND_INTERNAL;
678         }
679
680         if (result) {
681                 g_variant_get(result, "(&s)", &reply);
682                 debug_log("reply : %s", reply);
683                 if (!strcmp(reply, "STREAM_MANAGER_RETURN_ERROR"))
684                         ret = MM_ERROR_SOUND_INTERNAL;
685         } else {
686                 debug_error("reply null");
687         }
688
689 cleanup:
690         if (result)
691                 g_variant_unref(result);
692
693         debug_fleave();
694         return ret;
695 }
696
697 int mm_sound_proxy_control_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_controls)
698 {
699         int ret = MM_ERROR_NONE;
700         char *reply = NULL;
701         GVariant *params = NULL, *result = NULL;
702
703         debug_fenter();
704
705         params = g_variant_new("(sss)", filter_name, filter_controls, stream_type);
706         if (params) {
707                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_CONTROL_FILTER, params, &result)) != MM_ERROR_NONE) {
708                         debug_error("dbus control filter by type failed");
709                         goto cleanup;
710                 }
711         } else {
712                 debug_error("construct param for method call failed");
713                 return MM_ERROR_SOUND_INTERNAL;
714         }
715
716         if (result) {
717                 g_variant_get(result, "(&s)", &reply);
718                 debug_log("reply : %s", reply);
719                 if (!strcmp(reply, "STREAM_MANAGER_RETURN_ERROR"))
720                         ret = MM_ERROR_SOUND_INTERNAL;
721         } else {
722                 debug_error("reply null");
723         }
724
725 cleanup:
726         if (result)
727                 g_variant_unref(result);
728
729         debug_fleave();
730         return ret;
731 }
732
733 int mm_sound_proxy_play_tone(int tone, int repeat, int volume, int volume_config,
734                            int session_type, int session_options, int client_pid,
735                            bool enable_session, int *codechandle, char *stream_type, int stream_index)
736 {
737         int ret = MM_ERROR_NONE;
738         int handle = 0;
739         GVariant *params = NULL, *result = NULL;
740         gboolean _enable_session = enable_session;
741
742         if (!codechandle) {
743                 debug_error("Param for play is null");
744                 return MM_ERROR_INVALID_ARGUMENT;
745         }
746
747         debug_fenter();
748
749         params = g_variant_new("(iiiiiiibsi)", tone, repeat, volume, volume_config, session_type,
750                                session_options, client_pid , _enable_session, stream_type, stream_index);
751         if (params) {
752                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_DTMF, params, &result)) != MM_ERROR_NONE) {
753                         debug_error("dbus play tone failed");
754                         goto cleanup;
755                 }
756         } else {
757                 debug_error("Construct Param for method call failed");
758         }
759
760         if (result) {
761                 g_variant_get(result, "(i)",  &handle);
762                 debug_log("handle : %d", handle);
763                 *codechandle = handle;
764         } else {
765                 debug_error("reply null");
766         }
767
768 cleanup:
769         if (result)
770                 g_variant_unref(result);
771
772         debug_fleave();
773         return ret;
774 }
775
776 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)
777 {
778         int ret = MM_ERROR_NONE;
779         int handle = 0;
780         GVariant *params = NULL, *result = NULL;
781
782         debug_fenter();
783
784         if (!codechandle) {
785                 debug_error("Param for play is null");
786                 return MM_ERROR_INVALID_ARGUMENT;
787         }
788
789         params = g_variant_new("(iiiisi)", tone, repeat, volume, client_pid, stream_type, stream_index);
790         if (params) {
791                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_DTMF_WITH_STREAM_INFO, params, &result)) != MM_ERROR_NONE) {
792                         debug_error("dbus play tone failed");
793                         goto cleanup;
794                 }
795         } else {
796                 debug_error("Construct Param for method call failed");
797         }
798
799         if (result) {
800                 g_variant_get(result, "(i)",  &handle);
801                 debug_log("handle : %d", handle);
802                 *codechandle = handle;
803         } else {
804                 debug_error("reply null");
805         }
806
807 cleanup:
808         if (result)
809                 g_variant_unref(result);
810
811         debug_fleave();
812         return ret;
813 }
814
815 int mm_sound_proxy_play_sound(const char* filename, int tone, int repeat, int volume, int volume_config,
816                            int session_type, int session_options, int client_pid, bool enable_session, int *codechandle,
817                            char *stream_type, int stream_index)
818 {
819         int ret = MM_ERROR_NONE;
820         int handle = 0;
821         GVariant *params = NULL, *result = NULL;
822         gboolean _enable_session = enable_session;
823
824         if (!filename || !codechandle) {
825                 debug_error("Param for play is null");
826                 return MM_ERROR_INVALID_ARGUMENT;
827         }
828
829         debug_fenter();
830
831         params = g_variant_new("(siiiiiiibsi)", filename, tone, repeat, volume,
832                       volume_config, session_type, session_options, client_pid, _enable_session, stream_type, stream_index);
833         if (params) {
834                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_FILE_START, params, &result)) != MM_ERROR_NONE) {
835                         debug_error("dbus play file failed");
836                         goto cleanup;
837                 }
838         } else {
839                 debug_error("Construct Param for method call failed");
840         }
841
842         if (result) {
843                 g_variant_get(result, "(i)",  &handle);
844                 debug_log("handle : %d", handle);
845                 *codechandle = handle;
846         } else {
847                 debug_error("reply null");
848         }
849
850 cleanup:
851         if (result)
852                 g_variant_unref(result);
853
854         debug_fleave();
855         return ret;
856 }
857
858 int mm_sound_proxy_play_sound_with_stream_info(const char* filename, int repeat, int volume,
859                                 int client_pid, int *codechandle, char *stream_type, int stream_index)
860 {
861         int ret = MM_ERROR_NONE;
862         int handle = 0;
863         GVariant *params = NULL, *result = NULL;
864
865         if (!filename || !codechandle) {
866                 debug_error("Param for play is null");
867                 return MM_ERROR_INVALID_ARGUMENT;
868         }
869
870         debug_fenter();
871
872         params = g_variant_new("(siiisi)", filename, repeat, volume, client_pid, stream_type, stream_index);
873         if (params) {
874                 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) {
875                         debug_error("dbus play file failed");
876                         goto cleanup;
877                 }
878         } else {
879                 debug_error("Construct Param for method call failed");
880         }
881
882         if (result) {
883                 g_variant_get(result, "(i)",  &handle);
884                 debug_log("handle : %d", handle);
885                 *codechandle = handle;
886         } else {
887                 debug_error("reply null");
888         }
889
890 cleanup:
891         if (result)
892                 g_variant_unref(result);
893
894         debug_fleave();
895         return ret;
896
897
898 }
899
900 int mm_sound_proxy_stop_sound(int handle)
901 {
902         int ret = MM_ERROR_NONE;
903         GVariant *result = NULL;
904
905         debug_fenter();
906
907         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) {
908                 debug_error("dbus stop file playing failed");
909                 goto cleanup;
910         }
911
912 cleanup:
913         if (result)
914                 g_variant_unref(result);
915
916         debug_fleave();
917         return ret;
918 }
919
920 int mm_sound_proxy_clear_focus(int pid)
921 {
922         int ret = MM_ERROR_NONE;
923         GVariant *result = NULL;
924
925         debug_fenter();
926
927         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)
928                 debug_error("dbus clear focus failed");
929
930         if (result)
931                 g_variant_unref(result);
932
933         debug_fleave();
934         return ret;
935 }
936
937 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)
938 {
939         int ret = MM_ERROR_NONE;
940         struct callback_data *cb_data;
941
942         debug_fenter();
943
944         CB_DATA_NEW(cb_data, func, userdata, freefunc);
945
946         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)
947                 debug_error("add play sound end callback failed");
948         else
949                 *subs_id = cb_data->subs_id;
950
951         debug_fleave();
952
953         return ret;
954 }
955
956 int mm_sound_proxy_remove_play_sound_end_callback(unsigned subs_id)
957 {
958         int ret = MM_ERROR_NONE;
959         debug_fenter();
960
961         if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
962                 debug_error("Remove Play File End callback failed");
963
964         debug_fleave();
965         return ret;
966 }
967
968 int mm_sound_proxy_emergent_exit(int exit_pid)
969 {
970         int ret = MM_ERROR_NONE;
971         GVariant *params = NULL;
972
973         debug_fenter();
974
975         params = g_variant_new("(i)", exit_pid);
976         if (params) {
977                 if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_EMERGENT_EXIT, params)) != MM_ERROR_NONE) {
978                         debug_error("dbus emergent exit failed");
979                         goto cleanup;
980                 }
981         } else {
982                 debug_error("Construct Param for emergent exit signal failed");
983                 ret = MM_ERROR_SOUND_INTERNAL;
984         }
985
986 cleanup:
987
988         debug_fleave();
989         return ret;
990 }
991
992 /*------------------------------------------ FOCUS --------------------------------------------------*/
993 #ifdef USE_FOCUS
994
995 int mm_sound_proxy_get_unique_id(int *id)
996 {
997         int ret = MM_ERROR_NONE;
998         int res = 0;
999         GVariant *result = NULL;
1000
1001         debug_fenter();
1002
1003         if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_GET_UNIQUE_ID, NULL, &result)) != MM_ERROR_NONE)
1004                 debug_error("dbus get unique id failed");
1005
1006         if (result) {
1007                 g_variant_get(result, "(i)", &res);
1008                 *id = res;
1009                 debug_msg("got unique id(%d)", *id);
1010                 g_variant_unref(result);
1011         }
1012
1013         debug_fleave();
1014
1015         return ret;
1016 }
1017
1018 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)
1019 {
1020         int ret = MM_ERROR_NONE;
1021         GVariant *params = NULL, *result = NULL;
1022
1023         debug_fenter();
1024
1025         params = g_variant_new("(iisb)", instance, id, stream_type, is_for_session);
1026         if (params) {
1027                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_REGISTER_FOCUS, params, &result)) != MM_ERROR_NONE)
1028                         debug_error("dbus register focus failed");
1029         } else {
1030                 debug_error("Construct Param for method call failed");
1031         }
1032
1033         if (ret != MM_ERROR_NONE)
1034                 g_variant_get(result, "(i)",  &ret);
1035         if (result)
1036                 g_variant_unref(result);
1037
1038         debug_fleave();
1039
1040         return ret;
1041
1042 }
1043
1044 int mm_sound_proxy_unregister_focus(int instance, int id, bool is_for_session)
1045 {
1046         int ret = MM_ERROR_NONE;
1047         GVariant *params = NULL, *result = NULL;
1048
1049         debug_fenter();
1050
1051         params = g_variant_new("(iib)", instance, id, is_for_session);
1052         if (params) {
1053                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_UNREGISTER_FOCUS, params, &result)) != MM_ERROR_NONE)
1054                         debug_error("dbus unregister focus failed");
1055         } else {
1056                 debug_error("Construct Param for method call failed");
1057         }
1058
1059         if (ret != MM_ERROR_NONE)
1060                 g_variant_get(result, "(i)",  &ret);
1061         if (result)
1062                 g_variant_unref(result);
1063
1064         debug_fleave();
1065
1066         return ret;
1067 }
1068
1069 int mm_sound_proxy_set_focus_reacquisition(int instance, int id, bool reacquisition, bool is_for_session)
1070 {
1071         int ret = MM_ERROR_NONE;
1072         GVariant *params = NULL, *result = NULL;
1073
1074         debug_fenter();
1075
1076         params = g_variant_new("(iibb)", instance, id, reacquisition, is_for_session);
1077         if (params) {
1078                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_SET_FOCUS_REACQUISITION, params, &result)) != MM_ERROR_NONE)
1079                         debug_error("dbus set focus reacquisition failed");
1080         } else {
1081                 debug_error("Construct Param for method call failed");
1082         }
1083
1084         if (ret != MM_ERROR_NONE)
1085                 g_variant_get(result, "(i)",  &ret);
1086         if (result)
1087                 g_variant_unref(result);
1088
1089         debug_fleave();
1090         return ret;
1091 }
1092
1093 int mm_sound_proxy_get_acquired_focus_stream_type(int focus_type, char **stream_type, int *option, char **ext_info)
1094 {
1095         int ret = MM_ERROR_NONE;
1096         GVariant *params = NULL, *result = NULL;
1097
1098         debug_fenter();
1099
1100         if (!(params = g_variant_new("(i)", focus_type))) {
1101                 debug_error("Construct Param for method call failed");
1102                 return MM_ERROR_SOUND_INTERNAL;
1103         }
1104
1105         if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_GET_ACQUIRED_FOCUS_STREAM_TYPE, params, &result)) == MM_ERROR_NONE) {
1106                 if (result) {
1107                         g_variant_get(result, "(sis)", stream_type, option, ext_info);
1108                         g_variant_unref(result);
1109                 }
1110         } else {
1111                 debug_error("dbus get stream type of acquired focus failed");
1112         }
1113
1114         debug_fleave();
1115         return ret;
1116 }
1117
1118 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)
1119 {
1120         int ret = MM_ERROR_NONE;
1121         bool is_in_focus_cb_thread = false;
1122
1123         debug_fenter();
1124
1125         mm_sound_client_is_focus_cb_thread(g_thread_self(), &is_in_focus_cb_thread);
1126         if (is_in_focus_cb_thread) {
1127                 if ((ret = mm_sound_focus_socket_acquire(instance, id, type, option, ext_info ? ext_info : "", true, is_for_session)))
1128                         debug_error("failed to mm_sound_focus_socket_acquire(), ret[0x%x]", ret);
1129         } else {
1130                 GVariant *params = NULL, *result = NULL;
1131
1132                 params = g_variant_new("(iiiisb)", instance, id, type, option, ext_info ? ext_info : "", is_for_session);
1133                 if (params) {
1134                         if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_ACQUIRE_FOCUS, params, &result)) != MM_ERROR_NONE)
1135                                 debug_error("dbus acquire focus failed");
1136                 } else {
1137                         debug_error("Construct Param for method call failed");
1138                 }
1139
1140                 if (ret != MM_ERROR_NONE)
1141                         g_variant_get(result, "(i)",  &ret);
1142                 if (result)
1143                         g_variant_unref(result);
1144         }
1145
1146         debug_fleave();
1147         return ret;
1148 }
1149
1150 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)
1151 {
1152         int ret = MM_ERROR_NONE;
1153         bool is_in_focus_cb_thread = false;
1154
1155         debug_fenter();
1156
1157         mm_sound_client_is_focus_cb_thread(g_thread_self(), &is_in_focus_cb_thread);
1158         if (is_in_focus_cb_thread) {
1159                 if ((ret = mm_sound_focus_socket_release(instance, id, type, option, ext_info ? ext_info : "", true, is_for_session)))
1160                         debug_error("failed to mm_sound_focus_socket_release(), ret[0x%x]", ret);
1161         } else {
1162                 GVariant *params = NULL, *result = NULL;
1163
1164                 params = g_variant_new("(iiiisb)", instance, id, type, option, ext_info ? ext_info : "", is_for_session);
1165                 if (params) {
1166                         if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_RELEASE_FOCUS, params, &result)) != MM_ERROR_NONE)
1167                                 debug_error("dbus release focus failed");
1168                 } else {
1169                         debug_error("Construct Param for method call failed");
1170                 }
1171
1172                 if (ret != MM_ERROR_NONE)
1173                         g_variant_get(result, "(i)",  &ret);
1174                 if (result)
1175                         g_variant_unref(result);
1176         }
1177
1178         debug_fleave();
1179         return ret;
1180 }
1181
1182 int mm_sound_proxy_update_stream_focus_status(int focus_id, unsigned int status)
1183 {
1184         int ret = MM_ERROR_NONE;
1185         char *reply = NULL;
1186         GVariant *params = NULL, *result = NULL;
1187
1188         debug_fenter();
1189
1190         params = g_variant_new("(iu)", focus_id, status);
1191         if (params) {
1192                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_UPDATE_STREAM_FOCUS_STATUS, params, &result)) != MM_ERROR_NONE) {
1193                         debug_error("dbus set volume by type failed");
1194                         if (result) {
1195                                 g_variant_get(result, "(&s)",  &reply);
1196                                 debug_log("reply : %s", reply);
1197                                 if (!strcmp(reply, "STREAM_MANAGER_RETURN_ERROR"))
1198                                         ret = MM_ERROR_SOUND_INTERNAL;
1199                         }
1200                 }
1201         } else {
1202                 debug_error("Construct Param for method call failed");
1203                 return MM_ERROR_SOUND_INTERNAL;
1204         }
1205
1206         if (result)
1207                 g_variant_unref(result);
1208
1209         debug_fleave();
1210         return ret;
1211 }
1212
1213 int mm_sound_proxy_deliver_focus(int pid, int src_id, int dst_id, mm_sound_focus_type_e focus_type)
1214 {
1215         int ret = MM_ERROR_NONE;
1216         char *reply = NULL;
1217         GVariant *params = NULL, *result = NULL;
1218
1219         debug_fenter();
1220
1221         params = g_variant_new("(iiii)", pid, src_id, dst_id, focus_type);
1222         if (params) {
1223                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_DELIVER_FOCUS, params, &result)) != MM_ERROR_NONE) {
1224                         debug_error("dbus deliver focus failed");
1225                         if (result) {
1226                                 g_variant_get(result, "(&s)", &reply);
1227                                 debug_log("reply : %s", reply);
1228                                 if (!strcmp(reply, "STREAM_MANAGER_RETURN_ERROR"))
1229                                         ret = MM_ERROR_SOUND_INTERNAL;
1230                         }
1231                 }
1232         } else {
1233                 debug_error("Construct Param for method call failed");
1234                 return MM_ERROR_SOUND_INTERNAL;
1235         }
1236
1237         if (result)
1238                 g_variant_unref(result);
1239
1240         debug_fleave();
1241         return ret;
1242 }
1243
1244 int mm_sound_proxy_set_focus_watch_callback(int instance, int handle, mm_sound_focus_type_e type, bool is_for_session, bool is_for_monitor, mm_sound_focus_changed_watch_cb callback, void* userdata)
1245 {
1246         int ret = MM_ERROR_NONE;
1247         GVariant *params = NULL, *result = NULL;
1248
1249         debug_fenter();
1250
1251         params = g_variant_new("(iiibb)", instance, handle, type, is_for_session, is_for_monitor);
1252         if (params) {
1253                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_WATCH_FOCUS, params, &result)) != MM_ERROR_NONE)
1254                         debug_error("dbus set watch focus failed");
1255         } else {
1256                 debug_error("Construct Param for method call failed");
1257         }
1258
1259         if (ret != MM_ERROR_NONE)
1260                 g_variant_get(result, "(i)",  &ret);
1261         if (result)
1262                 g_variant_unref(result);
1263         debug_fleave();
1264
1265         return ret;
1266
1267 }
1268
1269 int mm_sound_proxy_unset_focus_watch_callback(int focus_tid, int handle, bool is_for_session)
1270 {
1271         int ret = MM_ERROR_NONE;
1272         GVariant *params = NULL, *result = NULL;
1273
1274         debug_fenter();
1275
1276         params = g_variant_new("(iib)", focus_tid, handle, is_for_session);
1277         if (params) {
1278                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_UNWATCH_FOCUS, params, &result)) != MM_ERROR_NONE)
1279                         debug_error("dbus unset watch focus failed");
1280         } else {
1281                 debug_error("Construct Param for method call failed");
1282         }
1283         if (ret != MM_ERROR_NONE)
1284                 g_variant_get(result, "(i)",  &ret);
1285         if (result)
1286                 g_variant_unref(result);
1287
1288         debug_fleave();
1289
1290         return ret;
1291 }
1292
1293 #endif /* USE_FOCUS */
1294 /*------------------------------------------ FOCUS --------------------------------------------------*/
1295
1296 int mm_sound_proxy_initialize(void)
1297 {
1298         int ret = MM_ERROR_NONE;
1299
1300         debug_fenter();
1301         debug_fleave();
1302
1303         return ret;
1304 }
1305
1306 int mm_sound_proxy_finalize(void)
1307 {
1308         int ret = MM_ERROR_NONE;
1309
1310         debug_fenter();
1311         debug_fleave();
1312
1313         return ret;
1314 }