Add API to change main loop functions 16/129616/7
authorJunghoon Park <jh9216.park@samsung.com>
Wed, 17 May 2017 07:23:10 +0000 (16:23 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Thu, 6 Jul 2017 10:58:06 +0000 (19:58 +0900)
Some service apps may not want to use ecore main loop.
To cover this requirement, the new API was added internally

Change-Id: I9eb3c4ae415d9319b6a38a11ce42f4e339d501a5
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
include/service_app_internal.h [new file with mode: 0644]
packaging/appcore-agent.spec
src/service_app_main.c

diff --git a/include/service_app_internal.h b/include/service_app_internal.h
new file mode 100644 (file)
index 0000000..51596fc
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2017 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
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Called before create-callback
+ * @since_tizen 4.0
+ * @param[in] argc The argument count
+ * @param[in] argv The argument vector
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see service_app_main_ext()
+ */
+typedef void (*service_app_loop_method_init_cb)(int argc, char **argv, void *user_data);
+
+/**
+ * @brief Called after terminate-callback
+ * @since_tizen 4.0
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see service_app_main_ext()
+ */
+typedef void (*service_app_loop_method_fini_cb)(void);
+
+
+/**
+ * @brief Called to run main loop
+ * @since_tizen 4.0
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see service_app_main_ext()
+ */
+typedef void (*service_app_loop_method_run_cb)(void *user_data);
+
+/**
+ * @brief Called to exit main loop
+ * @since_tizen 4.0
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see        service_app_maini_ext()
+ */
+typedef void (*service_app_loop_method_exit_cb)(void *user_data);
+
+/**
+ * @brief The structure type containing the set of callback functions to provide methods
+ * @since_tizen tizen 4.0
+ */
+typedef struct {
+       service_app_loop_method_init_cb init;
+       service_app_loop_method_fini_cb fini;
+       service_app_loop_method_run_cb run;
+       service_app_loop_method_exit_cb exit;
+} service_app_loop_method_s;
+
+/**
+ * @brief Runs the main loop of the application until service_app_exit() is called.
+ * @details This function is the main entry point of the Tizen service application.
+ * @since_tizen 4.0
+ * @param[in] argc The argument count
+ * @param[in] argv The argument vector
+ * @param[in] callback The set of callback functions to handle application events
+ * @param[in] method The set of callback functions to be used for entering and exiting main loop
+ * @param[in] user_data The user data to be passed to the callback functions
+ * @return @c 0 on success,
+ *         otherwise a negative error value.
+ * @retval #APP_ERROR_NONE Successful
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #APP_ERROR_INVALID_CONTEXT The application is launched illegally, not launched by the launch system.
+ * @retval #APP_ERROR_ALREADY_RUNNING The main loop has already started
+ * @see service_app_create_cb()
+ * @see service_app_terminate_cb()
+ * @see service_app_control_cb()
+ * @see service_app_exit()
+ * @see #service_app_lifecycle_callback_s
+ */
+int service_app_main_ext(int argc, char **argv, service_app_lifecycle_callback_s *callback,
+              service_app_loop_method_s *method, void *user_data);
+
+
+#ifdef __cplusplus
+}
+#endif
+
index a4982a1..6bd51f2 100644 (file)
@@ -71,5 +71,6 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %files -n capi-appfw-service-application-devel
 %{_includedir}/appcore-agent/service_app.h
 %{_includedir}/appcore-agent/service_app_extension.h
+%{_includedir}/appcore-agent/service_app_internal.h
 %{_libdir}/pkgconfig/capi-appfw-service-application.pc
 %{_libdir}/libappcore-agent.so
index 894fd03..8a75600 100644 (file)
@@ -26,6 +26,7 @@
 #include <service_app.h>
 
 #include "service_app_extension.h"
+#include "service_app_internal.h"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
@@ -75,10 +76,10 @@ static int __on_error(app_error_e error, const char *function, const char *descr
 static int __service_app_create(void *data)
 {
        appcore_base_on_create();
-       ecore_init();
+
        if (__context.callback.create == NULL ||
                        __context.callback.create(__context.data) == false)
-               return __on_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "service_app_create_cb() returns false"); 
+               return __on_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "service_app_create_cb() returns false");
 
        return APP_ERROR_NONE;
 }
@@ -111,6 +112,16 @@ static int __service_app_control(bundle *b, void *data)
        return 0;
 }
 
+static void __loop_init(int argc, char **argv, void *data)
+{
+       ecore_init();
+}
+
+static void __loop_fini(void)
+{
+       ecore_shutdown();
+}
+
 static void __loop_run(void *data)
 {
        ecore_main_loop_begin();
@@ -151,12 +162,13 @@ static int __on_error(app_error_e error, const char *function, const char *descr
        return error;
 }
 
-EXPORT_API int service_app_main(int argc, char **argv, service_app_lifecycle_callback_s *callback, void *user_data)
+EXPORT_API int service_app_main_ext(int argc, char **argv, service_app_lifecycle_callback_s *callback,
+               service_app_loop_method_s *method, void *user_data)
 {
        int ret;
        appcore_base_ops ops = appcore_base_get_default_ops();
 
-       if (argc < 1 || argv == NULL || callback == NULL)
+       if (argc < 1 || argv == NULL || callback == NULL || method == NULL)
                return __on_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
 
        if (callback->create == NULL)
@@ -169,8 +181,10 @@ EXPORT_API int service_app_main(int argc, char **argv, service_app_lifecycle_cal
        ops.create = __service_app_create;
        ops.terminate = __service_app_terminate;
        ops.control = __service_app_control;
-       ops.run = __loop_run;
-       ops.exit = __loop_exit;
+       ops.run = method->run;
+       ops.exit = method->exit;
+       ops.init = method->init;
+       ops.finish = method->fini;
 
        __context.callback = *callback;
        __context.data = user_data;
@@ -187,6 +201,18 @@ EXPORT_API int service_app_main(int argc, char **argv, service_app_lifecycle_cal
        return APP_ERROR_NONE;
 }
 
+EXPORT_API int service_app_main(int argc, char **argv, service_app_lifecycle_callback_s *callback, void *user_data)
+{
+       service_app_loop_method_s method = {
+               .init = __loop_init,
+               .fini = __loop_fini,
+               .run = __loop_run,
+               .exit = __loop_exit,
+       };
+
+       return service_app_main_ext(argc, argv, callback, &method, user_data);
+}
+
 EXPORT_API void service_app_exit(void)
 {
        __loop_exit(NULL);