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"
12 struct callback_data {
15 mm_sound_proxy_userdata_free free_func;
19 #define CB_DATA_NEW(_cb_data, _func, _userdata, _freefunc) \
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; \
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)
32 int ret = MM_ERROR_NONE;
33 GVariant *params = NULL;
34 const char *event_name = NULL;
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;
43 if (!(params = g_variant_new("(sub)", event_name, subs_id, subscribe))) {
44 debug_error("Construct Param failed");
45 return MM_ERROR_SOUND_INTERNAL;
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");
56 static int _notify_signal_handled(audio_event_t event, uint32_t event_id, uint32_t subs_id, GVariant *signal_params)
58 int ret = MM_ERROR_NONE;
59 GVariant *params = NULL;
60 const char *event_name = NULL;
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;
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;
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");
82 static int parse_device_variant(GVariant *v, int *device_id, const char **device_type, int *direction, int *state,
83 const char **device_name, int *stream_id, int *stream_num)
87 GVariantIter iter, array_iter;
89 int ret = MM_ERROR_NONE;
92 debug_error("Variant NULL");
96 v_type = g_variant_get_type_string(v);
97 if (g_variant_type_equal(v_type, "(isiisai)") == FALSE) {
98 debug_error("device variant type not matching '%s'", v_type);
102 g_variant_iter_init(&iter, v);
103 g_variant_iter_next(&iter, "i", device_id);
104 g_variant_iter_next(&iter, "&s", device_type);
105 g_variant_iter_next(&iter, "i", direction);
106 g_variant_iter_next(&iter, "i", state);
107 g_variant_iter_next(&iter, "&s", device_name);
109 array_v = g_variant_iter_next_value(&iter);
110 *stream_num = g_variant_iter_init(&array_iter, array_v);
111 if (*stream_num > MAX_STREAM_ON_DEVICE) {
112 debug_error("too many streams on device %d", *stream_num);
113 ret = MM_ERROR_SOUND_INTERNAL;
117 while (g_variant_iter_loop(&array_iter, "i", &stream_id[i++])) ;
119 g_variant_unref(array_v);
124 /* This callback unmarshall general-formed paramters to subject specific parameters,
125 * and call proper callback */
126 static void dbus_callback(audio_event_t event, GVariant *params, void *userdata)
128 struct callback_data *cb_data = (struct callback_data*) userdata;
130 const char *name = NULL, *device_type = NULL;
131 int device_id, direction, state;
135 int stream_id[MAX_STREAM_ON_DEVICE];
138 v_type = g_variant_get_type_string(params);
140 if (event == AUDIO_EVENT_VOLUME_CHANGED) {
141 char *volume_type_str = NULL, *direction = NULL;
142 unsigned volume_level;
144 g_variant_get(params, "(&s&su)", &direction, &volume_type_str, &volume_level);
145 ((mm_sound_volume_changed_wrapper_cb)(cb_data->user_cb))(direction, volume_type_str, volume_level, cb_data->user_data);
146 } else if (event == AUDIO_EVENT_DEVICE_CONNECTED) {
147 gboolean is_connected = FALSE;
149 if (g_variant_type_equal(v_type, "(u(isiisai)b)") == FALSE) {
150 debug_error("Device connection changed signature not matching : %s", v_type);
153 g_variant_iter_init(&iter, params);
154 g_variant_iter_next(&iter, "u", &event_id);
155 device_v = g_variant_iter_next_value(&iter);
156 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
157 &name, stream_id, &stream_num) < 0) {
158 debug_error("Failed to parse device variant");
161 g_variant_iter_next(&iter, "b", &is_connected);
163 ((mm_sound_device_connected_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
164 state, name, stream_id, stream_num, is_connected, cb_data->user_data);
165 _notify_signal_handled(event, event_id, cb_data->subs_id, g_variant_new("(ib)", device_id, is_connected));
166 } else if (event == AUDIO_EVENT_DEVICE_INFO_CHANGED) {
167 int changed_device_info_type = 0;
169 if (g_variant_type_equal(v_type, "(u(isiisai)i)") == FALSE) {
170 debug_error("Device information changed signature not matching : %s", v_type);
174 g_variant_iter_init(&iter, params);
175 g_variant_iter_next(&iter, "u", &event_id);
176 device_v = g_variant_iter_next_value(&iter);
177 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
178 &name, stream_id, &stream_num) < 0) {
179 debug_error("Failed to parse device variant");
182 g_variant_iter_next(&iter, "i", &changed_device_info_type);
184 ((mm_sound_device_info_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
185 state, name, stream_id, stream_num, changed_device_info_type, cb_data->user_data);
186 } else if (event == AUDIO_EVENT_DEVICE_STATE_CHANGED) {
188 if (g_variant_type_equal(v_type, "(u(isiisai))") == FALSE) {
189 debug_error("Device state changed signature not matching : %s", v_type);
193 g_variant_iter_init(&iter, params);
194 g_variant_iter_next(&iter, "u", &event_id);
195 device_v = g_variant_iter_next_value(&iter);
196 if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
197 &name, stream_id, &stream_num) < 0) {
198 debug_error("Failed to parse device variant");
202 ((mm_sound_device_state_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
203 state, name, stream_id, stream_num, cb_data->user_data);
204 } else if (event == AUDIO_EVENT_FOCUS_CHANGED) {
205 } else if (event == AUDIO_EVENT_FOCUS_WATCH) {
206 } else if (event == AUDIO_EVENT_TEST) {
208 g_variant_get(params, "(i)", &test_var);
209 ((mm_sound_test_cb)(cb_data->user_cb))(test_var, cb_data->user_data);
210 } else if (event == AUDIO_EVENT_PLAY_FILE_END) {
211 int ended_handle = 0;
212 g_variant_get(params, "(i)", &ended_handle);
213 ((mm_sound_stop_callback_wrapper_func)(cb_data->user_cb))(ended_handle, cb_data->user_data);
217 static void simple_callback_data_free_func(void *data)
219 struct callback_data *cb_data = (struct callback_data*) data;
222 if (cb_data->free_func)
223 cb_data->free_func(cb_data->user_data);
228 int mm_sound_proxy_add_test_callback(mm_sound_test_cb func, void *userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
230 int ret = MM_ERROR_NONE;
231 struct callback_data *cb_data;
235 CB_DATA_NEW(cb_data, func, userdata, freefunc);
237 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)
238 debug_error("add test callback failed");
240 *subs_id = cb_data->subs_id;
246 int mm_sound_proxy_remove_test_callback(unsigned subs_id)
248 int ret = MM_ERROR_NONE;
251 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
252 debug_error("remove test callback failed");
259 int mm_sound_proxy_test(int a, int b, int *get)
261 int ret = MM_ERROR_NONE;
263 GVariant *params = NULL, *result = NULL;
267 params = g_variant_new("(ii)", a, b);
269 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_TEST, params, &result)) != MM_ERROR_NONE) {
270 debug_error("dbus test call failed");
274 debug_error("Construct Param for method call failed");
275 return MM_ERROR_SOUND_INTERNAL;
279 g_variant_get(result, "(i)", &reply);
280 debug_log("reply : %d", reply);
283 debug_error("reply null");
288 g_variant_unref(result);
294 int mm_sound_proxy_is_stream_on_device(int stream_id, int device_id, bool *is_on)
296 int ret = MM_ERROR_NONE;
297 GVariant *params, *result;
303 debug_error("Invalid Parameter, is_on null");
304 return MM_ERROR_INVALID_ARGUMENT;
307 if ((params = g_variant_new("(ii)", stream_id, device_id)) == NULL) {
308 debug_error("Construct Param for query is stream on device failed");
309 return MM_ERROR_SOUND_INTERNAL;
312 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_IS_STREAM_ON_DEVICE, params, &result)) != MM_ERROR_NONE) {
313 debug_error("is stream on device failed");
318 g_variant_get(result, "(b)", &_is_on);
319 debug_log("is_on : %d", _is_on);
320 *is_on = (bool)_is_on;
322 debug_error("reply null");
323 ret = MM_ERROR_SOUND_INTERNAL;
328 g_variant_unref(params);
330 g_variant_unref(result);
336 int mm_sound_proxy_get_current_connected_device_list(int device_flags, GList** device_list)
338 int ret = MM_ERROR_NONE;
339 GVariant *result = NULL, *child = NULL;
340 GVariant *params = NULL;
342 mm_sound_device_t* device_item;
343 const gchar *device_name_tmp = NULL, *device_type_tmp = NULL;
348 debug_error("Invalid Parameter, device_list null");
349 ret = MM_ERROR_INVALID_ARGUMENT;
353 params = g_variant_new("(i)", device_flags);
356 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_GET_CONNECTED_DEVICE_LIST, params, &result)) != MM_ERROR_NONE) {
357 debug_error("Get current connected device list failed");
361 debug_error("Construct Param for get current connected device failed");
362 return MM_ERROR_SOUND_INTERNAL;
365 child = g_variant_get_child_value(result, 0);
366 g_variant_iter_init(&iter, child);
368 device_item = g_malloc0(sizeof(mm_sound_device_t));
369 if (device_item && g_variant_iter_loop(&iter, "(i&sii&s)",
370 &device_item->id, &device_type_tmp, &device_item->io_direction, &device_item->state,
372 MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM);
373 MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN);
374 *device_list = g_list_append(*device_list, device_item);
375 debug_log("Added device id(%d) type(%17s) direction(%d) state(%d) name(%s)",
376 device_item->id, device_item->type,device_item->io_direction, device_item->state,
378 device_item->stream_num = -1;
388 g_variant_unref(result);
394 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)
396 int ret = MM_ERROR_NONE;
397 struct callback_data *cb_data;
401 CB_DATA_NEW(cb_data, func, userdata, freefunc);
403 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) {
404 debug_error("add device connected callback failed");
408 if ((ret = _notify_subscription(AUDIO_EVENT_DEVICE_CONNECTED, cb_data->subs_id, TRUE)) != MM_ERROR_NONE) {
409 debug_error("failed to notify subscription of device connected event");
413 *subs_id = cb_data->subs_id;
420 int mm_sound_proxy_remove_device_connected_callback(unsigned subs_id)
422 int ret = MM_ERROR_NONE;
425 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
426 debug_error("remove device connected callback failed");
430 if ((ret = _notify_subscription(AUDIO_EVENT_DEVICE_CONNECTED, subs_id, FALSE)) != MM_ERROR_NONE)
431 debug_error("failed to notify unsubscription of device connected event");
438 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)
440 int ret = MM_ERROR_NONE;
441 struct callback_data *cb_data;
445 CB_DATA_NEW(cb_data, func, userdata, freefunc);
447 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)
448 debug_error("Add device info changed callback failed");
450 *subs_id = cb_data->subs_id;
456 int mm_sound_proxy_remove_device_info_changed_callback(unsigned subs_id)
458 int ret = MM_ERROR_NONE;
461 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
462 debug_error("remove device info changed callback failed");
469 int mm_sound_proxy_add_device_state_changed_callback(int device_flags, mm_sound_device_state_changed_wrapper_cb func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
471 int ret = MM_ERROR_NONE;
472 struct callback_data *cb_data;
476 CB_DATA_NEW(cb_data, func, userdata, freefunc);
478 if ((ret = mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_EVENT_DEVICE_STATE_CHANGED, dbus_callback, cb_data, simple_callback_data_free_func, &cb_data->subs_id)) != MM_ERROR_NONE)
479 debug_error("Add device state changed callback failed");
481 *subs_id = cb_data->subs_id;
487 int mm_sound_proxy_remove_device_state_changed_callback(unsigned subs_id)
489 int ret = MM_ERROR_NONE;
492 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
493 debug_error("remove device state changed callback failed");
500 int mm_sound_proxy_set_volume_by_type(const char *volume_type, const unsigned volume_level)
502 int ret = MM_ERROR_NONE;
503 char *reply = NULL, *direction = "out";
504 GVariant *params = NULL, *result = NULL;
508 params = g_variant_new("(ssu)", direction, volume_type, volume_level);
510 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_SET_VOLUME_LEVEL, params, &result)) != MM_ERROR_NONE) {
511 debug_error("dbus set volume by type failed");
515 debug_error("Construct Param for method call failed");
516 return MM_ERROR_SOUND_INTERNAL;
520 g_variant_get(result, "(&s)", &reply);
521 debug_log("reply : %s", reply);
522 if (!strcmp(reply, "STREAM_MANAGER_RETURN_ERROR"))
523 ret = MM_ERROR_SOUND_INTERNAL;
525 debug_error("reply null");
530 g_variant_unref(result);
536 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)
538 int ret = MM_ERROR_NONE;
539 struct callback_data *cb_data;
543 CB_DATA_NEW(cb_data, func, userdata, freefunc);
545 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)
546 debug_error("Add Volume changed callback failed");
548 *subs_id = cb_data->subs_id;
556 int mm_sound_proxy_remove_volume_changed_callback(unsigned subs_id)
558 int ret = MM_ERROR_NONE;
561 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
562 debug_error("Remove Volume changed callback failed");
569 int mm_sound_proxy_play_tone(int tone, int repeat, int volume, int volume_config,
570 int session_type, int session_options, int client_pid,
571 bool enable_session, int *codechandle, char *stream_type, int stream_index)
573 int ret = MM_ERROR_NONE;
575 GVariant *params = NULL, *result = NULL;
576 gboolean _enable_session = enable_session;
579 debug_error("Param for play is null");
580 return MM_ERROR_INVALID_ARGUMENT;
585 params = g_variant_new("(iiiiiiibsi)", tone, repeat, volume, volume_config, session_type,
586 session_options, client_pid , _enable_session, stream_type, stream_index);
588 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_DTMF, params, &result)) != MM_ERROR_NONE) {
589 debug_error("dbus play tone failed");
593 debug_error("Construct Param for method call failed");
597 g_variant_get(result, "(i)", &handle);
598 debug_log("handle : %d", handle);
599 *codechandle = handle;
601 debug_error("reply null");
606 g_variant_unref(result);
612 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)
614 int ret = MM_ERROR_NONE;
616 GVariant *params = NULL, *result = NULL;
621 debug_error("Param for play is null");
622 return MM_ERROR_INVALID_ARGUMENT;
625 params = g_variant_new("(iiiisi)", tone, repeat, volume, client_pid, stream_type, stream_index);
627 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_DTMF_WITH_STREAM_INFO, params, &result)) != MM_ERROR_NONE) {
628 debug_error("dbus play tone failed");
632 debug_error("Construct Param for method call failed");
636 g_variant_get(result, "(i)", &handle);
637 debug_log("handle : %d", handle);
638 *codechandle = handle;
640 debug_error("reply null");
645 g_variant_unref(result);
651 int mm_sound_proxy_play_sound(const char* filename, int tone, int repeat, int volume, int volume_config,
652 int session_type, int session_options, int client_pid, bool enable_session, int *codechandle,
653 char *stream_type, int stream_index)
655 int ret = MM_ERROR_NONE;
657 GVariant *params = NULL, *result = NULL;
658 gboolean _enable_session = enable_session;
660 if (!filename || !codechandle) {
661 debug_error("Param for play is null");
662 return MM_ERROR_INVALID_ARGUMENT;
667 params = g_variant_new("(siiiiiiibsi)", filename, tone, repeat, volume,
668 volume_config, session_type, session_options, client_pid, _enable_session, stream_type, stream_index);
670 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_FILE_START, params, &result)) != MM_ERROR_NONE) {
671 debug_error("dbus play file failed");
675 debug_error("Construct Param for method call failed");
679 g_variant_get(result, "(i)", &handle);
680 debug_log("handle : %d", handle);
681 *codechandle = handle;
683 debug_error("reply null");
688 g_variant_unref(result);
694 int mm_sound_proxy_play_sound_with_stream_info(const char* filename, int repeat, int volume,
695 int client_pid, int *codechandle, char *stream_type, int stream_index)
697 int ret = MM_ERROR_NONE;
699 GVariant *params = NULL, *result = NULL;
701 if (!filename || !codechandle) {
702 debug_error("Param for play is null");
703 return MM_ERROR_INVALID_ARGUMENT;
708 params = g_variant_new("(siiisi)", filename, repeat, volume, client_pid, stream_type, stream_index);
710 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) {
711 debug_error("dbus play file failed");
715 debug_error("Construct Param for method call failed");
719 g_variant_get(result, "(i)", &handle);
720 debug_log("handle : %d", handle);
721 *codechandle = handle;
723 debug_error("reply null");
728 g_variant_unref(result);
736 int mm_sound_proxy_stop_sound(int handle)
738 int ret = MM_ERROR_NONE;
739 GVariant *result = NULL;
743 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) {
744 debug_error("dbus stop file playing failed");
750 g_variant_unref(result);
756 int mm_sound_proxy_clear_focus(int pid)
758 int ret = MM_ERROR_NONE;
759 GVariant *result = NULL;
763 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) {
764 debug_error("dbus clear focus failed");
768 g_variant_unref(result);
774 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)
776 int ret = MM_ERROR_NONE;
777 struct callback_data *cb_data;
781 CB_DATA_NEW(cb_data, func, userdata, freefunc);
783 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)
784 debug_error("add play sound end callback failed");
786 *subs_id = cb_data->subs_id;
793 int mm_sound_proxy_remove_play_sound_end_callback(unsigned subs_id)
795 int ret = MM_ERROR_NONE;
798 if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
799 debug_error("Remove Play File End callback failed");
806 int mm_sound_proxy_emergent_exit(int exit_pid)
808 int ret = MM_ERROR_NONE;
809 GVariant *params = NULL;
813 params = g_variant_new("(i)", exit_pid);
815 if ((ret = mm_sound_dbus_emit_signal(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_EMERGENT_EXIT, params)) != MM_ERROR_NONE) {
816 debug_error("dbus emergent exit failed");
820 debug_error("Construct Param for emergent exit signal failed");
821 ret = MM_ERROR_SOUND_INTERNAL;
830 /*------------------------------------------ FOCUS --------------------------------------------------*/
833 int mm_sound_proxy_get_unique_id(int *id)
835 int ret = MM_ERROR_NONE;
837 GVariant *result = NULL;
841 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_GET_UNIQUE_ID, NULL, &result)) != MM_ERROR_NONE) {
842 debug_error("dbus get unique id failed");
846 g_variant_get(result, "(i)", &res);
848 debug_msg("got unique id(%d)", *id);
849 g_variant_unref(result);
857 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)
859 int ret = MM_ERROR_NONE;
860 GVariant *params = NULL, *result = NULL;
864 params = g_variant_new("(iisb)", instance, id, stream_type, is_for_session);
866 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_REGISTER_FOCUS, params, &result)) != MM_ERROR_NONE) {
867 debug_error("dbus register focus failed");
870 debug_error("Construct Param for method call failed");
873 if (ret != MM_ERROR_NONE)
874 g_variant_get(result, "(i)", &ret);
876 g_variant_unref(result);
884 int mm_sound_proxy_unregister_focus(int instance, int id, bool is_for_session)
886 int ret = MM_ERROR_NONE;
887 GVariant *params = NULL, *result = NULL;
891 params = g_variant_new("(iib)", instance, id, is_for_session);
893 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_UNREGISTER_FOCUS, params, &result)) != MM_ERROR_NONE) {
894 debug_error("dbus unregister focus failed");
897 debug_error("Construct Param for method call failed");
900 if (ret != MM_ERROR_NONE)
901 g_variant_get(result, "(i)", &ret);
903 g_variant_unref(result);
910 int mm_sound_proxy_set_foucs_reacquisition(int instance, int id, bool reacquisition)
912 int ret = MM_ERROR_NONE;
913 GVariant *params = NULL, *result = NULL;
917 params = g_variant_new("(iib)", instance, id, reacquisition);
919 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_SET_FOCUS_REACQUISITION, params, &result)) != MM_ERROR_NONE) {
920 debug_error("dbus set focus reacquisition failed");
923 debug_error("Construct Param for method call failed");
926 if (ret != MM_ERROR_NONE)
927 g_variant_get(result, "(i)", &ret);
929 g_variant_unref(result);
935 int mm_sound_proxy_get_acquired_focus_stream_type(int focus_type, char **stream_type, int *option, char **ext_info)
937 int ret = MM_ERROR_NONE;
938 GVariant *params = NULL, *result = NULL;
942 if (!(params = g_variant_new("(i)", focus_type))) {
943 debug_error("Construct Param for method call failed");
944 return MM_ERROR_SOUND_INTERNAL;
947 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_GET_ACQUIRED_FOCUS_STREAM_TYPE, params, &result)) == MM_ERROR_NONE) {
949 g_variant_get(result, "(sis)", stream_type, option, ext_info);
950 g_variant_unref(result);
953 debug_error("dbus get stream type of acquired focus failed");
960 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)
962 int ret = MM_ERROR_NONE;
963 GVariant *params = NULL, *result = NULL;
967 params = g_variant_new("(iiiisb)", instance, id, type, option, ext_info ? ext_info : "", is_for_session);
969 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_ACQUIRE_FOCUS, params, &result)) != MM_ERROR_NONE) {
970 debug_error("dbus acquire focus failed");
973 debug_error("Construct Param for method call failed");
976 if (ret != MM_ERROR_NONE)
977 g_variant_get(result, "(i)", &ret);
979 g_variant_unref(result);
985 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)
987 int ret = MM_ERROR_NONE;
988 GVariant *params = NULL, *result = NULL;
992 params = g_variant_new("(iiiisb)", instance, id, type, option, ext_info ? ext_info : "", is_for_session);
994 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_RELEASE_FOCUS, params, &result)) != MM_ERROR_NONE) {
995 debug_error("dbus release focus failed");
998 debug_error("Construct Param for method call failed");
1001 if (ret != MM_ERROR_NONE)
1002 g_variant_get(result, "(i)", &ret);
1004 g_variant_unref(result);
1010 int mm_sound_proxy_update_stream_focus_status(int focus_id, unsigned int status)
1012 int ret = MM_ERROR_NONE;
1014 GVariant *params = NULL, *result = NULL;
1018 params = g_variant_new("(iu)", focus_id, status);
1020 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_STREAM_MANAGER, AUDIO_METHOD_UPDATE_STREAM_FOCUS_STATUS, params, &result)) != MM_ERROR_NONE) {
1021 debug_error("dbus set volume by type failed");
1025 debug_error("Construct Param for method call failed");
1026 return MM_ERROR_SOUND_INTERNAL;
1030 g_variant_get(result, "(&s)", &reply);
1031 debug_log("reply : %s", reply);
1032 if (!strcmp(reply, "STREAM_MANAGER_RETURN_ERROR"))
1033 ret = MM_ERROR_SOUND_INTERNAL;
1035 debug_error("reply null");
1040 g_variant_unref(result);
1046 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)
1048 int ret = MM_ERROR_NONE;
1049 GVariant *params = NULL, *result = NULL;
1053 params = g_variant_new("(iiib)", instance, handle, type, is_for_session);
1055 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_WATCH_FOCUS, params, &result)) != MM_ERROR_NONE) {
1056 debug_error("dbus set watch focus failed");
1059 debug_error("Construct Param for method call failed");
1062 if (ret != MM_ERROR_NONE)
1063 g_variant_get(result, "(i)", &ret);
1065 g_variant_unref(result);
1072 int mm_sound_proxy_unset_focus_watch_callback(int focus_tid, int handle, bool is_for_session)
1074 int ret = MM_ERROR_NONE;
1075 GVariant *params = NULL, *result = NULL;
1079 params = g_variant_new("(iib)", focus_tid, handle, is_for_session);
1081 if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_UNWATCH_FOCUS, params, &result)) != MM_ERROR_NONE) {
1082 debug_error("dbus unset watch focus failed");
1085 debug_error("Construct Param for method call failed");
1087 if (ret != MM_ERROR_NONE)
1088 g_variant_get(result, "(i)", &ret);
1090 g_variant_unref(result);
1097 #endif /* USE_FOCUS */
1098 /*------------------------------------------ FOCUS --------------------------------------------------*/
1100 int mm_sound_proxy_initialize(void)
1102 int ret = MM_ERROR_NONE;
1110 int mm_sound_proxy_finalize(void)
1112 int ret = MM_ERROR_NONE;