From d6f179b8e6bafe69bd30fc09fdb5d2c01ce585c8 Mon Sep 17 00:00:00 2001 From: Jeongho Mok Date: Thu, 1 Dec 2016 22:16:15 +0900 Subject: [PATCH] Change set/unset cb to add/remove cb, and add device_state_changed cb [Version] 0.10.68 [Profile] Common [Issue Type] API Change-Id: I5202165e2efa2e1631982c7f68f4a37f897dbfdd --- common/mm_sound_dbus.c | 5 +++++ include/mm_sound.h | 17 ++++++++------ include/mm_sound_client.h | 4 ++++ include/mm_sound_intf.h | 1 + include/mm_sound_proxy.h | 2 ++ mm_sound_client.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++ mm_sound_device.c | 54 +++++++++++++++++++++++++++++++++++--------- mm_sound_proxy.c | 39 ++++++++++++++++++++++++++++++++ packaging/libmm-sound.spec | 2 +- 9 files changed, 162 insertions(+), 18 deletions(-) diff --git a/common/mm_sound_dbus.c b/common/mm_sound_dbus.c index 3c3350c..72c6b34 100644 --- a/common/mm_sound_dbus.c +++ b/common/mm_sound_dbus.c @@ -126,6 +126,9 @@ const mm_sound_dbus_signal_info_t g_events[AUDIO_EVENT_MAX] = { [AUDIO_EVENT_DEVICE_INFO_CHANGED] = { .name = "DeviceInfoChanged", }, + [AUDIO_EVENT_DEVICE_STATE_CHANGED] = { + .name = "DeviceStateChanged", + }, [AUDIO_EVENT_FOCUS_CHANGED] = { .name = "FocusChanged", }, @@ -429,6 +432,8 @@ static void _dbus_signal_callback(GDBusConnection *connection, (cb_data->user_cb)(AUDIO_EVENT_DEVICE_CONNECTED, params, cb_data->user_data); } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_DEVICE_INFO_CHANGED].name)) { (cb_data->user_cb)(AUDIO_EVENT_DEVICE_INFO_CHANGED, params, cb_data->user_data); + } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_DEVICE_STATE_CHANGED].name)) { + (cb_data->user_cb)(AUDIO_EVENT_DEVICE_STATE_CHANGED, params, cb_data->user_data); } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_FOCUS_CHANGED].name)) { (cb_data->user_cb)(AUDIO_EVENT_FOCUS_CHANGED, params, cb_data->user_data); } else if (!strcmp(signal_name, g_events[AUDIO_EVENT_FOCUS_WATCH].name)) { diff --git a/include/mm_sound.h b/include/mm_sound.h index 369a149..cd6db54 100644 --- a/include/mm_sound.h +++ b/include/mm_sound.h @@ -343,7 +343,7 @@ typedef void (*mm_sound_volume_changed_cb) (volume_type_t type, unsigned int vol -int mm_sound_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* user_data, unsigned int *subs_id); +int mm_sound_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* user_data, unsigned int *id); /** @@ -394,7 +394,7 @@ int mm_sound_volume_remove_callback(volume_type_t type); * @return This function returns MM_ERROR_NONE on success, or negative value * with error code. **/ -int mm_sound_remove_volume_changed_callback(unsigned int subs_id); +int mm_sound_remove_volume_changed_callback(unsigned int id); /** * This function is to set volume level of certain volume type. @@ -987,11 +987,14 @@ typedef void *MMSoundDevice_t; /**< MMsound Device handle */ typedef void *MMSoundDeviceList_t; /**< MMsound Device list handle */ typedef void (*mm_sound_device_connected_cb) (MMSoundDevice_t device_h, bool is_connected, void *user_data); typedef void (*mm_sound_device_info_changed_cb) (MMSoundDevice_t device_h, int changed_info_type, void *user_data); +typedef void (*mm_sound_device_state_changed_cb) (MMSoundDevice_t device_h, mm_sound_device_state_e state, void *user_data); -int mm_sound_add_device_connected_callback(mm_sound_device_flags_e flags, mm_sound_device_connected_cb func, void *user_data, unsigned int *subs_id); -int mm_sound_remove_device_connected_callback(unsigned int subs_id); -int mm_sound_add_device_information_changed_callback(mm_sound_device_flags_e flags, mm_sound_device_info_changed_cb func, void *user_data, unsigned int *subs_id); -int mm_sound_remove_device_information_changed_callback(unsigned int subs_id); +int mm_sound_add_device_connected_callback(int flags, mm_sound_device_connected_cb func, void *user_data, unsigned int *id); +int mm_sound_remove_device_connected_callback(unsigned int id); +int mm_sound_add_device_information_changed_callback(int flags, mm_sound_device_info_changed_cb func, void *user_data, unsigned int *id); +int mm_sound_remove_device_information_changed_callback(unsigned int id); +int mm_sound_add_device_state_changed_callback(int flags, mm_sound_device_state_changed_cb func, void *user_data, unsigned int *id); +int mm_sound_remove_device_state_changed_callback(unsigned int id); int mm_sound_get_current_device_list(mm_sound_device_flags_e device_mask, MMSoundDeviceList_t *device_list); int mm_sound_get_device_list(int device_mask, MMSoundDeviceList_t *device_list); @@ -1017,7 +1020,7 @@ typedef void (*mm_sound_active_device_changed_cb) (mm_sound_device_in device_in, typedef void (*mm_sound_test_cb) (int a, void *user_data); int mm_sound_test(int a, int b, int* get); -int mm_sound_add_test_callback(mm_sound_test_cb func, void *user_data, unsigned int *subs_id); +int mm_sound_add_test_callback(mm_sound_test_cb func, void *user_data, unsigned int *id); int mm_sound_remove_test_callback(unsigned int sub_id); void mm_sound_convert_volume_type_to_stream_type(int volume_type, char *stream_type); diff --git a/include/mm_sound_client.h b/include/mm_sound_client.h index 2149918..12ad054 100644 --- a/include/mm_sound_client.h +++ b/include/mm_sound_client.h @@ -45,6 +45,8 @@ int mm_sound_client_add_device_connected_callback(int device_flags, mm_sound_dev int mm_sound_client_remove_device_connected_callback(unsigned int subs_id); int mm_sound_client_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_cb func, void* user_data, unsigned int *subs_id); int mm_sound_client_remove_device_info_changed_callback(unsigned int subs_id); +int mm_sound_client_add_device_state_changed_callback(int device_flags, mm_sound_device_state_changed_cb func, void *userdata, unsigned int *id); +int mm_sound_client_remove_device_state_changed_callback(unsigned int id); #ifdef USE_FOCUS int mm_sound_client_set_session_interrupt_callback(mm_sound_focus_session_interrupt_cb callback, void* user_data); int mm_sound_client_unset_session_interrupt_callback(void); @@ -70,6 +72,8 @@ typedef void (*mm_sound_device_connected_wrapper_cb)(int device_id, const char * const char *name, gboolean is_connected, void *userdata); typedef void (*mm_sound_device_info_changed_wrapper_cb)(int device_id, const char *device_type, int io_direction, int state, const char *name, int changed_device_info_type, void *userdata); +typedef void (*mm_sound_device_state_changed_wrapper_cb)(int device_id, const char *device_type, int io_direction, int state, + const char *name, void *userdata); typedef void (*mm_sound_stop_callback_wrapper_func)(int id, void *userdata); #endif /* __MM_SOUND_CLIENT_H__ */ diff --git a/include/mm_sound_intf.h b/include/mm_sound_intf.h index d84ee94..d004e4f 100644 --- a/include/mm_sound_intf.h +++ b/include/mm_sound_intf.h @@ -76,6 +76,7 @@ typedef enum audio_event { AUDIO_EVENT_VOLUME_CHANGED, AUDIO_EVENT_DEVICE_CONNECTED, AUDIO_EVENT_DEVICE_INFO_CHANGED, + AUDIO_EVENT_DEVICE_STATE_CHANGED, AUDIO_EVENT_FOCUS_CHANGED, AUDIO_EVENT_FOCUS_WATCH, AUDIO_EVENT_EMERGENT_EXIT, diff --git a/include/mm_sound_proxy.h b/include/mm_sound_proxy.h index c2fea6f..447e4d9 100644 --- a/include/mm_sound_proxy.h +++ b/include/mm_sound_proxy.h @@ -58,6 +58,8 @@ int mm_sound_proxy_add_device_connected_callback(int device_flags, mm_sound_devi int mm_sound_proxy_remove_device_connected_callback(unsigned subs_id); 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); int mm_sound_proxy_remove_device_info_changed_callback(unsigned subs_id); +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); +int mm_sound_proxy_remove_device_state_changed_callback(unsigned subs_id); int mm_sound_proxy_set_volume_by_type(const char *volume_type, const unsigned volume_level); 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); int mm_sound_proxy_remove_volume_changed_callback(unsigned subs_id); diff --git a/mm_sound_client.c b/mm_sound_client.c index 5a2b5f4..26b0dbf 100644 --- a/mm_sound_client.c +++ b/mm_sound_client.c @@ -758,6 +758,62 @@ int mm_sound_client_remove_device_info_changed_callback(unsigned int subs_id) } +static void _mm_sound_device_state_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction, + int state, const char *name, void *userdata) +{ + mm_sound_device_t device_h; + struct callback_data *cb_data = (struct callback_data*) userdata; + int device_flags; + + debug_log("[Device State Changed] id(%d) type(%s) direction(%d) state(%d) name(%s)", + device_id, device_type, io_direction, state, name); + + if (cb_data == NULL) { + debug_warning("device state changed callback data null"); + return; + } + + device_flags = (int) cb_data->extra_data; + + if (!device_is_match_with_mask(device_type, io_direction, state, device_flags)) + return; + + device_h.id = device_id; + device_h.io_direction = io_direction; + device_h.state = state; + MMSOUND_STRNCPY(device_h.name, name, MAX_DEVICE_NAME_NUM); + MMSOUND_STRNCPY(device_h.type, device_type, MAX_DEVICE_TYPE_STR_LEN); + + ((mm_sound_device_state_changed_cb)(cb_data->user_cb))(&device_h, state, cb_data->user_data); +} + +int mm_sound_client_add_device_state_changed_callback(int device_flags, mm_sound_device_state_changed_cb func, void *userdata, unsigned int *id) +{ + int ret = MM_ERROR_NONE; + struct callback_data *cb_data = (struct callback_data*) userdata; + + debug_fenter(); + + GET_CB_DATA(cb_data, func, userdata, (void *) device_flags); + + ret = mm_sound_proxy_add_device_state_changed_callback(device_flags, _mm_sound_device_state_changed_callback_wrapper_func, cb_data, g_free, id); + + debug_fleave(); + return ret; +} + +int mm_sound_client_remove_device_state_changed_callback(unsigned int id) +{ + int ret = MM_ERROR_NONE; + debug_fenter(); + + ret = mm_sound_proxy_remove_device_state_changed_callback(id); + + debug_fleave(); + return ret; + +} + int __convert_volume_type_to_str(int volume_type, char **volume_type_str) { int ret = MM_ERROR_NONE; diff --git a/mm_sound_device.c b/mm_sound_device.c index b6f107b..5a1e2cc 100644 --- a/mm_sound_device.c +++ b/mm_sound_device.c @@ -111,17 +111,17 @@ static int __free_device_list(mm_sound_device_list_t *device_list_t) } EXPORT_API -int mm_sound_add_device_connected_callback(mm_sound_device_flags_e flags, mm_sound_device_connected_cb func, void *user_data, unsigned int *subs_id) +int mm_sound_add_device_connected_callback(int flags, mm_sound_device_connected_cb func, void *user_data, unsigned int *id) { int ret = MM_ERROR_NONE; - if (func == NULL || subs_id == NULL) { + if (func == NULL || id == NULL) { debug_error("argument is not valid\n"); return MM_ERROR_INVALID_ARGUMENT; } ret = _check_for_valid_mask(flags); if (ret == MM_ERROR_NONE) { - ret = mm_sound_client_add_device_connected_callback(flags, func, user_data, subs_id); + ret = mm_sound_client_add_device_connected_callback(flags, func, user_data, id); if (ret < 0) { debug_error("Could not add device connected callback, ret = %x\n", ret); } @@ -131,11 +131,11 @@ int mm_sound_add_device_connected_callback(mm_sound_device_flags_e flags, mm_sou } EXPORT_API -int mm_sound_remove_device_connected_callback(unsigned int subs_id) +int mm_sound_remove_device_connected_callback(unsigned int id) { int ret = MM_ERROR_NONE; - ret = mm_sound_client_remove_device_connected_callback(subs_id); + ret = mm_sound_client_remove_device_connected_callback(id); if (ret < 0) { debug_error("Could not remove device connected callback, ret = %x\n", ret); } @@ -144,17 +144,17 @@ int mm_sound_remove_device_connected_callback(unsigned int subs_id) } EXPORT_API -int mm_sound_add_device_information_changed_callback(mm_sound_device_flags_e flags, mm_sound_device_info_changed_cb func, void *user_data, unsigned int *subs_id) +int mm_sound_add_device_information_changed_callback(int flags, mm_sound_device_info_changed_cb func, void *user_data, unsigned int *id) { int ret = MM_ERROR_NONE; - if (func == NULL || subs_id == NULL) { + if (func == NULL || id == NULL) { debug_error("argument is not valid\n"); return MM_ERROR_INVALID_ARGUMENT; } ret = _check_for_valid_mask(flags); if (ret == MM_ERROR_NONE) { - ret = mm_sound_client_add_device_info_changed_callback(flags, func, user_data, subs_id); + ret = mm_sound_client_add_device_info_changed_callback(flags, func, user_data, id); if (ret < 0) { debug_error("Could not add device information changed callback, ret = %x\n", ret); } @@ -164,11 +164,11 @@ int mm_sound_add_device_information_changed_callback(mm_sound_device_flags_e fla } EXPORT_API -int mm_sound_remove_device_information_changed_callback(unsigned int subs_id) +int mm_sound_remove_device_information_changed_callback(unsigned int id) { int ret = MM_ERROR_NONE; - ret = mm_sound_client_remove_device_info_changed_callback(subs_id); + ret = mm_sound_client_remove_device_info_changed_callback(id); if (ret < 0) { debug_error("Could not remove device information changed callback, ret = %x\n", ret); } @@ -177,6 +177,40 @@ int mm_sound_remove_device_information_changed_callback(unsigned int subs_id) } EXPORT_API +int mm_sound_add_device_state_changed_callback(int flags, mm_sound_device_state_changed_cb func, void *user_data, unsigned int *id) +{ + int ret = MM_ERROR_NONE; + + if (func == NULL || id == NULL) { + debug_error("argument is not valid\n"); + return MM_ERROR_INVALID_ARGUMENT; + } + ret = _check_for_valid_mask(flags); + if (ret == MM_ERROR_NONE) { + ret = mm_sound_client_add_device_state_changed_callback(flags, func, user_data, id); + if (ret < 0) { + debug_error("Could not add device state changed callback, ret = %x\n", ret); + } + } + + return ret; +} + +EXPORT_API +int mm_sound_remove_device_state_changed_callback(unsigned int id) +{ + int ret = MM_ERROR_NONE; + + ret = mm_sound_client_remove_device_state_changed_callback(id); + if (ret < 0) { + debug_error("Could not remove device state changed callback, ret = %x\n", ret); + } + + return ret; +} + + +EXPORT_API int mm_sound_get_current_device_list(mm_sound_device_flags_e flags, MMSoundDeviceList_t *device_list) { int ret = MM_ERROR_NONE; diff --git a/mm_sound_proxy.c b/mm_sound_proxy.c index a4fd70b..af96967 100644 --- a/mm_sound_proxy.c +++ b/mm_sound_proxy.c @@ -111,6 +111,14 @@ static void dbus_callback(audio_event_t event, GVariant *params, void *userdata) &state, &name, &changed_device_info_type); ((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); + } else if (event == AUDIO_EVENT_DEVICE_STATE_CHANGED) { + const char *name = NULL, *device_type = NULL; + int device_id, io_direction, state; + + g_variant_get(params, "(u(i&sii&s))", &event_id, &device_id, &device_type, &io_direction, + &state, &name); + ((mm_sound_device_state_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, io_direction, + state, name, cb_data->user_data); } else if (event == AUDIO_EVENT_FOCUS_CHANGED) { } else if (event == AUDIO_EVENT_FOCUS_WATCH) { } else if (event == AUDIO_EVENT_TEST) { @@ -333,6 +341,37 @@ int mm_sound_proxy_remove_device_info_changed_callback(unsigned subs_id) return ret; } +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) +{ + int ret = MM_ERROR_NONE; + struct callback_data *cb_data; + + debug_fenter(); + + CB_DATA_NEW(cb_data, func, userdata, freefunc); + + 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) + debug_error("Add device state changed callback failed"); + else + *subs_id = cb_data->subs_id; + + debug_fleave(); + return ret; +} + +int mm_sound_proxy_remove_device_state_changed_callback(unsigned subs_id) +{ + int ret = MM_ERROR_NONE; + debug_fenter(); + + if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) { + debug_error("remove device state changed callback failed"); + } + + debug_fleave(); + return ret; +} + int mm_sound_proxy_set_volume_by_type(const char *volume_type, const unsigned volume_level) { int ret = MM_ERROR_NONE; diff --git a/packaging/libmm-sound.spec b/packaging/libmm-sound.spec index 2f40d3e..2c48ef6 100644 --- a/packaging/libmm-sound.spec +++ b/packaging/libmm-sound.spec @@ -1,6 +1,6 @@ Name: libmm-sound Summary: MMSound Package contains client lib and sound_server binary -Version: 0.10.67 +Version: 0.10.68 Release: 0 Group: System/Libraries License: Apache-2.0 -- 2.7.4