Create & use running context 86/216886/3
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 4 Nov 2019 11:12:19 +0000 (20:12 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 11 Nov 2019 03:30:33 +0000 (12:30 +0900)
If the application is already running, frame-broker creates the running
context while sending the launch request. And then, uses it when getting
the tzsh launcher service events.

Change-Id: I609f445817bd1fe8ed5efb46577b156cb416c9ad
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
frame-broker/src/frame_broker.c
frame-broker/src/frame_context.c
frame-broker/src/frame_context_private.h

index 82b640c..545fb01 100644 (file)
@@ -40,6 +40,7 @@ struct frame_broker_s {
        aul_launcher_service_h als;
        screen_connector_launcher_service_evas_h scls_evas;
        frame_context_h context;
+       frame_context_h pre_context;
 };
 
 static GList *__win_list;
@@ -92,6 +93,19 @@ static uint32_t __generate_serial(void)
        return (uint32_t)serial;
 }
 
+static void __check_pre_context(frame_broker_h broker)
+{
+       if (broker->context) {
+               _D("Destroy previous context");
+               frame_context_destroy(broker->context);
+       }
+
+       broker->context = broker->pre_context;
+       broker->pre_context = NULL;
+
+       frame_context_on_create(broker->context);
+}
+
 static void __aul_launcher_service_cb(const char *app_id,
                const char *inst_id,
                const int pid,
@@ -100,10 +114,27 @@ static void __aul_launcher_service_cb(const char *app_id,
 {
        frame_broker_h broker = user_data;
        frame_context_h context;
+       int ctx_pid = -1;
+       uint32_t ctx_serial = 0;
        int ret;
 
        _D("app_id(%s), inst_id(%s), pid(%d), serial(%u)",
                        app_id, inst_id, pid, serial);
+
+       if (broker->pre_context) {
+               __check_pre_context(broker);
+               return;
+       }
+
+       if (broker->context) {
+               frame_context_get_pid(broker->context, &ctx_pid);
+               frame_context_get_serial(broker->context, &ctx_serial);
+               if (ctx_pid == pid && ctx_serial == serial) {
+                       _D("Frame context already exists");
+                       return;
+               }
+       }
+
        ret = frame_context_create(broker, app_id, inst_id, pid, serial,
                        &broker->callback, broker->user_data,
                        &context);
@@ -137,8 +168,12 @@ static void __scls_evas_prepare_cb(Evas_Object *image,
 
        _D("[__SCLS_EVAS__] Prepare");
        if (context == NULL) {
-               _E("Invalid context");
-               return;
+               if (broker->pre_context) {
+                       __check_pre_context(broker);
+               } else {
+                       _E("Invalid context");
+                       return;
+               }
        }
 
        frame_context_set_serial(context, serial);
@@ -162,8 +197,12 @@ static void __scls_evas_stop_cb(uint32_t serial, void *user_data)
 
        _D("[__SCLS_EVAS__] Stop");
        if (context == NULL) {
-               _E("Invalid context");
-               return;
+               if (broker->pre_context) {
+                       __check_pre_context(broker);
+               } else {
+                       _E("Invalid context");
+                       return;
+               }
        }
 
        _D("Destroy context");
@@ -193,8 +232,12 @@ static void __scls_evas_error_cb(
 
        _D("[__SCLS_EVAS__] Error");
        if (context == NULL) {
-               _E("Invalid context");
-               return;
+               if (broker->pre_context) {
+                       __check_pre_context(broker);
+               } else {
+                       _E("Invalid context");
+                       return;
+               }
        }
 
        frame_context_on_error(context, __convert_error(error));
@@ -382,16 +425,31 @@ static int __send_launch_request(frame_broker_h handle,
                ret = frame_broker_launch(handle, app_id, inst_id, pid,
                                &serial);
        }
+
+       if (inst_id && pid > 0) {
+               frame_context_destroy(handle->pre_context);
+               handle->pre_context = NULL;
+
+               frame_context_create(handle, app_id, inst_id, pid, serial,
+                               &handle->callback, handle->user_data,
+                               &handle->pre_context);
+       }
+
        aul_running_context_destroy(context);
        free(app_id);
-       if (ret != FRAME_BROKER_ERROR_NONE)
+       if (ret != FRAME_BROKER_ERROR_NONE) {
+               frame_context_destroy(handle->pre_context);
+               handle->pre_context = NULL;
                return ret;
+       }
 
        snprintf(buf, sizeof(buf), "%u", serial);
        ret = app_control_add_extra_data(app_control,
                        AUL_K_LAUNCHER_SERVICE_SERIAL, buf);
        if (ret != APP_CONTROL_ERROR_NONE) {
                _E("Failed to add extra data. error(%d)", ret);
+               frame_context_destroy(handle->pre_context);
+               handle->pre_context = NULL;
                return ret;
        }
 
@@ -399,6 +457,8 @@ static int __send_launch_request(frame_broker_h handle,
                        AUL_K_LAUNCHER_SERVICE, handle->name);
        if (ret != APP_CONTROL_ERROR_NONE) {
                _E("Failed to add extra data. error(%d)", ret);
+               frame_context_destroy(handle->pre_context);
+               handle->pre_context = NULL;
                return ret;
        }
 
@@ -406,6 +466,8 @@ static int __send_launch_request(frame_broker_h handle,
                        result_cb, reply_cb, user_data);
        if (ret != APP_CONTROL_ERROR_NONE) {
                _E("Failed to send launch request. error(%d)", ret);
+               frame_context_destroy(handle->pre_context);
+               handle->pre_context = NULL;
                return ret;
        }
 
index ba72b84..b7e5c64 100644 (file)
@@ -207,6 +207,18 @@ API int frame_context_finish_animation(frame_context_h handle)
        return FRAME_BROKER_ERROR_NONE;
 }
 
+int frame_context_get_pid(frame_context_h handle, int *pid)
+{
+       if (!handle || !pid) {
+               _E("Invalid parameter");
+               return FRAME_BROKER_ERROR_INVALID_PARAMETER;
+       }
+
+       *pid = handle->pid;
+
+       return FRAME_BROKER_ERROR_NONE;
+}
+
 int frame_context_set_serial(frame_context_h handle, uint32_t serial)
 {
        if (!handle) {
index e4e6aef..66c964e 100644 (file)
@@ -41,6 +41,8 @@ int frame_context_create(frame_broker_h broker,
 
 int frame_context_destroy(frame_context_h handle);
 
+int frame_context_get_pid(frame_context_h handle, int *pid);
+
 int frame_context_set_serial(frame_context_h handle, uint32_t serial);
 
 int frame_context_get_serial(frame_context_h handle, uint32_t *serial);