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