diff options
author | hj kim <backto.kim@samsung.com> | 2018-03-12 17:47:08 +0900 |
---|---|---|
committer | hj kim <backto.kim@samsung.com> | 2018-03-15 19:21:46 +0900 |
commit | a3ffd4721de7e736f08cd775bd224e90784d5956 (patch) | |
tree | a8ba5509e76d1ac847877a6202efdf66f71ec610 | |
parent | 67b9bee42ff92a8bb897bcdfa52029cf4beb3087 (diff) | |
download | media-controller-a3ffd4721de7e736f08cd775bd224e90784d5956.tar.gz media-controller-a3ffd4721de7e736f08cd775bd224e90784d5956.tar.bz2 media-controller-a3ffd4721de7e736f08cd775bd224e90784d5956.zip |
[ACR-1173] Separate playback state and action
Change-Id: I0b32ef9f3a1407ab67197d5f3b355f86a2b39af3
-rwxr-xr-x | include/media_controller_client.h | 24 | ||||
-rwxr-xr-x | include/media_controller_private.h | 5 | ||||
-rwxr-xr-x | include/media_controller_server.h | 63 | ||||
-rwxr-xr-x | include/media_controller_type.h | 33 | ||||
-rwxr-xr-x | src/media_controller_client.c | 33 | ||||
-rwxr-xr-x | src/media_controller_db.c | 14 | ||||
-rwxr-xr-x | src/media_controller_server.c | 82 | ||||
-rwxr-xr-x | test/client_test/media_controller_client_test.c | 13 | ||||
-rwxr-xr-x | test/server_test/media_controller_server_test.c | 11 |
9 files changed, 256 insertions, 22 deletions
diff --git a/include/media_controller_client.h b/include/media_controller_client.h index bd37f47..9b97cbc 100755 --- a/include/media_controller_client.h +++ b/include/media_controller_client.h @@ -692,6 +692,7 @@ int mc_client_get_server_repeat_mode(mc_client_h client, const char *server_name int mc_client_foreach_server(mc_client_h client, mc_activated_server_cb callback, void *user_data); /** + * @deprecated Deprecated since 5.0. Use mc_client_send_playback_action() instead. * @brief Sends the playback state command to server. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @@ -710,7 +711,28 @@ int mc_client_foreach_server(mc_client_h client, mc_activated_server_cb callback * @see mc_client_create() * @see mc_client_get_server_playback_info() */ -int mc_client_send_playback_state_command(mc_client_h client, const char *server_name, mc_playback_states_e state); +int mc_client_send_playback_state_command(mc_client_h client, const char *server_name, mc_playback_states_e state) TIZEN_DEPRECATED_API; + +/** + * @brief Sends the playback action command to server. + * @since_tizen 5.0 + * + * @privlevel public + * @privilege %http://tizen.org/privilege/mediacontroller.client + * + * @param[in] client The handle to the media controller client + * @param[in] server_name The app_id of the media controller server + * @param[in] action The playback action command to send to the media controller server + * @return @c 0 on success, + * otherwise a negative error value + * @retval #MEDIA_CONTROLLER_ERROR_NONE Successful + * @retval #MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTROLLER_ERROR_PERMISSION_DENIED Permission denied + * @pre Create a media controller client handle by calling mc_client_create(). + * @see mc_client_create() + * @see mc_client_get_server_playback_info() + */ +int mc_client_send_playback_action(mc_client_h client, const char *server_name, mc_playback_action_e action); /** * @brief Sends the playback position command to server. diff --git a/include/media_controller_private.h b/include/media_controller_private.h index 5458a47..b3606f5 100755 --- a/include/media_controller_private.h +++ b/include/media_controller_private.h @@ -75,7 +75,7 @@ extern "C" { } while (0) #define mc_debug_fenter() do { \ - LOGD(FONT_COLOR_RESET"<Enter>"); \ + LOGD(FONT_COLOR_YELLOW"<ENTER>"FONT_COLOR_RESET); \ } while (0) #define mc_debug_fleave() do { \ @@ -149,6 +149,7 @@ extern "C" { #define MC_DBUS_SIGNAL_NAME_PLAYBACK_SHUFFLE "shuffle" #define MC_DBUS_SIGNAL_NAME_PLAYBACK_REPEAT "repeat" #define MC_DBUS_SIGNAL_NAME_PLAYBACK_STATE_CMD "pb_state_cmd" +#define MC_DBUS_SIGNAL_NAME_PLAYBACK_ACTION "pb_action_cmd" #define MC_DBUS_SIGNAL_NAME_PLAYBACK_POS_CMD "pb_position_cmd" #define MC_DBUS_SIGNAL_NAME_SHUFFLE_CMD "shuffle_cmd" #define MC_DBUS_SIGNAL_NAME_REPEAT_CMD "repeat_cmd" @@ -156,6 +157,7 @@ extern "C" { #define MC_DBUS_SIGNAL_NAME_CMD_REPLY "custom_cmd_reply" #define MC_COMMAND_PLAYBACKSTATE "_pb_state_cmd_" +#define MC_COMMAND_PLAYBACKACTION "_pb_action_cmd_" #define MC_COMMAND_PLAYBACKPOSITION "_pb_position_cmd_" #define MC_COMMAND_SHUFFLE "_shuffle_cmd_" #define MC_COMMAND_REPEAT "_repeat_cmd_" @@ -217,6 +219,7 @@ typedef struct { media_controller_metadata_s *metadata; media_controller_receiver_s playback_state_reciever; + media_controller_receiver_s playback_action_reciever; media_controller_receiver_s playback_position_reciever; media_controller_receiver_s shuffle_mode_reciever; media_controller_receiver_s repeat_mode_reciever; diff --git a/include/media_controller_server.h b/include/media_controller_server.h index eba28bc..f810635 100755 --- a/include/media_controller_server.h +++ b/include/media_controller_server.h @@ -35,6 +35,7 @@ extern "C" { */ /** + * @deprecated Deprecated since 5.0. * @brief Called when the server receives the playback state from the client. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @@ -51,6 +52,22 @@ extern "C" { typedef void (*mc_server_playback_state_command_received_cb)(const char* client_name, mc_playback_states_e state, void *user_data); /** + * @brief Called when the server receives the playback action commandfrom the client. + * @since_tizen 5.0 + * + * @remarks The callback is called in the dbus event loop. + * + * @param[in] client_name The app_id of the media controller client, it can be used only in the callback. To use outside, make a copy. + * @param[in] action The received playback action + * @param[in] user_data The user data passed from the mc_server_set_playback_action_received_cb() function + * + * @pre mc_server_set_playback_action_received_cb() + * + * @see mc_server_set_playback_action_received_cb() + */ +typedef void (*mc_server_playback_action_received_cb)(const char* client_name, mc_playback_action_e action, void *user_data); + +/** * @brief Called when the server receives the playback position from the client. * @since_tizen 5.0 * @@ -284,6 +301,7 @@ int mc_server_update_shuffle_mode(mc_server_h server, mc_shuffle_mode_e mode); int mc_server_update_repeat_mode(mc_server_h server, mc_repeat_mode_e mode); /** + * @deprecated Deprecated since 5.0. Use mc_server_set_playback_action_received_cb() instead. * @brief Sets the callback for receiving playback state command from client. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @@ -302,9 +320,10 @@ int mc_server_update_repeat_mode(mc_server_h server, mc_repeat_mode_e mode); * @see mc_server_create() * @see mc_server_destroy() */ -int mc_server_set_playback_state_command_received_cb(mc_server_h server, mc_server_playback_state_command_received_cb callback, void *user_data); +int mc_server_set_playback_state_command_received_cb(mc_server_h server, mc_server_playback_state_command_received_cb callback, void *user_data) TIZEN_DEPRECATED_API; /** + * @deprecated Deprecated since 5.0. Use mc_server_unset_playback_action_received_cb() instead. * @brief Unsets the callback for receiving playback state command from client. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @@ -321,7 +340,47 @@ int mc_server_set_playback_state_command_received_cb(mc_server_h server, mc_serv * @see mc_server_create() * @see mc_server_destroy() */ -int mc_server_unset_playback_state_command_received_cb(mc_server_h server); +int mc_server_unset_playback_state_command_received_cb(mc_server_h server) TIZEN_DEPRECATED_API; + +/** + * @brief Sets the callback for receiving playback action command from client. + * @since_tizen 5.0 + * + * @privlevel public + * @privilege %http://tizen.org/privilege/mediacontroller.server + * + * @param[in] server The handle to media controller server + * @param[in] callback The callback to be invoked when media controller server receives playback action from client. + * @param[in] user_data The user data to be passed to the callback function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #MEDIA_CONTROLLER_ERROR_NONE Successful + * @retval #MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTROLLER_ERROR_PERMISSION_DENIED Permission denied + * @pre Create a media controller server handle by calling mc_server_create(). + * @see mc_server_create() + * @see mc_server_destroy() + */ +int mc_server_set_playback_action_received_cb(mc_server_h server, mc_server_playback_action_received_cb callback, void *user_data); + +/** + * @brief Unsets the callback for receiving playback action command from client. + * @since_tizen 5.0 + * + * @privlevel public + * @privilege %http://tizen.org/privilege/mediacontroller.server + * + * @param[in] server The handle to media controller server + * @return @c 0 on success, + * otherwise a negative error value + * @retval #MEDIA_CONTROLLER_ERROR_NONE Successful + * @retval #MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTROLLER_ERROR_PERMISSION_DENIED Permission denied + * @pre Create a media controller server handle by calling mc_server_create(). + * @see mc_server_create() + * @see mc_server_destroy() + */ +int mc_server_unset_playback_action_received_cb(mc_server_h server); /** * @brief Sets the callback for receiving playback position command from client. diff --git a/include/media_controller_type.h b/include/media_controller_type.h index 63fddec..d0edab8 100755 --- a/include/media_controller_type.h +++ b/include/media_controller_type.h @@ -106,16 +106,35 @@ typedef enum { */ typedef enum { MC_PLAYBACK_STATE_NONE = 0, /**< None */ - MC_PLAYBACK_STATE_PLAYING, /**< Play */ - MC_PLAYBACK_STATE_PAUSED, /**< Pause */ - MC_PLAYBACK_STATE_STOPPED, /**< Stop */ - MC_PLAYBACK_STATE_NEXT_FILE, /**< Next file */ - MC_PLAYBACK_STATE_PREV_FILE, /**< Previous file */ - MC_PLAYBACK_STATE_FAST_FORWARD, /**< Fast forward */ - MC_PLAYBACK_STATE_REWIND, /**< Rewind */ + MC_PLAYBACK_STATE_PLAYING, /**< Playing */ + MC_PLAYBACK_STATE_PAUSED, /**< Paused */ + MC_PLAYBACK_STATE_STOPPED, /**< Stopped */ + MC_PLAYBACK_STATE_NEXT_FILE, /**< Next file (Deprecated since 5.0)*/ + MC_PLAYBACK_STATE_PREV_FILE, /**< Previous file (Deprecated since 5.0)*/ + MC_PLAYBACK_STATE_FAST_FORWARD, /**< Fast forward (Deprecated since 5.0)*/ + MC_PLAYBACK_STATE_REWIND, /**< Rewind (Deprecated since 5.0)*/ + MC_PLAYBACK_STATE_MOVING_TO_NEXT, /**< Moving to the next item (Since 5.0)*/ + MC_PLAYBACK_STATE_MOVING_TO_PREVIOUS, /**< Moving to the previous item (Since 5.0)*/ + MC_PLAYBACK_STATE_FAST_FORWARDING, /**< Fast forwarding (Since 5.0)*/ + MC_PLAYBACK_STATE_REWINDING, /**< Rewinding (Since 5.0)*/ } mc_playback_states_e; /** + * @brief Enumeration for the media playback action. + * @since_tizen 5.0 + */ +typedef enum { + MC_PLAYBACK_ACTION_PLAY, /**< Play */ + MC_PLAYBACK_ACTION_PAUSE, /**< Pause */ + MC_PLAYBACK_ACTION_STOP, /**< Stop */ + MC_PLAYBACK_ACTION_NEXT, /**< Next item */ + MC_PLAYBACK_ACTION_PREV, /**< Previous item */ + MC_PLAYBACK_ACTION_FAST_FORWARD, /**< Fast forward */ + MC_PLAYBACK_ACTION_REWIND, /**< Rewind */ + MC_PLAYBACK_ACTION_TOGGLE_PLAY_PAUSE, /**< Play/Pause toggle */ +} mc_playback_action_e; + +/** * @brief Enumeration for the shuffle mode. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif */ diff --git a/src/media_controller_client.c b/src/media_controller_client.c index d886af6..92037bc 100755 --- a/src/media_controller_client.c +++ b/src/media_controller_client.c @@ -957,6 +957,7 @@ int mc_client_send_playback_state_command(mc_client_h client, const char *server media_controller_client_s *mc_client = (media_controller_client_s *)client; bool exist_server = FALSE; + mc_warning("DEPRECATION WARNING: mc_client_send_playback_state_command() is deprecated and will be removed from next release. Use mc_client_send_playback_action() instead."); 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(((state < MC_PLAYBACK_STATE_PLAYING) || (state > MC_PLAYBACK_STATE_REWIND)), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "state is invalid"); @@ -982,6 +983,38 @@ int mc_client_send_playback_state_command(mc_client_h client, const char *server return ret; } +int mc_client_send_playback_action(mc_client_h client, const char *server_name, mc_playback_action_e action) +{ + int ret = MEDIA_CONTROLLER_ERROR_NONE; + char *message = NULL; + media_controller_client_s *mc_client = (media_controller_client_s *)client; + bool exist_server = FALSE; + + 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(((action < MC_PLAYBACK_ACTION_PLAY) || (action > MC_PLAYBACK_ACTION_TOGGLE_PLAY_PAUSE)), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid action"); + + ret = mc_db_check_server_table_exist(mc_client->db_handle, server_name, &exist_server); + mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "Error mc_db_check_server_table_exist [%d]", ret); + mc_retvm_if(exist_server == FALSE, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Error Invalid server_name"); + + ret = mc_util_set_command_availabe(mc_client->client_name, MC_COMMAND_PLAYBACKACTION, NULL); + mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "Error mc_util_set_command_availabe [%d]", ret); + + message = g_strdup_printf("%s%s%d", mc_client->client_name, MC_STRING_DELIMITER, action); + mc_retvm_if(message == NULL, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "fail making message [%d]", ret); + + char *interface_name = mc_util_get_interface_name(MC_SERVER, server_name); + ret = mc_ipc_send_message(mc_client->dconn, NULL, interface_name, MC_DBUS_SIGNAL_NAME_PLAYBACK_ACTION, message, 0); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) + mc_error("Error mc_ipc_send_message [%d]", ret); + + MC_SAFE_G_FREE(message); + MC_SAFE_G_FREE(interface_name); + + return ret; +} + int mc_client_send_playback_position_command(mc_client_h client, const char *server_name, unsigned long long position) { int ret = MEDIA_CONTROLLER_ERROR_NONE; diff --git a/src/media_controller_db.c b/src/media_controller_db.c index c366983..7f8232f 100755 --- a/src/media_controller_db.c +++ b/src/media_controller_db.c @@ -192,23 +192,29 @@ int mc_db_connect(void **handle) int ret = MEDIA_CONTROLLER_ERROR_NONE; sqlite3 *db_handle = NULL; - mc_debug("mc_db_connect"); + mc_debug_fenter(); mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); /*Connect DB*/ char * db_name = NULL; db_name = __mc_get_db_name(getuid()); - ret = db_util_open_with_options(db_name, &db_handle, SQLITE_OPEN_READONLY, NULL); - MC_SAFE_FREE(db_name); + if (db_name == NULL) { + mc_error("error __mc_get_db_name"); + return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION; + } + ret = db_util_open_with_options(db_name, &db_handle, SQLITE_OPEN_READONLY, NULL); if (SQLITE_OK != ret) { - mc_error("error when db open"); + mc_error("error when db open [%s]", db_name); *handle = NULL; + MC_SAFE_FREE(db_name); return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION; } + MC_SAFE_FREE(db_name); + if (db_handle == NULL) { mc_error("*db_handle is NULL"); return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION; diff --git a/src/media_controller_server.c b/src/media_controller_server.c index fd53f1e..82d0689 100755 --- a/src/media_controller_server.c +++ b/src/media_controller_server.c @@ -135,6 +135,39 @@ static void __server_playback_state_command_cb(const char *interface_name, const g_strfreev(params); } +static void __server_playback_action_cb(const char *interface_name, const char *signal_name, const char *message, int size, void *user_data) +{ + gchar **params = NULL; + media_controller_receiver_s *receiver = (media_controller_receiver_s *)user_data; + mc_retm_if(receiver == NULL, "reciever is NULL"); + mc_retm_if(message == NULL, "message is NULL"); + + mc_server_playback_action_received_cb callback = receiver->callback; + mc_retm_if(receiver->callback == NULL, "playback_action_command_received_cb is NULL"); + + mc_debug("__server_playback_action_cb(%s, %s, %s, %d, %p)", interface_name, signal_name, message, size, user_data); + + params = g_strsplit(message, MC_STRING_DELIMITER, 0); + mc_retm_if(params == NULL, "invalid playback_action command"); + + if (mc_util_get_command_availabe(params[0], MC_COMMAND_PLAYBACKACTION, NULL) != MEDIA_CONTROLLER_ERROR_NONE) { + mc_error("Error permission denied"); + g_strfreev(params); + return; + } + + int value = 0; + if (mc_safe_strtoi(params[1], &value) != MEDIA_CONTROLLER_ERROR_NONE) { + mc_error("Error get recieved value"); + g_strfreev(params); + return; + } + + callback(params[0], (mc_playback_action_e)value, receiver->user_data); + + g_strfreev(params); +} + static void __server_playback_position_command_cb(const char *interface_name, const char *signal_name, const char *message, int size, void *user_data) { gchar **params = NULL; @@ -148,7 +181,7 @@ static void __server_playback_position_command_cb(const char *interface_name, co mc_debug("__server_playback_position_command_cb(%s, %s, %s, %d, %p)", interface_name, signal_name, message, size, user_data); params = g_strsplit(message, MC_STRING_DELIMITER, 0); - mc_retm_if(params == NULL, "invalid playback state command"); + mc_retm_if(params == NULL, "invalid playback_position command"); if (mc_util_get_command_availabe(params[0], MC_COMMAND_PLAYBACKPOSITION, NULL) != MEDIA_CONTROLLER_ERROR_NONE) { mc_error("Error permission denied"); @@ -181,7 +214,7 @@ static void __server_shuffle_mode_command_cb(const char *interface_name, const c mc_debug("__server_shuffle_mode_command_cb(%s, %s, %s, %d, %p)", interface_name, signal_name, message, size, user_data); params = g_strsplit(message, MC_STRING_DELIMITER, 0); - mc_retm_if(params == NULL, "invalid playback state command"); + mc_retm_if(params == NULL, "invalid shuffle_mode command"); if (mc_util_get_command_availabe(params[0], MC_COMMAND_SHUFFLE, NULL) != MEDIA_CONTROLLER_ERROR_NONE) { mc_error("Error permission denied"); @@ -214,7 +247,7 @@ static void __server_repeat_mode_command_cb(const char *interface_name, const ch mc_debug("__server_repeat_mode_command_cb(%s, %s, %s, %d, %p)", interface_name, signal_name, message, size, user_data); params = g_strsplit(message, MC_STRING_DELIMITER, 0); - mc_retm_if(params == NULL, "invalid playback state command"); + mc_retm_if(params == NULL, "invalid repeat_mode command"); if (mc_util_get_command_availabe(params[0], MC_COMMAND_REPEAT, NULL) != MEDIA_CONTROLLER_ERROR_NONE) { mc_error("Error permission denied"); @@ -344,7 +377,7 @@ int mc_server_set_playback_state(mc_server_h server, mc_playback_states_e state) media_controller_server_s *mc_server = (media_controller_server_s *)server; mc_retvm_if(mc_server == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - mc_retvm_if(((state < MC_PLAYBACK_STATE_PLAYING) || (state > MC_PLAYBACK_STATE_REWIND)), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "state is invalid"); + mc_retvm_if(((state < MC_PLAYBACK_STATE_PLAYING) || (state > MC_PLAYBACK_STATE_REWINDING)), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "state is invalid"); mc_debug("playback state update [%d]", state); @@ -534,6 +567,8 @@ int mc_server_set_playback_state_command_received_cb(mc_server_h server, mc_serv int ret = MEDIA_CONTROLLER_ERROR_NONE; media_controller_server_s *mc_server = (media_controller_server_s *)server; + mc_warning("DEPRECATION WARNING: mc_server_set_playback_state_command_received_cb() is deprecated and will be removed from next release. Use mc_server_set_playback_action_received_cb() instead."); + mc_retvm_if(mc_server == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); mc_retvm_if(callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is NULL"); @@ -553,6 +588,8 @@ int mc_server_unset_playback_state_command_received_cb(mc_server_h server) int ret = MEDIA_CONTROLLER_ERROR_NONE; media_controller_server_s *mc_server = (media_controller_server_s *)server; + mc_warning("DEPRECATION WARNING: mc_server_set_playback_state_command_received_cb() is deprecated and will be removed from next release. Use mc_server_unset_playback_action_received_cb() instead."); + mc_retvm_if(mc_server == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); char *interface_name = mc_util_get_interface_name(MC_SERVER, mc_server->server_name); @@ -566,6 +603,43 @@ int mc_server_unset_playback_state_command_received_cb(mc_server_h server) return ret; } +int mc_server_set_playback_action_received_cb(mc_server_h server, mc_server_playback_action_received_cb callback, void *user_data) +{ + int ret = MEDIA_CONTROLLER_ERROR_NONE; + media_controller_server_s *mc_server = (media_controller_server_s *)server; + + mc_retvm_if(mc_server == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + mc_retvm_if(callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is NULL"); + + mc_server->playback_action_reciever.callback = callback; + mc_server->playback_action_reciever.user_data = user_data; + + char *interface_name = mc_util_get_interface_name(MC_SERVER, mc_server->server_name); + ret = mc_ipc_register_listener(&mc_server->listeners, mc_server->dconn, interface_name, MC_DBUS_SIGNAL_NAME_PLAYBACK_ACTION, __server_playback_action_cb, (void *)&(mc_server->playback_action_reciever)); + + MC_SAFE_FREE(interface_name); + + return ret; +} + +int mc_server_unset_playback_action_received_cb(mc_server_h server) +{ + int ret = MEDIA_CONTROLLER_ERROR_NONE; + media_controller_server_s *mc_server = (media_controller_server_s *)server; + + mc_retvm_if(mc_server == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + + char *interface_name = mc_util_get_interface_name(MC_SERVER, mc_server->server_name); + ret = mc_ipc_unregister_listener(&mc_server->listeners, mc_server->dconn, interface_name, MC_DBUS_SIGNAL_NAME_PLAYBACK_ACTION); + + mc_server->playback_action_reciever.callback = NULL; + mc_server->playback_action_reciever.user_data = NULL; + + MC_SAFE_FREE(interface_name); + + return ret; +} + int mc_server_set_playback_position_command_received_cb(mc_server_h server, mc_server_playback_position_command_received_cb callback, void *user_data) { int ret = MEDIA_CONTROLLER_ERROR_NONE; diff --git a/test/client_test/media_controller_client_test.c b/test/client_test/media_controller_client_test.c index 3d5de4b..cb69a67 100755 --- a/test/client_test/media_controller_client_test.c +++ b/test/client_test/media_controller_client_test.c @@ -342,7 +342,8 @@ static gboolean _get_info(int type) static gboolean _send() { g_print("== send command to latest server \n"); - int ret; + int ret = MEDIA_CONTROLLER_ERROR_NONE; + mc_playback_action_e action = MC_PLAYBACK_ACTION_PLAY; if (g_playback_state == MC_PLAYBACK_STATE_PLAYING) g_playback_state = MC_PLAYBACK_STATE_STOPPED; @@ -354,6 +355,12 @@ static gboolean _send() return FALSE; } + ret = mc_client_send_playback_action(g_mc_client, g_server_name, action); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) { + g_print("Fail to send playback action command %d", ret); + return FALSE; + } + g_playback_position += 1000; ret = mc_client_send_playback_position_command(g_mc_client, g_server_name, g_playback_position); if (ret != MEDIA_CONTROLLER_ERROR_NONE) { @@ -375,7 +382,7 @@ static gboolean _send() g_repeat_mode = MC_REPEAT_MODE_ON; else g_repeat_mode = MC_REPEAT_MODE_OFF; - ret = mc_client_send_shuffle_mode_command(g_mc_client, g_server_name, g_repeat_mode); + ret = mc_client_send_repeat_mode_command(g_mc_client, g_server_name, g_repeat_mode); if (ret != MEDIA_CONTROLLER_ERROR_NONE) { g_print("Fail to send shuffle mode command %d", ret); return FALSE; @@ -582,7 +589,7 @@ int client_sequential_test(void) mc_playback_h playback = NULL; char *str_val = NULL; int idx = 0; - mc_playback_states_e playback_state = MC_PLAYBACK_STATE_REWIND; + mc_playback_states_e playback_state = MC_PLAYBACK_STATE_REWINDING; unsigned long long playback_position = 0; /*Create Client*/ diff --git a/test/server_test/media_controller_server_test.c b/test/server_test/media_controller_server_test.c index 2ba1ac0..d978989 100755 --- a/test/server_test/media_controller_server_test.c +++ b/test/server_test/media_controller_server_test.c @@ -79,6 +79,11 @@ void __playback_state_command_received_cb(const char *client_name, mc_playback_s mc_debug("[%s] recieved playback state:[%d] from [%s]", client_name, state, client_name); } +void __playback_action_received_cb(const char *client_name, mc_playback_action_e action, void *user_data) +{ + mc_debug("[%s] recieved playback action:[%d] from [%s]", client_name, action, client_name); +} + void __playback_position_command_received_cb(const char *client_name, unsigned long long position, void *user_data) { mc_debug("[%s] recieved playback position:[%llu] from [%s]", client_name, position, client_name); @@ -157,6 +162,12 @@ static gboolean _set_cb() return FALSE; } + ret = mc_server_set_playback_action_received_cb(g_mc_server, __playback_action_received_cb, NULL); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) { + g_print("Fail to set mc_server_set_playback_action_received_cb"); + return FALSE; + } + ret = mc_server_set_playback_position_command_received_cb(g_mc_server, __playback_position_command_received_cb, NULL); if (ret != MEDIA_CONTROLLER_ERROR_NONE) { g_print("Fail to set playback_position_command_reciveed_cb"); |