Change some interfaces and enum values 21/37621/1 accepted/tizen/common/20150402.172715 accepted/tizen/mobile/20150402.123556 accepted/tizen/tv/20150402.122711 accepted/tizen/wearable/20150402.123101 submit/tizen/20150402.020450
authorHyunjun <zzoon.ko@samsung.com>
Wed, 1 Apr 2015 09:07:11 +0000 (18:07 +0900)
committerHyunjun <zzoon.ko@samsung.com>
Wed, 1 Apr 2015 09:07:11 +0000 (18:07 +0900)
Change-Id: I6ffd56970653b99e837f65817c7bccfa35ce57a7

CMakeLists.txt
capi-media-screen-mirroring.pc.in
include/scmirroring_private.h
include/scmirroring_src.h
include/scmirroring_type.h
miracast_server/CMakeLists.txt
miracast_server/miracast_server.c
org.tizen.scmirroring.server.service
packaging/capi-media-screen-mirroring.spec
src/scmirroring_sink.c
src/scmirroring_src.c

index a96eaf1d43dd37ab54c4959bea60dd17d925ddbc..7f9d1bf20d70cfda6bd3596d0fdedafb147f27a3 100755 (executable)
@@ -80,7 +80,7 @@ IF(UNIX)
 
 ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution)
 ADD_CUSTOM_COMMAND(
-        DEPENDS clean 
+        DEPENDS clean
         COMMENT "distribution clean"
         COMMAND find
         ARGS    . 
index 1997d91f362a69dea6a923c4f715fe7acc795399..15084891767c2af9ebb0eebe766dc40f74742af0 100755 (executable)
@@ -9,7 +9,7 @@ includedir=/usr/include/media
 Name: @PC_NAME@
 Description: @PACKAGE_DESCRIPTION@
 Version: @VERSION@
-Requires: @PC_REQUIRED@ 
+Requires: @PC_REQUIRED@
 Libs: -L${libdir} @PC_LDFLAGS@
 Cflags: -I${includedir}
 
index 583348e0121ffeba6f76ecc71c24ed00adb0f1fd..ed10a8179d95d6c3819e44a0b923a14b726a7c3d 100755 (executable)
@@ -66,6 +66,13 @@ extern "C" {
                        LOGE("NO-ERROR : <Leave>");     \
                } while (0)
 
+#define scmirroring_retvm_if(expr, val, fmt, arg...) do { \
+               if(expr) { \
+                       LOGE(""fmt"", ##arg);     \
+                       return (val); \
+               } \
+       } while (0)
+
 #define scmirroring_sucure_info(fmt, arg...) do { \
                        SECURE_LOGI(""fmt"", ##arg);     \
                } while (0)
@@ -73,6 +80,12 @@ extern "C" {
 #define SCMIRRORING_SAFE_FREE(src)      { if(src) {free(src); src = NULL;}}
 #define STRING_VALID(str)              ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
 
+#define SCMIRRORING_STATE_CMD_START                    "START"
+#define SCMIRRORING_STATE_CMD_PAUSE                    "PAUSE"
+#define SCMIRRORING_STATE_CMD_RESUME           "RESUME"
+#define SCMIRRORING_STATE_CMD_STOP                     "STOP"
+#define SCMIRRORING_STATE_CMD_DESTROY          "DESTROY"
+
 typedef struct
 {
        int error_code;
@@ -88,6 +101,7 @@ typedef struct
        bool use_hdcp;
        int resolution;
        /* To communicate with miracast server */
+       int connected;
        int sock;
        int source_id;
        GIOChannel *channel;
index 677611a744667820cd3077c194c2a6a6980d7f35..1ca21e41733c49b01bfb65855fcdb72906758e73 100755 (executable)
@@ -168,7 +168,7 @@ int scmirroring_src_set_resolution(scmirroring_src_h scmirroring_src, scmirrorin
 int scmirroring_src_connect(scmirroring_src_h scmirroring_src);
 
 /**
- * @brief Prepares screen mirroring as source, asynchronously.
+ * @brief Prepares screen mirroring as source.
  *
  * @since_tizen 2.4
  *
index bee641d7d75fa981a0535f0730ee080b25b1b10a..d493e4374d53a85653c1902770ac2a0fd9274b45 100755 (executable)
@@ -58,7 +58,6 @@ typedef enum
        SCMIRRORING_ERROR_CONNECTION_TIME_OUT   = TIZEN_ERROR_CONNECTION_TIME_OUT,  /**< Connection timeout */
        SCMIRRORING_ERROR_PERMISSION_DENIED             = TIZEN_ERROR_PERMISSION_DENIED,    /**< Permission denied */
        SCMIRRORING_ERROR_NOT_SUPPORTED                 = TIZEN_ERROR_NOT_SUPPORTED,        /**< Not supported */
-       SCMIRRORING_FILE_NO_SPACE_ON_DEVICE             = TIZEN_ERROR_FILE_NO_SPACE_ON_DEVICE, /**< No space left on device */
 } scmirroring_error_e;
 
 /**
index 37e6b20df68e1e06c54070fbe6d7708c5066642a..cbfa6f348af752d90296ae395628aa42e2a76771 100755 (executable)
@@ -10,7 +10,7 @@ FOREACH(flag ${${fw_test}_CFLAGS})
     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -Werror")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -Werror -pie")
 
 aux_source_directory(. sources)
 FOREACH(src ${sources})
index a44413c9d0df493edd0c0ae7803f39a17ffd5bf1..7d68455674c099abd969e47a594d99ab03c9ae2f 100755 (executable)
@@ -145,6 +145,8 @@ struct _MiracastServerObject {
        void *server;
        void *client;
        void *factory;
+       gint resolution;
+       gint connection_mode;
 };
 
 struct _MiracastServerObjectClass {
@@ -549,12 +551,19 @@ void __miracast_server_interpret(MiracastServerObject * server, char *buf)
 
        scmirroring_debug("Received : %s", buf);
 
-       if (g_strrstr(buf, "START")) {
+       if (g_strrstr(buf, SCMIRRORING_STATE_CMD_START)) {
+               ret = __miracast_server_start(server);
+               if (ret == SCMIRRORING_ERROR_NONE) {
+                       __miracast_server_send_resp(server, "OK:CONNECTED");
+               } else {
+                       __miracast_server_send_resp(server, "FAIL:CONNECTED");
+               }
+       } else if (g_strrstr(buf, "SET IP")) {
                gchar **addr_info;
                gchar **IP_Port;
 
                addr_info = g_strsplit(buf, " ", 0);
-               IP_Port = g_strsplit(addr_info[1], ":", 0);
+               IP_Port = g_strsplit(addr_info[2], ":", 0);
 
                scmirroring_debug("IP: %s, Port: %s", IP_Port[0], IP_Port[1]);
                server->ip = g_strdup(IP_Port[0]);
@@ -563,22 +572,45 @@ void __miracast_server_interpret(MiracastServerObject * server, char *buf)
                g_strfreev(IP_Port);
                g_strfreev(addr_info);
 
-               ret = __miracast_server_start(server);
-               if (ret == SCMIRRORING_ERROR_NONE) {
-                       __miracast_server_send_resp(server, "OK:CONNECTED");
-               } else {
-                       __miracast_server_send_resp(server, "FAIL:CONNECTED");
-               }
-       } else if (g_strrstr(buf, "PAUSE")) {
+               __miracast_server_send_resp(server, "OK:SET");
+       } else if (g_strrstr(buf, "SET CM")) {
+               gchar **conn_mode_info;
+               gint connection_mode = 0;
+
+               conn_mode_info = g_strsplit(buf, " ", 0);
+
+               connection_mode = atoi(conn_mode_info[2]);
+               scmirroring_debug("Connection mode %d", connection_mode);
+
+               server->connection_mode = connection_mode;
+
+               g_strfreev(conn_mode_info);
+
+               __miracast_server_send_resp(server, "OK:SET");
+       } else if (g_strrstr(buf, "SET RESO")) {
+               gchar **resolution_info;
+               gint resolution = 0;
+
+               resolution_info = g_strsplit(buf, " ", 0);
+
+               resolution = atoi(resolution_info[2]);
+               scmirroring_debug("Connection mode %d", resolution);
+
+               server->resolution = resolution;
+
+               g_strfreev(resolution_info);
+
+               __miracast_server_send_resp(server, "OK:SET");
+       } else if (g_strrstr(buf, SCMIRRORING_STATE_CMD_PAUSE)) {
                gst_rtsp_wfd_server_trigger_request (GST_RTSP_SERVER(server->server), WFD_TRIGGER_PAUSE);
                __miracast_server_send_resp(server, "OK:PAUSE");
-       } else if (g_strrstr(buf, "RESUME")) {
+       } else if (g_strrstr(buf, SCMIRRORING_STATE_CMD_RESUME)) {
                gst_rtsp_wfd_server_trigger_request (GST_RTSP_SERVER(server->server), WFD_TRIGGER_PLAY);
                __miracast_server_send_resp(server, "OK:RESUME");
-       } else if (g_strrstr(buf, "STOP")) {
+       } else if (g_strrstr(buf, SCMIRRORING_STATE_CMD_STOP)) {
                gst_rtsp_wfd_server_trigger_request (GST_RTSP_SERVER(server->server), WFD_TRIGGER_TEARDOWN);
                __miracast_server_send_resp(server, "OK:STOP");
-       } else if (g_strrstr(buf, "DESTROY")) {
+       } else if (g_strrstr(buf, SCMIRRORING_STATE_CMD_DESTROY)) {
                __miracast_server_quit_program(server);
        }
 }
index 44b9d0b3bd6b5619975fd0097a85e05617887c8a..3c1c6a3fa7834905793314af3c2d508d93c8df1c 100644 (file)
@@ -1,3 +1,4 @@
 [D-BUS Service]
 Name=org.tizen.scmirroring.server
 Exec=/bin/sh -c 'export GST_DEBUG=2,*rtsp*:5;/usr/bin/miracast_server'
+User=system
index 9e10590e94ee2af60352685d072b7302106b434b..af954f70f1cbff1c06ccafdde4804f4bef149b81 100755 (executable)
@@ -12,8 +12,8 @@ BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  pkgconfig(gstreamer-1.0)
 BuildRequires:  pkgconfig(gstreamer-plugins-base-1.0)
 BuildRequires:  pkgconfig(gstreamer-rtsp-server-1.0)
-BuildRequires:  pkgconfig(wifi-direct)
 BuildRequires:  pkgconfig(capi-network-wifi-direct)
+BuildRequires:  pkgconfig(wifi-direct)
 BuildRequires:  pkgconfig(mm-wfd)
 BuildRequires:  pkgconfig(iniparser)
 
@@ -75,7 +75,7 @@ cp -rf config/scmirroring_src.ini %{buildroot}/usr/etc/scmirroring_src.ini
 
 %files
 %manifest capi-media-screen-mirroring.manifest
-%{_libdir}/libcapi-media-screen-mirroring.so.*
+%{_libdir}/libcapi-media-screen-mirroring.so*
 %{_datadir}/dbus-1/services/org.tizen.scmirroring.server.service
 #License
 %{_datadir}/license/%{name}
index 588c5d7570b1e25b5d2bfa4b033c0dfa65a688b5..ea30552918b5de2311d867437fffa8d17ef74f14 100755 (executable)
@@ -85,24 +85,29 @@ static scmirroring_state_e __scmirroring_sink_state_convert(MMWfdSinkStateType m
        return state;
 }
 
+void __mm_scmirroring_sink_set_message_cb(MMWfdSinkStateType type, void *uData)
+{
+       int error_value = SCMIRRORING_ERROR_NONE;
+       scmirroring_state_e state = __scmirroring_sink_state_convert(type);
+       scmirroring_sink_s *handle = (scmirroring_sink_s*)uData;
+
+       /* call application callback */
+       if (handle->scmirroring_state_cb->state_cb)
+               handle->scmirroring_state_cb->state_cb((scmirroring_error_e)error_value, state, handle->scmirroring_state_cb->user_data);
+
+       return;
+}
+
 int scmirroring_sink_create(scmirroring_sink_h *scmirroring_sink)
 {
        int ret = SCMIRRORING_ERROR_NONE;
 
        scmirroring_error_fenter();
 
-       if(scmirroring_sink == NULL)
-       {
-               scmirroring_error("INVALID_PARAMETER(0x%08x)",SCMIRRORING_ERROR_INVALID_PARAMETER);
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(scmirroring_sink == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
        scmirroring_sink_s *handle = (scmirroring_sink_s*)calloc(1, sizeof(scmirroring_sink_s));
-       if(handle == NULL)
-       {
-               scmirroring_error("malloc fail");
-               return SCMIRRORING_ERROR_OUT_OF_MEMORY;
-       }
+       scmirroring_retvm_if(handle == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
        handle->mm_handle = 0;
        handle->ip= NULL;
@@ -132,23 +137,9 @@ int scmirroring_sink_set_ip_and_port(scmirroring_sink_h scmirroring_sink, const
 
        scmirroring_error_fenter();
 
-       if(handle == NULL)
-       {
-               scmirroring_error("INVALID_HANDLE(0x%08x)",SCMIRRORING_ERROR_INVALID_PARAMETER);
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
-
-       if(ip == NULL)
-       {
-               scmirroring_error("INVALID_IP(0x%08x)",SCMIRRORING_ERROR_INVALID_PARAMETER);
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
-
-       if(port == NULL)
-       {
-               scmirroring_error("INVALID_PORT(0x%08x)",SCMIRRORING_ERROR_INVALID_PARAMETER);
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(handle == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
+       scmirroring_retvm_if(ip == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "ip is NULL");
+       scmirroring_retvm_if(port == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "port is NULL");
 
        scmirroring_debug("ip[%s] port[%s]", ip, port);
 
@@ -168,11 +159,7 @@ int scmirroring_sink_prepare(scmirroring_sink_h scmirroring_sink)
 
        scmirroring_error_fenter();
 
-       if(handle == NULL)
-       {
-               scmirroring_error("INVALID_HANDLE(0x%08x)",SCMIRRORING_ERROR_INVALID_PARAMETER);
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(handle == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
        ret = mm_wfd_sink_realize(handle->mm_handle);
 
@@ -192,11 +179,7 @@ int scmirroring_sink_connect(scmirroring_sink_h scmirroring_sink)
 
        scmirroring_error_fenter();
 
-       if(handle == NULL)
-       {
-               scmirroring_error("INVALID_HANDLE(0x%08x)",SCMIRRORING_ERROR_INVALID_PARAMETER);
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(handle == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
        if(handle->ip == NULL)
        {
@@ -214,6 +197,7 @@ int scmirroring_sink_connect(scmirroring_sink_h scmirroring_sink)
        snprintf(server_uri, sizeof(server_uri), "rtsp://%s:%s/wfd1.0/streamid=0", handle->ip, handle->port);
 
        scmirroring_error("server_uri[%s]", server_uri);
+       printf("server_uri[%s]", server_uri);
 
        ret = mm_wfd_sink_connect(handle->mm_handle, server_uri);
 
@@ -232,11 +216,7 @@ int scmirroring_sink_unprepare(scmirroring_sink_h scmirroring_sink)
 
        scmirroring_error_fenter();
 
-       if(handle == NULL)
-       {
-               scmirroring_error("INVALID_HANDLE(0x%08x)",SCMIRRORING_ERROR_INVALID_PARAMETER);
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(handle == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
        ret = mm_wfd_sink_unrealize(handle->mm_handle);
 
@@ -255,11 +235,7 @@ int scmirroring_sink_destroy(scmirroring_sink_h scmirroring_sink)
 
        scmirroring_error_fenter();
 
-       if(handle == NULL)
-       {
-               scmirroring_error("INVALID_PARAMETER(0x%08x)",SCMIRRORING_ERROR_INVALID_PARAMETER);
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(handle == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
        ret = mm_wfd_sink_destroy(handle->mm_handle);
 
@@ -283,11 +259,7 @@ int scmirroring_sink_start(scmirroring_sink_h scmirroring_sink)
 
        scmirroring_error_fenter();
 
-       if(handle == NULL)
-       {
-               scmirroring_error("INVALID_PARAMETER(0x%08x)",SCMIRRORING_ERROR_INVALID_PARAMETER);
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(handle == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
        ret = mm_wfd_sink_start(handle->mm_handle);
 
@@ -306,11 +278,7 @@ int scmirroring_sink_stop(scmirroring_sink_h scmirroring_sink)
 
        scmirroring_error_fenter();
 
-       if(handle == NULL)
-       {
-               scmirroring_error("INVALID_PARAMETER(0x%08x)",SCMIRRORING_ERROR_INVALID_PARAMETER);
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(handle == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
        ret = mm_wfd_sink_stop(handle->mm_handle);
 
@@ -321,19 +289,6 @@ int scmirroring_sink_stop(scmirroring_sink_h scmirroring_sink)
        return ret;
 }
 
-void __mm_scmirroring_sink_set_message_cb(MMWfdSinkStateType type, void *uData)
-{
-       int error_value = SCMIRRORING_ERROR_NONE;
-       scmirroring_state_e state = __scmirroring_sink_state_convert(type);
-       scmirroring_sink_s *handle = (scmirroring_sink_s*)uData;
-
-       /* call application callback */
-       if (handle->scmirroring_state_cb->state_cb)
-               handle->scmirroring_state_cb->state_cb((scmirroring_error_e)error_value, state, handle->scmirroring_state_cb->user_data);
-
-       return;
-}
-
 int scmirroring_sink_set_state_changed_cb(scmirroring_sink_h scmirroring_sink, scmirroring_state_cb callback, void *user_data)
 {
        int ret = SCMIRRORING_ERROR_NONE;
@@ -342,11 +297,7 @@ int scmirroring_sink_set_state_changed_cb(scmirroring_sink_h scmirroring_sink, s
 
        scmirroring_error_fenter();
 
-       if(handle == NULL)
-       {
-               scmirroring_error("INVALID_PARAMETER(0x%08x)",SCMIRRORING_ERROR_INVALID_PARAMETER);
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(handle == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
        handle->scmirroring_state_cb = (scmirroring_state_cb_s*)calloc(1, sizeof(scmirroring_state_cb_s));
 
@@ -359,7 +310,7 @@ int scmirroring_sink_set_state_changed_cb(scmirroring_sink_h scmirroring_sink, s
        handle->scmirroring_state_cb->user_data = user_data;
        handle->scmirroring_state_cb->state_cb  = callback;
 
-       ret = mm_wfd_sink_set_message_callback(handle->mm_handle,__mm_scmirroring_sink_set_message_cb, handle);
+       ret = mm_wfd_sink_set_message_callback(handle->mm_handle, __mm_scmirroring_sink_set_message_cb, handle);
 
        ret = __scmirroring_sink_error_convert(__func__, ret);
 
@@ -376,11 +327,8 @@ int scmirroring_sink_set_display(scmirroring_sink_h scmirroring_sink, scmirrorin
 
        scmirroring_error_fenter();
 
-       if(handle == NULL)
-       {
-               scmirroring_error("INVALID_PARAMETER(0x%08x)",SCMIRRORING_ERROR_INVALID_PARAMETER);
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(handle == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
+       scmirroring_retvm_if(display_surface == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "display_surface is NULL");
 
        if((type != SCMIRRORING_DISPLAY_TYPE_OVERLAY) && (type != SCMIRRORING_DISPLAY_TYPE_EVAS))
        {
@@ -388,24 +336,16 @@ int scmirroring_sink_set_display(scmirroring_sink_h scmirroring_sink, scmirrorin
                return SCMIRRORING_ERROR_INVALID_PARAMETER;
        }
 
-       if(display_surface == NULL)
-       {
-               scmirroring_error("Invalid Display Handle (0x%08x)",SCMIRRORING_ERROR_INVALID_PARAMETER);
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
-
        scmirroring_debug("display type (%d)", type);
 
-       ret = mm_wfd_sink_set_attribute(handle->mm_handle, NULL, "display_surface_type",
-                       type, NULL);
+       ret = mm_wfd_sink_set_attribute(handle->mm_handle, NULL, "display_surface_type", type, NULL);
        if(ret != MM_ERROR_NONE)
        {
                scmirroring_error("Fail to Set Display Type");
                return __scmirroring_sink_error_convert(__func__,ret);
        }
 
-       ret = mm_wfd_sink_set_attribute(handle->mm_handle, NULL, "display_overlay",
-                       display_surface, NULL);
+       ret = mm_wfd_sink_set_attribute(handle->mm_handle, NULL, "display_overlay", display_surface, NULL);
        if(ret != MM_ERROR_NONE)
        {
                scmirroring_error("Fail to Set Display Overlay");
@@ -418,4 +358,3 @@ int scmirroring_sink_set_display(scmirroring_sink_h scmirroring_sink, scmirrorin
 
        return ret;
 }
-
index 28b2a3bf17a0283757eaadbfb2693648b67f3bef..26c99b2ef16dcdc8631a9bb8c7956f7cd22d54ef 100755 (executable)
@@ -24,6 +24,8 @@
 
 #define MAX_MSG_LEN 128
 #define TIMEOUT_SEC 2
+#define CONNECTED_TO_SERVER 1
+#define NOT_CONNECTED_TO_SERVER 0
 
 static gboolean __scmirroring_src_callback_call(gpointer data)
 {
@@ -56,15 +58,13 @@ static gboolean __scmirroring_src_callback_call(gpointer data)
        return FALSE;
 }
 
-int __scmirroring_src_send_cmd_to_server(scmirroring_src_s *scmirroring, char *cmd)
+static int __scmirroring_src_send_cmd_to_server(scmirroring_src_s *scmirroring, const char *cmd)
 {
        int ret = SCMIRRORING_ERROR_NONE;
        char *_cmd = NULL;
 
-       if (scmirroring == NULL) {
-               scmirroring_error("OUT_OF_MEMORY");
-               return SCMIRRORING_ERROR_OUT_OF_MEMORY;
-       }
+       scmirroring_retvm_if(scmirroring == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "scmirroring is NULL");
+       scmirroring_retvm_if(cmd == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "cmd is NULL");
 
        _cmd = g_strdup(cmd);
 
@@ -75,53 +75,54 @@ int __scmirroring_src_send_cmd_to_server(scmirroring_src_s *scmirroring, char *c
                scmirroring_debug("Sent message [%s] successfully", _cmd);
        }
 
-       g_free(_cmd);
+       SCMIRRORING_SAFE_FREE(_cmd);
+
        return ret;
 }
 
-int __miracast_server_launch(scmirroring_src_s *scmirroring)
+static int __miracast_server_launch(scmirroring_src_s *scmirroring)
 {
        int ret = SCMIRRORING_ERROR_NONE;
+       GDBusProxy *proxy = NULL;
+       GDBusConnection *conn = NULL;
+       GError *error = NULL;
 
 #if !GLIB_CHECK_VERSION(2,35,0)
        g_type_init();
 #endif
 
-       GError *error = NULL;
-
-       scmirroring_debug("-----------  socket connect failed it means server is not yet started ------------\n");
-       scmirroring_debug("going to start miracast server \n");
-
-    GDBusProxy *proxy = NULL;
-    GDBusConnection *conn = NULL;
+       scmirroring_debug("-----------  socket connect failed it means server is not yet started ------------");
+       scmirroring_debug("going to start miracast server");
 
-    conn = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
-    if (error) {
-      scmirroring_error("Failed to get dbus connection: %s", error->message);
-      return -1;
-    }    
-
-    proxy = g_dbus_proxy_new_sync (conn,
-                                            G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
-                                            NULL,
-                                            "org.tizen.scmirroring.server",
-                                            "/org/tizen/scmirroring/server",
-                                            "org.tizen.scmirroring.server",
-                                            NULL,
-                                            &error);
-    if (error) {
-        scmirroring_error("g_dbus_proxy_new_sync failed : %s\n", error->message);
-        return -1;
-    }
+       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (error) {
+               scmirroring_error("Failed to get dbus connection: %s", error->message);
+               g_error_free(error);
+               return SCMIRRORING_ERROR_INVALID_OPERATION;
+       }
 
-    g_dbus_proxy_call_sync (proxy, "launch_method", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-    if (error) {
-        scmirroring_error("g_dbus_proxy_call_sync failed : %s\n", error->message);
-        return -1;
-    }
+       proxy = g_dbus_proxy_new_sync(conn,
+                                                                       G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+                                                                       NULL,
+                                                                       "org.tizen.scmirroring.server",
+                                                                       "/org/tizen/scmirroring/server",
+                                                                       "org.tizen.scmirroring.server",
+                                                                       NULL,
+                                                                       &error);
+       if (error) {
+               scmirroring_error("g_dbus_proxy_new_sync failed : %s", error->message);
+               g_error_free(error);
+               return SCMIRRORING_ERROR_INVALID_OPERATION;
+       }
 
-    scmirroring_debug("scmirroring_proxy_initialize trying for connect\n");
+       g_dbus_proxy_call_sync (proxy, "launch_method", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (error) {
+               scmirroring_error("g_dbus_proxy_call_sync failed : %s", error->message);
+               g_error_free(error);
+               return SCMIRRORING_ERROR_INVALID_OPERATION;
+       }
 
+       scmirroring_debug("scmirroring_proxy_initialize trying for connect");
 
        return ret;
 }
@@ -140,7 +141,7 @@ int __miracast_server_launch(scmirroring_src_s *scmirroring)
  * - SET [sth]
 */
 
-int __scmirroring_src_get_error(gchar *str)
+static int __scmirroring_src_get_error(gchar *str)
 {
        if (g_strrstr(str, "OK")) {
                return SCMIRRORING_ERROR_NONE;
@@ -151,22 +152,28 @@ int __scmirroring_src_get_error(gchar *str)
        return SCMIRRORING_ERROR_NONE;
 }
 
-int __scmirroring_src_get_status(gchar *str)
+static int __scmirroring_src_get_status(gchar *str)
 {
        if (g_strrstr(str, "LISTENING")) {
                return SCMIRRORING_STATE_CONNECTION_WAIT;
        } else if (g_strrstr(str, "CONNECTED")) {
                return SCMIRRORING_STATE_CONNECTED;
-       } else if (g_strrstr(str, "STOP")) {
+       } else if (g_strrstr(str, "SET")) {
+               return SCMIRRORING_STATE_READY;
+       } else if (g_strrstr(str, SCMIRRORING_STATE_CMD_PAUSE)) {
+               return SCMIRRORING_STATE_PAUSED;
+       } else if (g_strrstr(str, SCMIRRORING_STATE_CMD_RESUME)) {
+               return SCMIRRORING_STATE_PLAYING;
+       } else if (g_strrstr(str, SCMIRRORING_STATE_CMD_STOP)) {
                return SCMIRRORING_STATE_TEARDOWN;
-       } else if (g_strrstr(str, "DESTROY")) {
+       } else if (g_strrstr(str, SCMIRRORING_STATE_CMD_DESTROY)) {
                return SCMIRRORING_STATE_NULL;
        }
 
        return SCMIRRORING_STATE_NONE;
 }
 
-void __scmirroring_src_set_callback_info (scmirroring_src_s *scmirroring, int error_code, int state)
+static void __scmirroring_src_set_callback_info (scmirroring_src_s *scmirroring, int error_code, int state)
 {
        scmirroring_state_cb_s *cb_info = scmirroring->scmirroring_state_cb;
        if (cb_info) {
@@ -184,7 +191,7 @@ void __scmirroring_src_set_callback_info (scmirroring_src_s *scmirroring, int er
        return;
 }
 
-void __scmirroring_src_interpret(scmirroring_src_s *scmirroring, char *buf)
+static void __scmirroring_src_interpret(scmirroring_src_s *scmirroring, char *buf)
 {
        scmirroring_debug("Received : %s", buf);
 
@@ -231,34 +238,92 @@ gboolean __scmirroring_src_read_cb(GIOChannel *src, GIOCondition condition, gpoi
        return TRUE;
 }
 
-int scmirroring_src_create(scmirroring_src_h *scmirroring)
+static int __scmirroring_src_send_set_cm (scmirroring_src_h scmirroring)
 {
+       /* Set connection mode to miracast server */
+       char *cmd = NULL;
        int ret = SCMIRRORING_ERROR_NONE;
+       scmirroring_src_s *_scmirroring = (scmirroring_src_s*)scmirroring;
 
-       scmirroring_debug_fenter();
+       cmd = g_strdup_printf("SET CM %d", _scmirroring->connect_mode);
+       ret = __scmirroring_src_send_cmd_to_server(_scmirroring, cmd);
+       if(ret != SCMIRRORING_ERROR_NONE)
+       {
+               SCMIRRORING_SAFE_FREE(cmd);
+               scmirroring_error("Failed to be ready [%d]", ret);
+               return SCMIRRORING_ERROR_INVALID_OPERATION;
+       }
+
+       SCMIRRORING_SAFE_FREE(cmd);
+
+       return ret;
+}
+
+static int __scmirroring_src_send_set_ip(scmirroring_src_h scmirroring)
+{
+       /* Set IP and Port to server */
+       char *cmd = NULL;
+       int ret = SCMIRRORING_ERROR_NONE;
+       scmirroring_src_s *_scmirroring = (scmirroring_src_s*)scmirroring;
 
-       if(scmirroring == NULL)
+       cmd = g_strdup_printf("SET IP %s:%s", _scmirroring->ip, _scmirroring->port);
+       ret = __scmirroring_src_send_cmd_to_server(_scmirroring, cmd);
+       if(ret != SCMIRRORING_ERROR_NONE)
        {
-               scmirroring_error("INVALID_PARAMETER");
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
+               SCMIRRORING_SAFE_FREE(cmd);
+               scmirroring_error("Failed to be ready [%d]", ret);
+               return SCMIRRORING_ERROR_INVALID_OPERATION;
        }
 
-       scmirroring_src_s *_scmirroring = (scmirroring_src_s*)calloc(1,sizeof(scmirroring_src_s));
-       if(_scmirroring == NULL)
+       SCMIRRORING_SAFE_FREE(cmd);
+
+       return ret;
+}
+
+static int __scmirroring_src_send_set_reso (scmirroring_src_h scmirroring)
+{
+       /* Set resolution to miracast server */
+       char *cmd = NULL;
+       int ret = SCMIRRORING_ERROR_NONE;
+       scmirroring_src_s *_scmirroring = (scmirroring_src_s*)scmirroring;
+
+       cmd = g_strdup_printf("SET RESO %d", _scmirroring->resolution);
+       ret = __scmirroring_src_send_cmd_to_server(_scmirroring, cmd);
+       if(ret != SCMIRRORING_ERROR_NONE)
        {
-               scmirroring_error("OUT_OF_MEMORY");
-               return SCMIRRORING_ERROR_OUT_OF_MEMORY;
+               SCMIRRORING_SAFE_FREE(cmd);
+               scmirroring_error("Failed to be ready [%d]", ret);
+               return SCMIRRORING_ERROR_INVALID_OPERATION;
        }
 
+       SCMIRRORING_SAFE_FREE(cmd);
+
+       return ret;
+}
+
+int scmirroring_src_create(scmirroring_src_h *scmirroring)
+{
+       int ret = SCMIRRORING_ERROR_NONE;
+       scmirroring_src_s *_scmirroring = NULL;
+       int sock = -1;
+       GIOChannel *channel = NULL;
+       struct timeval tv_timeout = { TIMEOUT_SEC, 0 };
+
+       scmirroring_debug_fenter();
+
+       scmirroring_retvm_if(scmirroring == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
+
+       _scmirroring = (scmirroring_src_s*)calloc(1,sizeof(scmirroring_src_s));
+       scmirroring_retvm_if(_scmirroring == NULL, SCMIRRORING_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+
        _scmirroring->ip= NULL;
        _scmirroring->port = NULL;
+       _scmirroring->connected = NOT_CONNECTED_TO_SERVER;
        _scmirroring->use_hdcp = TRUE;
        _scmirroring->resolution = 0;
        _scmirroring->connect_mode = SCMIRRORING_CONNECTION_WIFI_DIRECT;
 
        /*Create TCP Socket*/
-       int sock;
-       struct timeval tv_timeout = { TIMEOUT_SEC, 0 };
 
        if ((sock = socket(PF_FILE, SOCK_STREAM, 0)) < 0) {
                scmirroring_error("socket failed: %s", strerror(errno));
@@ -271,7 +336,6 @@ int scmirroring_src_create(scmirroring_src_h *scmirroring)
                return SCMIRRORING_ERROR_INVALID_OPERATION;
        }
 
-       GIOChannel *channel = NULL;
        channel = g_io_channel_unix_new(sock);
        if (channel == NULL) {
                scmirroring_error("g_io_channel_unix_new failed: %s", strerror(errno));
@@ -298,11 +362,7 @@ int scmirroring_src_set_connection_mode(scmirroring_src_h scmirroring, scmirrori
 
        scmirroring_debug_fenter();
 
-       if(_scmirroring == NULL)
-       {
-               scmirroring_error("INVALID Handle");
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(_scmirroring == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
        if((connect_mode < SCMIRRORING_CONNECTION_WIFI_DIRECT) ||(connect_mode > SCMIRRORING_CONNECTION_MAX))
        {
@@ -312,6 +372,11 @@ int scmirroring_src_set_connection_mode(scmirroring_src_h scmirroring, scmirrori
 
        _scmirroring->connect_mode = connect_mode;
 
+       if(_scmirroring->connected)
+       {
+               ret = __scmirroring_src_send_set_cm (_scmirroring);
+       }
+
        scmirroring_debug_fleave();
 
        return ret;
@@ -325,22 +390,14 @@ int scmirroring_src_set_state_changed_cb(scmirroring_src_h scmirroring, scmirror
 
        scmirroring_debug_fenter();
 
-       if(_scmirroring == NULL)
-       {
-               scmirroring_error("INVALID Handle");
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(_scmirroring == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
+       scmirroring_retvm_if(callback == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "callback is NULL");
 
-       if(callback != NULL)
-       {
-               _scmirroring->scmirroring_state_cb = (scmirroring_state_cb_s*)calloc(1, sizeof(scmirroring_state_cb_s));
-               if(!_scmirroring->scmirroring_state_cb) {
-                       scmirroring_error("Error Set CB");
-                       return SCMIRRORING_ERROR_OUT_OF_MEMORY;
-               }
-               _scmirroring->scmirroring_state_cb->user_data = user_data;
-               _scmirroring->scmirroring_state_cb->state_cb = callback;
-       }
+       _scmirroring->scmirroring_state_cb = (scmirroring_state_cb_s*)calloc(1, sizeof(scmirroring_state_cb_s));
+       scmirroring_retvm_if(_scmirroring->scmirroring_state_cb == NULL, SCMIRRORING_ERROR_OUT_OF_MEMORY, "Error Set CB");
+
+       _scmirroring->scmirroring_state_cb->user_data = user_data;
+       _scmirroring->scmirroring_state_cb->state_cb = callback;
 
        scmirroring_debug_fleave();
 
@@ -355,23 +412,9 @@ int scmirroring_src_set_ip_and_port(scmirroring_src_h scmirroring, const char *i
 
        scmirroring_debug_fenter();
 
-       if(_scmirroring == NULL)
-       {
-               scmirroring_error("INVALID Handle");
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
-
-       if(!STRING_VALID(ip))
-       {
-               scmirroring_error("INVALID IP");
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
-
-       if(!STRING_VALID(port))
-       {
-               scmirroring_error("INVALID PORT");
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(_scmirroring == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
+       scmirroring_retvm_if(!STRING_VALID(ip), SCMIRRORING_ERROR_INVALID_PARAMETER, "INVALID IP");
+       scmirroring_retvm_if(!STRING_VALID(port), SCMIRRORING_ERROR_INVALID_PARAMETER, "INVALID PORT");
 
        _scmirroring->ip = strdup(ip);
        _scmirroring->port = strdup(port);
@@ -382,7 +425,12 @@ int scmirroring_src_set_ip_and_port(scmirroring_src_h scmirroring, const char *i
                return SCMIRRORING_ERROR_OUT_OF_MEMORY;
        }
 
-       scmirroring_debug("");
+       if(_scmirroring->connected)
+       {
+               ret = __scmirroring_src_send_set_ip (_scmirroring);
+       }
+
+       scmirroring_debug_fleave();
 
        return ret;
 }
@@ -395,11 +443,7 @@ int scmirroring_src_set_resolution(scmirroring_src_h scmirroring, scmirroring_re
 
        scmirroring_debug_fenter();
 
-       if(_scmirroring == NULL)
-       {
-               scmirroring_error("INVALID Handle");
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(_scmirroring == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
        if((resolution < SCMIRRORING_RESOLUTION_1920x1080_P30) ||(resolution > SCMIRRORING_RESOLUTION_MAX))
        {
@@ -409,6 +453,11 @@ int scmirroring_src_set_resolution(scmirroring_src_h scmirroring, scmirroring_re
 
        _scmirroring->resolution = resolution;
 
+       if(_scmirroring->connected)
+       {
+               ret = __scmirroring_src_send_set_reso (_scmirroring);
+       }
+
        scmirroring_debug_fleave();
 
        return ret;
@@ -417,33 +466,22 @@ int scmirroring_src_set_resolution(scmirroring_src_h scmirroring, scmirroring_re
 int scmirroring_src_connect(scmirroring_src_h scmirroring)
 {
        int ret = SCMIRRORING_ERROR_NONE;
+       int retry = 0;
+       struct sockaddr_un serv_addr;
 
        scmirroring_src_s *_scmirroring = (scmirroring_src_s*)scmirroring;
 
        scmirroring_debug_fenter();
 
-       if(_scmirroring == NULL)
-       {
-               scmirroring_error("INVALID Handle");
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
-
-       if((_scmirroring->ip == NULL) ||(_scmirroring->port == NULL))
-       {
-               scmirroring_error("INVALID IP and Port");
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(_scmirroring == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
        /* Connecting to the miracast server */
-       int retry = 0;
-       struct sockaddr_un serv_addr;
-
        memset(&serv_addr, 0, sizeof(struct sockaddr_un));
        serv_addr.sun_family = AF_UNIX;
        strcpy(serv_addr.sun_path, _scmirroring->sock_path);
 
 try:
-       scmirroring_debug("Trying to connect to the miracast server\n");
+       scmirroring_debug("Trying to connect to the miracast server");
        if (connect(_scmirroring->sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
                /* Once failed to connect, try to launch miracast server */
                if (retry == 0) {
@@ -456,9 +494,9 @@ try:
                        usleep(10000);
                        goto try;
                } else {
-                       scmirroring_debug("Trying to connect failed\n");
+                       scmirroring_debug("Trying to connect failed");
                        if (retry < 5) {
-                               scmirroring_debug("Trying to connect again..\n");
+                               scmirroring_debug("Trying to connect again..");
                                retry++;
                                usleep(10000);
                                goto try;
@@ -478,13 +516,22 @@ try:
        source = g_io_create_watch(_scmirroring->channel, G_IO_IN | G_IO_HUP | G_IO_ERR);
        int source_id = -1;
 
+       if((_scmirroring->ip != NULL) ||(_scmirroring->port != NULL))
+       {
+               ret = __scmirroring_src_send_set_ip (_scmirroring);
+               ret = __scmirroring_src_send_set_cm (_scmirroring);
+               ret = __scmirroring_src_send_set_reso (_scmirroring);
+       }
+
        /* Set callback to be called when socket is readable */
        g_source_set_callback(source, (GSourceFunc)__scmirroring_src_read_cb, _scmirroring, NULL);
        source_id = g_source_attach(source, g_main_context_get_thread_default());
 
        _scmirroring->source_id = source_id;
+       _scmirroring->connected = CONNECTED_TO_SERVER;
 
        __scmirroring_src_set_callback_info (_scmirroring, SCMIRRORING_ERROR_NONE, SCMIRRORING_STATE_READY);
+
        scmirroring_debug_fleave();
 
        return ret;
@@ -498,9 +545,12 @@ int scmirroring_src_disconnect(scmirroring_src_h scmirroring)
 
        scmirroring_debug_fenter();
 
+       scmirroring_retvm_if(_scmirroring == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
+
        g_io_channel_shutdown (_scmirroring->channel, FALSE, NULL);
        g_io_channel_unref(_scmirroring->channel);
        close (_scmirroring->sock);
+       _scmirroring->connected = NOT_CONNECTED_TO_SERVER;
 
        scmirroring_debug_fleave();
 
@@ -510,29 +560,15 @@ int scmirroring_src_disconnect(scmirroring_src_h scmirroring)
 int scmirroring_src_start(scmirroring_src_h scmirroring)
 {
        int ret = SCMIRRORING_ERROR_NONE;
-
        scmirroring_src_s *_scmirroring = (scmirroring_src_s*)scmirroring;
 
        scmirroring_debug_fenter();
 
-       if(_scmirroring == NULL)
-       {
-               scmirroring_error("INVALID Handle");
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(_scmirroring == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
-       /* Set IP and Port to server and to be ready for miracast server */
-       char *cmd = NULL;
-       cmd = g_strdup_printf("START %s:%s", _scmirroring->ip, _scmirroring->port);
-       ret = __scmirroring_src_send_cmd_to_server(_scmirroring, cmd);
+       ret = __scmirroring_src_send_cmd_to_server(_scmirroring, SCMIRRORING_STATE_CMD_START);
        if(ret != SCMIRRORING_ERROR_NONE)
-       {
-               g_free(cmd);
-               scmirroring_error("Failed to be ready [%d]", ret);
-               return SCMIRRORING_ERROR_INVALID_OPERATION;
-       }
-
-       g_free(cmd);
+               scmirroring_error("Failed to start [%d]", ret);
 
        scmirroring_debug_fleave();
 
@@ -542,28 +578,15 @@ int scmirroring_src_start(scmirroring_src_h scmirroring)
 int scmirroring_src_pause(scmirroring_src_h scmirroring)
 {
        int ret = SCMIRRORING_ERROR_NONE;
-
        scmirroring_src_s *_scmirroring = (scmirroring_src_s*)scmirroring;
 
        scmirroring_debug_fenter();
 
-       if(_scmirroring == NULL)
-       {
-               scmirroring_error("INVALID Handle");
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(_scmirroring == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
-       char *cmd = NULL;
-       cmd = g_strdup_printf("PAUSE");
-       ret = __scmirroring_src_send_cmd_to_server(_scmirroring, cmd);
+       ret = __scmirroring_src_send_cmd_to_server(_scmirroring, SCMIRRORING_STATE_CMD_PAUSE);
        if(ret != SCMIRRORING_ERROR_NONE)
-       {
-               g_free(cmd);
-               scmirroring_error("Failed to be ready [%d]", ret);
-               return SCMIRRORING_ERROR_INVALID_OPERATION;
-       }
-
-       g_free(cmd);
+               scmirroring_error("Failed to pause [%d]", ret);
 
        scmirroring_debug_fleave();
 
@@ -573,28 +596,15 @@ int scmirroring_src_pause(scmirroring_src_h scmirroring)
 int scmirroring_src_resume(scmirroring_src_h scmirroring)
 {
        int ret = SCMIRRORING_ERROR_NONE;
-
        scmirroring_src_s *_scmirroring = (scmirroring_src_s*)scmirroring;
 
        scmirroring_debug_fenter();
 
-       if(_scmirroring == NULL)
-       {
-               scmirroring_error("INVALID Handle");
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(_scmirroring == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
-       char *cmd = NULL;
-       cmd = g_strdup_printf("RESUME");
-       ret = __scmirroring_src_send_cmd_to_server(_scmirroring, cmd);
+       ret = __scmirroring_src_send_cmd_to_server(_scmirroring, SCMIRRORING_STATE_CMD_RESUME);
        if(ret != SCMIRRORING_ERROR_NONE)
-       {
-               g_free(cmd);
-               scmirroring_error("Failed to be ready [%d]", ret);
-               return SCMIRRORING_ERROR_INVALID_OPERATION;
-       }
-
-       g_free(cmd);
+               scmirroring_error("Failed to resume [%d]", ret);
 
        scmirroring_debug_fleave();
 
@@ -604,28 +614,15 @@ int scmirroring_src_resume(scmirroring_src_h scmirroring)
 int scmirroring_src_stop(scmirroring_src_h scmirroring)
 {
        int ret = SCMIRRORING_ERROR_NONE;
-
        scmirroring_src_s *_scmirroring = (scmirroring_src_s*)scmirroring;
 
        scmirroring_debug_fenter();
 
-       if(_scmirroring == NULL)
-       {
-               scmirroring_error("INVALID Handle");
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(_scmirroring == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
-       char *cmd = NULL;
-       cmd = g_strdup_printf("STOP");
-       ret = __scmirroring_src_send_cmd_to_server(_scmirroring, cmd);
+       ret = __scmirroring_src_send_cmd_to_server(_scmirroring, SCMIRRORING_STATE_CMD_STOP);
        if(ret != SCMIRRORING_ERROR_NONE)
-       {
-               g_free(cmd);
-               scmirroring_error("Failed to be ready [%d]", ret);
-               return SCMIRRORING_ERROR_INVALID_OPERATION;
-       }
-
-       g_free(cmd);
+               scmirroring_error("Failed to be stop [%d]", ret);
 
        scmirroring_debug_fleave();
 
@@ -635,27 +632,15 @@ int scmirroring_src_stop(scmirroring_src_h scmirroring)
 int scmirroring_src_destroy(scmirroring_src_h scmirroring)
 {
        int ret = SCMIRRORING_ERROR_NONE;
-
        scmirroring_src_s *_scmirroring = (scmirroring_src_s*)scmirroring;
 
        scmirroring_debug_fenter();
 
-       if(_scmirroring == NULL)
-       {
-               scmirroring_error("INVALID Handle");
-               return SCMIRRORING_ERROR_INVALID_PARAMETER;
-       }
+       scmirroring_retvm_if(_scmirroring == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
-       char *cmd = NULL;
-       cmd = g_strdup_printf("DESTROY");
-       ret = __scmirroring_src_send_cmd_to_server(_scmirroring, cmd);
+       ret = __scmirroring_src_send_cmd_to_server(_scmirroring, SCMIRRORING_STATE_CMD_DESTROY);
        if(ret != SCMIRRORING_ERROR_NONE)
-       {
-               g_free(cmd);
-               scmirroring_error("Failed to be ready [%d]", ret);
-               return SCMIRRORING_ERROR_INVALID_OPERATION;
-       }
-       g_free(cmd);
+               scmirroring_error("Failed to destroy [%d]", ret);
 
        scmirroring_debug_fleave();