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