#include <glib/gprintf.h>
#include <media_controller_server.h>
+#include <media_controller_client.h>
#include "media_controller_private.h"
---------------------------------------------------------------------------*/
static mc_server_h g_mc_server;
+static mc_client_h g_mc_client;
static mc_meta_e g_metadata_type;
static mc_shuffle_mode_e g_shuffle_mode;
static mc_repeat_mode_e g_repeat_mode;
static char *g_event_name = NULL;
static char *g_client_name = NULL;
static char *g_request_id = NULL;
+static char *g_server_name = NULL;
GMainLoop *mainloop = NULL;
static int g_menu_set_state = CURRENT_STATE_SET_MODE_NONE;
static int g_menu_send_event = 0;
-#define TEST_SERVER_ID "org.tizen.testsuites"
-
/*---------------------------------------------------------------------------
| LOCAL FUNCTION PROTOTYPES: |
---------------------------------------------------------------------------*/
-void __get_and_check_metadata(mc_metadata_h metadata)
+static void __mc_server_state_updated_cb(const char *server_name, mc_server_state_e state, void *user_data)
+{
+ g_server_name = g_strdup(server_name);
+ mc_debug("Server[%s] Server state(%d)", server_name, state);
+
+ mc_client_destroy(g_mc_client);
+}
+
+static void __create_client()
+{
+ int ret = MEDIA_CONTROLLER_ERROR_NONE;
+
+ ret = mc_client_create(&g_mc_client);
+ mc_retm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, "Fail to mc_client_create [%d]", ret);
+
+ ret = mc_client_set_server_updated_cb(g_mc_client, __mc_server_state_updated_cb, NULL);
+ if (ret != MEDIA_CONTROLLER_ERROR_NONE)
+ mc_error("Fail to mc_client_set_server_updated_cb");
+}
+
+static void __get_and_check_metadata(mc_metadata_h metadata)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
int idx = 0;
}
}
-void __playback_action_received_cb(const char *client_name, const char *request_id, mc_playback_action_e action, void *user_data)
+static void __playback_action_received_cb(const char *client_name, const char *request_id, mc_playback_action_e action, void *user_data)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
g_print("[%s] recieved playback action:[%d] from [%s]\n", request_id, action, client_name);
}
}
-void __playback_position_cmd_received_cb(const char *client_name, const char *request_id, unsigned long long position, void *user_data)
+static void __playback_position_cmd_received_cb(const char *client_name, const char *request_id, unsigned long long position, void *user_data)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
g_print("[%s] recieved playback position:[%llu] from [%s]\n", request_id, position, client_name);
}
}
-void __shuffle_mode_cmd_received_cb(const char *client_name, const char *request_id, mc_shuffle_mode_e shuffle_mode, void *user_data)
+static void __shuffle_mode_cmd_received_cb(const char *client_name, const char *request_id, mc_shuffle_mode_e shuffle_mode, void *user_data)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
g_print("[%s] recieved shuffle mode:[%d] from [%s]\n", request_id, shuffle_mode, client_name);
}
}
-void __playlist_cmd_received_cb(const char* client_name, const char *request_id, const char *playlist_name, const char *index, mc_playback_action_e action, unsigned long long position, void *user_data)
+static void __playlist_cmd_received_cb(const char* client_name, const char *request_id, const char *playlist_name, const char *index, mc_playback_action_e action, unsigned long long position, void *user_data)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
g_print("[%s] recieved playlist play : playlist_name[%s] index[%s] action[%d] position[%llu] from [%s]\n", request_id, playlist_name, index, action, position, client_name);
}
}
-void __repeat_mode_cmd_received_cb(const char *client_name, const char *request_id, mc_repeat_mode_e repeat_mode, void *user_data)
+static void __repeat_mode_cmd_received_cb(const char *client_name, const char *request_id, mc_repeat_mode_e repeat_mode, void *user_data)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
g_print("[%s] recieved repeat mode:[%d] from [%s]\n", request_id, repeat_mode, client_name);
}
}
-bool __mc_search_item_cb(mc_content_type_e content_type, mc_search_category_e category, const char *search_keyword, bundle *data, void *user_data)
+static bool __mc_search_item_cb(mc_content_type_e content_type, mc_search_category_e category, const char *search_keyword, bundle *data, void *user_data)
{
char *get_value1 = NULL;
char *get_value2 = NULL;
return TRUE;
}
-void __search_cmd_received_cb(const char *client_name, const char *request_id, mc_search_h search, void *user_data)
+static void __search_cmd_received_cb(const char *client_name, const char *request_id, mc_search_h search, void *user_data)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
g_print("[%s] recieved search cmd from [%s]\n", request_id, client_name);
}
}
-bool server_playlist_item_cb(const char *index, mc_metadata_h meta, void *user_data)
+static bool __server_playlist_item_cb(const char *index, mc_metadata_h meta, void *user_data)
{
mc_debug("playlist index [%s]", index);
__get_and_check_metadata(meta);
-return true;
+ return true;
}
-bool server_playlist_list_cb(mc_playlist_h playlist, void *user_data)
+static bool __server_playlist_list_cb(mc_playlist_h playlist, void *user_data)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
char *playlist_name = NULL;
mc_debug("playlist_name [%s]", playlist_name);
- ret = mc_playlist_foreach_item(playlist, server_playlist_item_cb, NULL);
+ ret = mc_playlist_foreach_item(playlist, __server_playlist_item_cb, NULL);
if (ret != MEDIA_CONTROLLER_ERROR_NONE)
mc_error("Fail to mc_playlist_foreach_item [%d]", ret);
ret = mc_playlist_destroy(playlist_1);
ret = mc_playlist_destroy(playlist_2);
- ret = mc_playlist_get_playlist(TEST_SERVER_ID, playlist_name_1, &playlist_1);
+ ret = mc_playlist_get_playlist(g_server_name, playlist_name_1, &playlist_1);
if (ret != MEDIA_CONTROLLER_ERROR_NONE)
mc_error("Fail to mc_playlist_get_playlist [%d]", ret);
} else {
- ret = mc_playlist_foreach_playlist(TEST_SERVER_ID, server_playlist_list_cb, &playlist_list);
+ ret = mc_playlist_foreach_playlist(g_server_name, __server_playlist_list_cb, &playlist_list);
if (ret != MEDIA_CONTROLLER_ERROR_NONE)
mc_error("Fail to mc_playlist_foreach_playlist [%d]", ret);
return ret;
}
-void __custom_cmd_received_cb(const char *client_name, const char *request_id, const char *command, bundle *data, void *user_data)
+static void __custom_cmd_received_cb(const char *client_name, const char *request_id, const char *command, bundle *data, void *user_data)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
g_free(bundle_data);
}
-void __event_reply_received_cb(const char *client_name, const char *request_id, const int result_code, bundle *data, void *user_data)
+static void __event_reply_received_cb(const char *client_name, const char *request_id, const int result_code, bundle *data, void *user_data)
{
const char *bundle_key = "key1";
char *bundle_value = NULL;
request_id, result_code, bundle_key, bundle_value, client_name);
}
-bool _mc_activated_client_cb(const char *client_name, void *user_data)
+static bool __mc_activated_client_cb(const char *client_name, void *user_data)
{
char **_client = (char **)user_data;
if (_client == NULL) return FALSE;
return FALSE;
}
-static gboolean _create()
+static gboolean __create()
{
g_print("== create \n");
int ret;
return TRUE;
}
-static gboolean _set_cb()
+static gboolean __set_cb()
{
g_print("== set default callback for commands \n");
int ret = MEDIA_CONTROLLER_ERROR_NONE;
return encoded_meta;
}
-static gboolean _set_info(int type, char *cmd)
+static gboolean __set_info(int type, char *cmd)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
int playback_state = 0;
if ((g_metadata_type == MC_META_MEDIA_SEASON) || (g_metadata_type == MC_META_MEDIA_EPISODE) || (g_metadata_type == MC_META_MEDIA_RESOLUTION))
metadata = __make_meta(cmd);
else
- metadata = strdup(cmd);
+ metadata = g_strdup(cmd);
ret = mc_server_set_metadata(g_mc_server, g_metadata_type, metadata);
if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
g_print("Fail to set metadata");
- if (metadata != NULL)
- free(metadata);
+ g_free(metadata);
return FALSE;
}
g_print("set metadata value: %s", metadata);
- if (metadata != NULL)
- free(metadata);
+
+ g_free(metadata);
break;
default:
g_print(" == unknown type!\n");
return TRUE;
}
-static gboolean _update_info(int type)
+static gboolean __update_info(int type)
{
g_print(" == update information \n");
int ret;
return TRUE;
}
-static gboolean _send_event(int type, char *cmd)
+static gboolean __send_event(int type, char *cmd)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
bundle *bundle_data = NULL;
switch (type) {
case 1:
- if (g_client_name != NULL) {
- g_free(g_client_name);
- g_client_name = NULL;
- }
- ret = mc_server_foreach_client(g_mc_server, _mc_activated_client_cb, &g_client_name);
+ g_free(g_client_name);
+ g_client_name = NULL;
+
+ ret = mc_server_foreach_client(g_mc_server, __mc_activated_client_cb, &g_client_name);
break;
case 2:
- if (g_event_name != NULL) {
- g_free(g_event_name);
- g_event_name = NULL;
- }
+ g_free(g_event_name);
+ g_event_name = NULL;
+
g_event_name = g_strdup(cmd);
if (g_event_name == NULL) {
g_print("Fail to set event_name \n");
break;
case 3:
- if (g_request_id != NULL) {
- g_free(g_request_id);
- g_request_id = NULL;
- }
+ g_free(g_request_id);
+ g_request_id = NULL;
bundle_data = bundle_create();
if (bundle_data == NULL) {
return TRUE;
}
-static gboolean _destroy()
+static gboolean __destroy()
{
g_print("== destroy \n");
int ret;
/***************************************************************/
/** Testsuite */
/***************************************************************/
-void quit(void)
+static void __quit(void)
{
if (g_mc_server != NULL)
- _destroy();
+ __destroy();
+
+ g_free(g_event_name);
+ g_event_name = NULL;
+
+ g_free(g_request_id);
+ g_request_id = NULL;
+
+ g_free(g_client_name);
+ g_client_name = NULL;
+
+ g_free(g_server_name);
+ g_server_name = NULL;
g_main_loop_quit(mainloop);
+
+ return;
}
-void reset_current_send_menu_state()
+static void __reset_current_send_menu_state()
{
g_menu_send_event = 0;
return;
}
-void reset_current_set_menu_state()
+static void __reset_current_set_menu_state()
{
g_menu_set_state = CURRENT_STATE_SET_MODE_NONE;
return;
}
-void reset_current_menu_state()
+static void __reset_current_menu_state()
{
g_menu_state = CURRENT_STATE_MAIN_MENU;
return;
}
-static void display_update_info_menu(void)
+static void __display_update_info_menu(void)
{
g_print("\n");
g_print("====================================================\n");
}
-static void display_set_info_menu(void)
+static void __display_set_info_menu(void)
{
g_print("\n");
g_print("====================================================\n");
}
-static void display_send_menu(void)
+static void __display_send_menu(void)
{
g_print("\n");
g_print("====================================================\n");
}
-static void display_main_menu(void)
+static void __display_main_menu(void)
{
g_print("\n");
g_print("====================================================\n");
}
-static void display_menu(void)
+static void __display_menu(void)
{
if (g_menu_state == CURRENT_STATE_MAIN_MENU)
- display_main_menu();
+ __display_main_menu();
else if (g_menu_state == CURRENT_STATE_INFORMATION_SET_MENU)
- display_set_info_menu();
+ __display_set_info_menu();
else if (g_menu_state == CURRENT_STATE_INFORMATION_UPDATE_MENU)
- display_update_info_menu();
+ __display_update_info_menu();
else if (g_menu_state == CURRENT_STATE_SEND_EVENT_MENU)
- display_send_menu();
+ __display_send_menu();
else
g_print("*** Unknown status.\n");
}
-void _interpret_update_info_menu(char *cmd)
+static void __interpret_update_info_menu(char *cmd)
{
int len = strlen(cmd);
if (len == 1) {
if (!strncmp(cmd, "1", len))
- _update_info(1);
+ __update_info(1);
else if (!strncmp(cmd, "2", len))
- _update_info(2);
+ __update_info(2);
else if (!strncmp(cmd, "3", len))
- _update_info(3);
+ __update_info(3);
else if (!strncmp(cmd, "4", len))
- _update_info(4);
+ __update_info(4);
else if (!strncmp(cmd, "5", len))
- _update_info(5);
+ __update_info(5);
else if (!strncmp(cmd, "6", len))
- _update_info(6);
+ __update_info(6);
else if (!strncmp(cmd, "7", len))
- _update_info(7);
+ __update_info(7);
else if (!strncmp(cmd, "8", len))
- _update_info(8);
+ __update_info(8);
else if (!strncmp(cmd, "9", len))
- _update_info(9);
+ __update_info(9);
else if (!strncmp(cmd, "0", len))
- reset_current_menu_state();
+ __reset_current_menu_state();
} else {
g_print("wrong command\n");
}
}
-void _interpret_set_info_menu(char *cmd)
+static void __interpret_set_info_menu(char *cmd)
{
int len = strlen(cmd);
else if (!strncmp(cmd, "7", len))
g_menu_set_state = CURRENT_STATE_SET_METADATA_VALUE;
else if (!strncmp(cmd, "0", len)) {
- reset_current_menu_state();
- display_menu();
+ __reset_current_menu_state();
+ __display_menu();
}
} else {
g_print("wrong command\n");
}
}
-void _interpret_send_menu(char *cmd)
+static void __interpret_send_menu(char *cmd)
{
int len = strlen(cmd);
if (len == 1) {
if (!strncmp(cmd, "1", len)) {
- _send_event(1, cmd);
- reset_current_send_menu_state();
- display_menu();
+ __send_event(1, cmd);
+ __reset_current_send_menu_state();
+ __display_menu();
} else if (!strncmp(cmd, "2", len)) {
g_menu_send_event = 2;
} else if (!strncmp(cmd, "3", len)) {
- _send_event(3, cmd);
- reset_current_send_menu_state();
- display_menu();
+ __send_event(3, cmd);
+ __reset_current_send_menu_state();
+ __display_menu();
} else if (!strncmp(cmd, "0", len)) {
- reset_current_menu_state();
- display_menu();
+ __reset_current_menu_state();
+ __display_menu();
}
} else {
g_print("wrong command\n");
}
}
-void _interpret_main_menu(char *cmd)
+static void __interpret_main_menu(char *cmd)
{
int len = strlen(cmd);
if (len == 1) {
if (!strncmp(cmd, "1", len))
- _create();
+ __create();
else if (!strncmp(cmd, "2", len))
- _set_cb();
+ __set_cb();
else if (!strncmp(cmd, "3", len))
g_menu_state = CURRENT_STATE_INFORMATION_SET_MENU;
else if (!strncmp(cmd, "4", len))
else if (!strncmp(cmd, "6", len))
g_menu_state = CURRENT_STATE_SEND_EVENT_MENU;
else if (!strncmp(cmd, "9", len))
- _destroy();
+ __destroy();
else if (!strncmp(cmd, "0", len))
- quit();
+ __quit();
else
g_print("wrong command [%s]\n", cmd);
} else {
}
}
-static void interpret_cmd(char *cmd)
+static void __interpret_cmd(char *cmd)
{
switch (g_menu_state) {
case CURRENT_STATE_MAIN_MENU:
- _interpret_main_menu(cmd);
- display_menu();
+ __interpret_main_menu(cmd);
+ __display_menu();
break;
case CURRENT_STATE_INFORMATION_SET_MENU:
switch (g_menu_set_state) {
case CURRENT_STATE_SET_MODE_NONE:
- _interpret_set_info_menu(cmd);
+ __interpret_set_info_menu(cmd);
break;
case CURRENT_STATE_SET_PLAYBACK_STATE:
case CURRENT_STATE_SET_PLAYBACK_POSITION:
case CURRENT_STATE_SET_AGE_RATING:
case CURRENT_STATE_SET_METADATA_NAME:
case CURRENT_STATE_SET_METADATA_VALUE:
- _set_info(g_menu_set_state, cmd);
- reset_current_set_menu_state();
- display_menu();
+ __set_info(g_menu_set_state, cmd);
+ __reset_current_set_menu_state();
+ __display_menu();
default:
break;
}
break;
case CURRENT_STATE_INFORMATION_UPDATE_MENU:
- _interpret_update_info_menu(cmd);
- display_menu();
+ __interpret_update_info_menu(cmd);
+ __display_menu();
break;
case CURRENT_STATE_SEND_EVENT_MENU:
switch (g_menu_send_event) {
case 0:
- _interpret_send_menu(cmd);
+ __interpret_send_menu(cmd);
break;
case 2:
- _send_event(g_menu_send_event, cmd);
- reset_current_send_menu_state();
- display_menu();
+ __send_event(g_menu_send_event, cmd);
+ __reset_current_send_menu_state();
+ __display_menu();
default:
break;
}
}
}
-gboolean input(GIOChannel *channel)
+static gboolean __input(GIOChannel *channel)
{
gchar buf[MAX_STRING_LEN];
gsize read;
buf[read] = '\0';
g_strstrip(buf);
- interpret_cmd(buf);
+ __interpret_cmd(buf);
return TRUE;
GIOChannel *stdin_channel;
stdin_channel = g_io_channel_unix_new(0);
g_io_channel_set_flags(stdin_channel, G_IO_FLAG_NONBLOCK, NULL);
- g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
+ g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)__input, NULL);
g_shuffle_mode = MC_SHUFFLE_MODE_OFF;
g_repeat_mode = MC_REPEAT_MODE_OFF;
mainloop = g_main_loop_new(NULL, FALSE);
- display_menu();
+ __create_client();
+
+ __display_menu();
g_main_loop_run(mainloop);
g_main_loop_unref(mainloop);