diff options
author | Jiyong Min <jiyong.min@samsung.com> | 2017-11-22 12:12:57 +0900 |
---|---|---|
committer | hj kim <backto.kim@samsung.com> | 2017-12-18 08:39:36 +0000 |
commit | 7c716cbe0145672258bd335bb393d2cb00ea3f77 (patch) | |
tree | 0b36515606873f40386b0c0d137924f53a07afd0 | |
parent | 1c70c6a122f21d7b3662639d9ca0db21e34afa71 (diff) | |
download | media-controller-7c716cbe0145672258bd335bb393d2cb00ea3f77.tar.gz media-controller-7c716cbe0145672258bd335bb393d2cb00ea3f77.tar.bz2 media-controller-7c716cbe0145672258bd335bb393d2cb00ea3f77.zip |
Add to send playback positin/shuffle mode/repeat mode command
Change-Id: I373e626d0552a1d74b0fa91de46b18d3cf65df07
Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
-rwxr-xr-x | include/media_controller_private.h | 27 | ||||
-rwxr-xr-x | src/media_controller_client.c | 95 | ||||
-rwxr-xr-x | src/media_controller_server.c | 220 | ||||
-rwxr-xr-x | src/media_controller_util.c | 46 | ||||
-rwxr-xr-x | svc/media_controller_svc.c | 1 | ||||
-rwxr-xr-x | test/client_test/media_controller_client_test.c | 33 | ||||
-rwxr-xr-x | test/server_test/media_controller_server_test.c | 45 |
7 files changed, 451 insertions, 16 deletions
diff --git a/include/media_controller_private.h b/include/media_controller_private.h index b42019d..33d21b5 100755 --- a/include/media_controller_private.h +++ b/include/media_controller_private.h @@ -130,14 +130,20 @@ extern "C" { #define MC_DBUS_SIGNAL_NAME_SERVER_STATE "server_state" #define MC_DBUS_SIGNAL_NAME_PLAY_BACK "playback" #define MC_DBUS_SIGNAL_NAME_METADATA "metadata" -#define MC_DBUS_SIGNAL_NAME_PLAYBACK_SHUFFLE "playback_shuffle" -#define MC_DBUS_SIGNAL_NAME_PLAYBACK_REPEAT "playback_repeat" -#define MC_DBUS_SIGNAL_NAME_PLAYBACK_STATE_CMD "playback_state_command" -#define MC_DBUS_SIGNAL_NAME_CUSTOM_CMD "custom_command" -#define MC_DBUS_SIGNAL_NAME_CMD_REPLY "command_reply" - -#define MC_COMMAND_PLAYBACKSTATE "_playback_command_" -#define MC_COMMAND_CUSTOM "_custom_command_" +#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_POS_CMD "pb_position_cmd" +#define MC_DBUS_SIGNAL_NAME_SHUFFLE_CMD "shuffle_cmd" +#define MC_DBUS_SIGNAL_NAME_REPEAT_CMD "repeat_cmd" +#define MC_DBUS_SIGNAL_NAME_CUSTOM_CMD "custom_cmd" +#define MC_DBUS_SIGNAL_NAME_CMD_REPLY "custom_cmd_reply" + +#define MC_COMMAND_PLAYBACKSTATE "_pb_state_cmd_" +#define MC_COMMAND_PLAYBACKPOSITION "_pb_position_cmd_" +#define MC_COMMAND_SHUFFLE "_shuffle_cmd_" +#define MC_COMMAND_REPEAT "_repeat_cmd_" +#define MC_COMMAND_CUSTOM "_custom_cmd_" #define DEFAULT_USER_UID 5001 /* owner */ @@ -195,6 +201,9 @@ typedef struct { media_controller_metadata_s *metadata; media_controller_receiver_s playback_state_reciever; + media_controller_receiver_s playback_position_reciever; + media_controller_receiver_s shuffle_mode_reciever; + media_controller_receiver_s repeat_mode_reciever; media_controller_receiver_s custom_cmd_reciever; } media_controller_server_s; @@ -234,6 +243,8 @@ char* mc_util_get_interface_name(const char *type, const char *name); int mc_util_make_filter_interface_name(const char *prefix, const char *filter, char **interface_name); int mc_util_set_command_availabe(const char *name, const char *command_type, const char *command); int mc_util_get_command_availabe(const char *name, const char *command_type, const char *command); +int mc_safe_strtoi(const char *buffer, int *value); +int mc_safe_strtoull(const char *buffer, unsigned long long *value); /* for d-bus IPC */ int mc_ipc_get_dbus_connection(GDBusConnection **conn, int *dref_count); diff --git a/src/media_controller_client.c b/src/media_controller_client.c index ac20f2a..d2f142c 100755 --- a/src/media_controller_client.c +++ b/src/media_controller_client.c @@ -982,6 +982,101 @@ int mc_client_send_playback_state_command(mc_client_h client, const char *server 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; + 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"); + + 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_PLAYBACKPOSITION, NULL); + mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "Error mc_util_set_command_availabe [%d]", ret); + + message = g_strdup_printf("%s%s%llu", mc_client->client_name, MC_STRING_DELIMITER, position); + 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_POS_CMD, 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_shuffle_mode_command(mc_client_h client, const char *server_name, mc_shuffle_mode_e shuffle_mode) +{ + 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(((shuffle_mode < MC_SHUFFLE_MODE_ON) || (shuffle_mode > MC_SHUFFLE_MODE_OFF)), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "shuffle is invalid"); + + 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_SHUFFLE, 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, shuffle_mode); + 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_SHUFFLE_CMD, 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_repeat_mode_command(mc_client_h client, const char *server_name, mc_repeat_mode_e repeat_mode) +{ + 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(((repeat_mode < MC_REPEAT_MODE_ON) || (repeat_mode > MC_REPEAT_MODE_OFF)), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "repeat is invalid"); + + 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_REPEAT, 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, repeat_mode); + 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_REPEAT_CMD, 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_custom_command(mc_client_h client, const char *server_name, const char *command, bundle *data, mc_command_reply_received_cb callback, void *user_data) { int ret = MEDIA_CONTROLLER_ERROR_NONE; diff --git a/src/media_controller_server.c b/src/media_controller_server.c index fc2d6fa..ba90c4e 100755 --- a/src/media_controller_server.c +++ b/src/media_controller_server.c @@ -119,10 +119,117 @@ static void __server_playback_state_command_cb(const char *interface_name, const if (mc_util_get_command_availabe(params[0], MC_COMMAND_PLAYBACKSTATE, 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_states_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; + 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_position_command_received_cb callback = receiver->callback; + mc_retm_if(receiver->callback == NULL, "playback_position_command_received_cb is NULL"); + + mc_debug("__server_playback_state_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"); + + if (mc_util_get_command_availabe(params[0], MC_COMMAND_PLAYBACKPOSITION, NULL) != MEDIA_CONTROLLER_ERROR_NONE) { + mc_error("Error permission denied"); + g_strfreev(params); + return ; + } + + unsigned long long value = 0; + if (mc_safe_strtoull(params[1], &value) != MEDIA_CONTROLLER_ERROR_NONE) { + mc_error("Error get recieved value"); + g_strfreev(params); + return ; + } + + callback(params[0], value, receiver->user_data); + + g_strfreev(params); +} + +static void __server_shuffle_mode_command_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_shuffle_mode_command_received_cb callback = receiver->callback; + mc_retm_if(receiver->callback == NULL, "shuffle_mode_command_received_cb is NULL"); + + mc_debug("__server_playback_state_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"); + + if (mc_util_get_command_availabe(params[0], MC_COMMAND_SHUFFLE, 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_shuffle_mode_e)value, receiver->user_data); + + g_strfreev(params); +} + +static void __server_repeat_mode_command_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_repeat_mode_command_received_cb callback = receiver->callback; + mc_retm_if(receiver->callback == NULL, "repeat_mode_command_received_cb is NULL"); + + mc_debug("__server_playback_state_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"); + + if (mc_util_get_command_availabe(params[0], MC_COMMAND_REPEAT, 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_states_e)atoi(params[1]), receiver->user_data); + callback(params[0], (mc_repeat_mode_e)value, receiver->user_data); g_strfreev(params); } @@ -463,6 +570,117 @@ int mc_server_unset_playback_state_command_received_cb(mc_server_h server) 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; + 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_position_reciever.callback = callback; + mc_server->playback_position_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_POS_CMD, __server_playback_position_command_cb, (void *)&(mc_server->playback_position_reciever)); + + MC_SAFE_FREE(interface_name); + + return ret; +} + +int mc_server_unset_playback_position_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_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_POS_CMD); + + mc_server->playback_position_reciever.callback = NULL; + mc_server->playback_position_reciever.user_data = NULL; + + MC_SAFE_FREE(interface_name); + + return ret; +} + +int mc_server_set_shuffle_mode_command_received_cb(mc_server_h server, mc_server_shuffle_mode_command_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->shuffle_mode_reciever.callback = callback; + mc_server->shuffle_mode_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_SHUFFLE_CMD, __server_shuffle_mode_command_cb, (void *)&(mc_server->shuffle_mode_reciever)); + + MC_SAFE_FREE(interface_name); + + return ret; +} + +int mc_server_unset_shuffle_mode_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_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_SHUFFLE_CMD); + + mc_server->shuffle_mode_reciever.callback = NULL; + mc_server->shuffle_mode_reciever.user_data = NULL; + + MC_SAFE_FREE(interface_name); + + return ret; +} + +int mc_server_set_repeat_mode_command_received_cb(mc_server_h server, mc_server_repeat_mode_command_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->repeat_mode_reciever.callback = callback; + mc_server->repeat_mode_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_REPEAT_CMD, __server_repeat_mode_command_cb, (void *)&(mc_server->repeat_mode_reciever)); + + MC_SAFE_FREE(interface_name); + + return ret; +} + +int mc_server_unset_repeat_mode_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_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_REPEAT_CMD); + + mc_server->repeat_mode_reciever.callback = NULL; + mc_server->repeat_mode_reciever.user_data = NULL; + + MC_SAFE_FREE(interface_name); + + return ret; +} + int mc_server_set_custom_command_received_cb(mc_server_h server, mc_server_custom_command_received_cb callback, void *user_data) { int ret = MEDIA_CONTROLLER_ERROR_NONE; diff --git a/src/media_controller_util.c b/src/media_controller_util.c index 6c842e6..aa6fbd5 100755 --- a/src/media_controller_util.c +++ b/src/media_controller_util.c @@ -15,8 +15,12 @@ */ #include <aul.h> +#include <errno.h> +#include <limits.h> +#include <stdlib.h> #include "media_controller_private.h" +//#define UNIT_TEST /* for testsuite */ #define MAX_NAME_LENGTH 255 static void _mc_util_check_valid_name(const char *name, char **valid_name) @@ -75,8 +79,14 @@ int mc_util_get_own_name(char **name) return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION; } if (AUL_R_OK != aul_app_get_appid_bypid(pid, temp, sizeof(temp))) { +#ifdef UNIT_TEST + mc_error("Fix the name of the unit-tests!"); + *name = g_strdup("org.tizen.testsuites"); + return MEDIA_CONTROLLER_ERROR_NONE; +#else mc_error("Error failed to get appid!"); return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION; +#endif } *name = g_strdup(temp); @@ -163,3 +173,39 @@ int mc_util_get_command_availabe(const char *name, const char *command_type, con return ret; } + +int mc_safe_strtoi(const char *buffer, int *value) +{ + char *end = NULL; + errno = 0; + mc_retvm_if(buffer == NULL || value == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid parameter"); + + const long sl = strtol(buffer, &end, 10); + + mc_retvm_if(end == buffer, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "not a decimal number"); + mc_retvm_if('\0' != *end, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "extra characters at end of input: %s", end); + mc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "out of range of type long"); + mc_retvm_if(sl > INT_MAX, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "greater than INT_MAX"); + mc_retvm_if(sl < INT_MIN, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "smaller than INT_MIN"); + + *value = (int)sl; + + return MEDIA_CONTROLLER_ERROR_NONE; +} + +int mc_safe_strtoull(const char *buffer, unsigned long long *value) +{ + char *end = NULL; + errno = 0; + mc_retvm_if(buffer == NULL || value == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid parameter"); + + const unsigned long long ull = strtoull(buffer, &end, 10); + + mc_retvm_if(end == buffer, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "not a decimal number"); + mc_retvm_if('\0' != *end, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "extra characters at end of input: %s", end); + mc_retvm_if((ULLONG_MAX == ull) && (ERANGE == errno), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "out of range of type long"); + + *value = (unsigned long long)ull; + + return MEDIA_CONTROLLER_ERROR_NONE; +} diff --git a/svc/media_controller_svc.c b/svc/media_controller_svc.c index 6849ea8..87c8c7f 100755 --- a/svc/media_controller_svc.c +++ b/svc/media_controller_svc.c @@ -136,6 +136,7 @@ static void __mc_get_data(gpointer data, gpointer user_data) mc_list_data_set_t *_data = (mc_list_data_set_t *)data; mc_list_user_data *_user_data = (mc_list_user_data *)user_data; mc_comm_msg_s *_message = (mc_comm_msg_s *)_user_data->message; + if (_data->pid == _message->pid) { if (_data->s_data != NULL) { unsigned int i = 0; diff --git a/test/client_test/media_controller_client_test.c b/test/client_test/media_controller_client_test.c index 3f82a71..3d5de4b 100755 --- a/test/client_test/media_controller_client_test.c +++ b/test/client_test/media_controller_client_test.c @@ -40,6 +40,9 @@ static mc_client_h g_mc_client; static char *g_server_name; static mc_playback_states_e g_playback_state; +static unsigned long long g_playback_position; +static mc_shuffle_mode_e g_shuffle_mode; +static mc_repeat_mode_e g_repeat_mode; GMainLoop *mainloop = NULL; @@ -351,6 +354,33 @@ static gboolean _send() 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) { + g_print("Fail to send playback position command %d", ret); + return FALSE; + } + + if (g_shuffle_mode == MC_SHUFFLE_MODE_OFF) + g_shuffle_mode = MC_SHUFFLE_MODE_ON; + else + g_shuffle_mode = MC_SHUFFLE_MODE_OFF; + ret = mc_client_send_shuffle_mode_command(g_mc_client, g_server_name, g_shuffle_mode); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) { + g_print("Fail to send shuffle mode command %d", ret); + return FALSE; + } + + if (g_repeat_mode == MC_REPEAT_MODE_OFF) + 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); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) { + g_print("Fail to send shuffle mode command %d", ret); + return FALSE; + } + struct timespec reqtime; reqtime.tv_sec = 0; reqtime.tv_nsec = 500000000; @@ -646,6 +676,9 @@ int main(int argc, char **argv) g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL); g_playback_state = MC_PLAYBACK_STATE_PLAYING; + g_playback_position = 1000; + g_shuffle_mode = MC_SHUFFLE_MODE_OFF; + g_repeat_mode = MC_REPEAT_MODE_OFF; mainloop = g_main_loop_new(NULL, FALSE); diff --git a/test/server_test/media_controller_server_test.c b/test/server_test/media_controller_server_test.c index d61bd2f..2ba1ac0 100755 --- a/test/server_test/media_controller_server_test.c +++ b/test/server_test/media_controller_server_test.c @@ -76,14 +76,27 @@ int g_menu_set_state = CURRENT_STATE_SET_MODE_NONE; void __playback_state_command_received_cb(const char *client_name, mc_playback_states_e state, void *user_data) { - media_controller_server_s *mc_server = (media_controller_server_s *)g_mc_server; - mc_debug("[%s] recieved playback state:[%d] from [%s]", mc_server->server_name, state, client_name); + mc_debug("[%s] recieved playback state:[%d] from [%s]", client_name, state, 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); +} + +void __shuffle_mode_command_received_cb(const char *client_name, mc_shuffle_mode_e shuffle_mode, void *user_data) +{ + mc_debug("[%s] recieved shuffle mode:[%d] from [%s]", client_name, shuffle_mode, client_name); +} + +void __repeat_mode_command_received_cb(const char *client_name, mc_repeat_mode_e repeat_mode, void *user_data) +{ + mc_debug("[%s] recieved repeat mode:[%d] from [%s]", client_name, repeat_mode, client_name); } void __custom_command_received_cb(const char *client_name, const char *command, bundle *data, void *user_data) { int ret = MEDIA_CONTROLLER_ERROR_NONE; - media_controller_server_s *mc_server = (media_controller_server_s *)g_mc_server; char *bundle_data = NULL; char *get_value1 = NULL; @@ -100,8 +113,8 @@ void __custom_command_received_cb(const char *client_name, const char *command, bundle_data = g_strdup_printf("%s, %s, %s, %s", get_value1, get_value2, get_value3, get_value4); } - mc_debug("[%s] recieved command:[%s] from [%s]", mc_server->server_name, command, client_name); - mc_debug("[%s] recieved bundle:[%s] from [%s]", mc_server->server_name, bundle_data, client_name); + mc_debug("[%s] recieved command:[%s] from [%s]", client_name, command, client_name); + mc_debug("[%s] recieved bundle:[%s] from [%s]", client_name, bundle_data, client_name); bundle *bundle_reply = bundle_create(); bundle_add_str(bundle_reply, "key1", "result1"); @@ -140,13 +153,31 @@ static gboolean _set_cb() ret = mc_server_set_playback_state_command_received_cb(g_mc_server, __playback_state_command_received_cb, NULL); if (ret != MEDIA_CONTROLLER_ERROR_NONE) { - g_print("Fail to create media contoller server"); + g_print("Fail to set playback_state_command_reciveed_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"); + return FALSE; + } + + ret = mc_server_set_shuffle_mode_command_received_cb(g_mc_server, __shuffle_mode_command_received_cb, NULL); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) { + g_print("Fail to set shuffle_mode_command_reciveed_cb"); + return FALSE; + } + + ret = mc_server_set_repeat_mode_command_received_cb(g_mc_server, __repeat_mode_command_received_cb, NULL); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) { + g_print("Fail to set repeat_mode_command_reciveed_cb"); return FALSE; } ret = mc_server_set_custom_command_received_cb(g_mc_server, __custom_command_received_cb, NULL); if (ret != MEDIA_CONTROLLER_ERROR_NONE) { - g_print("Fail to create media contoller server"); + g_print("Fail to set custom_command_reciveed_cb"); return FALSE; } |