Change the code to be simple When add new empty playlist 17/206017/4
authorhj kim <backto.kim@samsung.com>
Mon, 13 May 2019 08:32:30 +0000 (17:32 +0900)
committerhj kim <backto.kim@samsung.com>
Tue, 14 May 2019 05:00:50 +0000 (14:00 +0900)
Change-Id: I8f5d40d077587e92a5489f76bf0c0e8977c718b9

include/media_controller_db.h
include/media_controller_private.h
src/media_controller_db.c
src/media_controller_playlist.c
svc/media_controller_db_util.c
test/server_test/media_controller_server_test.c

index 27b9260..99294ed 100644 (file)
@@ -53,6 +53,7 @@ int mc_db_foreach_client_list(void *handle, mc_activated_client_cb callback, voi
 int mc_db_update_latest_server_table(const char *server_name);
 int mc_db_remove_playlist(const char *server_name, const char *playlist_name);
 int mc_db_update_playlist(const char *server_name, const char *playlist_name, GList *query_list);
+int _mc_db_add_playlist(const char *server_name, const char *playlist_name);
 
 
 #endif /*__TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_DB_H__*/
index 8521f6d..e2e7158 100644 (file)
@@ -201,6 +201,7 @@ extern "C" {
 #define MC_DB_CMD_UPDATE_REPEAT                "DB_CMD_UPDATE_REPEAT"                  /* Update Server Repeat mode*/
 #define MC_DB_CMD_UPDATE_LATEST                "DB_CMD_UPDATE_LATEST"                  /* Update Latest Server info*/
 #define MC_DB_CMD_UPDATE_PLAYLIST      "DB_CMD_UPDATE_PLAYLIST"                /* Update Server Playlist*/
+#define MC_DB_CMD_ADD_PLAYLIST         "DB_CMD_ADD_PLAYLIST"                   /* Add new Server Playlist*/
 #define MC_DB_CMD_UPDATE_ICON          "DB_CMD_UPDATE_ICON"                    /* Update Server Icon*/
 #define MC_DB_CMD_UPDATE_ABILITY               "DB_CMD_UPDATE_ABILITY"                 /* Update Server abilities*/
 
@@ -397,7 +398,7 @@ int mc_ipc_send_reply(GDBusConnection *connection, const char *dbus_name, const
 int mc_ipc_send_message_to_server(mc_msg_type_e msg_type, mc_priv_type_e priv_type, const char *request_msg);
 int mc_ipc_service_connect(mc_priv_type_e type);
 
-int _mc_playlist_update(mc_priv_type_e type, const char *controller_name, mc_playlist_h playlist);
+int _mc_playlist_update(mc_priv_type_e type, const char *server_name, mc_playlist_h playlist);
 int _mc_metadata_set(mc_metadata_h metadata, mc_meta_e attribute, const char *value);
 int _parse_encoded_meta(mc_meta_e attribute, const char *encoded_meta, int *int_val_1, char **str_val, int *int_val_2);
 
index f293369..d6854bb 100644 (file)
@@ -1048,3 +1048,17 @@ int mc_db_update_playlist(const char *server_name, const char *playlist_name, GL
 
        return ret;
 }
+
+int _mc_db_add_playlist(const char *server_name, const char *playlist_name)
+{
+       int ret = MEDIA_CONTROLLER_ERROR_NONE;
+       char *sql_str = NULL;
+
+       sql_str = g_strdup_printf("%s%s%s%s%s", MC_DB_CMD_ADD_PLAYLIST, MC_STRING_DELIMITER, server_name, MC_STRING_DELIMITER, playlist_name);
+
+       ret = __mc_db_update_db(MC_PRIV_TYPE_SERVER, sql_str);
+
+       MC_SAFE_FREE(sql_str);
+
+       return ret;
+}
index e063a0f..87ebc5d 100755 (executable)
@@ -50,7 +50,7 @@ static void __query_destroy(gpointer data)
        SQLITE3_SAFE_FREE(query_str);
 }
 
-int _mc_playlist_update(mc_priv_type_e type, const char *controller_name, mc_playlist_h playlist)
+int _mc_playlist_update(mc_priv_type_e type, const char *server_name, mc_playlist_h playlist)
 {
        int ret = MEDIA_CONTROLLER_ERROR_NONE;
        GList *query_list = NULL;
@@ -62,11 +62,12 @@ int _mc_playlist_update(mc_priv_type_e type, const char *controller_name, mc_pla
        void* db_handle = NULL;
        gboolean is_exist = FALSE;
 
-       mc_retvm_if(_playlist == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid playlist");
-       mc_retvm_if(_playlist->playlist_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid playlist_name");
+       mc_retvm_if(!_playlist, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid playlist");
+       mc_retvm_if(!server_name, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid server_name");
+       mc_retvm_if(!_playlist->playlist_name, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid playlist_name");
 
        _playlist->type = type;
-       _playlist->server_name = g_strdup(controller_name);
+       _playlist->server_name = g_strdup(server_name);
 
        if (_playlist->item_list != NULL) {
                length = g_list_length(_playlist->item_list);
@@ -88,6 +89,14 @@ int _mc_playlist_update(mc_priv_type_e type, const char *controller_name, mc_pla
                                mc_error("wrong playlist item");
                        }
                }
+
+               ret = mc_db_update_playlist(server_name, _playlist->playlist_name, query_list);
+               g_list_free_full(_playlist->item_list, __item_destroy);
+               _playlist->item_list = NULL;
+               g_list_free_full(query_list, __query_destroy);
+
+               return ret;
+
        } else {
                ret = mc_db_connect(&db_handle, getuid(), FALSE);
                mc_retvm_if(db_handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "fail to mc_db_connect [%d]", ret);
@@ -96,26 +105,9 @@ int _mc_playlist_update(mc_priv_type_e type, const char *controller_name, mc_pla
                mc_db_disconnect(db_handle);
                mc_retvm_if(is_exist, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "playlist already exists");
 
-               sql_str = sqlite3_mprintf("INSERT INTO '%q' (server_name, playlist_name) VALUES (%Q, %Q);", MC_DB_TABLE_PLAYLIST, _playlist->server_name, _playlist->playlist_name);
-
-               if (sql_str != NULL)
-                       query_list = g_list_append(query_list, sql_str);
-               else
-                       mc_error("wrong playlist query");
+               return _mc_db_add_playlist(server_name, _playlist->playlist_name);
        }
 
-       ret = mc_db_update_playlist(controller_name, _playlist->playlist_name, query_list);
-       if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
-               mc_error("fail to mc_db_update_playlist");
-               goto RELEASE;
-       }
-
-RELEASE:
-       g_list_free_full(_playlist->item_list, __item_destroy);
-       _playlist->item_list = NULL;
-       g_list_free_full(query_list, __query_destroy);
-
-       return ret;
 }
 
 int mc_playlist_create(const char *playlist_name, mc_playlist_h *playlist)
index d63b367..e329125 100644 (file)
@@ -592,7 +592,7 @@ int mc_db_parse_and_update_db(uid_t uid, const char *data, int data_size)
        mc_retvm_if(params == NULL, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "fail to parsing query");
 
        if (params[0] == NULL || params[1] == NULL) {
-               mc_error("wrong query");
+               mc_error("invalid query");
                ret = MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
                goto ERROR;
        }
@@ -607,7 +607,7 @@ int mc_db_parse_and_update_db(uid_t uid, const char *data, int data_size)
 
        } else if (strncmp(MC_DB_CMD_UPDATE_SHUFFLE, params[0], strlen(MC_DB_CMD_UPDATE_SHUFFLE)) == 0) {
                if (params[2] == NULL) {
-                       mc_error("wrong query");
+                       mc_error("invalid query");
                        ret = MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
                        goto ERROR;
                }
@@ -617,7 +617,7 @@ int mc_db_parse_and_update_db(uid_t uid, const char *data, int data_size)
 
        } else if (strncmp(MC_DB_CMD_UPDATE_REPEAT, params[0], strlen(MC_DB_CMD_UPDATE_REPEAT)) == 0) {
                if (params[2] == NULL) {
-                       mc_error("wrong query");
+                       mc_error("invalid query");
                        ret = MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
                        goto ERROR;
                }
@@ -628,9 +628,19 @@ int mc_db_parse_and_update_db(uid_t uid, const char *data, int data_size)
        } else if (strncmp(MC_DB_CMD_UPDATE_LATEST, params[0], strlen(MC_DB_CMD_UPDATE_LATEST)) == 0) {
                sql_str = sqlite3_mprintf("DELETE FROM '%q'; INSERT INTO '%q' (server_name) VALUES ('%q');", MC_DB_TABLE_LATEST_SERVER, MC_DB_TABLE_LATEST_SERVER, params[1]);
 
+
+       } else if (strncmp(MC_DB_CMD_ADD_PLAYLIST, params[0], strlen(MC_DB_CMD_ADD_PLAYLIST)) == 0) {
+               if (params[2] == NULL) {
+                       mc_error("invalid query");
+                       ret = MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
+                       goto ERROR;
+               }
+
+               sql_str = sqlite3_mprintf("INSERT INTO '%q' (server_name, playlist_name) VALUES (%Q, %Q);", MC_DB_TABLE_PLAYLIST, params[1], params[2]);
+
        } else if (strncmp(MC_DB_CMD_UPDATE_PLAYLIST, params[0], strlen(MC_DB_CMD_UPDATE_PLAYLIST)) == 0) {
                if (params[2] == NULL || params[3] == NULL) {
-                       mc_error("wrong query");
+                       mc_error("invalid query");
                        ret = MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
                        goto ERROR;
                }
@@ -643,7 +653,7 @@ int mc_db_parse_and_update_db(uid_t uid, const char *data, int data_size)
 
        } else if (strncmp(MC_DB_CMD_UPDATE_ABILITY, params[0], strlen(MC_DB_CMD_UPDATE_ABILITY)) == 0) {
                if (params[2] == NULL || params[3] == NULL) {
-                       mc_error("wrong query");
+                       mc_error("invalid query");
                        ret = MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
                        goto ERROR;
                }
@@ -655,7 +665,7 @@ int mc_db_parse_and_update_db(uid_t uid, const char *data, int data_size)
 
        } else if (strncmp(MC_DB_CMD_REMOVE_PLAYLIST, params[0], strlen(MC_DB_CMD_REMOVE_PLAYLIST)) == 0) {
                if (params[2] == NULL) {
-                       mc_error("wrong query");
+                       mc_error("invalid query");
                        ret = MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
                        goto ERROR;
                }
@@ -663,7 +673,7 @@ int mc_db_parse_and_update_db(uid_t uid, const char *data, int data_size)
                sql_str = sqlite3_mprintf("DELETE FROM '%q' WHERE server_name='%q' and playlist_name=%Q;", MC_DB_TABLE_PLAYLIST, params[1], params[2]);
 
        } else {
-               mc_error("wrong request");
+               mc_error("invalid request");
                ret = MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
                goto ERROR;
        }
index ef8eba2..c42901d 100755 (executable)
@@ -22,6 +22,7 @@
 #include <glib/gprintf.h>
 
 #include <media_controller_server.h>
+#include <media_controller_client.h>
 #include "media_controller_private.h"
 
 
@@ -35,6 +36,7 @@
 ---------------------------------------------------------------------------*/
 
 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;
@@ -46,6 +48,7 @@ static mc_ability_support_e g_ability_support;
 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;
 
@@ -81,13 +84,31 @@ static int g_menu_state = CURRENT_STATE_MAIN_MENU;
 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;
@@ -134,7 +155,7 @@ void __get_and_check_metadata(mc_metadata_h metadata)
        }
 }
 
-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);
@@ -146,7 +167,7 @@ void __playback_action_received_cb(const char *client_name, const char *request_
        }
 }
 
-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);
@@ -158,7 +179,7 @@ void __playback_position_cmd_received_cb(const char *client_name, const char *re
        }
 }
 
-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);
@@ -170,7 +191,7 @@ void __shuffle_mode_cmd_received_cb(const char *client_name, const char *request
        }
 }
 
-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);
@@ -182,7 +203,7 @@ void __playlist_cmd_received_cb(const char* client_name, const  char *request_id
        }
 }
 
-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);
@@ -194,7 +215,7 @@ void __repeat_mode_cmd_received_cb(const char *client_name, const char *request_
        }
 }
 
-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;
@@ -210,7 +231,7 @@ bool __mc_search_item_cb(mc_content_type_e content_type, mc_search_category_e ca
        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);
@@ -224,15 +245,15 @@ void __search_cmd_received_cb(const char *client_name, const char *request_id, m
        }
 }
 
-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;
@@ -256,7 +277,7 @@ bool server_playlist_list_cb(mc_playlist_h playlist, void *user_data)
 
        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);
 
@@ -352,7 +373,7 @@ static int __update_playlist(mc_server_h server, mc_playlist_update_mode_e mode)
                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);
 
@@ -379,7 +400,7 @@ static int __update_playlist(mc_server_h server, mc_playlist_update_mode_e mode)
 
        } 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);
 
@@ -413,7 +434,7 @@ static int __update_playlist(mc_server_h server, mc_playlist_update_mode_e mode)
        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;
 
@@ -454,7 +475,7 @@ void __custom_cmd_received_cb(const char *client_name, const char *request_id, c
                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;
@@ -471,7 +492,7 @@ void __event_reply_received_cb(const char *client_name, const char *request_id,
                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;
@@ -480,7 +501,7 @@ bool _mc_activated_client_cb(const char *client_name, void *user_data)
        return FALSE;
 }
 
-static gboolean _create()
+static gboolean __create()
 {
        g_print("== create \n");
        int ret;
@@ -495,7 +516,7 @@ static gboolean _create()
        return TRUE;
 }
 
-static gboolean _set_cb()
+static gboolean __set_cb()
 {
        g_print("== set default callback for commands \n");
        int ret = MEDIA_CONTROLLER_ERROR_NONE;
@@ -571,7 +592,7 @@ static char *__make_meta(const char *meta)
        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;
@@ -645,17 +666,16 @@ static gboolean _set_info(int type, char *cmd)
                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");
@@ -667,7 +687,7 @@ static gboolean _set_info(int type, char *cmd)
        return TRUE;
 }
 
-static gboolean _update_info(int type)
+static gboolean __update_info(int type)
 {
        g_print(" == update information \n");
        int ret;
@@ -777,7 +797,7 @@ static gboolean _update_info(int type)
        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;
@@ -786,18 +806,16 @@ static gboolean _send_event(int type, char *cmd)
 
        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");
@@ -807,10 +825,8 @@ static gboolean _send_event(int type, char *cmd)
                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) {
@@ -836,7 +852,7 @@ static gboolean _send_event(int type, char *cmd)
        return TRUE;
 }
 
-static gboolean _destroy()
+static gboolean __destroy()
 {
        g_print("== destroy \n");
        int ret;
@@ -855,33 +871,47 @@ static gboolean _destroy()
 /***************************************************************/
 /** 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");
@@ -902,7 +932,7 @@ static void display_update_info_menu(void)
 
 }
 
-static void display_set_info_menu(void)
+static void __display_set_info_menu(void)
 {
        g_print("\n");
        g_print("====================================================\n");
@@ -921,7 +951,7 @@ static void display_set_info_menu(void)
 
 }
 
-static void display_send_menu(void)
+static void __display_send_menu(void)
 {
        g_print("\n");
        g_print("====================================================\n");
@@ -936,7 +966,7 @@ static void display_send_menu(void)
 
 }
 
-static void display_main_menu(void)
+static void __display_main_menu(void)
 {
        g_print("\n");
        g_print("====================================================\n");
@@ -954,52 +984,52 @@ static void display_main_menu(void)
 
 }
 
-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);
 
@@ -1019,47 +1049,47 @@ void _interpret_set_info_menu(char *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))
@@ -1067,9 +1097,9 @@ void _interpret_main_menu(char *cmd)
                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 {
@@ -1077,17 +1107,17 @@ void _interpret_main_menu(char *cmd)
        }
 }
 
-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:
@@ -1096,26 +1126,26 @@ static void interpret_cmd(char *cmd)
                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;
                }
@@ -1125,7 +1155,7 @@ static void interpret_cmd(char *cmd)
        }
 }
 
-gboolean input(GIOChannel *channel)
+static gboolean __input(GIOChannel *channel)
 {
        gchar buf[MAX_STRING_LEN];
        gsize read;
@@ -1135,7 +1165,7 @@ gboolean input(GIOChannel *channel)
 
        buf[read] = '\0';
        g_strstrip(buf);
-       interpret_cmd(buf);
+       __interpret_cmd(buf);
 
        return TRUE;
 
@@ -1222,7 +1252,7 @@ int main(int argc, char **argv)
        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;
@@ -1231,7 +1261,9 @@ int main(int argc, char **argv)
 
        mainloop = g_main_loop_new(NULL, FALSE);
 
-       display_menu();
+       __create_client();
+
+       __display_menu();
 
        g_main_loop_run(mainloop);
        g_main_loop_unref(mainloop);