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