--- /dev/null
+/*
+ * 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
+
#include <service_app.h>
#include "service_app_extension.h"
+#include "service_app_internal.h"
#ifdef LOG_TAG
#undef LOG_TAG
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;
}
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();
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)
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;
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);