Add new API for customizing main loop 53/73153/4 accepted/tizen/common/20160610.175906 accepted/tizen/ivi/20160609.091414 accepted/tizen/mobile/20160609.091549 accepted/tizen/tv/20160609.091352 accepted/tizen/wearable/20160609.091333 submit/tizen/20160609.010102
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 7 Jun 2016 02:27:03 +0000 (11:27 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 7 Jun 2016 08:54:26 +0000 (17:54 +0900)
- ui_app_init, ui_app_fini are added

Change-Id: I2b97ed5ecefd71edee81195f9c464daed804d118
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/app_internal.h
src/app_main.c

index 66f0520..91fb53b 100644 (file)
@@ -257,6 +257,33 @@ void app_exit(void);
  */
 void app_efl_exit(void);
 
+/**
+ * @brief Initialize the application main loop.
+ *
+ * @details After calling this API, the application main loop doesn't run.
+ * @since_tizen 3.0
+ * @param[in] argc The argument count
+ * @param[in] argv The argument vector
+ * @param[in] callback The set of callback functions to handle application lifecycle events
+ * @param[in] user_data The user data to be passed to the callback functions
+ *
+ * @return 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 illegally launched, not launched by the launch system
+ * @retval #APP_ERROR_ALREADY_RUNNING The main loop already starts
+ * @sett ui_app_fini()
+ */
+int ui_app_init(int argc, char **argv, ui_app_lifecycle_callback_s *callback, void *user_data);
+
+/**
+ * @brief Finalize the application main loop.
+ *
+ * @since_tizen 3.0
+ * @see ui_app_init()
+ */
+void ui_app_fini(void);
+
 #ifdef __cplusplus
 }
 #endif
index ccf972c..e215afc 100644 (file)
@@ -676,24 +676,21 @@ static int _ui_app_appcore_reset(bundle *appcore_bundle, void *data)
        return APP_ERROR_NONE;
 }
 
-int ui_app_main(int argc, char **argv, ui_app_lifecycle_callback_s *callback, void *user_data)
-{
-       struct ui_app_context app_context = {
-               .package = NULL,
-               .app_name = NULL,
-               .state = APP_STATE_NOT_RUNNING,
-               .callback = callback,
-               .data = user_data
-       };
+static struct ui_app_context __app_context;
+static struct appcore_ops appcore_context = {
+       .data = &__app_context,
+       .create = _ui_app_appcore_create,
+       .terminate = _ui_app_appcore_terminate,
+       .pause = _ui_app_appcore_pause,
+       .resume = _ui_app_appcore_resume,
+       .reset = _ui_app_appcore_reset,
+};
 
-       struct appcore_ops appcore_context = {
-               .data = &app_context,
-               .create = _ui_app_appcore_create,
-               .terminate = _ui_app_appcore_terminate,
-               .pause = _ui_app_appcore_pause,
-               .resume = _ui_app_appcore_resume,
-               .reset = _ui_app_appcore_reset,
-       };
+int ui_app_init(int argc, char **argv, ui_app_lifecycle_callback_s *callback, void *user_data)
+{
+       __app_context.state = APP_STATE_NOT_RUNNING;
+       __app_context.callback = callback;
+       __app_context.data = user_data;
 
        if (argc < 1 || argv == NULL || callback == NULL)
                return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
@@ -701,24 +698,59 @@ int ui_app_main(int argc, char **argv, ui_app_lifecycle_callback_s *callback, vo
        if (callback->create == NULL)
                return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "app_create_cb() callback must be registered");
 
-       if (app_context.state != APP_STATE_NOT_RUNNING)
+       if (__app_context.state != APP_STATE_NOT_RUNNING)
                return app_error(APP_ERROR_ALREADY_RUNNING, __FUNCTION__, NULL);
 
-       if (app_get_id(&(app_context.package)) != APP_ERROR_NONE)
-               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
+       if (__app_context.package == NULL) {
+               if (app_get_id(&__app_context.package) != APP_ERROR_NONE)
+                       return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
+       }
 
-       if (app_get_package_app_name(app_context.package, &(app_context.app_name)) != APP_ERROR_NONE) {
-               free(app_context.package);
-               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package's app name");
+       if (__app_context.app_name == NULL) {
+               if (app_get_package_app_name(__app_context.package, &__app_context.app_name) != APP_ERROR_NONE) {
+                       free(__app_context.package);
+                       __app_context.package = NULL;
+                       return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package's app name");
+               }
        }
 
-       app_context.state = APP_STATE_CREATING;
+       __app_context.state = APP_STATE_CREATING;
 
-       LOGI("app_efl_main");
-       appcore_efl_main(app_context.app_name, &argc, &argv, &appcore_context);
+       LOGI("app_efl_init");
+       return appcore_efl_init(__app_context.app_name, &argc, &argv, &appcore_context);
+}
 
-       free(app_context.package);
-       free(app_context.app_name);
+void ui_app_fini(void)
+{
+       appcore_efl_fini();
+
+       if (__app_context.app_name) {
+               free(__app_context.app_name);
+               __app_context.app_name = NULL;
+       }
+
+       if (__app_context.package) {
+               free(__app_context.package);
+               __app_context.package = NULL;
+       }
+}
+
+int ui_app_main(int argc, char **argv, ui_app_lifecycle_callback_s *callback, void *user_data)
+{
+       int ret;
+
+       ret = ui_app_init(argc, argv, callback, user_data);
+       if (ret != APP_ERROR_NONE) {
+               free(__app_context.app_name);
+               __app_context.app_name = NULL;
+               free(__app_context.package);
+               __app_context.package = NULL;
+               return ret;
+       }
+
+       elm_run();
+
+       ui_app_fini();
 
        return APP_ERROR_NONE;
 }