Split do_update function into update.c 52/312352/2
authorSangYoun Kwak <sy.kwak@samsung.com>
Fri, 7 Jun 2024 06:08:29 +0000 (15:08 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Tue, 11 Jun 2024 02:03:54 +0000 (11:03 +0900)
There are two functionalities in the osu: resize, update.
Function for resize is separated into its file so it is easy to find and
maintain. On the other hand, update is embeded in the osu.c with main
function.

To increase readability and maintainability, update function is
separated into update.c and update.h.

Change-Id: Iaf84325f1ef8edc7236a4a324f1194e1ec9f8b25
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
tools/osu/CMakeLists.txt
tools/osu/osu.c
tools/osu/update.c [new file with mode: 0644]
tools/osu/update.h [new file with mode: 0644]

index a1e662871ae6f8c960484f7f943e9b638cedc71d..42f2cf2423099a6814fd8db34cd573791afc7e8b 100644 (file)
@@ -4,7 +4,7 @@ PROJECT(update-control-tools-${OUTPUT_BIN_NAME} C)
 
 INCLUDE_DIRECTORIES(. ${CMAKE_SOURCE_DIR}/include)
 
-FILE(GLOB_RECURSE SRCS osu.c resize.c)
+FILE(GLOB_RECURSE SRCS osu.c resize.c update.c)
 ADD_EXECUTABLE(${OUTPUT_BIN_NAME} ${SRCS})
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
 TARGET_LINK_LIBRARIES(${OUTPUT_BIN_NAME} ${REQUIRED_PKGS_LDFLAGS} update-control)
index 744ba47d914cb506b2842c5c34efc90b94c8b356..b08f63907d36e956ea5fc019bb8725aaa79924fe 100644 (file)
@@ -23,8 +23,8 @@
 #include <getopt.h>
 #include <assert.h>
 
-#include "update_control.h"
 #include "resize.h"
+#include "update.h"
 
 
 struct arguments {
@@ -90,45 +90,6 @@ static void print_help(char *my_name)
               "By default, without an argument, the OS Upgrade will be triggered.\n\n", my_name);
 }
 
-static int do_update()
-{
-       int ret = 0;
-       ret = update_control_initialize();
-       if (ret != UPDATE_CONTROL_ERROR_NONE) {
-               printf("Failed to initialize: %d\n", ret);
-               return ret;
-       }
-       printf("Succeed to initialize\n");
-
-       ret = update_control_check_new_version();
-       if (ret != UPDATE_CONTROL_ERROR_NONE) {
-               printf("Failed to check new version: %d\n", ret);
-               goto cleanup;
-       }
-
-       ret = update_control_download_package();
-       if (ret != UPDATE_CONTROL_ERROR_NONE) {
-               printf("Failed to download delta: %d\n", ret);
-               goto cleanup;
-       }
-       printf("Succeed to download delta\n");
-
-       ret = update_control_do_update();
-       if (ret != UPDATE_CONTROL_ERROR_NONE) {
-               printf("Failed to trigger update: %d\n", ret);
-               goto cleanup;
-       }
-
-       printf("Succeed to trigger update: %d\n", ret);
-
-cleanup:
-       ret = update_control_deinitialize();
-       if (ret != UPDATE_CONTROL_ERROR_NONE)
-               printf("Failed to deinitialize: %d\n", ret);
-
-       return ret;
-}
-
 int main(int argc, char **argv)
 {
        int ret = 0;
diff --git a/tools/osu/update.c b/tools/osu/update.c
new file mode 100644 (file)
index 0000000..458bb90
--- /dev/null
@@ -0,0 +1,43 @@
+#include <stdio.h>
+
+#include "update_control.h"
+#include "update.h"
+
+int do_update(void)
+{
+       int ret = 0;
+       ret = update_control_initialize();
+       if (ret != UPDATE_CONTROL_ERROR_NONE) {
+               printf("Failed to initialize: %d\n", ret);
+               return ret;
+       }
+       printf("Succeed to initialize\n");
+
+       ret = update_control_check_new_version();
+       if (ret != UPDATE_CONTROL_ERROR_NONE) {
+               printf("Failed to check new version: %d\n", ret);
+               goto cleanup;
+       }
+
+       ret = update_control_download_package();
+       if (ret != UPDATE_CONTROL_ERROR_NONE) {
+               printf("Failed to download delta: %d\n", ret);
+               goto cleanup;
+       }
+       printf("Succeed to download delta\n");
+
+       ret = update_control_do_update();
+       if (ret != UPDATE_CONTROL_ERROR_NONE) {
+               printf("Failed to trigger update: %d\n", ret);
+               goto cleanup;
+       }
+
+       printf("Succeed to trigger update: %d\n", ret);
+
+cleanup:
+       ret = update_control_deinitialize();
+       if (ret != UPDATE_CONTROL_ERROR_NONE)
+               printf("Failed to deinitialize: %d\n", ret);
+
+       return ret;
+}
diff --git a/tools/osu/update.h b/tools/osu/update.h
new file mode 100644 (file)
index 0000000..5c64bbc
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+int do_update(void);