From 3f1751e3871b9610bd9fa6075610d656bba8defa Mon Sep 17 00:00:00 2001 From: "chleun.moon" Date: Thu, 28 Dec 2017 10:14:13 +0900 Subject: [PATCH] Add new source file for main function Change-Id: I42e86a1ff0558931b063035a1a9299c30332d774 Signed-off-by: Cheoleun Moon --- include/asp-manager.h | 3 +++ packaging/asp-manager.spec | 2 +- src/CMakeLists.txt | 1 + src/asp-manager-main.c | 37 +++++++++++++++++++++++++++++++++++++ src/asp-manager.c | 37 +++++++++++++------------------------ 5 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 src/asp-manager-main.c diff --git a/include/asp-manager.h b/include/asp-manager.h index 6f2e20a..585a41d 100755 --- a/include/asp-manager.h +++ b/include/asp-manager.h @@ -50,6 +50,9 @@ typedef struct { asp_s *asp_get_manager(); +gint32 asp_manager_load(); +void asp_manager_unload(); + #ifdef __cplusplus } #endif diff --git a/packaging/asp-manager.spec b/packaging/asp-manager.spec index 59afd24..c3144d5 100755 --- a/packaging/asp-manager.spec +++ b/packaging/asp-manager.spec @@ -1,6 +1,6 @@ Name: asp-manager Summary: ASP(application service platform) manager -Version: 0.0.26 +Version: 0.0.27 Release: 1 Group: Network & Connectivity/Other License: Apache-2.0 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aebb55c..3f7b423 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,6 +26,7 @@ SET(SRCS ${CMAKE_SOURCE_DIR}/src/asp-manager-event.c ${CMAKE_SOURCE_DIR}/src/asp-manager-gdbus.c ${CMAKE_SOURCE_DIR}/src/asp-manager-util.c + ${CMAKE_SOURCE_DIR}/src/asp-manager-main.c ${CMAKE_SOURCE_DIR}/interfaces/generated-code.c ) diff --git a/src/asp-manager-main.c b/src/asp-manager-main.c new file mode 100644 index 0000000..de35edc --- /dev/null +++ b/src/asp-manager-main.c @@ -0,0 +1,37 @@ +#include "asp-manager.h" +#include "asp-manager-util.h" + +gint32 main(gint32 argc, gchar *argv[]) +{ + GMainLoop *main_loop = NULL; + asp_s *manager = NULL; + + /* Initialize required subsystems */ +#if !GLIB_CHECK_VERSION(2, 35, 0) + g_type_init(); +#endif + + if (asp_manager_load() < 0) { + ASP_LOGE("Failed to load asp-manager"); + asp_manager_unload(); + return -1; + } + + manager = asp_get_manager(); + if (!manager) { + ASP_LOGE("Failed to get asp_s"); + return -1; + } + /* Crate the GLIB main loop */ + main_loop = g_main_loop_new(NULL, FALSE); + manager->main_loop = main_loop; + + /* Run the main loop */ + g_main_loop_run(main_loop); + + asp_manager_unload(); + + g_main_loop_unref(main_loop); + + return 0; +} diff --git a/src/asp-manager.c b/src/asp-manager.c index eea9f46..30aff54 100755 --- a/src/asp-manager.c +++ b/src/asp-manager.c @@ -221,34 +221,23 @@ static asp_s *__asp_manager_init() return asp; } -gint32 main(gint32 argc, gchar *argv[]) +gint32 asp_manager_load() { - GMainLoop *main_loop = NULL; - gint32 ret = -1; - - /* Initialize required subsystems */ -#if !GLIB_CHECK_VERSION(2, 35, 0) - g_type_init(); -#endif + __ASP_LOG_FUNC_ENTER__; g_asp = __asp_manager_init(); - if (!g_asp) - goto fail; - - /* Crate the GLIB main loop */ - main_loop = g_main_loop_new(NULL, FALSE); - g_asp->main_loop = main_loop; - - /* Run the main loop */ - g_main_loop_run(main_loop); - - ret = 0; + if (!g_asp) { + ASP_LOGE("Failed to initialize asp-manager"); + return -1; + } -fail: + __ASP_LOG_FUNC_EXIT__; + return 0; +} +void asp_manager_unload() +{ + __ASP_LOG_FUNC_ENTER__; __asp_manager_deinit(); - - g_main_loop_unref(main_loop); - - return ret; + __ASP_LOG_FUNC_EXIT__; } -- 2.7.4