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