Tested for sign-up/sign-in/sign-out 36/139936/3
authorSangkoo Kim <sangkoo.kim@samsung.com>
Fri, 21 Jul 2017 05:58:36 +0000 (14:58 +0900)
committerSangkoo Kim <sangkoo.kim@samsung.com>
Fri, 21 Jul 2017 06:03:21 +0000 (15:03 +0900)
Change-Id: Icef81f2c3bc26c583add13d61d28699f6ac3cb94
Signed-off-by: Sangkoo Kim <sangkoo.kim@samsung.com>
packaging/controlee-firmware-resource.spec
test/controlee_firmware_test.c

index f48562f19d4fb7812d311d0bffa891f821b28a03..c0b012217eb99a4da76383397d16b20acefe253b 100644 (file)
@@ -65,6 +65,7 @@ rm -rf %{buildroot}
 %{_includedir}/controlee-firmware-resource/*
 
 %files test
+%defattr(-,root,root,-)
 %{_bindir}/controlee_firmware_test
 %config(noreplace) /opt/usr/data/ua-client/thawte.cert.pem
 %config(noreplace) /opt/usr/data/ua-client/oic_svr_db_client.dat
index 23c2574fc53fbc8d0975f1cdadc3a8ff087eaec9..ed9ac398168cf6ee2368f341bbdeb82b4bc770e0 100644 (file)
@@ -20,7 +20,6 @@
 #include <controlee_firmware_resource.h>
 
 
-#define OCF_SERVER_URL ""
 #define DEFAULT_CONTEXT_VALUE 0x99
 #define LOGIN_OK 4
 
@@ -32,6 +31,8 @@ OCResourceHandle aircon_handle = NULL;
 OCResourceHandle binary_switch_handle = NULL;
 OCResourceHandle firmware_handle = NULL;
 
+OCPersistentStorage *ps;
+
 #define CLOUD_STG_SERVER                       "52.202.112.20:443"
 #define CLOUD_DEV_SERVER                       "54.86.109.131:443"
 #define CLOUD_AUTH_PROVIDER            "samsung-us"
@@ -104,18 +105,11 @@ int _set_auth_cert_info()
                return -1;
        }
 
-       if (loginDetails.certificate) {
-               free(loginDetails.certificate);
-               loginDetails.certificate = NULL;
-       }
-
+       loginDetails.certificate = cert->raw_cert;
        loginDetails.certificateLength = cert->cert_size;
-       loginDetails.certificate = (uint8_t *)calloc(1, sizeof(uint8_t)*cert->cert_size + 1);
        loginDetails.encodingType = OIC_ENCODING_PEM;
 
        if (loginDetails.certificate) {
-               memcpy(loginDetails.certificate, cert->raw_cert, sizeof(uint8_t)*cert->cert_size);
-
                printf("Save cert file Data\n");
                if (OCSaveTrustCertChain(loginDetails.certificate, loginDetails.certificateLength, \
                                loginDetails.encodingType, &g_cred_id) != OC_STACK_OK) {
@@ -129,7 +123,7 @@ int _set_auth_cert_info()
        return 0;
 }
 
-static FILE *client_open(const char *path, const char *mode)
+static FILE *_client_open(const char *path, const char *mode)
 {
        (void)path;
 
@@ -142,7 +136,6 @@ static FILE *client_open(const char *path, const char *mode)
 }
 
 
-
 static void _parse_payload(OCRepPayload *payload)
 {
        if (!payload)
@@ -160,11 +153,16 @@ static void _parse_payload(OCRepPayload *payload)
 static OCStackApplicationResult _send_keep_alive_cb(void *context, OCDoHandle handle,
                                                        OCClientResponse * clientResponse)
 {
-       printf("_send_keep_alive_cb() is called\n");
-
        (void)context;
        (void)handle;
 
+       if (!clientResponse) {
+               printf("clientResponse is NULL!\n");
+               return OC_STACK_DELETE_TRANSACTION;
+       }
+
+       printf("_send_keep_alive_cb() is called, result=[%d]\n", clientResponse->result);
+
        if(clientResponse->result > OC_STACK_RESOURCE_CHANGED) {
                pthread_detach(pthread_self());
                pthread_mutex_lock(&pingcycle_mutex);
@@ -176,87 +174,75 @@ static OCStackApplicationResult _send_keep_alive_cb(void *context, OCDoHandle ha
        return OC_STACK_DELETE_TRANSACTION;
 }
 
-static void _keep_alive_cb(OCRepPayload *payload)
+static void *_send_keep_alive(void *data)
 {
-       printf("_keep_alive_cb() is called\n");
-
-       if (!payload)
-               return;
+       OCStackResult ocResult = OC_STACK_ERROR;
+       int i = 0;
+       int timeout = 0;
+       int timer_count = 0;
 
-       char *intervals;
+       int64_t *array = (int64_t *)data;
 
-       if (OCRepPayloadGetPropString(payload, "inarray", &intervals)) {
-               printf("[keep alive cb] intervals=[%s]\n", intervals);
+       while (is_ping_timer) {
+               if(timeout == timer_count) {
+                       timer_count = 0;
 
-               char *temp_intervals = strdup(intervals);
-               char *token = NULL;
-               int interval[4] = {0};
-               int i = 0;
+                       if(i >= MAX_INTERVAL_NUMBER)
+                               i = MAX_INTERVAL_NUMBER - 1;
 
-               token = strtok(temp_intervals, "[");
-               token = strtok(token, "]");
-               token = strtok(token, ",");
-               interval[0] = atoi(token);
-               ++i;
+                       OCRepPayload *keepAlivePayload = OCRepPayloadCreate();
+                       if (!keepAlivePayload) break;
 
-               while ((token = strtok(NULL, ", "))) {
-                       interval[i] = atoi(token);
+                       OCRepPayloadSetPropInt(keepAlivePayload, "in", (int64_t)array[i]);
+                       timeout = array[i] * 60;
                        ++i;
-               }
 
-               // Send KeepAlive each interval
+                       char uri[MAX_URI_LENGTH] = { 0 };
+                       snprintf(uri, MAX_URI_LENGTH, "coaps+tcp://%s", CLOUD_STG_SERVER);
+
+                       OCCallbackData cbData = {0,};
+                       cbData.cb = _send_keep_alive_cb;
+
+                       ocResult = OCSendKeepAliveRequest(NULL, uri, (OCPayload *)keepAlivePayload, &cbData);
+                       printf("sendKeepAliveRequest() result : %d\n", ocResult);
+                       if (OC_STACK_OK != ocResult) {
+                               pthread_detach(pthread_self());
+                               pthread_mutex_lock(&pingcycle_mutex);
+                               is_ping_timer = false;
+                               pthread_mutex_unlock(&pingcycle_mutex);
+                               pthread_exit(NULL);
+                       }
+               }
                pthread_mutex_lock(&pingcycle_mutex);
-               is_ping_timer = true;
+               ++timer_count;
                pthread_mutex_unlock(&pingcycle_mutex);
+               sleep(1);
+       }
 
-               i = 0;
-               int timeout = 0;
-               int timer_count = 0;
-
-               while (is_ping_timer) {
-                       if(timeout == timer_count) {
-                               timer_count = 0;
-                               OCStackResult ocResult = OC_STACK_ERROR;
-
-                               if(i >= MAX_INTERVAL_NUMBER) {
-                                       i = MAX_INTERVAL_NUMBER - 1;
-                               }
-
-                               OCRepPayload *payload = OCRepPayloadCreate();
-                               if (!payload) break;
-
-                               OCRepPayloadSetPropInt(payload, "in", (int64_t)interval[i]);
-                               timeout = interval[i] * 60;
-                               ++i;
-
-                               char uri[MAX_URI_LENGTH] = { 0 };
-                               snprintf(uri, MAX_URI_LENGTH, "coap+tcp://%s%s",
-                                               CLOUD_STG_SERVER, OC_RSRVD_ACCOUNT_URI);
-
-                               OCCallbackData *cbData = (OCCallbackData *)calloc(1, sizeof(OCCallbackData));
-                               cbData->cb = _send_keep_alive_cb;
-                               cbData->context = (void *)DEFAULT_CONTEXT_VALUE;
-
-                               ocResult = OCSendKeepAliveRequest(NULL, uri, (OCPayload *)payload, cbData);
-                               printf("sendKeepAliveRequest() result : %d\n", ocResult);
-                               if (OC_STACK_OK != ocResult) {
-                                       pthread_detach(pthread_self());
-                                       pthread_mutex_lock(&pingcycle_mutex);
-                                       is_ping_timer = false;
-                                       pthread_mutex_unlock(&pingcycle_mutex);
-                                       pthread_exit(NULL);
-                               }
-                       }
+       return NULL;
+}
 
-                       pthread_mutex_lock(&pingcycle_mutex);
-                       ++timer_count;
-                       pthread_mutex_unlock(&pingcycle_mutex);
+static void _keep_alive_cb(OCRepPayload *payload)
+{
+       printf("_keep_alive_cb() is called\n");
 
-                       sleep(1);
-               }
+       if (!payload)
+               return;
+
+       int64_t *array = NULL;
+       size_t dim[MAX_REP_ARRAY_DEPTH];
+       bool ocBoolResult = false;
+
+       ocBoolResult = OCRepPayloadGetIntArray(payload, "inarray", &array, dim);
+       printf("OCRepPayloadGetStringArray() return = [%d]\n", ocBoolResult);
 
-               g_free(token);
-               g_free(temp_intervals);
+       if (ocBoolResult == true && array) {
+               pthread_mutex_lock(&pingcycle_mutex);
+               is_ping_timer = true;
+               pthread_mutex_unlock(&pingcycle_mutex);
+
+               pthread_t _keep_alive_thd;
+               pthread_create(&_keep_alive_thd, NULL, _send_keep_alive, (void *)array);
        } else {
                pthread_detach(pthread_self());
                pthread_mutex_lock(&pingcycle_mutex);
@@ -332,7 +318,6 @@ void _get_login_info()
 
        loginDetails.deviceId = g_strdup(OCGetServerInstanceIDString());
        printf("Device ID = [%s]\n", loginDetails.deviceId);
-
 }
 
 
@@ -347,15 +332,11 @@ static OCStackApplicationResult _handle_keepalive_cb(void *context, OCDoHandle h
                return OC_STACK_DELETE_TRANSACTION;
        }
 
-       if (clientResponse->payload) {
-               printf("Payload received\n");
-       }
-
        if (clientResponse->result == OC_STACK_OK) {
                _keep_alive_cb((OCRepPayload*)clientResponse->payload);
        }
 
-       return OC_STACK_DELETE_TRANSACTION;
+       return OC_STACK_KEEP_TRANSACTION;
 }
 
 void *_ping_timer(void *timer)
@@ -364,12 +345,11 @@ void *_ping_timer(void *timer)
        (void)timer;
 
        char uri[MAX_URI_LENGTH] = { 0 };
-       snprintf(uri, MAX_URI_LENGTH, "coap+tcp://%s%s",
-                       CLOUD_STG_SERVER, OC_RSRVD_ACCOUNT_URI);
+       snprintf(uri, MAX_URI_LENGTH, "coaps+tcp://%s", CLOUD_STG_SERVER);
 
        OCCallbackData keepAliveCb = {0,};
        keepAliveCb.cb = _handle_keepalive_cb;
-       OCFindKeepAliveResource(NULL, uri, &keepAliveCb);
+       ocResult = OCFindKeepAliveResource(NULL, uri, &keepAliveCb);
        printf("OCFindKeepAliveResource() result : %d\n", ocResult);
 
        if (OC_STACK_OK != ocResult) {
@@ -404,11 +384,11 @@ static OCStackApplicationResult _handle_signin_response(void *ctx,
                printf("Login error: %d\n", response->result);
 
                pthread_mutex_lock(&pingcycle_mutex);
-               is_ping_timer = FALSE;
+               is_ping_timer = false;
                pthread_mutex_unlock(&pingcycle_mutex);
        } else {
                bSignin = true;
-               printf("Sign In Success\n");
+               printf("Sign-In Success!!!\n");
 
                pthread_t pingThread;
                pthread_mutex_lock(&pingcycle_mutex);
@@ -420,7 +400,7 @@ static OCStackApplicationResult _handle_signin_response(void *ctx,
                        printf("ping pthread_create fail!\n");
        }
 
-       return OC_STACK_DELETE_TRANSACTION;
+       return OC_STACK_KEEP_TRANSACTION;
 
 }
 
@@ -436,32 +416,53 @@ static OCStackApplicationResult _handle_signup_response(void *ctx,
                return OC_STACK_DELETE_TRANSACTION;
        }
 
-       if (response->payload) {
-               printf("Payload received\n");
-       }
-
        if (response->result != LOGIN_OK) {
                printf("Login error: %d\n", response->result);
        } else {
                _parse_payload((OCRepPayload*)response->payload);
-               printf("Sign Up OK\n");
+               printf("Sign-Up OK!!!\n");
+               sleep(1);
                _signin();
        }
 
+       return OC_STACK_KEEP_TRANSACTION;
+}
+
+
+static OCStackApplicationResult _handle_signout_response(void *ctx,
+                                                                         OCDoHandle handle,
+                                                                         OCClientResponse *response)
+{
+       (void)(ctx);
+       (void)(handle);
+
+       if (response) {
+               if (response->result == LOGIN_OK)
+                       printf("Sign-Out Success!!!\n");
+               else
+                       printf("Sign-Out Failed [%d]!!!\n", response->result);
+       }
+
+       pthread_mutex_lock(&pingcycle_mutex);
+       is_ping_timer = FALSE;
+       pthread_mutex_unlock(&pingcycle_mutex);
+
        return OC_STACK_DELETE_TRANSACTION;
 }
 
+
 int _signin()
 {
        char uri[MAX_URI_LENGTH] = { 0 };
-       snprintf(uri, MAX_URI_LENGTH, "coap+tcp://%s%s",
-                       CLOUD_STG_SERVER, OC_RSRVD_ACCOUNT_URI);
+       snprintf(uri, MAX_URI_LENGTH, "coaps+tcp://%s%s",
+                       CLOUD_STG_SERVER, OC_RSRVD_ACCOUNT_SESSION_URI);
        printf("server uri=[%s]\n", uri);
 
-       OCCallbackData *cbData = (OCCallbackData *)calloc(1, sizeof(OCCallbackData));
-       cbData->cb = _handle_signin_response;
-       cbData->context = (void *)DEFAULT_CONTEXT_VALUE;
-       cbData->cd = NULL;
+       OCCallbackData cbData;
+       memset(&cbData, 0, sizeof(OCCallbackData));
+       cbData.cb = _handle_signin_response;
+       cbData.cd = NULL;
+       cbData.context = (void *) DEFAULT_CONTEXT_VALUE;
 
        OCRepPayload *payload = OCRepPayloadCreate();
        if (!payload) return -1;
@@ -470,12 +471,12 @@ int _signin()
        OCRepPayloadSetPropString(payload, ACCESS_TOKEN, (const char *)loginDetails.accessToken);
        OCRepPayloadSetPropString(payload, USER_ID, (const char *)loginDetails.uid);
        OCRepPayloadSetPropBool(payload, CLOUD_LOGIN, true);
-       OCRepPayloadAddResourceType(payload, CLOUD_SESSION_RES_TYPE);
-       OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
+//     OCRepPayloadAddResourceType(payload, CLOUD_SESSION_RES_TYPE);
+//     OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
 
        int ret;
        if (OCDoResource(NULL, OC_REST_POST, uri, NULL, (OCPayload *)payload,
-                                       CT_ADAPTER_TCP, OC_LOW_QOS, cbData, NULL, 0) == OC_STACK_OK) {
+                                       CT_ADAPTER_TCP|CT_IP_USE_V4, OC_LOW_QOS, &cbData, NULL, 0) == OC_STACK_OK) {
                ret = 0;
                printf("OCDoResource() is succeeded\n");
        } else {
@@ -501,14 +502,15 @@ int _signup()
        _set_auth_cert_info();
 
        char uri[MAX_URI_LENGTH] = { 0 };
-       snprintf(uri, MAX_URI_LENGTH, "coap+tcp://%s%s",
+       snprintf(uri, MAX_URI_LENGTH, "coaps+tcp://%s%s",
                        CLOUD_STG_SERVER, OC_RSRVD_ACCOUNT_URI);
        printf("server uri=[%s]\n", uri);
 
-       OCCallbackData *cbData = (OCCallbackData *)calloc(1, sizeof(OCCallbackData));
-       cbData->cb = _handle_signup_response;
-       cbData->context = (void *)DEFAULT_CONTEXT_VALUE;
-       cbData->cd = NULL;
+       OCCallbackData cbData;
+       memset(&cbData, 0, sizeof(OCCallbackData));
+       cbData.cb = _handle_signup_response;
+       cbData.cd = NULL;
+       cbData.context = (void *) DEFAULT_CONTEXT_VALUE;
 
        OCRepPayload *payload = OCRepPayloadCreate();
        if (!payload) return -1;
@@ -519,12 +521,12 @@ int _signup()
        OCRepPayloadSetPropString(payload, CLIENT_ID, (const char *)loginDetails.clientId);
        OCRepPayloadSetPropString(payload, ACCESS_TOKEN, (const char *)loginDetails.accessToken);
        OCRepPayloadSetPropString(payload, USER_ID, (const char *)loginDetails.uid);
-       OCRepPayloadAddResourceType(payload, CLOUD_ACCOUNT_RES_TYPE);
-       OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
+//     OCRepPayloadAddResourceType(payload, CLOUD_ACCOUNT_RES_TYPE);
+//     OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
 
        int ret;
        if (OCDoResource(NULL, OC_REST_POST, uri, NULL, (OCPayload *)payload,
-                                       CT_ADAPTER_TCP, OC_LOW_QOS, cbData, NULL, 0) == OC_STACK_OK) {
+                                       CT_ADAPTER_TCP|CT_IP_USE_V4, OC_LOW_QOS, &cbData, NULL, 0) == OC_STACK_OK) {
                ret = 0;
                printf("OCDoResource() is succeeded\n");
        } else {
@@ -536,29 +538,40 @@ int _signup()
 }
 
 
-int _initialize_oc_stack()
+int _signout()
 {
-       OCPersistentStorage ps = {client_open, fread, fwrite, fclose, unlink};
-       OCRegisterPersistentStorageHandler(&ps);
+       char uri[MAX_URI_LENGTH] = { 0 };
+       snprintf(uri, MAX_URI_LENGTH, "coaps+tcp://%s%s",
+                       CLOUD_STG_SERVER, OC_RSRVD_ACCOUNT_SESSION_URI);
+       printf("server uri=[%s]\n", uri);
 
-       if (OCInit(NULL, 0, OC_SERVER) == OC_STACK_OK) {
-               printf("OCInit() succeeded\n");
-       } else {
-               printf("OCInit() failed\n");
-               return -1;
-       }
+       OCCallbackData cbData;
+       memset(&cbData, 0, sizeof(OCCallbackData));
+       cbData.cb = _handle_signout_response;
+       cbData.cd = NULL;
+       cbData.context = (void *) DEFAULT_CONTEXT_VALUE;
 
-       if (OCInitPM(OC_SECURITY_SQL_DB_FILE_NAME) == OC_STACK_OK) {
-               printf("OCInitPM() is succeeded!\n");
+       OCRepPayload *payload = OCRepPayloadCreate();
+       if (!payload) return -1;
+
+       OCRepPayloadSetPropString(payload, DEVICE_ID, (const char *)loginDetails.deviceId);
+       OCRepPayloadSetPropString(payload, ACCESS_TOKEN, (const char *)loginDetails.accessToken);
+       OCRepPayloadSetPropString(payload, USER_ID, (const char *)loginDetails.uid);
+       OCRepPayloadSetPropBool(payload, CLOUD_LOGIN, false);
+
+       int ret;
+       if (OCDoResource(NULL, OC_REST_POST, uri, NULL, (OCPayload *)payload,
+                                       CT_ADAPTER_TCP|CT_IP_USE_V4, OC_LOW_QOS, &cbData, NULL, 0) == OC_STACK_OK) {
+               ret = 0;
+               printf("OCDoResource() is succeeded\n");
        } else {
-               printf("OCInitPM() is failed");
-               return -1;
+               ret = -1;
+               printf("OCDoResource() is failed\n");
        }
 
-       return 0;
+       return ret;
 }
 
-
 bool _compare_resource_interface(char *from, char *iface)
 {
        char *str = g_strdup(from);
@@ -768,6 +781,61 @@ OCStackApplicationResult _handle_rd_delete_callback(void *ctx, OCDoHandle handle
        return OC_STACK_KEEP_TRANSACTION;
 }
 
+
+void* _oc_process_thd(void * ptr)
+{
+       (void) ptr;
+       while (!isExit) {
+               if (OCProcess() != OC_STACK_OK) {
+                       printf("OCStack process error\n");
+                       return NULL;
+               }
+               sleep(1);
+       }
+
+       return NULL;
+}
+
+
+int _init_oc_stack()
+{
+       ps = (OCPersistentStorage *)calloc(1, sizeof(OCPersistentStorage));
+       if (!ps) return -1;
+
+       ps->open = _client_open;
+       ps->read = fread;
+       ps->write = fwrite;
+       ps->close = fclose;
+       ps->unlink = unlink;
+
+       if (OCRegisterPersistentStorageHandler(ps) == OC_STACK_OK) {
+               printf("OCRegisterPersistentStorageHandler() succeeded\n");
+       } else {
+               printf("OCRegisterPersistentStorageHandler() failed\n");
+               return -1;
+       }
+
+       if (OCInit(NULL, 0, OC_SERVER) == OC_STACK_OK) {
+               printf("OCInit() succeeded\n");
+       } else {
+               printf("OCInit() failed\n");
+               return -1;
+       }
+
+       if (OCInitPM(OC_SECURITY_SQL_DB_FILE_NAME) == OC_STACK_OK) {
+               printf("OCInitPM() is succeeded!\n");
+       } else {
+               printf("OCInitPM() is failed");
+               return -1;
+       }
+
+       _set_platform_info();
+
+       _set_device_info();
+
+       return 0;
+}
+
 int  _init_default_test_res()
 {
 #if 0
@@ -780,10 +848,6 @@ int  _init_default_test_res()
        }
 #endif
 
-       _set_platform_info();
-
-       _set_device_info();
-
        /* Create air conditioner resource handle */
        if (OCCreateResource(&aircon_handle, "x.com.samsung.da.device",
                                                OC_RSRVD_INTERFACE_DEFAULT,
@@ -841,7 +905,10 @@ int _publish_fw_res_to_rd()
        cb_data.cb = _handle_rd_publish_callback;
        cb_data.context = (void *)DEFAULT_CONTEXT_VALUE;
 
-       if (OCRDPublish(NULL, OCF_SERVER_URL, CT_ADAPTER_TCP,
+       char uri[MAX_URI_LENGTH] = { 0 };
+       snprintf(uri, MAX_URI_LENGTH, "coaps+tcp://%s", CLOUD_STG_SERVER);
+
+       if (OCRDPublish(NULL, uri, CT_ADAPTER_TCP|CT_IP_USE_V4,
                        aircon_handle, 3,
                        &cb_data, OC_LOW_QOS) != OC_STACK_OK) {
                printf("OCRDPublish() failed\n");
@@ -858,7 +925,10 @@ int _delete_fw_res_from_rd()
        cb_data.cb = _handle_rd_delete_callback;
        cb_data.context = (void *)DEFAULT_CONTEXT_VALUE;
 
-       if (OCRDDelete(NULL, OCF_SERVER_URL, CT_ADAPTER_TCP,
+       char uri[MAX_URI_LENGTH] = { 0 };
+       snprintf(uri, MAX_URI_LENGTH, "coaps+tcp://%s", CLOUD_STG_SERVER);
+
+       if (OCRDDelete(NULL, uri, CT_ADAPTER_TCP|CT_IP_USE_V4,
                        aircon_handle, 3,
                        &cb_data, OC_LOW_QOS) != OC_STACK_OK) {
                printf("OCRDDelete() failed\n");
@@ -871,7 +941,6 @@ int _delete_fw_res_from_rd()
 
 int _destory_fw_res()
 {
-
        if (controlee_destory_firmware_resource(firmware_handle) != CONTROLEE_FIRMWARE_SUCCESS) {
                return -1;
        }
@@ -917,8 +986,15 @@ void _show_menu()
        printf("Input test menu : \n");
 }
 
+#define _G_IO_WATCH_
+
+#ifdef _G_IO_WATCH_
 gboolean _main_thread(GIOChannel *channel, GIOCondition condition, gpointer data)
+#else
+void* _main_thread(void *data)
+#endif
 {
+#ifdef _G_IO_WATCH_
        if (condition != G_IO_IN)
                return false;
 
@@ -929,6 +1005,17 @@ gboolean _main_thread(GIOChannel *channel, GIOCondition condition, gpointer data
        g_io_channel_read_line(channel, &str_ret, &length, NULL, NULL);
        if (!str_ret)
                return false;
+#else
+       (void)data;
+       int rv = 0;
+       char str_ret[10];
+
+       while (true) {
+       memset(str_ret, 0x00, sizeof(str_ret));
+
+       scanf("%s", str_ret);
+
+#endif
 
        if (str_ret[0] == '\n' || str_ret[0] == '\r') {
                _show_menu();
@@ -940,7 +1027,7 @@ gboolean _main_thread(GIOChannel *channel, GIOCondition condition, gpointer data
                        break;
                case 'Z' :
                case 'z' :
-                       //rv = _signout();
+                       rv = _signout();
                        break;
                case '1':
                        rv = _init_default_test_res();
@@ -985,22 +1072,15 @@ gboolean _main_thread(GIOChannel *channel, GIOCondition condition, gpointer data
                printf("\n*** Press 'enter' to show menu *** \n");
        }
 
+#ifdef _G_IO_WATCH_
        g_free(str_ret);
-
        return true;
-}
+#else
 
-void* _OCProcess_thd(void * ptr)
-{
-       (void) ptr;
-       while (!isExit) {
-               if (OCProcess() != OC_STACK_OK) {
-                       printf("OCStack process error\n");
-                       return NULL;
-               }
        }
 
        return NULL;
+#endif
 }
 
 
@@ -1014,17 +1094,32 @@ int main(int argc, char *argv[])
 
        bSignin = false;
        isExit = false;
+       ps = NULL;
+
        mainloop = g_main_loop_new(NULL, false);
 
-       _initialize_oc_stack();
+       if (_init_oc_stack() != 0) {
+               printf("Fail to _init_oc_stack()\n");
+               return -1;
+       }
 
        pthread_t oc_proc_thd;
-       pthread_create(&oc_proc_thd, NULL, _OCProcess_thd, unlink);
+       pthread_create(&oc_proc_thd, NULL, _oc_process_thd, NULL);
 
        _show_menu();
+
+#ifdef _G_IO_WATCH_
        GIOChannel *channel = g_io_channel_unix_new(0);
        g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), _main_thread, NULL);
+#else
+       pthread_t test_thd;
+       pthread_create(&test_thd, NULL, _main_thread, NULL);
+#endif
+
        g_main_loop_run(mainloop);
 
+       if (ps)
+               free(ps);
+
        return 0;
 }