From 28d1e72dadec1f55a41e7df606ad4081ce35b2d8 Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Wed, 11 Jun 2025 10:39:58 +0900 Subject: [PATCH] core: Separate main logic to storaged_init/exit function for common usage To make the init/exit sequences of the main function can be used by other source files such as plugin library, the init/exit logics are separated as 'storaged_init' and 'storaged_exit' respectively. Accordingly, main.c file which includes main function is renamed to storaged.c. Also, to make them callable, header storaged.h is added. Change-Id: I7f5512ae13a84095e94b9d56f9970ce09b1f9f0b Signed-off-by: SangYoun Kwak --- CMakeLists.txt | 2 +- src/core/{main.c => storaged.c} | 33 +++++++++++++++++++++++++-------- src/core/storaged.h | 25 +++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 9 deletions(-) rename src/core/{main.c => storaged.c} (94%) create mode 100644 src/core/storaged.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6577dd9..e0d38d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ SET(CMAKE_VERBOSE_MAKEFILE OFF) SET(STORAGED_APPS ${CMAKE_SOURCE_DIR}/apps) SET(SRCS - src/core/main.c + src/core/storaged.c src/core/modules.c src/shared/common.c ) diff --git a/src/core/main.c b/src/core/storaged.c similarity index 94% rename from src/core/main.c rename to src/core/storaged.c index ad5e948..4a1835f 100644 --- a/src/core/main.c +++ b/src/core/storaged.c @@ -28,6 +28,7 @@ #include #include "log.h" +#include "storaged.h" #include "modules.h" #include "storaged_common.h" @@ -81,7 +82,7 @@ static void dir_init(void) } -int main(int argc, char **argv) +int storaged_init(void *data) { guint timer; int ret; @@ -90,12 +91,6 @@ int main(int argc, char **argv) if (!g_handle) _E("Failed to get dbus connection."); - loop = g_main_loop_new(NULL, TRUE); - if (!loop) { - _E("Failed to make main loop."); - return -ENOMEM; - } - dir_init(); modules_init((void *)&g_handle); @@ -115,7 +110,12 @@ int main(int argc, char **argv) _E("Failed to aw_register."); } - g_main_loop_run(loop); + return 0; +} + +int storaged_exit(void *data) +{ + int ret = 0; modules_deinit(NULL); @@ -133,3 +133,20 @@ int main(int argc, char **argv) return 0; } + +int main(int argc, char **argv) +{ + loop = g_main_loop_new(NULL, TRUE); + if (!loop) { + _E("Failed to make main loop."); + return -ENOMEM; + } + + storaged_init(NULL); + + g_main_loop_run(loop); + + storaged_exit(NULL); + + return 0; +} diff --git a/src/core/storaged.h b/src/core/storaged.h new file mode 100644 index 0000000..13fa3bf --- /dev/null +++ b/src/core/storaged.h @@ -0,0 +1,25 @@ +/* + * storaged + * + * Copyright (c) 2012 - 2013 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. + */ + +#ifndef __STORAGED_H__ +#define __STORAGED_H__ + +int storaged_init(void *data); +int storaged_exit(void *data); + +#endif /* __STORAGED_H__ */ -- 2.34.1