{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_COMMAND_REPLY, __client_reply_cb},
{MC_DBUS_SIGNAL_NAME_CUSTOM_EVENT, __client_custom_event_received_cb},
};
return __mc_client_unset_updated_cb(client, MC_EVENT_SERVER_CUSTOM);
}
-static int __mc_client_subscribe(mc_client_h client, mc_client_receive_event_e event, const char *server_name)
+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");
- 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");
-
- 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;
-}
-
-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;
-
- switch (subscription_type) {
- case MC_SUBSCRIPTION_TYPE_SERVER_STATE:
- ret = __mc_client_subscribe(client, MC_EVENT_SERVER_STATE, server_name);
- break;
-
- case MC_SUBSCRIPTION_TYPE_PLAYBACK:
- ret = __mc_client_subscribe(client, MC_EVENT_PLAYBACK_INFO, server_name);
- break;
-
- case MC_SUBSCRIPTION_TYPE_METADATA:
- ret = __mc_client_subscribe(client, MC_EVENT_METADATA, server_name);
- break;
-
- case MC_SUBSCRIPTION_TYPE_SHUFFLE_MODE:
- ret = __mc_client_subscribe(client, MC_EVENT_SHUFFLE, server_name);
- break;
-
- case MC_SUBSCRIPTION_TYPE_REPEAT_MODE:
- ret = __mc_client_subscribe(client, MC_EVENT_REPEAT, server_name);
- break;
+ mc_retvm_if(((subscription_type < MC_SUBSCRIPTION_TYPE_SERVER_STATE) || (subscription_type > MC_SUBSCRIPTION_TYPE_PLAYLIST)) , MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid subscription_type [%d]", subscription_type);
+ mc_retvm_if(mc_client->updated_cb[subscription_type].callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback");
- case MC_SUBSCRIPTION_TYPE_PLAYLIST:
- ret = __mc_client_subscribe(client, MC_EVENT_PLAYLIST, server_name);
- break;
+ ret = mc_ipc_unregister_listener(&mc_client->listeners, mc_client->dconn, MC_DBUS_UPDATE_INTERFACE, cb_event[subscription_type].signal_name);
- default:
- mc_error("Invalid subscription_type [%d]", subscription_type);
- return MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER;
+ if (subscription_type == MC_SUBSCRIPTION_TYPE_METADATA) {
+ ret = __mc_client_register_filter_listener(mc_client, &mc_client->updated_cb[subscription_type].filter_list, server_name, cb_event[subscription_type].signal_name,
+ cb_event[subscription_type].cb_func, (void *)(mc_client));
+ } else {
+ ret = __mc_client_register_filter_listener(mc_client, &mc_client->updated_cb[subscription_type].filter_list, server_name, cb_event[subscription_type].signal_name,
+ cb_event[subscription_type].cb_func, (void *)&(mc_client->updated_cb[subscription_type]));
}
return ret;
}
-static int __mc_client_unsubscribe(mc_client_h client, mc_client_receive_event_e event, const char *server_name)
+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;
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:
- ret = __mc_client_unsubscribe(client, MC_EVENT_SERVER_STATE, server_name);
- break;
-
- case MC_SUBSCRIPTION_TYPE_PLAYBACK:
- ret = __mc_client_unsubscribe(client, MC_EVENT_PLAYBACK_INFO, server_name);
- break;
-
- case MC_SUBSCRIPTION_TYPE_METADATA:
- ret = __mc_client_unsubscribe(client, MC_EVENT_METADATA, server_name);
- break;
-
- case MC_SUBSCRIPTION_TYPE_SHUFFLE_MODE:
- ret = __mc_client_unsubscribe(client, MC_EVENT_SHUFFLE, server_name);
- break;
-
- case MC_SUBSCRIPTION_TYPE_REPEAT_MODE:
- ret = __mc_client_unsubscribe(client, MC_EVENT_REPEAT, server_name);
- break;
+ mc_retvm_if(((subscription_type < MC_SUBSCRIPTION_TYPE_SERVER_STATE) || (subscription_type > MC_SUBSCRIPTION_TYPE_PLAYLIST)) , MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid subscription_type [%d]", subscription_type);
- case MC_SUBSCRIPTION_TYPE_PLAYLIST:
- ret = __mc_client_unsubscribe(client, MC_EVENT_PLAYLIST, server_name);
- break;
+ mc_retvm_if(mc_client->updated_cb[subscription_type].callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback. No list to unsubscribe [%d]", subscription_type);
+ mc_retvm_if(mc_client->updated_cb[subscription_type].filter_list == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid filter_list. No list to unsubscribe [%d]", subscription_type);
- default:
- mc_error("Invalid subscription_type [%d]", subscription_type);
- return MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER;
- }
+ ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->updated_cb[subscription_type].filter_list, server_name, cb_event[subscription_type].signal_name);
return ret;
}
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(((subscription_type < MC_SUBSCRIPTION_TYPE_SERVER_STATE) || (subscription_type > MC_SUBSCRIPTION_TYPE_PLAYLIST)) , MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid subscription_type [%d]", subscription_type);
- switch (subscription_type) {
- case MC_SUBSCRIPTION_TYPE_SERVER_STATE:
- filter_list = mc_client->updated_cb[MC_EVENT_SERVER_STATE].filter_list;
- break;
- case MC_SUBSCRIPTION_TYPE_PLAYBACK:
- filter_list = mc_client->updated_cb[MC_EVENT_PLAYBACK_INFO].filter_list;
- break;
- case MC_SUBSCRIPTION_TYPE_METADATA:
- filter_list = mc_client->updated_cb[MC_EVENT_METADATA].filter_list;
- break;
- case MC_SUBSCRIPTION_TYPE_SHUFFLE_MODE:
- filter_list = mc_client->updated_cb[MC_EVENT_SHUFFLE].filter_list;
- break;
- case MC_SUBSCRIPTION_TYPE_REPEAT_MODE:
- filter_list = mc_client->updated_cb[MC_EVENT_REPEAT].filter_list;
- break;
- case MC_SUBSCRIPTION_TYPE_PLAYLIST:
- filter_list = mc_client->updated_cb[MC_EVENT_PLAYLIST].filter_list;
- break;
- default:
- mc_error("Invalid subscription_type [%d]", subscription_type);
- return MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER;
- }
+ filter_list = mc_client->updated_cb[subscription_type].filter_list;
if (filter_list == NULL) {
mc_debug("No filter list for the subscription_type [%d]", subscription_type);
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
media_controller_client_s *mc_client = (media_controller_client_s *)client;
+ int idx = 0;
mc_debug_fenter();
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->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);
+ for (idx = 0; idx <= MC_SUBSCRIPTION_TYPE_PLAYLIST; idx++) {
+ ret = __mc_client_unregister_filter_listener(mc_client, &mc_client->updated_cb[idx].filter_list, NULL, cb_event[idx].signal_name);
+ if (ret != MEDIA_CONTROLLER_ERROR_NONE)
+ mc_error("Error __mc_client_unregister_filter_listener [%d]", ret);
+ }
/*Unregister all listener*/
ret = mc_ipc_unregister_all_listener(&mc_client->listeners, mc_client->dconn);