5ca029b2a30c9050e38ff9bcad11610d8dec12b7
[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(int tone, int repeat, int volume, int volume_config,
833                            int session_type, int session_options, int client_pid,
834                            bool enable_session, int *codechandle, char *stream_type, int stream_index)
835 {
836         int ret = MM_ERROR_NONE;
837         int handle = 0;
838         GVariant *params = NULL, *result = NULL;
839         gboolean _enable_session = enable_session;
840
841         if (!codechandle) {
842                 debug_error("Param for play is null");
843                 return MM_ERROR_INVALID_ARGUMENT;
844         }
845
846         debug_fenter();
847
848         params = g_variant_new("(iiiiiiibsi)", tone, repeat, volume, volume_config, session_type,
849                                                 session_options, client_pid, _enable_session, stream_type, stream_index);
850         if (params) {
851                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_DTMF, params, &result)) != MM_ERROR_NONE) {
852                         debug_error("dbus play tone failed");
853                         goto cleanup;
854                 }
855         } else {
856                 debug_error("Construct Param for method call failed");
857         }
858
859         if (result) {
860                 g_variant_get(result, "(i)",  &handle);
861                 debug_log("handle : %d", handle);
862                 *codechandle = handle;
863         } else {
864                 debug_error("reply null");
865         }
866
867 cleanup:
868         if (result)
869                 g_variant_unref(result);
870
871         debug_fleave();
872         return ret;
873 }
874
875 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)
876 {
877         int ret = MM_ERROR_NONE;
878         int handle = 0;
879         GVariant *params = NULL, *result = NULL;
880
881         debug_fenter();
882
883         if (!codechandle) {
884                 debug_error("Param for play is null");
885                 return MM_ERROR_INVALID_ARGUMENT;
886         }
887
888         params = g_variant_new("(iiiisi)", tone, repeat, volume, client_pid, stream_type, stream_index);
889         if (params) {
890                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_DTMF_WITH_STREAM_INFO, params, &result)) != MM_ERROR_NONE) {
891                         debug_error("dbus play tone failed");
892                         goto cleanup;
893                 }
894         } else {
895                 debug_error("Construct Param for method call failed");
896         }
897
898         if (result) {
899                 g_variant_get(result, "(i)",  &handle);
900                 debug_log("handle : %d", handle);
901                 *codechandle = handle;
902         } else {
903                 debug_error("reply null");
904         }
905
906 cleanup:
907         if (result)
908                 g_variant_unref(result);
909
910         debug_fleave();
911         return ret;
912 }
913
914 int mm_sound_proxy_play_sound(const char* filename, int tone, int repeat, int volume, int volume_config,
915                            int session_type, int session_options, int client_pid, bool enable_session, int *codechandle,
916                            char *stream_type, int stream_index)
917 {
918         int ret = MM_ERROR_NONE;
919         int handle = 0;
920         GVariant *params = NULL, *result = NULL;
921         gboolean _enable_session = enable_session;
922
923         if (!filename || !codechandle) {
924                 debug_error("Param for play is null");
925                 return MM_ERROR_INVALID_ARGUMENT;
926         }
927
928         debug_fenter();
929
930         params = g_variant_new("(siiiiiiibsi)", filename, tone, repeat, volume,
931                                 volume_config, session_type, session_options, client_pid, _enable_session, stream_type, stream_index);
932         if (params) {
933                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_FILE_START, params, &result)) != MM_ERROR_NONE) {
934                         debug_error("dbus play file failed");
935                         goto cleanup;
936                 }
937         } else {
938                 debug_error("Construct Param for method call failed");
939         }
940
941         if (result) {
942                 g_variant_get(result, "(i)",  &handle);
943                 debug_log("handle : %d", handle);
944                 *codechandle = handle;
945         } else {
946                 debug_error("reply null");
947         }
948
949 cleanup:
950         if (result)
951                 g_variant_unref(result);
952
953         debug_fleave();
954         return ret;
955 }
956
957 int mm_sound_proxy_play_sound_with_stream_info(const char* filename, int repeat, int volume,
958                                 int client_pid, int *codechandle, char *stream_type, int stream_index)
959 {
960         int ret = MM_ERROR_NONE;
961         int handle = 0;
962         GVariant *params = NULL, *result = NULL;
963
964         if (!filename || !codechandle) {
965                 debug_error("Param for play is null");
966                 return MM_ERROR_INVALID_ARGUMENT;
967         }
968
969         debug_fenter();
970
971         params = g_variant_new("(siiisi)", filename, repeat, volume, client_pid, stream_type, stream_index);
972         if (params) {
973                 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) {
974                         debug_error("dbus play file failed");
975                         goto cleanup;
976                 }
977         } else {
978                 debug_error("Construct Param for method call failed");
979         }
980
981         if (result) {
982                 g_variant_get(result, "(i)",  &handle);
983                 debug_log("handle : %d", handle);
984                 *codechandle = handle;
985         } else {
986                 debug_error("reply null");
987         }
988
989 cleanup:
990         if (result)
991                 g_variant_unref(result);
992
993         debug_fleave();
994         return ret;
995
996
997 }
998
999 int mm_sound_proxy_stop_sound(int handle)
1000 {
1001         int ret = MM_ERROR_NONE;
1002         GVariant *result = NULL;
1003
1004         debug_fenter();
1005
1006         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) {
1007                 debug_error("dbus stop file playing failed");
1008                 goto cleanup;
1009         }
1010
1011 cleanup:
1012         if (result)
1013                 g_variant_unref(result);
1014
1015         debug_fleave();
1016         return ret;
1017 }
1018
1019 int mm_sound_proxy_clear_focus(int pid)
1020 {
1021         int ret = MM_ERROR_NONE;
1022         GVariant *result = NULL;
1023
1024         debug_fenter();
1025
1026         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)
1027                 debug_error("dbus clear focus failed");
1028
1029         if (result)
1030                 g_variant_unref(result);
1031
1032         debug_fleave();
1033         return ret;
1034 }
1035
1036 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)
1037 {
1038         int ret = MM_ERROR_NONE;
1039         struct callback_data *cb_data;
1040
1041         debug_fenter();
1042
1043         CB_DATA_NEW(cb_data, func, userdata, freefunc);
1044
1045         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)
1046                 debug_error("add play sound end callback failed");
1047         else
1048                 *subs_id = cb_data->subs_id;
1049
1050         debug_fleave();
1051
1052         return ret;
1053 }
1054
1055 int mm_sound_proxy_remove_play_sound_end_callback(unsigned subs_id)
1056 {
1057         int ret = MM_ERROR_NONE;
1058         debug_fenter();
1059
1060         if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
1061                 debug_error("Remove Play File End callback failed");
1062
1063         debug_fleave();
1064         return ret;
1065 }
1066
1067 int mm_sound_proxy_emergent_exit(int exit_pid)
1068 {
1069         int ret = MM_ERROR_NONE;
1070         GVariant *params = NULL;
1071
1072 #ifndef TIZEN_TV
1073         debug_fenter();
1074 #endif
1075
1076         params = g_variant_new("(i)", exit_pid);
1077         if (params) {
1078                 if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_EMERGENT_EXIT, params)) != MM_ERROR_NONE) {
1079 #ifndef TIZEN_TV
1080                         debug_error("dbus emergent exit failed");
1081 #endif
1082                         goto cleanup;
1083                 }
1084         } else {
1085 #ifndef TIZEN_TV
1086                 debug_error("Construct Param for emergent exit signal failed");
1087 #endif
1088                 ret = MM_ERROR_SOUND_INTERNAL;
1089         }
1090
1091 cleanup:
1092
1093 #ifndef TIZEN_TV
1094         debug_fleave();
1095 #endif
1096         return ret;
1097 }
1098
1099 /*------------------------------------------ FOCUS --------------------------------------------------*/
1100 #ifdef USE_FOCUS
1101
1102 int mm_sound_proxy_get_unique_id(int *id)
1103 {
1104         int ret = MM_ERROR_NONE;
1105         int res = 0;
1106         GVariant *result = NULL;
1107
1108         debug_fenter();
1109
1110         if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_GET_UNIQUE_ID, NULL, &result)) != MM_ERROR_NONE)
1111                 debug_error("dbus get unique id failed");
1112
1113         if (result) {
1114                 g_variant_get(result, "(i)", &res);
1115                 *id = res;
1116                 debug_msg("got unique id(%d)", *id);
1117                 g_variant_unref(result);
1118         }
1119
1120         debug_fleave();
1121
1122         return ret;
1123 }
1124
1125 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)
1126 {
1127         int ret = MM_ERROR_NONE;
1128         GVariant *params = NULL, *result = NULL;
1129
1130         debug_fenter();
1131
1132         params = g_variant_new("(iisb)", instance, id, stream_type, is_for_session);
1133         if (params) {
1134                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_REGISTER_FOCUS, params, &result)) != MM_ERROR_NONE)
1135                         debug_error("dbus register 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         debug_fleave();
1146
1147         return ret;
1148
1149 }
1150
1151 int mm_sound_proxy_unregister_focus(int instance, int id, bool is_for_session)
1152 {
1153         int ret = MM_ERROR_NONE;
1154         GVariant *params = NULL, *result = NULL;
1155
1156         debug_fenter();
1157
1158         params = g_variant_new("(iib)", instance, id, is_for_session);
1159         if (params) {
1160                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_UNREGISTER_FOCUS, params, &result)) != MM_ERROR_NONE)
1161                         debug_error("dbus unregister focus failed");
1162         } else {
1163                 debug_error("Construct Param for method call failed");
1164         }
1165
1166         if (ret != MM_ERROR_NONE)
1167                 g_variant_get(result, "(i)",  &ret);
1168         if (result)
1169                 g_variant_unref(result);
1170
1171         debug_fleave();
1172
1173         return ret;
1174 }
1175
1176 int mm_sound_proxy_set_focus_reacquisition(int instance, int id, bool reacquisition, bool is_for_session)
1177 {
1178         int ret = MM_ERROR_NONE;
1179         GVariant *params = NULL, *result = NULL;
1180
1181         debug_fenter();
1182
1183         params = g_variant_new("(iibb)", instance, id, reacquisition, is_for_session);
1184         if (params) {
1185                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_SET_FOCUS_REACQUISITION, params, &result)) != MM_ERROR_NONE)
1186                         debug_error("dbus set focus reacquisition failed");
1187         } else {
1188                 debug_error("Construct Param for method call failed");
1189         }
1190
1191         if (ret != MM_ERROR_NONE)
1192                 g_variant_get(result, "(i)",  &ret);
1193         if (result)
1194                 g_variant_unref(result);
1195
1196         debug_fleave();
1197         return ret;
1198 }
1199
1200 int mm_sound_proxy_get_acquired_focus_stream_type(int focus_type, char **stream_type, int *option, char **ext_info)
1201 {
1202         int ret = MM_ERROR_NONE;
1203         GVariant *params = NULL, *result = NULL;
1204
1205         debug_fenter();
1206
1207         if (!(params = g_variant_new("(i)", focus_type))) {
1208                 debug_error("Construct Param for method call failed");
1209                 return MM_ERROR_SOUND_INTERNAL;
1210         }
1211
1212         if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_GET_ACQUIRED_FOCUS_STREAM_TYPE, params, &result)) == MM_ERROR_NONE) {
1213                 if (result) {
1214                         g_variant_get(result, "(sis)", stream_type, option, ext_info);
1215                         g_variant_unref(result);
1216                 }
1217         } else {
1218                 debug_error("dbus get stream type of acquired focus failed");
1219         }
1220
1221         debug_fleave();
1222         return ret;
1223 }
1224
1225 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)
1226 {
1227         int ret = MM_ERROR_NONE;
1228         bool is_in_focus_cb_thread = false;
1229
1230         debug_fenter();
1231
1232         mm_sound_client_is_focus_cb_thread(g_thread_self(), &is_in_focus_cb_thread);
1233         if (is_in_focus_cb_thread) {
1234                 if ((ret = mm_sound_focus_socket_acquire(instance, id, type, option, ext_info ? ext_info : "", true, is_for_session)))
1235                         debug_error("failed to mm_sound_focus_socket_acquire(), ret[0x%x]", ret);
1236         } else {
1237                 GVariant *params = NULL, *result = NULL;
1238
1239                 params = g_variant_new("(iiiisb)", instance, id, type, option, ext_info ? ext_info : "", is_for_session);
1240                 if (params) {
1241                         if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_ACQUIRE_FOCUS, params, &result)) != MM_ERROR_NONE)
1242                                 debug_error("dbus acquire focus failed");
1243                 } else {
1244                         debug_error("Construct Param for method call failed");
1245                 }
1246
1247                 if (ret != MM_ERROR_NONE)
1248                         g_variant_get(result, "(i)",  &ret);
1249                 if (result)
1250                         g_variant_unref(result);
1251         }
1252
1253         debug_fleave();
1254         return ret;
1255 }
1256
1257 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)
1258 {
1259         int ret = MM_ERROR_NONE;
1260         bool is_in_focus_cb_thread = false;
1261
1262         debug_fenter();
1263
1264         mm_sound_client_is_focus_cb_thread(g_thread_self(), &is_in_focus_cb_thread);
1265         if (is_in_focus_cb_thread) {
1266                 if ((ret = mm_sound_focus_socket_release(instance, id, type, option, ext_info ? ext_info : "", true, is_for_session)))
1267                         debug_error("failed to mm_sound_focus_socket_release(), ret[0x%x]", ret);
1268         } else {
1269                 GVariant *params = NULL, *result = NULL;
1270
1271                 params = g_variant_new("(iiiisb)", instance, id, type, option, ext_info ? ext_info : "", is_for_session);
1272                 if (params) {
1273                         if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_RELEASE_FOCUS, params, &result)) != MM_ERROR_NONE)
1274                                 debug_error("dbus release focus failed");
1275                 } else {
1276                         debug_error("Construct Param for method call failed");
1277                 }
1278
1279                 if (ret != MM_ERROR_NONE)
1280                         g_variant_get(result, "(i)",  &ret);
1281                 if (result)
1282                         g_variant_unref(result);
1283         }
1284
1285         debug_fleave();
1286         return ret;
1287 }
1288
1289 int mm_sound_proxy_update_stream_focus_status(int focus_id, unsigned int status)
1290 {
1291         int ret = MM_ERROR_NONE;
1292         char *reply = NULL;
1293         GVariant *params = NULL, *result = NULL;
1294
1295         debug_fenter();
1296
1297         params = g_variant_new("(iu)", focus_id, status);
1298         if (params) {
1299                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_UPDATE_STREAM_FOCUS_STATUS, params, &result)) != MM_ERROR_NONE) {
1300                         debug_error("dbus set volume by type failed");
1301                         if (result) {
1302                                 g_variant_get(result, "(&s)",  &reply);
1303                                 debug_log("reply : %s", reply);
1304                                 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
1305                                         ret = MM_ERROR_SOUND_INTERNAL;
1306                         }
1307                 }
1308         } else {
1309                 debug_error("Construct Param for method call failed");
1310                 return MM_ERROR_SOUND_INTERNAL;
1311         }
1312
1313         if (result)
1314                 g_variant_unref(result);
1315
1316         debug_fleave();
1317         return ret;
1318 }
1319
1320 int mm_sound_proxy_deliver_focus(int pid, int src_id, int dst_id, mm_sound_focus_type_e focus_type)
1321 {
1322         int ret = MM_ERROR_NONE;
1323         char *reply = NULL;
1324         GVariant *params = NULL, *result = NULL;
1325
1326         debug_fenter();
1327
1328         params = g_variant_new("(iiii)", pid, src_id, dst_id, focus_type);
1329         if (params) {
1330                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_DELIVER_FOCUS, params, &result)) != MM_ERROR_NONE) {
1331                         debug_error("dbus deliver focus failed");
1332                         if (result) {
1333                                 g_variant_get(result, "(&s)", &reply);
1334                                 debug_log("reply : %s", reply);
1335                                 if (strcmp(reply, "STREAM_MANAGER_RETURN_OK"))
1336                                         ret = MM_ERROR_SOUND_INTERNAL;
1337                         }
1338                 }
1339         } else {
1340                 debug_error("Construct Param for method call failed");
1341                 return MM_ERROR_SOUND_INTERNAL;
1342         }
1343
1344         if (result)
1345                 g_variant_unref(result);
1346
1347         debug_fleave();
1348         return ret;
1349 }
1350
1351 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)
1352 {
1353         int ret = MM_ERROR_NONE;
1354         GVariant *params = NULL, *result = NULL;
1355
1356         debug_fenter();
1357
1358         params = g_variant_new("(iiibb)", instance, handle, type, is_for_session, is_for_monitor);
1359         if (params) {
1360                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_WATCH_FOCUS, params, &result)) != MM_ERROR_NONE)
1361                         debug_error("dbus set watch focus failed");
1362         } else {
1363                 debug_error("Construct Param for method call failed");
1364         }
1365
1366         if (ret != MM_ERROR_NONE)
1367                 g_variant_get(result, "(i)",  &ret);
1368         if (result)
1369                 g_variant_unref(result);
1370         debug_fleave();
1371
1372         return ret;
1373
1374 }
1375
1376 int mm_sound_proxy_unset_focus_watch_callback(int focus_tid, int handle, bool is_for_session)
1377 {
1378         int ret = MM_ERROR_NONE;
1379         GVariant *params = NULL, *result = NULL;
1380
1381         debug_fenter();
1382
1383         params = g_variant_new("(iib)", focus_tid, handle, is_for_session);
1384         if (params) {
1385                 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_UNWATCH_FOCUS, params, &result)) != MM_ERROR_NONE)
1386                         debug_error("dbus unset watch focus failed");
1387         } else {
1388                 debug_error("Construct Param for method call failed");
1389         }
1390         if (ret != MM_ERROR_NONE)
1391                 g_variant_get(result, "(i)",  &ret);
1392         if (result)
1393                 g_variant_unref(result);
1394
1395         debug_fleave();
1396
1397         return ret;
1398 }
1399
1400 #endif /* USE_FOCUS */
1401 /*------------------------------------------ FOCUS --------------------------------------------------*/
1402
1403 int mm_sound_proxy_initialize(void)
1404 {
1405         int ret = MM_ERROR_NONE;
1406
1407         debug_fenter();
1408         debug_fleave();
1409
1410         return ret;
1411 }
1412
1413 int mm_sound_proxy_finalize(void)
1414 {
1415         int ret = MM_ERROR_NONE;
1416
1417         debug_fenter();
1418         debug_fleave();
1419
1420         return ret;
1421 }