Integrate some common codes from tota-ua 65/138865/2
authorSunmin Lee <sunm.lee@samsung.com>
Tue, 23 May 2017 02:56:12 +0000 (11:56 +0900)
committerSunmin Lee <sunm.lee@samsung.com>
Fri, 14 Jul 2017 07:04:06 +0000 (16:04 +0900)
There were duplicated codes in libtota and tota-ua.
It would be better to integrate in one place and manage them.

Change-Id: I58f813d3b6ff9b28d3f032a88cb6eef6e1688f78
Signed-off-by: Sunmin Lee <sunm.lee@samsung.com>
CMakeLists.txt
packaging/libtota.spec
ss_engine/SS_FSUpdate.h
ss_engine/fota_common.h
ss_engine/fota_log.c [new file with mode: 0755]
ss_engine/fota_log.h
ss_engine/fota_tar.h

index f1979a291aec5ae971ea9dd7d47a11dd72bee0ff..6a0f93e28c2998b65262175179e869862274084a 100755 (executable)
@@ -9,6 +9,8 @@ SET(SRCS
        ss_engine/fota_tar.c
        ss_engine/SS_ApplyPatch.c
        ss_engine/SS_PatchDelta.c
+       ss_engine/fota_log.c
+       ss_engine/fota_tar.c
        bsdiff/ss_bspatch_common.c
 )
 SET(HEADERS
index 39f290902646c8187f3a5a7447601d13da173053..b9e7a586c77452ca4a36835fee5bba1c0e14be92 100755 (executable)
@@ -1,8 +1,8 @@
 Name:          libtota
 Summary:       fota update library
 ExclusiveArch:         %{arm}
-Version:       0.1.4
-Release:       5
+Version:       0.2.0
+Release:       1
 Group:         System
 License:       Apache-2.0 and BSD-2-Clause and BSD-3-Clause and PD
 Source0:       %{name}-%{version}.tar.gz
index 7b5d1a65fbf9003e6f2b5395c51d8ad1396b7618..b2215824985f35efe70cc441d82d0a95c3a7d223 100755 (executable)
@@ -343,6 +343,26 @@ extern "C" {
     SS_UINT32 SS_Trace(void *pbUserData, const char *aFormat, ...
         );
 
+/**
+ *******************************************************************************
+ * Allocate a memory block.
+ *
+ * \param      size    Memory block size, in blocks
+ *
+ * \return     A pointer to the memory block on success, NULL on failure
+ *******************************************************************************
+ */
+    void *SS_Malloc(SS_UINT32 size);
+
+/**
+ *******************************************************************************
+ * Free a memory block.
+ *
+ * \param      pMemBlock       Pointer to the memory block
+ *******************************************************************************
+ */
+    void SS_Free(void *pMemBlock);
+
 #ifdef __cplusplus
 }
 #endif                          /* __cplusplus */
index fa690b69feccb81329dce26883dbe10eb80df339..8424a4516a7255fe54f7b7c40f34b250889e6f5a 100755 (executable)
@@ -41,6 +41,9 @@ typedef unsigned long long u64;
 #ifndef TIME_PROFILING
        //#define TIME_PROFILING
 #endif
+#ifndef HEAP_PROFILING
+       //#define HEAP_PROFILING;
+#endif
 #ifndef MEM_PROFILING
        //#define MEM_PROFILING
 #endif
diff --git a/ss_engine/fota_log.c b/ss_engine/fota_log.c
new file mode 100755 (executable)
index 0000000..7d7c44e
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * libtota
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+long curr_offset = 0;
+long next_offset = 0;
+long cut_offset = 0;
+long max_logfile_size = (2*1024*1024);
+
+/*-----------------------------------------------------------------------------
+  log_printf
+ ----------------------------------------------------------------------------*/
+int log_printf(FILE* log_fp, char* format_str, ...)
+{
+       int ret = 0;
+       char log_str[4096];
+       int len;
+       int wlen;
+       va_list list;
+
+       va_start(list, format_str);
+       vsprintf(log_str, format_str, list);
+       va_end(list);
+
+       len = strlen(log_str);
+       next_offset = curr_offset + len;
+
+       if (next_offset <= max_logfile_size) {
+               wlen = len;
+               if (fwrite(log_str, 1, wlen, log_fp) != wlen) {
+                       ret = -1;
+                       goto exit;
+               }
+               curr_offset = next_offset;
+               if (curr_offset == max_logfile_size) {
+                       rewind(log_fp);
+                       curr_offset = 0;
+               }
+       } else {
+               cut_offset = max_logfile_size - curr_offset;
+               wlen = cut_offset;
+               if (fwrite(log_str, 1, wlen, log_fp) != wlen) {
+                       ret = -1;
+                       goto exit;
+               }
+               rewind(log_fp);
+               wlen = next_offset - max_logfile_size;
+               if (fwrite(log_str+cut_offset, 1, wlen, log_fp) != wlen) {
+                       ret = -1;
+                       goto exit;
+               }
+               curr_offset = next_offset - max_logfile_size;
+       }
+
+exit:
+       return ret;
+}
+
+/*-----------------------------------------------------------------------------
+  truncate_log_file
+ ----------------------------------------------------------------------------*/
+void truncate_log_file(char *log_path, int size_kb)
+{
+       FILE *log_fp;
+
+       if (size_kb == 0) {
+               log_fp = fopen(log_path, "w");
+               if (log_fp == NULL) {
+                       perror("file open error\n");
+               } else {
+                       fclose(log_fp);
+               }
+       }
+
+       sync();
+}
+
+
index 9b4999a3905610ad5ef76a3920b1606cb15b4ba2..e03beed7b3374e94904c475331240e5c279ad6f6 100755 (executable)
@@ -28,6 +28,7 @@
 extern unsigned int __log_level__;
 extern FILE *__log_out_file__;
 extern int log_printf(FILE* log_fp, char* format_str, ...);
+extern void truncate_log_file(char *log_path, int size_kb);
 
 #define LOG_INFO       (1<<8)
 #define LOG_ENGINE     (1<<7)
@@ -38,7 +39,6 @@ extern int log_printf(FILE* log_fp, char* format_str, ...);
 #define LOG_FLASH      (1<<2)
 
 #define LOG_SSENGINE  LOG_ENGINE
-//#define LOG_REDBEND LOG_ENGINE
 
 //#define DEBUG_STDOUT
 #define DEBUG_FILE
index e6a528fed58c74e2361a3ac7d85738957921ad92..6d141ef5c5d0465e9f1df68e9224a83a87ae6d81 100755 (executable)
 #ifndef _FOTA_TAR_H_
 #define _FOTA_TAR_H_
 
-extern void SS_Free(void *pMemBlock);
-extern int tar_get_item_offset(char *tar, char *item);
+int tar_get_item_offset(char *tar, char *item);
 
-extern int tar_get_item_size(char *tar, char *item);
+int tar_get_item_size(char *tar, char *item);
 
-extern int tar_get_cfg_data(char *tar, char *item, char *buf, int buflen);
+int tar_get_cfg_data(char *tar, char *item, char *buf, int buflen);
 
-extern int tar_get_folder_size(char *tar, char *item);
+int tar_get_folder_size(char *tar, char *item);
 
 #endif                          /* _FOTA_TAR_H_ */