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