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"
13 #include <security-server.h>
14 #define COOKIE_SIZE 20
18 struct callback_data {
21 mm_sound_proxy_userdata_free free_func;
25 #define CB_DATA_NEW(_cb_data, _func, _userdata, _freefunc) \
27 _cb_data = (struct callback_data*) g_malloc0(sizeof(struct callback_data)); \
28 _cb_data->user_cb = _func; \
29 _cb_data->user_data = _userdata; \
30 _cb_data->free_func = _freefunc; \
31 _cb_data->subs_id = 0; \
34 /* subscribe is true when add callback,
35 * false when remove callback */
36 static int _notify_subscription(audio_event_t event, uint32_t subs_id, gboolean subscribe)
38 int ret = MM_ERROR_NONE;
39 GVariant *params = NULL;
40 const char *event_name = NULL;
44 if ((ret = mm_sound_dbus_get_event_name(event, &event_name) != MM_ERROR_NONE)) {
45 debug_error("Failed to get event name");
46 return MM_ERROR_SOUND_INTERNAL;
49 if (!(params = g_variant_new("(sub)", event_name, subs_id, subscribe))) {
50 debug_error("Construct Param failed");
51 return MM_ERROR_SOUND_INTERNAL;
54 if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_CLIENT_SUBSCRIBED, params))) {
55 debug_error("dbus send signal for client subscribed failed");
62 static int _notify_signal_handled(audio_event_t event, uint32_t event_id, uint32_t subs_id, GVariant *signal_params)
64 int ret = MM_ERROR_NONE;
65 GVariant *params = NULL;
66 const char *event_name = NULL;
70 if ((ret = mm_sound_dbus_get_event_name(event, &event_name) != MM_ERROR_NONE)) {
71 debug_error("Failed to get event name");
72 return MM_ERROR_SOUND_INTERNAL;
75 if (!(params = g_variant_new("(usuv)", event_id, event_name, subs_id, signal_params))) {
76 debug_error("Construct Param failed");
77 return MM_ERROR_SOUND_INTERNAL;
80 if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_CLIENT_HANDLED, params))) {
81 debug_error("dbus send signal for client handled failed");
88 /* This callback unmarshall general-formed paramters to subject specific parameters,
89 * and call proper callback */
90 static void dbus_callback(audio_event_t event, GVariant *params, void *userdata)
92 struct callback_data *cb_data = (struct callback_data*) userdata;
95 if (event == AUDIO_EVENT_VOLUME_CHANGED) {
96 char *volume_type_str = NULL, *direction = NULL;
97 unsigned volume_level;
99 g_variant_get(params, "(&s&su)", &direction, &volume_type_str, &volume_level);
100 ((mm_sound_volume_changed_wrapper_cb)(cb_data->user_cb))(direction, volume_type_str, volume_level, cb_data->user_data);
101 } else if (event == AUDIO_EVENT_DEVICE_CONNECTED) {
102 const char *name = NULL, *device_type = NULL;
103 gboolean is_connected = FALSE;
104 int device_id, io_direction, state;
106 g_variant_get(params, "(u(i&sii&s)b)", &event_id, &device_id, &device_type, &io_direction,
107 &state, &name, &is_connected);
108 ((mm_sound_device_connected_wrapper_cb)(cb_data->user_cb))(device_id, device_type, io_direction, state, name, is_connected, cb_data->user_data);
109 _notify_signal_handled(event, event_id, cb_data->subs_id, g_variant_new("(ib)", device_id, is_connected));
110 } else if (event == AUDIO_EVENT_DEVICE_INFO_CHANGED) {
111 const char *name = NULL, *device_type = NULL;
112 int changed_device_info_type = 0;
113 int device_id, io_direction, state;
115 g_variant_get(params, "(u(i&sii&s)i)", &event_id, &device_id, &device_type, &io_direction,
116 &state, &name, &changed_device_info_type);
117 ((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);
118 } else if (event == AUDIO_EVENT_FOCUS_CHANGED) {
119 } else if (event == AUDIO_EVENT_FOCUS_WATCH) {
120 } else if (event == AUDIO_EVENT_TEST) {
122 g_variant_get(params, "(i)", &test_var);
123 ((mm_sound_test_cb)(cb_data->user_cb))(test_var, cb_data->user_data);
124 } else if (event == AUDIO_EVENT_PLAY_FILE_END) {
125 int ended_handle = 0;
126 g_variant_get(params, "(i)", &ended_handle);
127 ((mm_sound_stop_callback_wrapper_func)(cb_data->user_cb))(ended_handle, cb_data->user_data);
131 static void simple_callback_data_free_func(void *data)
133 struct callback_data *cb_data = (struct callback_data*) data;
136 if (cb_data->free_func)
137 cb_data->free_func(cb_data->user_data);
142 int mm_sound_proxy_add_test_callback(mm_sound_test_cb func, void *userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
144 int ret = MM_ERROR_NONE;
145 struct callback_data *cb_data;
149 CB_DATA_NEW(cb_data, func, userdata, freefunc);
151 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)
152 debug_error("add test callback failed");
154 *subs_id = cb_data->subs_id;
160 int mm_sound_proxy_remove_test_callback(unsigned subs_id)
162 int ret = MM_ERROR_NONE;
165 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
166 debug_error("remove test callback failed");
173 int mm_sound_proxy_test(int a, int b, int *get)
175 int ret = MM_ERROR_NONE;
177 GVariant *params = NULL, *result = NULL;
181 params = g_variant_new("(ii)", a, b);
183 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_TEST, params, &result)) != MM_ERROR_NONE) {
184 debug_error("dbus test call failed");
188 debug_error("Construct Param for method call failed");
189 return MM_ERROR_SOUND_INTERNAL;
193 g_variant_get(result, "(i)", &reply);
194 debug_log("reply : %d", reply);
197 debug_error("reply null");
202 g_variant_unref(result);
208 int mm_sound_proxy_get_current_connected_device_list(int device_flags, GList** device_list)
210 int ret = MM_ERROR_NONE;
211 GVariant *result = NULL, *child = NULL;
212 GVariant *params = NULL;
214 mm_sound_device_t* device_item;
215 const gchar *device_name_tmp = NULL, *device_type_tmp = NULL;
220 debug_error("Invalid Parameter, device_list null");
221 ret = MM_ERROR_INVALID_ARGUMENT;
225 params = g_variant_new("(i)", device_flags);
228 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_GET_CONNECTED_DEVICE_LIST, params, &result)) != MM_ERROR_NONE) {
229 debug_error("Get current connected device list failed");
233 debug_error("Construct Param for get current connected device failed");
234 return MM_ERROR_SOUND_INTERNAL;
237 child = g_variant_get_child_value(result, 0);
238 g_variant_iter_init(&iter, child);
240 device_item = g_malloc0(sizeof(mm_sound_device_t));
241 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)) {
242 MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM);
243 MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN);
244 *device_list = g_list_append(*device_list, device_item);
245 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);
255 g_variant_unref(result);
261 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)
263 int ret = MM_ERROR_NONE;
264 struct callback_data *cb_data;
268 CB_DATA_NEW(cb_data, func, userdata, freefunc);
270 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) {
271 debug_error("add device connected callback failed");
275 if ((ret = _notify_subscription(AUDIO_EVENT_DEVICE_CONNECTED, cb_data->subs_id, TRUE)) != MM_ERROR_NONE) {
276 debug_error("failed to notify subscription of device connected event");
280 *subs_id = cb_data->subs_id;
287 int mm_sound_proxy_remove_device_connected_callback(unsigned subs_id)
289 int ret = MM_ERROR_NONE;
292 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
293 debug_error("remove device connected callback failed");
297 if ((ret = _notify_subscription(AUDIO_EVENT_DEVICE_CONNECTED, subs_id, FALSE)) != MM_ERROR_NONE)
298 debug_error("failed to notify unsubscription of device connected event");
305 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)
307 int ret = MM_ERROR_NONE;
308 struct callback_data *cb_data;
312 CB_DATA_NEW(cb_data, func, userdata, freefunc);
314 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)
315 debug_error("Add device info changed callback failed");
317 *subs_id = cb_data->subs_id;
323 int mm_sound_proxy_remove_device_info_changed_callback(unsigned subs_id)
325 int ret = MM_ERROR_NONE;
328 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
329 debug_error("remove device info changed callback failed");
336 int mm_sound_proxy_set_volume_by_type(const char *volume_type, const unsigned volume_level)
338 int ret = MM_ERROR_NONE;
339 char *reply = NULL, *direction = "out";
340 GVariant *params = NULL, *result = NULL;
344 params = g_variant_new("(ssu)", direction, volume_type, volume_level);
346 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_SET_VOLUME_LEVEL, params, &result)) != MM_ERROR_NONE) {
347 debug_error("dbus set volume by type failed");
351 debug_error("Construct Param for method call failed");
352 return MM_ERROR_SOUND_INTERNAL;
356 g_variant_get(result, "(&s)", &reply);
357 debug_log("reply : %s", reply);
358 if (!strcmp(reply, "STREAM_MANAGER_RETURN_ERROR"))
359 ret = MM_ERROR_SOUND_INTERNAL;
361 debug_error("reply null");
366 g_variant_unref(result);
372 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)
374 int ret = MM_ERROR_NONE;
375 struct callback_data *cb_data;
379 CB_DATA_NEW(cb_data, func, userdata, freefunc);
381 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)
382 debug_error("Add Volume changed callback failed");
384 *subs_id = cb_data->subs_id;
392 int mm_sound_proxy_remove_volume_changed_callback(unsigned subs_id)
394 int ret = MM_ERROR_NONE;
397 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
398 debug_error("Remove Volume changed callback failed");
405 int mm_sound_proxy_play_tone(int tone, int repeat, int volume, int volume_config,
406 int session_type, int session_options, int client_pid,
407 bool enable_session, int *codechandle, char *stream_type, int stream_index)
409 int ret = MM_ERROR_NONE;
411 GVariant *params = NULL, *result = NULL;
412 gboolean _enable_session = enable_session;
415 debug_error("Param for play is null");
416 return MM_ERROR_INVALID_ARGUMENT;
421 params = g_variant_new("(iiiiiiibsi)", tone, repeat, volume,
422 volume_config, session_type, session_options, client_pid , _enable_session, stream_type, stream_index);
424 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_DTMF, params, &result)) != MM_ERROR_NONE) {
425 debug_error("dbus play tone failed");
429 debug_error("Construct Param for method call failed");
433 g_variant_get(result, "(i)", &handle);
434 debug_log("handle : %d", handle);
435 *codechandle = handle;
437 debug_error("reply null");
442 g_variant_unref(result);
450 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)
452 int ret = MM_ERROR_NONE;
454 GVariant *params = NULL, *result = NULL;
459 debug_error("Param for play is null");
460 return MM_ERROR_INVALID_ARGUMENT;
463 params = g_variant_new("(iiiisi)", tone, repeat, volume, client_pid, stream_type, stream_index);
465 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_DTMF_WITH_STREAM_INFO, params, &result)) != MM_ERROR_NONE) {
466 debug_error("dbus play tone failed");
470 debug_error("Construct Param for method call failed");
474 g_variant_get(result, "(i)", &handle);
475 debug_log("handle : %d", handle);
476 *codechandle = handle;
478 debug_error("reply null");
483 g_variant_unref(result);
491 int mm_sound_proxy_play_sound(const char* filename, int tone, int repeat, int volume, int volume_config,
492 int priority, int session_type, int session_options, int client_pid, int handle_route,
493 bool enable_session, int *codechandle, char *stream_type, int stream_index)
495 int ret = MM_ERROR_NONE;
497 GVariant *params = NULL, *result = NULL;
498 gboolean _enable_session = enable_session;
500 if (!filename || !codechandle) {
501 debug_error("Param for play is null");
502 return MM_ERROR_INVALID_ARGUMENT;
507 params = g_variant_new("(siiiiiiiiibsi)", filename, tone, repeat, volume,
508 volume_config, priority, session_type, session_options, client_pid, handle_route, _enable_session, stream_type, stream_index);
510 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_FILE_START, params, &result)) != MM_ERROR_NONE) {
511 debug_error("dbus play file failed");
515 debug_error("Construct Param for method call failed");
519 g_variant_get(result, "(i)", &handle);
520 debug_log("handle : %d", handle);
521 *codechandle = handle;
523 debug_error("reply null");
528 g_variant_unref(result);
534 int mm_sound_proxy_play_sound_with_stream_info(const char* filename, int repeat, int volume,
535 int priority, int client_pid, int handle_route, int *codechandle, char *stream_type, int stream_index)
537 int ret = MM_ERROR_NONE;
539 GVariant *params = NULL, *result = NULL;
541 if (!filename || !codechandle) {
542 debug_error("Param for play is null");
543 return MM_ERROR_INVALID_ARGUMENT;
548 params = g_variant_new("(siiiiisi)", filename, repeat, volume,
549 priority, client_pid, handle_route, stream_type, stream_index);
551 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) {
552 debug_error("dbus play file failed");
556 debug_error("Construct Param for method call failed");
560 g_variant_get(result, "(i)", &handle);
561 debug_log("handle : %d", handle);
562 *codechandle = handle;
564 debug_error("reply null");
569 g_variant_unref(result);
578 int mm_sound_proxy_stop_sound(int handle)
580 int ret = MM_ERROR_NONE;
581 GVariant *result = NULL;
585 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) {
586 debug_error("dbus stop file playing failed");
592 g_variant_unref(result);
598 int mm_sound_proxy_clear_focus(int pid)
600 int ret = MM_ERROR_NONE;
601 GVariant *result = NULL;
605 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) {
606 debug_error("dbus clear focus failed");
610 g_variant_unref(result);
616 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)
618 int ret = MM_ERROR_NONE;
619 struct callback_data *cb_data;
623 CB_DATA_NEW(cb_data, func, userdata, freefunc);
625 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)
626 debug_error("add play sound end callback failed");
628 *subs_id = cb_data->subs_id;
635 int mm_sound_proxy_remove_play_sound_end_callback(unsigned subs_id)
637 int ret = MM_ERROR_NONE;
640 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
641 debug_error("Remove Play File End callback failed");
648 int mm_sound_proxy_emergent_exit(int exit_pid)
650 int ret = MM_ERROR_NONE;
651 GVariant *params = NULL;
655 params = g_variant_new("(i)", exit_pid);
657 if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_EMERGENT_EXIT, params)) != MM_ERROR_NONE) {
658 debug_error("dbus emergent exit failed");
662 debug_error("Construct Param for emergent exit signal failed");
663 ret = MM_ERROR_SOUND_INTERNAL;
672 /*------------------------------------------ FOCUS --------------------------------------------------*/
675 #ifdef SUPPORT_CONTAINER
677 char* _get_cookie(int cookie_size)
682 if (security_server_get_cookie_size() != cookie_size) {
683 debug_error ("[Security] security_server_get_cookie_size() != COOKIE_SIZE(%d)\n", cookie_size);
687 cookie = (char*)malloc (cookie_size);
689 retval = security_server_request_cookie (cookie, cookie_size);
690 if (retval == SECURITY_SERVER_API_SUCCESS) {
691 debug_msg ("[Security] security_server_request_cookie() returns [%d]\n", retval);
693 debug_error ("[Security] security_server_request_cookie() returns [%d]\n", retval);
699 static GVariant* _get_cookie_variant ()
702 GVariantBuilder builder;
705 cookie = _get_cookie(COOKIE_SIZE);
710 g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
711 for (i = 0; i < COOKIE_SIZE; i++)
712 g_variant_builder_add(&builder, "y", cookie[i]);
715 return g_variant_builder_end(&builder);
718 #endif /* USE_SECURITY */
719 #endif /* SUPPORT_CONTAINER */
721 int mm_sound_proxy_get_unique_id(int *id)
723 int ret = MM_ERROR_NONE;
725 GVariant *result = NULL;
729 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_GET_UNIQUE_ID, NULL, &result)) != MM_ERROR_NONE) {
730 debug_error("dbus get unique id failed");
734 g_variant_get(result, "(i)", &res);
736 debug_msg("got unique id(%d)", *id);
737 g_variant_unref(result);
745 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)
747 int ret = MM_ERROR_NONE;
748 GVariant *params = NULL, *result = NULL;
749 #ifdef SUPPORT_CONTAINER
755 #ifdef SUPPORT_CONTAINER
757 params = g_variant_new("(@ayiisb)", _get_cookie_variant(), instance, id, stream_type, is_for_session);
758 #else /* USE_SECURITY */
759 gethostname(container, sizeof(container));
760 debug_error("container = %s", container);
761 params = g_variant_new("(siisb)", container, instance, id, stream_type, is_for_session);
762 #endif /* USE_SECURITY */
764 #else /* SUPPORT_CONTAINER */
765 params = g_variant_new("(iisb)", instance, id, stream_type, is_for_session);
767 #endif /* SUPPORT_CONTAINER */
770 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_REGISTER_FOCUS, params, &result)) != MM_ERROR_NONE) {
771 debug_error("dbus register focus failed");
774 debug_error("Construct Param for method call failed");
777 if (ret != MM_ERROR_NONE)
778 g_variant_get(result, "(i)", &ret);
780 g_variant_unref(result);
788 int mm_sound_proxy_unregister_focus(int instance, int id, bool is_for_session)
790 int ret = MM_ERROR_NONE;
791 GVariant *params = NULL, *result = NULL;
795 params = g_variant_new("(iib)", instance, id, is_for_session);
797 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_UNREGISTER_FOCUS, params, &result)) != MM_ERROR_NONE) {
798 debug_error("dbus unregister focus failed");
801 debug_error("Construct Param for method call failed");
804 if (ret != MM_ERROR_NONE)
805 g_variant_get(result, "(i)", &ret);
807 g_variant_unref(result);
814 int mm_sound_proxy_set_foucs_reacquisition(int instance, int id, bool reacquisition)
816 int ret = MM_ERROR_NONE;
817 GVariant *params = NULL, *result = NULL;
821 params = g_variant_new("(iib)", instance, id, reacquisition);
823 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_SET_FOCUS_REACQUISITION, params, &result)) != MM_ERROR_NONE) {
824 debug_error("dbus set focus reacquisition failed");
827 debug_error("Construct Param for method call failed");
830 if (ret != MM_ERROR_NONE)
831 g_variant_get(result, "(i)", &ret);
833 g_variant_unref(result);
839 int mm_sound_proxy_get_acquired_focus_stream_type(int focus_type, char **stream_type, char **additional_info)
841 int ret = MM_ERROR_NONE;
842 GVariant *params = NULL, *result = NULL;
846 if (!(params = g_variant_new("(i)", focus_type))) {
847 debug_error("Construct Param for method call failed");
848 return MM_ERROR_SOUND_INTERNAL;
851 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_GET_ACQUIRED_FOCUS_STREAM_TYPE, params, &result)) == MM_ERROR_NONE) {
853 g_variant_get(result, "(ss)", stream_type, additional_info);
854 g_variant_unref(result);
857 debug_error("dbus get stream type of acquired focus failed");
864 int mm_sound_proxy_acquire_focus(int instance, int id, mm_sound_focus_type_e type, const char *option, bool is_for_session)
866 int ret = MM_ERROR_NONE;
867 GVariant *params = NULL, *result = NULL;
871 params = g_variant_new("(iiisb)", instance, id, type, option ? option : "", is_for_session);
873 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_ACQUIRE_FOCUS, params, &result)) != MM_ERROR_NONE) {
874 debug_error("dbus acquire focus failed");
877 debug_error("Construct Param for method call failed");
880 if (ret != MM_ERROR_NONE)
881 g_variant_get(result, "(i)", &ret);
883 g_variant_unref(result);
889 int mm_sound_proxy_release_focus(int instance, int id, mm_sound_focus_type_e type, const char *option, bool is_for_session)
891 int ret = MM_ERROR_NONE;
892 GVariant *params = NULL, *result = NULL;
896 params = g_variant_new("(iiisb)", instance, id, type, option ? option : "", is_for_session);
898 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_RELEASE_FOCUS, params, &result)) != MM_ERROR_NONE) {
899 debug_error("dbus release focus failed");
902 debug_error("Construct Param for method call failed");
905 if (ret != MM_ERROR_NONE)
906 g_variant_get(result, "(i)", &ret);
908 g_variant_unref(result);
914 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)
916 int ret = MM_ERROR_NONE;
917 GVariant *params = NULL, *result = NULL;
918 #ifdef SUPPORT_CONTAINER
923 #ifdef SUPPORT_CONTAINER
925 params = g_variant_new("(@ayiiib)", _get_cookie_variant(), instance, handle, type, is_for_session);
926 #else /* USE_SECURITY */
927 gethostname(container, sizeof(container));
928 debug_error("container = %s", container);
929 params = g_variant_new("(siiib)", container, instance, handle, type, is_for_session);
930 #endif /* USE_SECURITY */
932 #else /* SUPPORT_CONTAINER */
933 params = g_variant_new("(iiib)", instance, handle, type, is_for_session);
934 #endif /* SUPPORT_CONTAINER */
937 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_WATCH_FOCUS, params, &result)) != MM_ERROR_NONE) {
938 debug_error("dbus set watch focus failed");
941 debug_error("Construct Param for method call failed");
944 if (ret != MM_ERROR_NONE)
945 g_variant_get(result, "(i)", &ret);
947 g_variant_unref(result);
954 int mm_sound_proxy_unset_focus_watch_callback(int focus_tid, int handle, bool is_for_session)
956 int ret = MM_ERROR_NONE;
957 GVariant *params = NULL, *result = NULL;
961 params = g_variant_new("(iib)", focus_tid, handle, is_for_session);
963 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_UNWATCH_FOCUS, params, &result)) != MM_ERROR_NONE) {
964 debug_error("dbus unset watch focus failed");
967 debug_error("Construct Param for method call failed");
969 if (ret != MM_ERROR_NONE)
970 g_variant_get(result, "(i)", &ret);
972 g_variant_unref(result);
979 #endif /* USE_FOCUS */
980 /*------------------------------------------ FOCUS --------------------------------------------------*/
982 int mm_sound_proxy_initialize(void)
984 int ret = MM_ERROR_NONE;
992 int mm_sound_proxy_finalize(void)
994 int ret = MM_ERROR_NONE;