Refactor code to process request 41/240841/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Wed, 12 Aug 2020 05:14:09 +0000 (14:14 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Wed, 12 Aug 2020 05:14:09 +0000 (14:14 +0900)
Change-Id: Ied2db039175209241d47af7322db70fcb2b4088c
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
receiver/src/main.cpp

index 7fa1a9f..06c2c4f 100644 (file)
@@ -151,12 +151,57 @@ bool check_rw_mount()
     return rw_mount;
 }
 
+static void process_request(app_control_h app_control, char *request)
+{
+    char* mode = NULL;
+    char* type = NULL;
+
+    if (strcmp(request, "sync") == 0) {
+        bool param_error = false;
+        if (app_control_get_extra_data(app_control, "mode", &mode) != APP_CONTROL_ERROR_NONE) {
+            STLOGE("No given mode");
+            param_error = true;
+        }
+
+        if (app_control_get_extra_data(app_control, "type", &type) != APP_CONTROL_ERROR_NONE) {
+            STLOGE("No given type");
+            param_error = true;
+        }
+
+        STLOGI("[sync request] mode : %s, type : %s", mode, type);
+        if (param_error)
+            goto cleanup;
+
+        if (mode && type) {
+            if (!is_init_sap()) {
+                initialize_sap();
+                request_all_sticker_data(mode, type);
+            }
+        }
+    }
+    else if (strcmp(request, "oobe") == 0) {
+        initialize_sap();
+        request_sticker_feature();
+    }
+    else {
+        STLOGW("Unknown command : %s", request);
+        if (!is_init_sap()) {
+            service_app_exit();
+        }
+    }
+
+cleanup:
+    if (NULL != mode)
+        free(mode);
+
+    if (NULL != type)
+        free(type);
+}
+
 static void app_control(app_control_h app_control, void *data)
 {
     /* Handle the launch request. */
     char* request = NULL;
-    char* mode = NULL;
-    char* type = NULL;
     char* operation = NULL;
     char* event_value = NULL;
     char* uri = NULL;
@@ -187,6 +232,7 @@ static void app_control(app_control_h app_control, void *data)
                     {
                         if (string(event_value) == "connected")
                         {
+                            STLOGI("The charger state is connected");
                             if (!is_init_sap()) {
                                 if (check_sync_time_condition()) {
                                     if (check_battery_condition()) {
@@ -196,6 +242,7 @@ static void app_control(app_control_h app_control, void *data)
                                         request_auto_sync();
                                     }
                                     else {
+                                        STLOGI("The status of battery is low");
                                         if (!get_job_progress()) {
                                             STLOGD("exit");
                                             service_app_exit();
@@ -220,43 +267,11 @@ static void app_control(app_control_h app_control, void *data)
             }
         }
         else if (strcmp(operation, APP_CONTROL_OPERATION_DEFAULT) == 0) {
-            // sync request
             res = app_control_get_extra_data(app_control, "request", &request);
+            STLOGD("get extra data result : %d, request : %s", res, request);
             if (APP_CONTROL_ERROR_NONE == res && NULL != request) {
-                if (strcmp(request, "sync") == 0) {
-                    bool param_error = false;
-                    if (app_control_get_extra_data(app_control, "mode", &mode) != APP_CONTROL_ERROR_NONE) {
-                        STLOGE("No given mode");
-                        param_error = true;
-                    }
-
-                    if (app_control_get_extra_data(app_control, "type", &type) != APP_CONTROL_ERROR_NONE) {
-                        STLOGE("No given type");
-                        param_error = true;
-                    }
-
-                    STLOGI("[sync request] mode : %s, type : %s", mode, type);
-                    if (param_error)
-                        goto cleanup;
-
-                    if (mode && type) {
-                        if (!is_init_sap()) {
-                            initialize_sap();
-                            request_all_sticker_data(mode, type);
-                        }
-                    }
-                }
-                else if (strcmp(request, "oobe") == 0) {
-                    initialize_sap();
-                    request_sticker_feature();
-                }
-                else {
-                    STLOGW("Unknown command : %s", request);
-                    if (!is_init_sap()) {
-                        service_app_exit();
-                    }
-                }
-            } // end of request
+                process_request(app_control, request);
+            }
             else {
                 STLOGD("booting");
 #ifdef VCONFKEY_STICKER_SUPPORTED_FEATURE
@@ -285,12 +300,6 @@ cleanup:
 
     if (NULL != request)
         free(request);
-
-    if (NULL != mode)
-        free(mode);
-
-    if (NULL != type)
-        free(type);
 }
 
 static void app_terminate(void *data)