From 94bd14a76d673fc4e4f2fde156b126305b74190e Mon Sep 17 00:00:00 2001 From: hj kim Date: Tue, 28 Aug 2018 15:40:05 +0900 Subject: [PATCH] Code refactoring. Unify client callback register/unregister APIs Change-Id: I29dacfda1bf6bef0f7b400b0b535d8426ddc442c --- include/media_controller_private.h | 23 +- src/media_controller_client.c | 621 ++++++++++--------------------------- 2 files changed, 186 insertions(+), 458 deletions(-) diff --git a/include/media_controller_private.h b/include/media_controller_private.h index 4d0e630..b3d810a 100755 --- a/include/media_controller_private.h +++ b/include/media_controller_private.h @@ -270,6 +270,19 @@ typedef struct { media_controller_receiver_s event_reply_receiver; } media_controller_server_s; +typedef enum { + MC_EVENT_SERVER_STATE, + MC_EVENT_PLAYBACK_INFO, + MC_EVENT_METADATA, + MC_EVENT_SHUFFLE, + MC_EVENT_REPEAT, + MC_EVENT_CLIENT_CUSTOM, //from client to server + MC_EVENT_PLAYLIST, + MC_EVENT_CMD_REPLY, + MC_EVENT_SERVER_CUSTOM, //from server to client + MC_EVENT_MAX, +} mc_client_receive_event_e; + typedef struct { char *client_name; void *db_handle; @@ -279,15 +292,7 @@ typedef struct { GList *listeners; - media_controller_receiver_s playback_cb; - media_controller_receiver_s metadata_cb; - media_controller_receiver_s server_state_cb; - media_controller_receiver_s shuffle_cb; - media_controller_receiver_s repeat_cb; - media_controller_receiver_s reply_cb; - media_controller_receiver_s playlist_cb; - media_controller_receiver_s cmd_reply_cb; - media_controller_receiver_s custom_event_cb; + media_controller_receiver_s updated_cb[MC_EVENT_MAX]; } media_controller_client_s; typedef struct { diff --git a/src/media_controller_client.c b/src/media_controller_client.c index 63b7185..d403bff 100755 --- a/src/media_controller_client.c +++ b/src/media_controller_client.c @@ -19,6 +19,33 @@ #include "media_controller_db.h" #include +static void __client_server_cb(const char *interface_name, const char *signal_name, const char *message, const char *request_id, void *user_data); +static void __client_playback_cb(const char *interface_name, const char *signal_name, const char *message, const char *request_id, void *user_data); +static void __client_metadata_cb(const char *interface_name, const char *signal_name, const char *message, const char *request_id, void *user_data); +static void __client_shuffle_cb(const char *interface_name, const char *signal_name, const char *message, const char *request_id, void *user_data); +static void __client_repeat_cb(const char *interface_name, const char *signal_name, const char *message, const char *request_id, void *user_data); +static void __client_reply_cb(const char *interface_name, const char *signal_name, const char *message, const char *request_id, void *user_data); +static void __client_playlist_cb(const char *interface_name, const char *signal_name, const char *message, const char *request_id, void *user_data); +static void __client_cmd_reply_received_cb(const char *interface_name, const char *signal_name, const char *message, const char *request_id, void *user_data); +static void __client_custom_event_received_cb(const char *interface_name, const char *signal_name, const char *message, const char *request_id, void *user_data); + +typedef struct { + const char *signal_name; + mc_signal_received_cb cb_func; +} mc_cb_event_s; + +mc_cb_event_s cb_event[MC_EVENT_MAX] = { + {MC_DBUS_SIGNAL_NAME_SERVER_STATE, __client_server_cb}, + {MC_DBUS_SIGNAL_NAME_PLAY_BACK, __client_playback_cb}, + {MC_DBUS_SIGNAL_NAME_METADATA, __client_metadata_cb}, + {MC_DBUS_SIGNAL_NAME_PLAYBACK_SHUFFLE, __client_shuffle_cb}, + {MC_DBUS_SIGNAL_NAME_PLAYBACK_REPEAT, __client_repeat_cb}, + {MC_DBUS_SIGNAL_NAME_CUSTOM_COMMAND_REPLY, __client_reply_cb}, + {MC_DBUS_SIGNAL_NAME_PLAYLIST, __client_playlist_cb}, + {MC_DBUS_SIGNAL_NAME_CMD_REPLY, __client_cmd_reply_received_cb}, + {MC_DBUS_SIGNAL_NAME_CUSTOM_EVENT, __client_custom_event_received_cb}, +}; + static void __client_server_cb(const char *interface_name, const char *signal_name, const char *message, const char *request_id, void *user_data) { gchar **params = NULL; @@ -79,9 +106,9 @@ static void __client_metadata_cb(const char *interface_name, const char *signal_ mc_metadata_h metadata = NULL; media_controller_client_s *mc_client = (media_controller_client_s *)user_data; mc_retm_if(mc_client == NULL, "mc_client is NULL"); - mc_metadata_updated_cb callback = (mc_metadata_updated_cb)mc_client->metadata_cb.callback; + mc_metadata_updated_cb callback = (mc_metadata_updated_cb)mc_client->updated_cb[MC_EVENT_METADATA].callback; - mc_retm_if(mc_client->metadata_cb.callback == NULL, "metadata_cb is NULL"); + mc_retm_if(callback == NULL, "metadata_cb is NULL"); mc_retm_if(message == NULL, "message is NULL"); mc_debug("__client_metadata_cb(%s, %s, %s, %s, %p)", interface_name, signal_name, message, request_id, user_data); @@ -90,7 +117,7 @@ static void __client_metadata_cb(const char *interface_name, const char *signal_ if (ret != MEDIA_CONTROLLER_ERROR_NONE) mc_error("Fail to mc_db_get_metadata_info"); - callback(message, metadata, mc_client->metadata_cb.user_data); + callback(message, metadata, mc_client->updated_cb[MC_EVENT_METADATA].user_data); mc_metadata_destroy(metadata); } @@ -163,13 +190,12 @@ static void __client_playlist_cb(const char *interface_name, const char *signal_ { gchar **params = NULL; mc_playlist_update_mode_e mode = MC_PLAYLIST_UPDATED; - media_controller_client_s *mc_client = (media_controller_client_s *)user_data; - mc_retm_if(mc_client == NULL, "mc_client is NULL"); - - mc_playlist_updated_cb callback = (mc_playlist_updated_cb)mc_client->playlist_cb.callback; mc_playlist_s *_playlist = NULL; - mc_retm_if(mc_client->playlist_cb.callback == NULL, "playlist_cb is NULL"); + media_controller_receiver_s *reciever = (media_controller_receiver_s *)user_data; + mc_retm_if(reciever == NULL, "reciever is NULL"); + mc_playlist_updated_cb callback = (mc_playlist_updated_cb)reciever->callback; + mc_retm_if(reciever->callback == NULL, "playlist_cb is NULL"); mc_retm_if(message == NULL, "message is NULL"); mc_debug("__client_playlist_cb(%s, %s, %s, %s, %p)", interface_name, signal_name, message, request_id, user_data); @@ -190,7 +216,7 @@ static void __client_playlist_cb(const char *interface_name, const char *signal_ _playlist->server_name = g_strdup(params[0]); _playlist->playlist_name = g_strdup(params[2]); - callback(params[0], mode, params[2], (mc_playlist_h)_playlist, mc_client->playlist_cb.user_data); + callback(params[0], mode, params[2], (mc_playlist_h)_playlist, reciever->user_data); g_strfreev(params); @@ -520,460 +546,219 @@ int mc_client_create(mc_client_h *client) return MEDIA_CONTROLLER_ERROR_NONE; } -int mc_client_set_server_update_cb(mc_client_h client, mc_server_state_updated_cb callback, void *user_data) +static int __mc_client_set_updated_cb(mc_client_h client, mc_client_receive_event_e event, void *callback, void *user_data) { int ret = MEDIA_CONTROLLER_ERROR_NONE; media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_warning("DEPRECATION WARNING: mc_client_set_server_update_cb() is deprecated and will be removed from next release. Use mc_client_set_server_updated_cb() instead."); + char *interface_name = NULL; mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); mc_retvm_if(callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is NULL"); - mc_retvm_if(mc_client->server_state_cb.callback != NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is already set"); + mc_retvm_if(((event < MC_EVENT_SERVER_STATE) || (event >= MC_EVENT_MAX)) , MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid event [%d]", event); + mc_retvm_if(mc_client->updated_cb[event].callback != NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is already set [%d]", event); + + mc_client->updated_cb[event].callback = callback; + mc_client->updated_cb[event].user_data = user_data; - mc_client->server_state_cb.callback = callback; - mc_client->server_state_cb.user_data = user_data; + if ((event == MC_EVENT_CMD_REPLY) || (event == MC_EVENT_SERVER_CUSTOM)) { + interface_name = mc_util_get_interface_name(MC_CLIENT, mc_client->client_name); + ret = mc_ipc_register_listener(&mc_client->listeners, mc_client->dconn, interface_name, cb_event[event].signal_name, + cb_event[event].cb_func, (void *)&(mc_client->updated_cb[event])); - ret = mc_ipc_register_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_SERVER_STATE, - __client_server_cb, (void *)&(mc_client->server_state_cb)); + MC_SAFE_FREE(interface_name); + + } else if (event == MC_EVENT_METADATA) { + ret = mc_ipc_register_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, cb_event[event].signal_name, + cb_event[event].cb_func, (void *)(mc_client)); + } else { + ret = mc_ipc_register_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, cb_event[event].signal_name, + cb_event[event].cb_func, (void *)&(mc_client->updated_cb[event])); + } return ret; } -int mc_client_unset_server_update_cb(mc_client_h client) +static int __mc_client_unset_updated_cb(mc_client_h client, mc_client_receive_event_e event) { int ret = MEDIA_CONTROLLER_ERROR_NONE; media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_warning("DEPRECATION WARNING: mc_client_unset_server_update_cb() is deprecated and will be removed from next release. Use mc_client_unset_server_updated_cb() instead."); + char *interface_name = NULL; mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + mc_retvm_if(((event < MC_EVENT_SERVER_STATE) || (event >= MC_EVENT_MAX)) , MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid event [%d]", event); + + if ((event == MC_EVENT_CMD_REPLY) || (event == MC_EVENT_SERVER_CUSTOM)) { + interface_name = mc_util_get_interface_name(MC_CLIENT, mc_client->client_name); - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_SERVER_STATE); + ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, interface_name, cb_event[event].signal_name); - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->server_state_cb.filter_list, NULL, MC_DBUS_SIGNAL_NAME_SERVER_STATE); + MC_SAFE_FREE(interface_name); + } else { + ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, cb_event[event].signal_name); - mc_client->server_state_cb.callback = NULL; - mc_client->server_state_cb.user_data = NULL; - mc_client->server_state_cb.filter_list = NULL; + ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->updated_cb[event].filter_list, NULL, cb_event[event].signal_name); + } + + mc_client->updated_cb[event].callback = NULL; + mc_client->updated_cb[event].user_data = NULL; + mc_client->updated_cb[event].filter_list = NULL; return ret; } -int mc_client_set_playback_update_cb(mc_client_h client, mc_playback_updated_cb callback, void *user_data) +int mc_client_set_server_update_cb(mc_client_h client, mc_server_state_updated_cb callback, void *user_data) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_warning("DEPRECATION WARNING: mc_client_set_playback_update_cb() is deprecated and will be removed from next release. Use mc_client_set_playback_updated_cb() instead."); - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - mc_retvm_if(callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is NULL"); - mc_retvm_if(mc_client->playback_cb.callback != NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is already set"); - - mc_client->playback_cb.callback = callback; - mc_client->playback_cb.user_data = user_data; + return __mc_client_set_updated_cb(client, MC_EVENT_SERVER_STATE, callback, user_data); +} - ret = mc_ipc_register_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAY_BACK, - __client_playback_cb, (void *)&(mc_client->playback_cb)); +int mc_client_unset_server_update_cb(mc_client_h client) +{ + return __mc_client_unset_updated_cb(client, MC_EVENT_SERVER_STATE); +} - return ret; +int mc_client_set_playback_update_cb(mc_client_h client, mc_playback_updated_cb callback, void *user_data) +{ + return __mc_client_set_updated_cb(client, MC_EVENT_PLAYBACK_INFO, callback, user_data); } int mc_client_unset_playback_update_cb(mc_client_h client) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_warning("DEPRECATION WARNING: mc_client_unset_playback_update_cb() is deprecated and will be removed from next release. Use mc_client_unset_playback_updated_cb() instead."); - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAY_BACK); - - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->playback_cb.filter_list, NULL, MC_DBUS_SIGNAL_NAME_PLAY_BACK); - - mc_client->playback_cb.callback = NULL; - mc_client->playback_cb.user_data = NULL; - mc_client->playback_cb.filter_list = NULL; - - return ret; + return __mc_client_unset_updated_cb(client, MC_EVENT_PLAYBACK_INFO); } int mc_client_set_metadata_update_cb(mc_client_h client, mc_metadata_updated_cb callback, void *user_data) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - mc_warning("DEPRECATION WARNING: mc_client_set_metadata_update_cb() is deprecated and will be removed from next release. Use mc_client_set_metadata_updated_cb() instead."); - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - mc_retvm_if(callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is NULL"); - mc_retvm_if(mc_client->metadata_cb.callback != NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is already set"); - - mc_client->metadata_cb.callback = callback; - mc_client->metadata_cb.user_data = user_data; - - ret = mc_ipc_register_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_METADATA, - __client_metadata_cb, (void *)(mc_client)); - - return ret; + return __mc_client_set_updated_cb(client, MC_EVENT_METADATA, callback, user_data); } int mc_client_unset_metadata_update_cb(mc_client_h client) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_warning("DEPRECATION WARNING: mc_client_unset_metadata_update_cb() is deprecated and will be removed from next release. Use mc_client_unset_metadata_updated_cb() instead."); - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_METADATA); - - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->metadata_cb.filter_list, NULL, MC_DBUS_SIGNAL_NAME_METADATA); - - mc_client->metadata_cb.callback = NULL; - mc_client->metadata_cb.user_data = NULL; - mc_client->metadata_cb.filter_list = NULL; - - return ret; + return __mc_client_unset_updated_cb(client, MC_EVENT_METADATA); } int mc_client_set_shuffle_mode_update_cb(mc_client_h client, mc_shuffle_mode_changed_cb callback, void *user_data) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - mc_warning("DEPRECATION WARNING: mc_client_set_shuffle_mode_update_cb() is deprecated and will be removed from next release. Use mc_client_set_shuffle_mode_updated_cb() instead."); - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - mc_retvm_if(callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is NULL"); - mc_retvm_if(mc_client->shuffle_cb.callback != NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is already set"); - - mc_client->shuffle_cb.callback = callback; - mc_client->shuffle_cb.user_data = user_data; - - ret = mc_ipc_register_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAYBACK_SHUFFLE, - __client_shuffle_cb, (void *)&(mc_client->shuffle_cb)); - - return ret; + return __mc_client_set_updated_cb(client, MC_EVENT_SHUFFLE, callback, user_data); } int mc_client_unset_shuffle_mode_update_cb(mc_client_h client) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - mc_warning("DEPRECATION WARNING: mc_client_unset_shuffle_mode_update_cb() is deprecated and will be removed from next release. Use mc_client_unset_shuffle_mode_updated_cb() instead."); - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAYBACK_SHUFFLE); - - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->shuffle_cb.filter_list, NULL, MC_DBUS_SIGNAL_NAME_PLAYBACK_SHUFFLE); - - mc_client->shuffle_cb.callback = NULL; - mc_client->shuffle_cb.user_data = NULL; - mc_client->shuffle_cb.filter_list = NULL; - - - return ret; + return __mc_client_unset_updated_cb(client, MC_EVENT_SHUFFLE); } - int mc_client_set_repeat_mode_update_cb(mc_client_h client, mc_repeat_mode_changed_cb callback, void *user_data) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - mc_warning("DEPRECATION WARNING: mc_client_set_repeat_mode_update_cb() is deprecated and will be removed from next release. Use mc_client_set_repeat_mode_updated_cb() instead."); - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - mc_retvm_if(callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is NULL"); - mc_retvm_if(mc_client->repeat_cb.callback != NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is already set"); - - mc_client->repeat_cb.callback = callback; - mc_client->repeat_cb.user_data = user_data; - - ret = mc_ipc_register_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAYBACK_REPEAT, - __client_repeat_cb, (void *)&(mc_client->repeat_cb)); - - return ret; + return __mc_client_set_updated_cb(client, MC_EVENT_REPEAT, callback, user_data); } int mc_client_unset_repeat_mode_update_cb(mc_client_h client) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - mc_warning("DEPRECATION WARNING: mc_client_unset_repeat_mode_update_cb() is deprecated and will be removed from next release. Use mc_client_unset_repeat_mode_updated_cb() instead."); - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAYBACK_REPEAT); - - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->repeat_cb.filter_list, NULL, MC_DBUS_SIGNAL_NAME_PLAYBACK_REPEAT); - - mc_client->repeat_cb.callback = NULL; - mc_client->repeat_cb.user_data = NULL; - mc_client->repeat_cb.filter_list = NULL; - - return ret; + return __mc_client_unset_updated_cb(client, MC_EVENT_REPEAT); } int mc_client_set_server_updated_cb(mc_client_h client, mc_server_state_updated_cb callback, void *user_data) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - mc_retvm_if(callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is NULL"); - mc_retvm_if(mc_client->server_state_cb.callback != NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is already set"); - - mc_client->server_state_cb.callback = callback; - mc_client->server_state_cb.user_data = user_data; - - ret = mc_ipc_register_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_SERVER_STATE, - __client_server_cb, (void *)&(mc_client->server_state_cb)); - - return ret; + return __mc_client_set_updated_cb(client, MC_EVENT_SERVER_STATE, callback, user_data); } int mc_client_unset_server_updated_cb(mc_client_h client) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_SERVER_STATE); - - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->server_state_cb.filter_list, NULL, MC_DBUS_SIGNAL_NAME_SERVER_STATE); - - mc_client->server_state_cb.callback = NULL; - mc_client->server_state_cb.user_data = NULL; - mc_client->server_state_cb.filter_list = NULL; - - return ret; + return __mc_client_unset_updated_cb(client, MC_EVENT_SERVER_STATE); } int mc_client_set_playback_updated_cb(mc_client_h client, mc_playback_updated_cb callback, void *user_data) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - mc_retvm_if(callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is NULL"); - mc_retvm_if(mc_client->playback_cb.callback != NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is already set"); - - mc_client->playback_cb.callback = callback; - mc_client->playback_cb.user_data = user_data; - - ret = mc_ipc_register_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAY_BACK, - __client_playback_cb, (void *)&(mc_client->playback_cb)); - - return ret; + return __mc_client_set_updated_cb(client, MC_EVENT_PLAYBACK_INFO, callback, user_data); } int mc_client_unset_playback_updated_cb(mc_client_h client) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAY_BACK); - - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->playback_cb.filter_list, NULL, MC_DBUS_SIGNAL_NAME_PLAY_BACK); - - mc_client->playback_cb.callback = NULL; - mc_client->playback_cb.user_data = NULL; - mc_client->playback_cb.filter_list = NULL; - - return ret; + return __mc_client_unset_updated_cb(client, MC_EVENT_PLAYBACK_INFO); } int mc_client_set_metadata_updated_cb(mc_client_h client, mc_metadata_updated_cb callback, void *user_data) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - mc_retvm_if(callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is NULL"); - mc_retvm_if(mc_client->metadata_cb.callback != NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is already set"); - - mc_client->metadata_cb.callback = callback; - mc_client->metadata_cb.user_data = user_data; - - ret = mc_ipc_register_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_METADATA, - __client_metadata_cb, (void *)(mc_client)); - - return ret; + return __mc_client_set_updated_cb(client, MC_EVENT_METADATA, callback, user_data); } int mc_client_unset_metadata_updated_cb(mc_client_h client) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_METADATA); - - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->metadata_cb.filter_list, NULL, MC_DBUS_SIGNAL_NAME_METADATA); - - mc_client->metadata_cb.callback = NULL; - mc_client->metadata_cb.user_data = NULL; - mc_client->metadata_cb.filter_list = NULL; - - return ret; + return __mc_client_unset_updated_cb(client, MC_EVENT_METADATA); } int mc_client_set_shuffle_mode_updated_cb(mc_client_h client, mc_shuffle_mode_updated_cb callback, void *user_data) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - mc_retvm_if(callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is NULL"); - mc_retvm_if(mc_client->shuffle_cb.callback != NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is already set"); - - mc_client->shuffle_cb.callback = callback; - mc_client->shuffle_cb.user_data = user_data; - - ret = mc_ipc_register_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAYBACK_SHUFFLE, - __client_shuffle_cb, (void *)&(mc_client->shuffle_cb)); - - return ret; + return __mc_client_set_updated_cb(client, MC_EVENT_SHUFFLE, callback, user_data); } int mc_client_unset_shuffle_mode_updated_cb(mc_client_h client) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAYBACK_SHUFFLE); - - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->shuffle_cb.filter_list, NULL, MC_DBUS_SIGNAL_NAME_PLAYBACK_SHUFFLE); - - mc_client->shuffle_cb.callback = NULL; - mc_client->shuffle_cb.user_data = NULL; - mc_client->shuffle_cb.filter_list = NULL; - - - return ret; + return __mc_client_unset_updated_cb(client, MC_EVENT_SHUFFLE); } int mc_client_set_repeat_mode_updated_cb(mc_client_h client, mc_repeat_mode_updated_cb callback, void *user_data) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - mc_retvm_if(callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is NULL"); - mc_retvm_if(mc_client->repeat_cb.callback != NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is already set"); - - mc_client->repeat_cb.callback = callback; - mc_client->repeat_cb.user_data = user_data; - - ret = mc_ipc_register_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAYBACK_REPEAT, - __client_repeat_cb, (void *)&(mc_client->repeat_cb)); - - return ret; + return __mc_client_set_updated_cb(client, MC_EVENT_REPEAT, callback, user_data); } int mc_client_unset_repeat_mode_updated_cb(mc_client_h client) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAYBACK_REPEAT); - - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->repeat_cb.filter_list, NULL, MC_DBUS_SIGNAL_NAME_PLAYBACK_REPEAT); - - mc_client->repeat_cb.callback = NULL; - mc_client->repeat_cb.user_data = NULL; - mc_client->repeat_cb.filter_list = NULL; - - return ret; + return __mc_client_unset_updated_cb(client, MC_EVENT_REPEAT); } int mc_client_set_playlist_updated_cb(mc_client_h client, mc_playlist_updated_cb callback, void *user_data) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - mc_retvm_if(callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is NULL"); - mc_retvm_if(mc_client->playlist_cb.callback != NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is already set"); - - mc_client->playlist_cb.callback = callback; - mc_client->playlist_cb.user_data = user_data; - - ret = mc_ipc_register_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAYLIST, - __client_playlist_cb, (void *)(mc_client)); - - return ret; + return __mc_client_set_updated_cb(client, MC_EVENT_PLAYLIST, callback, user_data); } int mc_client_unset_playlist_updated_cb(mc_client_h client) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAYLIST); - - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->playlist_cb.filter_list, NULL, MC_DBUS_SIGNAL_NAME_PLAYLIST); - - mc_client->playlist_cb.callback = NULL; - mc_client->playlist_cb.user_data = NULL; - mc_client->playlist_cb.filter_list = NULL; - - return ret; + return __mc_client_unset_updated_cb(client, MC_EVENT_PLAYLIST); } int mc_client_set_cmd_reply_received_cb(mc_client_h client, mc_cmd_reply_received_cb callback, void *user_data) { - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - mc_retvm_if(callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is NULL"); - mc_retvm_if(mc_client->cmd_reply_cb.callback != NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is already set"); - - mc_client->cmd_reply_cb.callback = callback; - mc_client->cmd_reply_cb.user_data = user_data; + return __mc_client_set_updated_cb(client, MC_EVENT_CMD_REPLY, callback, user_data); +} - char *interface_name = mc_util_get_interface_name(MC_CLIENT, mc_client->client_name); - ret = mc_ipc_register_listener(&mc_client->listeners, mc_client->dconn, interface_name, MC_DBUS_SIGNAL_NAME_CMD_REPLY, - __client_cmd_reply_received_cb, (void *)&(mc_client->cmd_reply_cb)); +int mc_client_unset_cmd_reply_received_cb(mc_client_h client) +{ + return __mc_client_unset_updated_cb(client, MC_EVENT_CMD_REPLY); +} - MC_SAFE_FREE(interface_name); +int mc_client_set_custom_event_received_cb(mc_client_h client, mc_client_custom_event_received_cb callback, void *user_data) +{ + return __mc_client_set_updated_cb(client, MC_EVENT_SERVER_CUSTOM, callback, user_data); +} - return ret; +int mc_client_unset_custom_event_received_cb(mc_client_h client) +{ + return __mc_client_unset_updated_cb(client, MC_EVENT_SERVER_CUSTOM); } -int mc_client_unset_cmd_reply_received_cb(mc_client_h client) +static int __mc_client_subscribe(mc_client_h client, mc_client_receive_event_e event, const char *server_name) { int ret = MEDIA_CONTROLLER_ERROR_NONE; media_controller_client_s *mc_client = (media_controller_client_s *)client; mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + mc_retvm_if(!MC_STRING_VALID(server_name), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid server_name"); + mc_retvm_if(((event < MC_EVENT_SERVER_STATE) || (event >= MC_EVENT_MAX)) , MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid event [%d]", event); - char *interface_name = mc_util_get_interface_name(MC_CLIENT, mc_client->client_name); - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, interface_name, MC_DBUS_SIGNAL_NAME_CMD_REPLY); - - mc_client->cmd_reply_cb.callback = NULL; - mc_client->cmd_reply_cb.user_data = NULL; - mc_client->cmd_reply_cb.filter_list = NULL; + mc_retvm_if(mc_client->updated_cb[event].callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback"); - MC_SAFE_FREE(interface_name); + ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, cb_event[event].signal_name); + ret = __mc_client_register_filter_listener(mc_client, &mc_client->updated_cb[event].filter_list, server_name, cb_event[event].signal_name, + cb_event[event].cb_func, (void *)&(mc_client->updated_cb[event])); return ret; } @@ -981,54 +766,32 @@ int mc_client_unset_cmd_reply_received_cb(mc_client_h client) int mc_client_subscribe(mc_client_h client, const mc_subscription_type_e subscription_type, const char *server_name) { int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - mc_retvm_if(!MC_STRING_VALID(server_name), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid server_name"); switch (subscription_type) { case MC_SUBSCRIPTION_TYPE_SERVER_STATE: - mc_retvm_if(mc_client->server_state_cb.callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback"); - - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_SERVER_STATE); - ret = __mc_client_register_filter_listener(mc_client, &mc_client->server_state_cb.filter_list, server_name, MC_DBUS_SIGNAL_NAME_SERVER_STATE, - __client_server_cb, (void *)&(mc_client->server_state_cb)); + ret = __mc_client_subscribe(client, MC_EVENT_SERVER_STATE, server_name); break; - case MC_SUBSCRIPTION_TYPE_PLAYBACK: - mc_retvm_if(mc_client->playback_cb.callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback"); - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAY_BACK); - ret = __mc_client_register_filter_listener(mc_client, &mc_client->playback_cb.filter_list, server_name, MC_DBUS_SIGNAL_NAME_PLAY_BACK, - __client_playback_cb, (void *)&(mc_client->playback_cb)); + case MC_SUBSCRIPTION_TYPE_PLAYBACK: + ret = __mc_client_subscribe(client, MC_EVENT_PLAYBACK_INFO, server_name); break; - case MC_SUBSCRIPTION_TYPE_METADATA: - mc_retvm_if(mc_client->metadata_cb.callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback"); - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_METADATA); - ret = __mc_client_register_filter_listener(mc_client, &mc_client->metadata_cb.filter_list, server_name, MC_DBUS_SIGNAL_NAME_METADATA, - __client_metadata_cb, (void *)(mc_client)); + case MC_SUBSCRIPTION_TYPE_METADATA: + ret = __mc_client_subscribe(client, MC_EVENT_METADATA, server_name); break; - case MC_SUBSCRIPTION_TYPE_SHUFFLE_MODE: - mc_retvm_if(mc_client->shuffle_cb.callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback"); - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAYBACK_SHUFFLE); - ret = __mc_client_register_filter_listener(mc_client, &mc_client->shuffle_cb.filter_list, server_name, MC_DBUS_SIGNAL_NAME_PLAYBACK_SHUFFLE, - __client_shuffle_cb, (void *)&(mc_client->shuffle_cb)); + case MC_SUBSCRIPTION_TYPE_SHUFFLE_MODE: + ret = __mc_client_subscribe(client, MC_EVENT_SHUFFLE, server_name); break; - case MC_SUBSCRIPTION_TYPE_REPEAT_MODE: - mc_retvm_if(mc_client->repeat_cb.callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback"); - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAYBACK_REPEAT); - ret = __mc_client_register_filter_listener(mc_client, &mc_client->repeat_cb.filter_list, server_name, MC_DBUS_SIGNAL_NAME_PLAYBACK_REPEAT, - __client_repeat_cb, (void *)&(mc_client->repeat_cb)); + case MC_SUBSCRIPTION_TYPE_REPEAT_MODE: + ret = __mc_client_subscribe(client, MC_EVENT_REPEAT, server_name); break; - case MC_SUBSCRIPTION_TYPE_PLAYLIST: - mc_retvm_if(mc_client->playlist_cb.callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback"); - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAYLIST); - ret = __mc_client_register_filter_listener(mc_client, &mc_client->playlist_cb.filter_list, server_name, MC_DBUS_SIGNAL_NAME_PLAYLIST, - __client_playlist_cb, (void *)&(mc_client)); + case MC_SUBSCRIPTION_TYPE_PLAYLIST: + ret = __mc_client_subscribe(client, MC_EVENT_PLAYLIST, server_name); break; + default: mc_error("Invalid subscription_type [%d]", subscription_type); return MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER; @@ -1037,51 +800,52 @@ int mc_client_subscribe(mc_client_h client, const mc_subscription_type_e subscri return ret; } -int mc_client_unsubscribe(mc_client_h client, const mc_subscription_type_e subscription_type, const char *server_name) +static int __mc_client_unsubscribe(mc_client_h client, mc_client_receive_event_e event, const char *server_name) { int ret = MEDIA_CONTROLLER_ERROR_NONE; media_controller_client_s *mc_client = (media_controller_client_s *)client; mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); mc_retvm_if(!MC_STRING_VALID(server_name), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid server_name"); + mc_retvm_if(((event < MC_EVENT_SERVER_STATE) || (event >= MC_EVENT_MAX)) , MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid event [%d]", event); + + mc_retvm_if(mc_client->updated_cb[event].callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback. No list to unsubscribe [%d]", event); + mc_retvm_if(mc_client->updated_cb[event].filter_list == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid filter_list. No list to unsubscribe [%d]", event); + + ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->updated_cb[event].filter_list, server_name, cb_event[event].signal_name); + + return ret; +} + +int mc_client_unsubscribe(mc_client_h client, const mc_subscription_type_e subscription_type, const char *server_name) +{ + int ret = MEDIA_CONTROLLER_ERROR_NONE; switch (subscription_type) { case MC_SUBSCRIPTION_TYPE_SERVER_STATE: - mc_retvm_if(mc_client->server_state_cb.callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback. No list to unsubscribe"); - mc_retvm_if(mc_client->server_state_cb.filter_list == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid filter_list. No list to unsubscribe"); - - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->server_state_cb.filter_list, server_name, MC_DBUS_SIGNAL_NAME_SERVER_STATE); + ret = __mc_client_unsubscribe(client, MC_EVENT_SERVER_STATE, server_name); break; - case MC_SUBSCRIPTION_TYPE_PLAYBACK: - mc_retvm_if(mc_client->playback_cb.callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback. No list to unsubscribe"); - mc_retvm_if(mc_client->playback_cb.filter_list == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid filter_list. No list to unsubscribe"); - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->playback_cb.filter_list, server_name, MC_DBUS_SIGNAL_NAME_PLAY_BACK); + case MC_SUBSCRIPTION_TYPE_PLAYBACK: + ret = __mc_client_unsubscribe(client, MC_EVENT_PLAYBACK_INFO, server_name); break; - case MC_SUBSCRIPTION_TYPE_METADATA: - mc_retvm_if(mc_client->metadata_cb.callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback. No list to unsubscribe"); - mc_retvm_if(mc_client->metadata_cb.filter_list == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid filter_list. No list to unsubscribe"); - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->metadata_cb.filter_list, server_name, MC_DBUS_SIGNAL_NAME_METADATA); + case MC_SUBSCRIPTION_TYPE_METADATA: + ret = __mc_client_unsubscribe(client, MC_EVENT_METADATA, server_name); break; - case MC_SUBSCRIPTION_TYPE_SHUFFLE_MODE: - mc_retvm_if(mc_client->shuffle_cb.callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback. No list to unsubscribe"); - mc_retvm_if(mc_client->shuffle_cb.filter_list == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid filter_list. No list to unsubscribe"); - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->shuffle_cb.filter_list, server_name, MC_DBUS_SIGNAL_NAME_PLAYBACK_SHUFFLE); + case MC_SUBSCRIPTION_TYPE_SHUFFLE_MODE: + ret = __mc_client_unsubscribe(client, MC_EVENT_SHUFFLE, server_name); break; - case MC_SUBSCRIPTION_TYPE_REPEAT_MODE: - mc_retvm_if(mc_client->repeat_cb.callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback. No list to unsubscribe"); - mc_retvm_if(mc_client->repeat_cb.filter_list == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid filter_list. No list to unsubscribe"); - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->repeat_cb.filter_list, server_name, MC_DBUS_SIGNAL_NAME_PLAYBACK_REPEAT); + case MC_SUBSCRIPTION_TYPE_REPEAT_MODE: + ret = __mc_client_unsubscribe(client, MC_EVENT_REPEAT, server_name); break; - case MC_SUBSCRIPTION_TYPE_PLAYLIST: - mc_retvm_if(mc_client->playlist_cb.callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback. No list to unsubscribe"); - mc_retvm_if(mc_client->playlist_cb.filter_list == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid filter_list. No list to unsubscribe"); - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->playlist_cb.filter_list, server_name, MC_DBUS_SIGNAL_NAME_PLAYLIST); + case MC_SUBSCRIPTION_TYPE_PLAYLIST: + ret = __mc_client_unsubscribe(client, MC_EVENT_PLAYLIST, server_name); break; + default: mc_error("Invalid subscription_type [%d]", subscription_type); return MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER; @@ -1104,22 +868,22 @@ int mc_client_foreach_server_subscribed(mc_client_h client, const mc_subscriptio switch (subscription_type) { case MC_SUBSCRIPTION_TYPE_SERVER_STATE: - filter_list = mc_client->server_state_cb.filter_list; + filter_list = mc_client->updated_cb[MC_EVENT_SERVER_STATE].filter_list; break; case MC_SUBSCRIPTION_TYPE_PLAYBACK: - filter_list = mc_client->playback_cb.filter_list; + filter_list = mc_client->updated_cb[MC_EVENT_PLAYBACK_INFO].filter_list; break; case MC_SUBSCRIPTION_TYPE_METADATA: - filter_list = mc_client->metadata_cb.filter_list; + filter_list = mc_client->updated_cb[MC_EVENT_METADATA].filter_list; break; case MC_SUBSCRIPTION_TYPE_SHUFFLE_MODE: - filter_list = mc_client->shuffle_cb.filter_list; + filter_list = mc_client->updated_cb[MC_EVENT_SHUFFLE].filter_list; break; case MC_SUBSCRIPTION_TYPE_REPEAT_MODE: - filter_list = mc_client->repeat_cb.filter_list; + filter_list = mc_client->updated_cb[MC_EVENT_REPEAT].filter_list; break; case MC_SUBSCRIPTION_TYPE_PLAYLIST: - filter_list = mc_client->playlist_cb.filter_list; + filter_list = mc_client->updated_cb[MC_EVENT_PLAYLIST].filter_list; break; default: mc_error("Invalid subscription_type [%d]", subscription_type); @@ -1541,11 +1305,8 @@ int mc_client_send_custom_command(mc_client_h client, const char *server_name, c mc_retvm_if(!MC_STRING_VALID(server_name), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid server_name"); if (callback) { - char *interface_name_for_reply = mc_util_get_interface_name(MC_CLIENT, mc_client->client_name); - mc_client->reply_cb.callback = callback; - mc_client->reply_cb.user_data = user_data; - mc_ipc_register_listener(&mc_client->listeners, mc_client->dconn, interface_name_for_reply, MC_DBUS_SIGNAL_NAME_CUSTOM_COMMAND_REPLY, __client_reply_cb, (void *)&(mc_client->reply_cb)); - MC_SAFE_FREE(interface_name_for_reply); + ret = __mc_client_set_updated_cb(client, MC_EVENT_CLIENT_CUSTOM, callback, user_data); + mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "Error when __mc_client_set_updated_cb [%d]", ret); } ret = mc_util_bundle_to_string(data, &bundle_str); @@ -1608,44 +1369,6 @@ int mc_client_send_custom_cmd(mc_client_h client, const char *server_name, const return ret; } -int mc_client_set_custom_event_received_cb(mc_client_h client, mc_client_custom_event_received_cb callback, void *user_data) -{ - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - mc_retvm_if(callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is NULL"); - - mc_client->custom_event_cb.callback = callback; - mc_client->custom_event_cb.user_data = user_data; - - char *interface_name = mc_util_get_interface_name(MC_CLIENT, mc_client->client_name); - ret = mc_ipc_register_listener(&mc_client->listeners, mc_client->dconn, interface_name, MC_DBUS_SIGNAL_NAME_CUSTOM_EVENT, - __client_custom_event_received_cb, (void *)&(mc_client->custom_event_cb)); - - MC_SAFE_FREE(interface_name); - - return ret; -} - -int mc_client_unset_custom_event_received_cb(mc_client_h client) -{ - int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_client_s *mc_client = (media_controller_client_s *)client; - - mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - - char *interface_name = mc_util_get_interface_name(MC_CLIENT, mc_client->client_name); - ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, interface_name, MC_DBUS_SIGNAL_NAME_CUSTOM_EVENT); - - mc_client->custom_event_cb.callback = NULL; - mc_client->custom_event_cb.user_data = NULL; - - MC_SAFE_FREE(interface_name); - - return ret; -} - int mc_client_send_event_reply(mc_client_h client, const char *server_name, const char *request_id, int result_code, bundle *data) { int ret = MEDIA_CONTROLLER_ERROR_NONE; @@ -1685,12 +1408,12 @@ int mc_client_destroy(mc_client_h client) mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); /*Unregister all filter listener*/ - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->server_state_cb.filter_list, NULL, MC_DBUS_SIGNAL_NAME_SERVER_STATE); - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->playback_cb.filter_list, NULL, MC_DBUS_SIGNAL_NAME_PLAY_BACK); - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->metadata_cb.filter_list, NULL, MC_DBUS_SIGNAL_NAME_METADATA); - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->shuffle_cb.filter_list, NULL, MC_DBUS_SIGNAL_NAME_PLAYBACK_SHUFFLE); - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->repeat_cb.filter_list, NULL, MC_DBUS_SIGNAL_NAME_PLAYBACK_REPEAT); - ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->playlist_cb.filter_list, NULL, MC_DBUS_SIGNAL_NAME_PLAYLIST); + ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->updated_cb[MC_EVENT_SERVER_STATE].filter_list, NULL, cb_event[MC_EVENT_SERVER_STATE].signal_name); + ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->updated_cb[MC_EVENT_PLAYBACK_INFO].filter_list, NULL, cb_event[MC_EVENT_PLAYBACK_INFO].signal_name); + ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->updated_cb[MC_EVENT_METADATA].filter_list, NULL, cb_event[MC_EVENT_METADATA].signal_name); + ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->updated_cb[MC_EVENT_SHUFFLE].filter_list, NULL, cb_event[MC_EVENT_SHUFFLE].signal_name); + ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->updated_cb[MC_EVENT_REPEAT].filter_list, NULL, cb_event[MC_EVENT_REPEAT].signal_name); + ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->updated_cb[MC_EVENT_PLAYLIST].filter_list, NULL, cb_event[MC_EVENT_PLAYLIST].signal_name); /*Unregister all listener*/ ret = mc_ipc_unregister_all_listener(&mc_client->listeners, mc_client->dconn); -- 2.7.4