/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015 - 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.
#include <stdlib.h>
+#include <stdbool.h>
#include <bundle.h>
+#include <bundle_internal.h>
#include <aul.h>
#include <dlog.h>
#include <glib.h>
#include <glib-object.h>
-#include <app_control.h>
-#include <app_control_internal.h>
-#include <widget.h>
-#include <widget_service.h>
-#include <widget_service_internal.h>
-#include <widget_provider_app.h>
-#include <widget_provider_app_internal.h>
+#include <stdlib.h>
#include <Elementary.h>
-#include <vconf.h>
#include <widget_errno.h>
+#include <widget_instance.h>
+#include <aul_app_com.h>
+#include <Ecore_Wayland.h>
#include <system_info.h>
+#include <vconf.h>
+#include <vconf-internal-keys.h>
+#include <screen_connector_provider.h>
+#include <appcore_multiwindow_base.h>
#include "widget_app.h"
#include "widget-log.h"
#undef LOG_TAG
#endif
-#define STR_MAX_BUF 128
#define LOG_TAG "CAPI_WIDGET_APPLICATION"
-#define K_REASON "__WC_K_REASON__"
-
-#define ELM_WIN_TIZEN_WIDGET -1
-/* TODO
- * This definition is intended to prevent the build break.
- * This should be removed after adding ELM_WIN_TIZEN_WIDGET in Elm_Win_Type.
- */
+#define APP_TYPE_WIDGET "widgetapp"
+#define STATUS_FOREGROUND "fg"
+#define STATUS_BACKGROUND "bg"
+
+struct widget_extra {
+ void *extra;
+ char *instance_id;
+ bundle *args;
+ char *content;
+ Evas_Object *win;
+};
-#define WIDGET_APP_EVENT_MAX 5
-static GList *handler_list[WIDGET_APP_EVENT_MAX] = {NULL, };
+struct widget_class_context {
+ widget_instance_lifecycle_callback_s callback;
+ void *data;
+};
-typedef enum _widget_obj_state_e {
- WC_READY = 0,
- WC_RUNNING = 1,
- WC_PAUSED = 2,
- WC_TERMINATED = 3
-} widget_obj_state_e;
+struct widget_app_context {
+ widget_app_lifecycle_callback_s callback;
+ void *data;
+ bool dirty;
+};
-struct app_event_handler {
- app_event_type_e type;
- app_event_cb cb;
+struct widget_foreach_context {
+ widget_context_cb callback;
void *data;
};
void *value;
};
-struct _widget_class {
- widget_instance_lifecycle_callback_s ops;
- widget_obj_private_ops_s ops_private;
+struct app_event_handler {
+ app_event_type_e type;
+ app_event_cb cb;
+ void *data;
+ void *raw;
};
struct _widget_context {
- char *id;
- int state;
- void *tag;
- widget_instance_lifecycle_callback_s ops;
- widget_obj_private_ops_s ops_private;
+ int dummy;
};
-typedef struct _widget_class widget_class_s;
-typedef struct _widget_context widget_context_s;
-
-static widget_app_lifecycle_callback_s *app_ops = NULL;
-static void *app_user_data = NULL;
-static widget_class_factory_full_s factory;
-static widget_class_s *widget_class = NULL;
-static widget_class_s widget_class_tmp;
-static GList *contexts = NULL;
-static int is_init_provider = 0;
-static char *appid = NULL;
-static int is_background = -1;
-
-static gint __comp_by_id(gconstpointer a, gconstpointer b)
-{
- widget_context_s *wc = (widget_context_s*)a;
+static int __app_event_converter[APPCORE_BASE_EVENT_MAX] = {
+ [APP_EVENT_LOW_MEMORY] = APPCORE_BASE_EVENT_LOW_MEMORY,
+ [APP_EVENT_LOW_BATTERY] = APPCORE_BASE_EVENT_LOW_BATTERY,
+ [APP_EVENT_LANGUAGE_CHANGED] = APPCORE_BASE_EVENT_LANG_CHANGE,
+ [APP_EVENT_DEVICE_ORIENTATION_CHANGED] = APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED,
+ [APP_EVENT_REGION_FORMAT_CHANGED] = APPCORE_BASE_EVENT_REGION_CHANGE,
+ [APP_EVENT_SUSPENDED_STATE_CHANGED] = APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE,
+};
- return strcmp(wc->id, (const char*)b);
-}
+static struct widget_app_context __context;
+static char *__appid;
+static char *__package_id;
+static bool __fg_signal;
+char *_viewer_endpoint;
-static void __check_status_for_cgroup(void)
+static bool __is_widget_feature_enabled(void)
{
- GList *iter = g_list_first(contexts);
-
- while (iter != NULL) {
- widget_context_s *cxt = (widget_context_s*) iter->data;
-
- if (cxt->state != WC_PAUSED) {
- if (is_background != 0) {
- is_background = 0;
- _I("enter foreground group");
- //TODO: Do something to enter foreground group
- }
- return;
- }
- iter = g_list_next(iter);
+ static bool feature = false;
+ static bool retrieved = false;
+ int ret;
+
+ if (retrieved == true)
+ return feature;
+
+ ret = system_info_get_platform_bool(
+ "http://tizen.org/feature/shell.appwidget", &feature);
+ if (ret != SYSTEM_INFO_ERROR_NONE) {
+ _E("failed to get system info"); /* LCOV_EXCL_LINE */
+ return false; /* LCOV_EXCL_LINE */
}
- if (g_list_length(contexts) > 0 && is_background == 0) {
- is_background = 1;
- _I("enter background group");
- //TODO: DO something to enter background group
- }
+ retrieved = true;
+
+ return feature;
}
-static widget_context_s* __find_context_by_id(const char *id)
+/* LCOV_EXCL_START */
+static void __on_poweroff(keynode_t *key, void *data)
{
- GList* ret = g_list_find_custom(contexts, id, __comp_by_id);
-
- if ( ret == NULL)
- return NULL;
+ int val;
- return ret->data;
+ val = vconf_keynode_get_int(key);
+ switch (val) {
+ case VCONFKEY_SYSMAN_POWER_OFF_DIRECT:
+ case VCONFKEY_SYSMAN_POWER_OFF_RESTART:
+ _I("power off changed: %d", val);
+ widget_app_exit();
+ break;
+ case VCONFKEY_SYSMAN_POWER_OFF_NONE:
+ case VCONFKEY_SYSMAN_POWER_OFF_POPUP:
+ default:
+ /* DO NOTHING */
+ break;
+ }
}
+/* LCOV_EXCL_STOP */
-static int __provider_create_cb(const char *id, const char *content, int w,
- int h,
- void *data)
+static int __widget_app_create(void *data)
{
- int ret = WIDGET_ERROR_FAULT;
- widget_context_s *wc = (widget_context_s*)malloc(sizeof(widget_context_s));
- if (wc == NULL)
- return WIDGET_ERROR_OUT_OF_MEMORY;
+ char pkgid[256] = {0, };
- wc->id = strdup(id);
- wc->state = WC_READY;
- wc->tag = NULL;
- wc->ops = widget_class->ops;
- wc->ops_private = widget_class->ops_private;
- contexts = g_list_append(contexts, wc);
+ appcore_multiwindow_base_on_create();
+ app_get_id(&__appid);
+ if (aul_app_get_pkgid_bypid(getpid(), pkgid, sizeof(pkgid)) == 0)
+ __package_id = strdup(pkgid);
- if (wc->ops.create) {
- bundle *b = bundle_decode((const bundle_raw*)content, strlen(content));
- ret = wc->ops.create(wc, b, w, h);
- bundle_free(b);
+ if (!__package_id || !__appid) {
+ _E("__package_id is NULL");
+ return -1;
}
- _I("widget obj was created");
- return ret;
-}
+ screen_connector_provider_init();
+ vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, __on_poweroff, NULL);
-static int __provider_resize_cb(const char *id, int w, int h, void *data)
-{
- int ret = WIDGET_ERROR_FAULT;
- widget_context_s *cxt = __find_context_by_id(id);
+ if (__context.callback.create == NULL) {
+ _E("__context.callback.create(is NULL");
+ return -1;
+ }
- if (cxt) {
- if (cxt->ops.resize)
- ret = cxt->ops.resize(cxt, w, h);
- _I("received resizing signal");
- } else {
- _E("could not find widget obj : %s", __FUNCTION__);
+ if (__context.callback.create(__context.data) == NULL) {
+ _E("app_create_cb() returns NULL");
+ return -1;
}
- return ret;
+ _D("widget app is created");
+ return 0;
}
-static int __provider_destroy_cb(const char *id, widget_destroy_type_e reason,
- void *data)
+static int __widget_app_terminate(void *data)
{
- int ret = WIDGET_ERROR_FAULT;
- widget_context_s *cxt = __find_context_by_id(id);
-
- if (cxt) {
- cxt->state = WC_TERMINATED;
- if (cxt->ops.destroy) {
- bundle *b = bundle_create();
- ret = cxt->ops.destroy(cxt,(widget_app_destroy_type_e)reason, b);
+ if (__context.callback.terminate)
+ __context.callback.terminate(__context.data);
- bundle_raw *raw = NULL;
- int len;
+ vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, __on_poweroff);
+ screen_connector_provider_fini();
- bundle_encode(b, &raw, &len);
- if (raw) {
- widget_provider_app_send_extra_info(id, (const char*)raw, NULL);
- free(raw);
- }
-
- bundle_free(b);
- contexts = g_list_remove(contexts, cxt);
-
- free(cxt->id);
- free(cxt);
- }
- _I("widget obj was deleted");
- } else {
- _E("could not find widget obj : %s", __FUNCTION__);
+ if (_viewer_endpoint) {
+ free(_viewer_endpoint);
+ _viewer_endpoint = NULL;
}
- return ret;
-}
-
-static int __provider_update_cb(const char *id, const char *content, int force,
- void *data)
-{
- int ret = WIDGET_ERROR_FAULT;
- widget_context_s *cxt = __find_context_by_id(id);
-
- if (cxt) {
- if (cxt->ops.update) {
- bundle *b = bundle_decode((const bundle_raw*)content, strlen(content));
- ret = cxt->ops.update(cxt, b, force);
- bundle_free(b);
- }
- _I("received updating signal");
- } else {
- _E("could not find widget obj : %s", __FUNCTION__);
+ if (__package_id) {
+ free(__package_id);
+ __package_id = NULL;
}
- return ret;
-}
-
-static int __provider_pause_cb(const char *id, void *data)
-{
- int ret = WIDGET_ERROR_FAULT;
- widget_context_s *cxt = __find_context_by_id(id);
-
- if (cxt) {
- if (cxt->ops.pause)
- ret = cxt->ops.pause(cxt);
- cxt->state = WC_PAUSED;
- _I("widget obj was paused");
- } else {
- _E("could not find widget obj : %s", __FUNCTION__);
+ if (__appid) {
+ free(__appid);
+ __appid = NULL;
}
- __check_status_for_cgroup();
- return ret;
-}
-
-static int __provider_resume_cb(const char *id, void *data)
-{
- int ret = WIDGET_ERROR_FAULT;
- widget_context_s *cxt = __find_context_by_id(id);
-
- if (cxt) {
- if (cxt->ops.resume)
- ret = cxt->ops.resume(cxt);
- cxt->state = WC_RUNNING;
- _I("widget obj was resumed");
- } else {
- _E("could not find widget obj : %s", __FUNCTION__);
- }
+ appcore_multiwindow_base_on_terminate();
- __check_status_for_cgroup();
- return ret;
+ _D("widget app is terminated");
+ return 0;
}
-static int __provider_text_signal_cb(const char *id, const char *signal_name,
- const char *source, struct widget_event_info *info, void *data)
+static int __send_lifecycle_event(const char *class_id, const char *instance_id,
+ int status)
{
- int ret = WIDGET_ERROR_FAULT;
- widget_context_s *cxt = __find_context_by_id(id);
+ bundle *b = bundle_create();
+ int ret;
- if (cxt) {
- if (cxt->ops_private.text_signal) {
- ret = cxt->ops_private.text_signal(cxt, signal_name, source,
- (widget_obj_event_info_s*)info);
- }
- _I("received text signal");
- } else {
- _E("could not find widget obj : %s", __FUNCTION__);
+ if (b == NULL) {
+ _E("out of memory"); /* LCOV_EXCL_LINE */
+ return -1; /* LCOV_EXCL_LINE */
}
- return ret;
-}
+ bundle_add_str(b, AUL_K_WIDGET_ID, class_id);
+ bundle_add_str(b, AUL_K_WIDGET_INSTANCE_ID, instance_id);
+ bundle_add_byte(b, AUL_K_WIDGET_STATUS, &status, sizeof(int));
+ bundle_add_str(b, AUL_K_PKGID, __package_id);
-static const widget_class_factory_full_s*
-__widget_class_factory_override_text_signal(widget_instance_text_signal_cb op)
-{
- widget_class_tmp.ops_private.text_signal = op;
- return &factory;
-}
+ _D("send lifecycle %s(%d)", instance_id, status);
+ ret = aul_app_com_send("widget.status", b);
+ if (ret < 0)
+ _E("send lifecycle error:%d", ret); /* LCOV_EXCL_LINE */
-static void __free_handler_cb(gpointer data)
-{
- if (data)
- free(data);
+ bundle_free(b);
+
+ return ret;
}
-static void __free_handler_list(void)
+static int __send_update_status(const char *class_id, const char *instance_id,
+ int status, bundle *extra)
{
- int i;
+ bundle *b;
+ int lifecycle = -1;
+ bundle_raw *raw = NULL;
+ int len;
- for (i = 0; i < WIDGET_APP_EVENT_MAX; i++) {
- g_list_free_full(handler_list[i], __free_handler_cb);
- handler_list[i] = NULL;
+ b = bundle_create();
+ if (!b) {
+ _E("out of memory"); /* LCOV_EXCL_LINE */
+ return -1; /* LCOV_EXCL_LINE */
}
-}
-static void __control(bundle *b)
-{
- app_control_h app_control;
+ bundle_add_str(b, AUL_K_WIDGET_ID, class_id);
+ bundle_add_str(b, AUL_K_WIDGET_INSTANCE_ID, instance_id);
+ bundle_add_byte(b, AUL_K_WIDGET_STATUS, &status, sizeof(int));
- if (is_init_provider) {
- _E("already initialized");
- return;
+ if (extra) {
+ bundle_encode(extra, &raw, &len);
+ bundle_add_str(b, WIDGET_K_CONTENT_INFO, (const char *)raw);
+ aul_widget_instance_add(class_id, instance_id);
}
- if (app_control_create_event(b, &app_control) != 0) {
- _E("failed to get the app_control handle");
- return;
- }
+ _D("send update %s(%d) to %s", instance_id, status, _viewer_endpoint);
+ aul_app_com_send(_viewer_endpoint, b);
- char *op = NULL;
- app_control_get_operation(app_control, &op);
+ switch (status) {
+ case WIDGET_INSTANCE_EVENT_CREATE:
+ lifecycle = WIDGET_LIFE_CYCLE_EVENT_CREATE;
+ break;
+ case WIDGET_INSTANCE_EVENT_DESTROY:
+ lifecycle = WIDGET_LIFE_CYCLE_EVENT_DESTROY;
+ break;
+ case WIDGET_INSTANCE_EVENT_PAUSE:
+ lifecycle = WIDGET_LIFE_CYCLE_EVENT_PAUSE;
+ break;
+ case WIDGET_INSTANCE_EVENT_RESUME:
+ lifecycle = WIDGET_LIFE_CYCLE_EVENT_RESUME;
+ break;
+ }
- if (op && strcmp(op, "http://tizen.org/appcontrol/operation/main") == 0) {
- static struct widget_provider_event_callback cb = {
- .create = __provider_create_cb,
- .resize = __provider_resize_cb,
- .destroy = __provider_destroy_cb,
+ if (lifecycle > -1)
+ __send_lifecycle_event(class_id, instance_id, lifecycle);
- .update = __provider_update_cb,
- .text_signal = __provider_text_signal_cb,
+ bundle_free(b);
+ if (raw)
+ free(raw);
- .pause = __provider_pause_cb,
- .resume = __provider_resume_cb,
+ return 0;
+}
- .connected = NULL,
- .disconnected = NULL,
+static void __instance_resume(const char *class_id, const char *id, bundle *b)
+{
+ appcore_multiwindow_base_instance_h cxt;
- .data = NULL,
- };
+ cxt = appcore_multiwindow_base_instance_find(id);
- if (widget_provider_app_init(app_control, &cb) == 0) {
- is_init_provider = 1;
- }
+ if (!cxt) {
+ _E("context not found: %s", id);
+ return;
}
- app_control_destroy(app_control);
- if (op)
- free(op);
+ appcore_multiwindow_base_instance_resume(cxt);
+
+ __send_update_status(class_id, id,
+ WIDGET_INSTANCE_EVENT_RESUME, NULL);
+ if (!__fg_signal) {
+ _D("Send fg signal to resourceD");
+ aul_send_app_status_change_signal(getpid(),
+ __appid,
+ __package_id,
+ STATUS_FOREGROUND,
+ APP_TYPE_WIDGET);
+ __fg_signal = true;
+ }
}
-static void __pause_all()
+static void __instance_pause(const char *class_id, const char *id, bundle *b)
{
- GList *iter = g_list_first(contexts);
+ appcore_multiwindow_base_instance_h cxt;
- while (iter != NULL) {
- widget_context_s *cxt = (widget_context_s*) iter->data;
- const char *id = cxt->id;
+ cxt = appcore_multiwindow_base_instance_find(id);
- switch (cxt->state) {
- case WC_READY:
- __provider_resume_cb(id, NULL);
- __provider_pause_cb(id, NULL);
- break;
-
- case WC_RUNNING:
- __provider_pause_cb(id, NULL);
- break;
- }
- iter = g_list_next(iter);
+ if (!cxt) {
+ _E("context not found: %s", id);
+ return;
}
-}
-static int __aul_handler(aul_type type, bundle *b, void *data)
-{
- switch (type) {
- case AUL_START:
- __control(b);
- break;
- case AUL_RESUME:
- break;
- case AUL_TERMINATE:
- widget_app_exit();
- break;
- default:
- break;
- }
+ appcore_multiwindow_base_instance_pause(cxt);
- return 0;
+ if (__fg_signal) {
+ _D("Send bg signal to resourceD");
+ aul_send_app_status_change_signal(getpid(),
+ __appid,
+ __package_id,
+ STATUS_BACKGROUND,
+ APP_TYPE_WIDGET);
+ __fg_signal = false;
+ }
}
-static char* __get_domain_name(const char *aid)
+static void __instance_resize(const char *class_id, const char *id, bundle *b)
{
- char *name_token = NULL;
-
- if (aid == NULL) {
- _E("appid is NULL");
- return NULL;
+ appcore_multiwindow_base_instance_h cxt;
+ struct widget_class_context *class_cxt;
+ const appcore_multiwindow_base_class *cls;
+ struct widget_extra *we;
+ char *remain = NULL;
+ char *w_str = NULL;
+ char *h_str = NULL;
+ int w = 0;
+ int h = 0;
+
+ cxt = appcore_multiwindow_base_instance_find(id);
+
+ if (!cxt) {
+ _E("context not found: %s", id);
+ return;
}
- // com.vendor.name -> name
- name_token = strrchr(aid, '.');
+ cls = appcore_multiwindow_base_instance_get_class(cxt);
+ if (!cls)
+ return;
- if (name_token == NULL) {
- _E("appid is invalid");
- return strdup(aid);
+ class_cxt = cls->data;
+ if (!class_cxt) {
+ _E("class is NULL");
+ return;
}
- name_token++;
+ we = appcore_multiwindow_base_instance_get_extra(cxt);
+ if (!we) {
+ _E("widget extra is NULL");
+ return;
+ }
- return strdup(name_token);
-}
+ bundle_get_str(b, WIDGET_K_WIDTH, &w_str);
+ bundle_get_str(b, WIDGET_K_HEIGHT, &h_str);
-static int __before_loop(int argc, char **argv)
-{
- int r;
+ if (w_str)
+ w = (int)g_ascii_strtoll(w_str, &remain, 10);
-#if !(GLIB_CHECK_VERSION(2, 36, 0))
- g_type_init();
-#endif
+ if (h_str)
+ h = (int)g_ascii_strtoll(h_str, &remain, 10);
- elm_init(argc, argv);
+ if (we->win)
+ evas_object_resize(we->win, w, h);
+ else
+ _E("unable to find window of %s", id);
- factory.override_text_signal = __widget_class_factory_override_text_signal;
+ if (class_cxt->callback.resize)
+ class_cxt->callback.resize(cxt, w, h, class_cxt->data);
+ _D("%s is resized to %dx%d", id, w, h);
+ __send_update_status(class_id, id,
+ WIDGET_INSTANCE_EVENT_SIZE_CHANGED, NULL);
+}
- r = aul_launch_init(__aul_handler, NULL);
- if (r < 0) {
- return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__,
- "Fail to call the aul_launch_init");
+static void __inst_cb(const char *class_id, const char *id,
+ appcore_multiwindow_base_instance_h cxt, void *data)
+{
+ struct widget_class_context *class_cxt;
+ const appcore_multiwindow_base_class *cls;
+ bundle *content = NULL;
+ char *content_raw = NULL;
+ char *force_str = NULL;
+ int force;
+ bundle *b = data;
+
+ if (!b) {
+ _E("bundle is NULL");
+ return;
}
- r = aul_launch_argv_handler(argc, argv);
- if (r < 0) {
- return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__,
- "Fail to call the aul_launch_argv_handler");
+ cls = appcore_multiwindow_base_instance_get_class(cxt);
+ if (!cls) {
+ _E("class is NULL");
+ return;
}
- r = app_get_id(&appid);
- if (r != APP_ERROR_NONE)
- return r;
-
- char *name = __get_domain_name(appid);
-
- if (name == NULL) {
- return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__,
- "Fail to call __get_domain_name");
+ class_cxt = cls->data;
+ if (!class_cxt) {
+ _E("class context is NULL");
+ return;
}
- r = _set_i18n(name);
-
- free(name);
- if (r < 0) {
- return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__,
- "Fail to call _set_i18n");
+ if (!class_cxt->callback.update) {
+ _E("update callback is NULL");
+ return;
}
- widget_provider_app_create_app();
-
- memset(&widget_class_tmp, 0, sizeof(widget_class_tmp));
- widget_class = app_ops->create(app_user_data);
- if (widget_class == NULL) {
- return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__,
- "widget_class is NULL");
- }
+ bundle_get_str(b, WIDGET_K_FORCE, &force_str);
- return WIDGET_ERROR_NONE;
-}
+ if (force_str && strcmp(force_str, "true") == 0)
+ force = 1;
+ else
+ force = 0;
-static void __after_loop()
-{
- __pause_all();
- widget_provider_app_terminate_app(WIDGET_DESTROY_TYPE_TEMPORARY, 1);
+ bundle_get_str(b, WIDGET_K_CONTENT_INFO, &content_raw);
- if (app_ops->terminate)
- app_ops->terminate(app_user_data);
+ if (content_raw)
+ content = bundle_decode((const bundle_raw *)content_raw, strlen(content_raw));
+ class_cxt->callback.update(cxt, content, force, class_cxt->data);
+ __send_update_status(class_id, id,
+ WIDGET_INSTANCE_EVENT_UPDATE, NULL);
+ _D("updated:%s", id);
- if (is_init_provider) {
- widget_provider_app_fini();
- is_init_provider = 0;
- }
- __free_handler_list();
- elm_shutdown();
- if (appid)
- free(appid);
- if (contexts)
- g_list_free(contexts);
- contexts = NULL;
+ if (content)
+ bundle_free(content);
}
-static gboolean __finish_event_cb(gpointer user_data)
+static void __instance_update(const char *class_id, const char *id, bundle *b)
{
- if (user_data == NULL)
- return FALSE;
-
- widget_context_s *wc = (widget_context_s*) user_data;
- const char* id = wc->id;
+ appcore_multiwindow_base_instance_h cxt;
- switch (wc->state) {
- case WC_READY:
- __provider_resume_cb(id, NULL);
- __provider_pause_cb(id, NULL);
- __provider_destroy_cb(id, WIDGET_DESTROY_TYPE_DEFAULT, NULL);
- break;
+ if (!id) {
+ appcore_multiwindow_base_instance_foreach(class_id, __inst_cb, b);
+ return;
+ }
- case WC_RUNNING:
- __provider_pause_cb(id, NULL);
- __provider_destroy_cb(id, WIDGET_DESTROY_TYPE_DEFAULT, NULL);
- break;
+ cxt = appcore_multiwindow_base_instance_find(id);
- case WC_PAUSED:
- __provider_destroy_cb(id, WIDGET_DESTROY_TYPE_DEFAULT, NULL);
- break;
+ if (!cxt) {
+ _E("context not found: %s", id);
+ return;
}
- widget_provider_app_send_deleted(id);
- return FALSE;
+ __inst_cb(class_id, id, cxt, b);
}
-static void __on_low_memory(keynode_t *key, void *data)
+static void __instance_create(const char *class_id, const char *id, bundle *b)
{
- int val;
+ struct widget_extra *we;
+ char *content = NULL;
- val = vconf_keynode_get_int(key);
- if (val == VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING) {
- app_event_handler_h handler;
- struct app_event_info event;
-
- _I("widget_app_low_memory");
-
- event.type = APP_EVENT_LOW_MEMORY;
- event.value = (void*)&val;
+ we = (struct widget_extra *)calloc(1, sizeof(struct widget_extra));
+ if (!we) {
+ _E("Out of memory");
+ return;
+ }
- GList *iter = g_list_first(handler_list[APP_EVENT_LOW_MEMORY]);
+ we->instance_id = strdup(id);
+ we->args = b;
+ appcore_multiwindow_base_instance_run(class_id, id, we);
+ we->args = NULL;
+ we->win = NULL;
+ bundle_get_str(b, WIDGET_K_CONTENT_INFO, &content);
+ if (content)
+ we->content = strdup(content);
- while (iter) {
- handler = (app_event_handler_h) iter->data;
- handler->cb(&event, handler->data);
- iter = g_list_next(iter);
- }
- }
}
-static void __on_low_battery(keynode_t *key, void *data)
+static void __check_empty_instance(void)
{
- int val;
-
- val = vconf_keynode_get_int(key);
- if (val <= VCONFKEY_SYSMAN_BAT_CRITICAL_LOW) {
- app_event_handler_h handler;
- struct app_event_info event;
-
- _I("widget_app_low_battery");
+ int cnt = appcore_multiwindow_base_instance_get_cnt();
- event.type = APP_EVENT_LOW_BATTERY;
- event.value = (void*)&val;
+ if (cnt == 0)
+ widget_app_exit();
+}
- GList *iter = g_list_first(handler_list[APP_EVENT_LOW_BATTERY]);
+static void __instance_destroy(const char *class_id, const char *id, bundle *b)
+{
+ appcore_multiwindow_base_instance_h cxt;
+ struct widget_extra *we;
- while (iter) {
- handler = (app_event_handler_h) iter->data;
- handler->cb(&event, handler->data);
- iter = g_list_next(iter);
- }
+ cxt = appcore_multiwindow_base_instance_find(id);
+ if (!cxt) {
+ _E("could not find widget obj: %s, clear amd info", id);
+ aul_widget_instance_del(class_id, id);
+ return;
}
+
+ we = appcore_multiwindow_base_instance_get_extra(cxt);
+ we->args = b;
+ appcore_multiwindow_base_instance_exit(cxt);
+ free(we->instance_id);
+ free(we->content);
+ free(we);
+ __check_empty_instance();
}
-static void __on_lang_changed(keynode_t *key, void *data)
+static int __widget_app_control(bundle *b, void *data)
{
- char *val;
+ char *class_id = NULL;
+ char *id = NULL;
+ char *operation = NULL;
- _update_lang();
- val = vconf_keynode_get_str(key);
+ appcore_multiwindow_base_on_control(b);
- app_event_handler_h handler;
- struct app_event_info event;
+ bundle_get_str(b, WIDGET_K_CLASS, &class_id);
+ /* for previous version compatibility, use appid for default class id */
+ if (class_id == NULL)
+ class_id = __appid;
- _I("widget_app_lang_changed");
+ bundle_get_str(b, AUL_K_WIDGET_INSTANCE_ID, &id);
+ bundle_get_str(b, WIDGET_K_OPERATION, &operation);
- event.type = APP_EVENT_LANGUAGE_CHANGED;
- event.value = (void*)val;
-
- GList *iter = g_list_first(handler_list[APP_EVENT_LANGUAGE_CHANGED]);
+ if (!operation) {
+ _E("operation is NULL");
+ return 0;
+ }
- while (iter) {
- handler = (app_event_handler_h) iter->data;
- handler->cb(&event, handler->data);
- iter = g_list_next(iter);
+ if (strcmp(operation, "create") == 0) {
+ __instance_create(class_id, id, b);
+ } else if (strcmp(operation, "resize") == 0) {
+ __instance_resize(class_id, id, b);
+ } else if (strcmp(operation, "update") == 0) {
+ __instance_update(class_id, id, b);
+ } else if (strcmp(operation, "destroy") == 0) {
+ __instance_destroy(class_id, id, b);
+ } else if (strcmp(operation, "resume") == 0) {
+ __instance_resume(class_id, id, b);
+ } else if (strcmp(operation, "pause") == 0) {
+ __instance_pause(class_id, id, b);
+ } else if (strcmp(operation, "terminate") == 0) {
+ __instance_destroy(class_id, id, b);
}
+
+ return 0;
}
-static void __on_region_changed(keynode_t *key, void *data)
+static void __inst_resume_cb(const char *class_id, const char *id,
+ appcore_multiwindow_base_instance_h cxt, void *data)
{
- char *val;
-
- _update_region();
- val = vconf_keynode_get_str(key);
+ __instance_resume(class_id, id, data);
+}
- app_event_handler_h handler;
- struct app_event_info event;
+static void __get_content(bundle *b)
+{
+ char *instance_id = NULL;
+ appcore_multiwindow_base_instance_h cxt;
+ struct widget_extra *we;
- _I("widget_app_region_changed");
+ bundle_get_str(b, AUL_K_WIDGET_INSTANCE_ID, &instance_id);
+ if (!instance_id) {
+ _E("instance id is NULL");
+ return;
+ }
- event.type = APP_EVENT_REGION_FORMAT_CHANGED;
- event.value = (void*)val;
+ cxt = appcore_multiwindow_base_instance_find(instance_id);
+ if (!cxt) {
+ _E("could not find widget obj: %s", instance_id);
+ return;
+ }
- GList *iter = g_list_first(handler_list[APP_EVENT_REGION_FORMAT_CHANGED]);
+ we = appcore_multiwindow_base_instance_get_extra(cxt);
+ if (!we) {
+ _E("widget extra is NULL");
+ return;
+ }
- while (iter) {
- handler = (app_event_handler_h) iter->data;
- handler->cb(&event, handler->data);
- iter = g_list_next(iter);
+ if (we->content) {
+ bundle_add_str(b, AUL_K_WIDGET_CONTENT_INFO, we->content);
+ _D("content info of %s found", instance_id);
+ } else {
+ bundle_add_str(b, AUL_K_WIDGET_CONTENT_INFO, "");
+ _D("empty content info added");
}
}
-static void __register_event(int event_type)
+static int __widget_app_receive(aul_type type, bundle *b, void *data)
{
- switch (event_type) {
- case APP_EVENT_LOW_MEMORY:
- vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __on_low_memory, NULL);
- break;
+ appcore_multiwindow_base_on_receive(type, b);
- case APP_EVENT_LOW_BATTERY:
- vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery,
- NULL);
+ switch (type) {
+ case AUL_RESUME:
+ appcore_multiwindow_base_instance_foreach_full(__inst_resume_cb, b);
break;
-
- case APP_EVENT_LANGUAGE_CHANGED:
- vconf_notify_key_changed(VCONFKEY_LANGSET, __on_lang_changed, NULL);
+ case AUL_TERMINATE:
+ widget_app_exit();
break;
-
- case APP_EVENT_REGION_FORMAT_CHANGED:
- vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, __on_region_changed, NULL);
+ case AUL_WIDGET_CONTENT:
+ __get_content(b);
+ break;
+ default:
break;
}
+
+ return 0;
}
-static void __unregister_event(int event_type)
+static int __widget_app_init(int argc, char **argv, void *data)
{
- switch (event_type) {
- case APP_EVENT_LOW_MEMORY:
- vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __on_low_memory);
- break;
-
- case APP_EVENT_LOW_BATTERY:
- vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery);
- break;
+ elm_init(argc, argv);
+ return 0;
+}
- case APP_EVENT_LANGUAGE_CHANGED:
- vconf_ignore_key_changed(VCONFKEY_LANGSET, __on_lang_changed);
- break;
+static void __widget_app_finish(void)
+{
+ elm_shutdown();
- case APP_EVENT_REGION_FORMAT_CHANGED:
- vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, __on_region_changed);
- break;
+ /* Check Loader case */
+ if (getenv("AUL_LOADER_INIT")) {
+ unsetenv("AUL_LOADER_INIT");
+ elm_shutdown();
}
}
-EXPORT_API int widget_app_main(int argc, char **argv,
- widget_app_lifecycle_callback_s *callback, void *user_data)
+static void __widget_app_run(void *data)
{
- int r;
- bool feature;
+ elm_run();
+}
- r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
- if (r < 0)
- return WIDGET_ERROR_FAULT;
+static void __widget_app_exit(void *data)
+{
+ elm_exit();
+}
- if (!feature)
- return WIDGET_ERROR_NOT_SUPPORTED;
+EXPORT_API int widget_app_main(int argc, char **argv,
+ widget_app_lifecycle_callback_s *callback, void *user_data)
+{
+ bundle *kb;
+ char *viewer_endpoint = NULL;
+
+ if (!__is_widget_feature_enabled()) {
+ _E("not supported"); /* LCOV_EXCL_LINE */
+ return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */
+ }
if (argc <= 0 || argv == NULL || callback == NULL)
- return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+ return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
+ __FUNCTION__, NULL);
+
+ if (__context.dirty) {
+ _E("Already started");
+ return widget_app_error(WIDGET_ERROR_FAULT, __FUNCTION__, NULL);
+ }
if (callback->create == NULL)
- return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, "widget_app_create_cb() callback must be registered");
+ return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
+ __FUNCTION__,
+ "widget_app_create_cb() callback must be "
+ "registered");
+
+ appcore_multiwindow_base_ops ops = appcore_multiwindow_base_get_default_ops();
+
+ /* override methods */
+ ops.base.create = __widget_app_create;
+ ops.base.control = __widget_app_control;
+ ops.base.terminate = __widget_app_terminate;
+ ops.base.receive = __widget_app_receive;
+ ops.base.init = __widget_app_init;
+ ops.base.finish = __widget_app_finish;
+ ops.base.run = __widget_app_run;
+ ops.base.exit = __widget_app_exit;
+
+ __context.callback = *callback;
+ __context.data = user_data;
+ kb = bundle_import_from_argv(argc, argv);
+ if (kb) {
+ bundle_get_str(kb, WIDGET_K_ENDPOINT, &viewer_endpoint);
+ if (viewer_endpoint) {
+ _D("viewer endpoint :%s", viewer_endpoint);
+ _viewer_endpoint = strdup(viewer_endpoint);
+ } else {
+ _E("endpoint is missing");
+ }
- app_ops = callback;
- app_user_data = user_data;
- r = __before_loop(argc, argv);
- if (r < 0)
- return r;
+ bundle_free(kb);
+ } else {
+ _E("failed to get launch argv"); /* LCOV_EXCL_LINE */
+ return widget_app_error(WIDGET_ERROR_FAULT, __FUNCTION__, NULL);
+ }
- ecore_main_loop_begin();
- //aul_status_update(STATUS_DYING);
- __after_loop();
+ __context.dirty = true;
+ appcore_multiwindow_base_init(ops, argc, argv, NULL);
+ appcore_multiwindow_base_fini();
+ __context.dirty = false;
return WIDGET_ERROR_NONE;
}
EXPORT_API int widget_app_exit(void)
{
- int r;
- bool feature;
-
- r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
- if (r < 0)
- return WIDGET_ERROR_FAULT;
-
- if (!feature)
- return WIDGET_ERROR_NOT_SUPPORTED;
+ if (!__is_widget_feature_enabled()) {
+ _E("not supported"); /* LCOV_EXCL_LINE */
+ return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */
+ }
- ecore_main_loop_quit();
+ appcore_multiwindow_base_exit();
+ aul_widget_notify_exit();
return WIDGET_ERROR_NONE;
}
-EXPORT_API int widget_app_terminate_context(widget_context_h context)
+static gboolean __finish_event_cb(gpointer user_data)
{
- int r;
- bool feature;
+ appcore_multiwindow_base_instance_h cxt = user_data;
+ bundle *b;
+ const char *id;
+ const char *class_id;
- r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
- if (r < 0)
- return WIDGET_ERROR_FAULT;
+ if (!cxt) {
+ _E("user_data is NULL");
+ return FALSE;
+ }
- if (!feature)
- return WIDGET_ERROR_NOT_SUPPORTED;
+ id = appcore_multiwindow_base_instance_get_id(cxt);
+ class_id = appcore_multiwindow_base_instance_get_class_id(cxt);
+ b = bundle_create();
+
+ if (!b) {
+ _E("Out-of-memory");
+ return FALSE;
+ }
- if (context == NULL) {
- return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__,
- "obj is NULL");
+ bundle_add_str(b, WIDGET_K_OPERATION, "terminate");
+ __instance_destroy(class_id, id, b);
+ bundle_free(b);
+
+ return FALSE;
+}
+
+EXPORT_API int widget_app_terminate_context(widget_context_h context)
+{
+ if (!__is_widget_feature_enabled()) {
+ _E("not supported"); /* LCOV_EXCL_LINE */
+ return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */
}
+ if (context == NULL)
+ return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
+ __FUNCTION__, NULL);
+
g_idle_add(__finish_event_cb, context);
return WIDGET_ERROR_NONE;
}
-EXPORT_API int widget_app_foreach_context(widget_context_cb cb, void *data)
+static void __inst_full_cb(const char *class_id, const char *id,
+ appcore_multiwindow_base_instance_h cxt, void *data)
{
- int r;
- bool feature;
-
- r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
- if (r < 0)
- return WIDGET_ERROR_FAULT;
+ struct widget_foreach_context *foreach_context = data;
- if (!feature)
- return WIDGET_ERROR_NOT_SUPPORTED;
+ if (!data)
+ return;
- if (cb == NULL)
- return WIDGET_ERROR_INVALID_PARAMETER;
+ if (foreach_context->callback)
+ foreach_context->callback(cxt, foreach_context->data);
+}
- GList *iter = g_list_first(contexts);
+EXPORT_API int widget_app_foreach_context(widget_context_cb cb, void *data)
+{
+ struct widget_foreach_context foreach_context;
- while (iter != NULL) {
- widget_context_s *cxt = (widget_context_s*) iter->data;
- if ( !cb(cxt, data)) {
- return WIDGET_ERROR_CANCELED;
- }
+ if (!__is_widget_feature_enabled()) {
+ _E("not supported"); /* LCOV_EXCL_LINE */
+ return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */
+ }
- iter = g_list_next(iter);
+ if (!cb) {
+ _E("callback is NULL");
+ return WIDGET_ERROR_INVALID_PARAMETER;
}
+ foreach_context.callback = cb;
+ foreach_context.data = data;
+ appcore_multiwindow_base_instance_foreach_full(__inst_full_cb, &foreach_context);
+
return WIDGET_ERROR_NONE;
}
+int __event_cb(void *event, void *data)
+{
+ app_event_handler_h handler = data;
+
+ struct app_event_info app_event;
+
+ app_event.type = handler->type;
+ app_event.value = event;
+
+ if (handler->cb)
+ handler->cb(&app_event, handler->data);
+
+ return 0;
+}
+
EXPORT_API int widget_app_add_event_handler(app_event_handler_h *event_handler,
- app_event_type_e event_type, app_event_cb callback, void *user_data)
+ app_event_type_e event_type, app_event_cb callback,
+ void *user_data)
{
int r;
bool feature;
+ app_event_handler_h handler;
r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
if (r < 0)
if (!feature)
return WIDGET_ERROR_NOT_SUPPORTED;
- app_event_handler_h handler;
-
if (event_handler == NULL || callback == NULL)
return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
if (event_type == APP_EVENT_DEVICE_ORIENTATION_CHANGED)
return widget_app_error(WIDGET_ERROR_NOT_SUPPORTED, __FUNCTION__, NULL);
- GList *iter = g_list_first(handler_list[event_type]);
-
- while (iter) {
- handler = (app_event_handler_h) iter->data;
-
- if (handler->cb == callback)
- return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- iter = g_list_next(iter);
- }
handler = calloc(1, sizeof(struct app_event_handler));
if (!handler)
- return widget_app_error(WIDGET_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
-
- if (g_list_length(handler_list[event_type]) == 0) {
- __register_event(event_type);
- }
+ return widget_app_error(WIDGET_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create handler");
handler->type = event_type;
handler->cb = callback;
handler->data = user_data;
- handler_list[event_type] = g_list_append(handler_list[event_type], handler);
-
+ handler->raw = appcore_base_add_event(__app_event_converter[event_type], __event_cb, handler);
*event_handler = handler;
return WIDGET_ERROR_NONE;
}
EXPORT_API int widget_app_remove_event_handler(app_event_handler_h
- event_handler)
+ event_handler)
{
int r;
bool feature;
if (type < APP_EVENT_LOW_MEMORY || type > APP_EVENT_REGION_FORMAT_CHANGED)
return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- handler_list[type] = g_list_remove(handler_list[type], event_handler);
- free(event_handler);
+ r = appcore_base_remove_event(event_handler->raw);
+ if (r < 0)
+ return widget_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid raw handler");
- if (g_list_length(handler_list[type]) == 0)
- __unregister_event(type);
+ free(event_handler);
return WIDGET_ERROR_NONE;
}
-EXPORT_API const char* widget_app_get_id(widget_context_h context)
+EXPORT_API const char *widget_app_get_id(widget_context_h context)
{
- int r;
- bool feature;
-
- r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
- if (r < 0) {
- set_last_result(WIDGET_ERROR_FAULT);
- return NULL;
+ if (!__is_widget_feature_enabled()) {
+ _E("not supported"); /* LCOV_EXCL_LINE */
+ set_last_result(WIDGET_ERROR_NOT_SUPPORTED); /* LCOV_EXCL_LINE */
+ return NULL; /* LCOV_EXCL_LINE */
}
- if (!feature) {
- set_last_result(WIDGET_ERROR_NOT_SUPPORTED);
- return NULL;
- }
-
- if (context == NULL) {
+ if (!context) {
set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
return NULL;
}
- widget_context_s *cxt = (widget_context_s*)context;
-
set_last_result(WIDGET_ERROR_NONE);
- return cxt->id;
+ return appcore_multiwindow_base_instance_get_id(context);
+}
+
+static void __win_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+ char *plug_id;
+ plug_id = evas_object_data_del(obj, "___PLUGID");
+ free(plug_id);
}
EXPORT_API int widget_app_get_elm_win(widget_context_h context,
- Evas_Object **win)
+ Evas_Object **win)
{
- int r;
- bool feature;
+ Evas_Object *ret_win;
+ Ecore_Wl_Window *wl_win;
+ struct wl_surface *surface;
+ struct widget_extra *we;
+ char buffer[256];
+ int rots[3] = {0};
+ int win_id;
+ const char *id;
+ appcore_multiwindow_base_instance_h cxt;
+
+ if (!__is_widget_feature_enabled()) {
+ _E("not supported"); /* LCOV_EXCL_LINE */
+ return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */
+ }
- r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
- if (r < 0)
- return WIDGET_ERROR_FAULT;
+ if (context == NULL || win == NULL)
+ return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
+ __FUNCTION__, NULL);
- if (!feature)
- return WIDGET_ERROR_NOT_SUPPORTED;
+ cxt = (appcore_multiwindow_base_instance_h)context;
+ id = appcore_multiwindow_base_instance_get_id(cxt);
+ ret_win = elm_win_add(NULL, id, ELM_WIN_BASIC);
+ if (ret_win == NULL) {
+ _E("failed to create window"); /* LCOV_EXCL_LINE */
+ goto fault; /* LCOV_EXCL_LINE */
+ }
- if (context == NULL || win == NULL) {
- return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+ elm_win_wm_rotation_preferred_rotation_set(ret_win, -1);
+ elm_win_wm_rotation_available_rotations_set(ret_win, rots, 1);
+
+ wl_win = elm_win_wl_window_get(ret_win);
+ if (wl_win == NULL) {
+ _E("failed to get wayland window"); /* LCOV_EXCL_LINE */
+ goto fault;
}
- widget_context_s *cxt = (widget_context_s*)context;
- Evas *evas;
- Evas_Object *ret_win = NULL;
-
- evas = widget_get_evas(cxt->id);
- if (evas) {
- Evas_Object *widget_parent;
- widget_parent = evas_object_rectangle_add(evas);
- if (widget_parent) {
- ret_win = elm_win_add(widget_parent, cxt->id, ELM_WIN_TIZEN_WIDGET);
- evas_object_del(widget_parent);
- if (ret_win == NULL) {
- _E("win is NULL");
- return widget_app_error(WIDGET_ERROR_FAULT, __FUNCTION__, NULL);
- }
- } else {
- _E("Failed to get parent widget");
- return widget_app_error(WIDGET_ERROR_FAULT, __FUNCTION__, NULL);
- }
- } else {
- _E("parent evas object is NULL");
- return widget_app_error(WIDGET_ERROR_FAULT, __FUNCTION__, NULL);
+ surface = ecore_wl_window_surface_get(wl_win);
+ if (surface == NULL) {
+ _E("failed to get surface"); /* LCOV_EXCL_LINE */
+ goto fault; /* LCOV_EXCL_LINE */
}
+ screen_connector_provider_remote_enable(id, surface);
+
+ ecore_wl_window_class_name_set(wl_win, id);
+ elm_win_aux_hint_add(ret_win, "wm.policy.win.user.geometry", "1");
*win = ret_win;
+ we = appcore_multiwindow_base_instance_get_extra(cxt);
+ we->win = ret_win;
+ win_id = ecore_wl_window_id_get(wl_win);
+
+ /* Set data to use in accessibility */
+ snprintf(buffer, sizeof(buffer), "%s:%d", id, getpid());
+ evas_object_data_set(ret_win, "___PLUGID", strdup(buffer));
+ evas_object_event_callback_add(ret_win, EVAS_CALLBACK_DEL, __win_del_cb, NULL);
+ appcore_multiwindow_base_window_bind(cxt, wl_win);
+
+ _D("window created: %d", win_id);
+
return WIDGET_ERROR_NONE;
+
+fault:
+ if (ret_win) /* LCOV_EXCL_LINE */
+ evas_object_del(ret_win); /* LCOV_EXCL_LINE */
+
+ return WIDGET_ERROR_FAULT; /* LCOV_EXCL_LINE */
}
-EXPORT_API widget_class_h widget_app_class_create(widget_instance_lifecycle_callback_s callback)
+static void __instance_drop(appcore_multiwindow_base_instance_h cxt)
{
- int r;
- bool feature;
+ struct widget_extra *we;
+
+ we = appcore_multiwindow_base_instance_get_extra(cxt);
+ appcore_multiwindow_base_instance_drop(cxt);
+ free(we->instance_id);
+ free(we->content);
+ free(we);
+ __check_empty_instance();
+}
- r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
- if (r < 0) {
- set_last_result(WIDGET_ERROR_FAULT);
- return NULL;
+static void __stub_create(appcore_multiwindow_base_instance_h context, void *data)
+{
+ struct widget_class_context *cxt = data;
+ struct widget_extra *we;
+ bundle *b;
+ bundle *content_info = NULL;
+ char *id = NULL;
+ char *class_id = NULL;
+ char *operation = NULL;
+ char *content = NULL;
+ char *w_str = NULL;
+ char *h_str = NULL;
+ char *remain = NULL;
+ int w = 0;
+ int h = 0;
+ int ret = -1;
+
+ appcore_multiwindow_base_class_on_create(context);
+ we = appcore_multiwindow_base_instance_get_extra((appcore_multiwindow_base_instance_h)context);
+ b = we->args;
+
+ bundle_get_str(b, WIDGET_K_CLASS, &class_id);
+ /* for previous version compatibility, use appid for default class id */
+ if (class_id == NULL)
+ class_id = __appid;
+
+ bundle_get_str(b, AUL_K_WIDGET_INSTANCE_ID, &id);
+ bundle_get_str(b, WIDGET_K_OPERATION, &operation);
+
+ if (!operation) {
+ _E("no operation provided");
+ return;
+ }
+
+ bundle_get_str(b, WIDGET_K_CONTENT_INFO, &content);
+ bundle_get_str(b, WIDGET_K_WIDTH, &w_str);
+ bundle_get_str(b, WIDGET_K_HEIGHT, &h_str);
+
+ if (w_str)
+ w = (int)g_ascii_strtoll(w_str, &remain, 10);
+
+ if (h_str)
+ h = (int)g_ascii_strtoll(h_str, &remain, 10);
+
+ if (content)
+ content_info = bundle_decode((const bundle_raw *)content, strlen(content));
+
+ if (cxt->callback.create)
+ ret = cxt->callback.create(context, content_info, w, h, cxt->data);
+ _D("%s is created %d", id);
+
+ if (ret < 0) {
+ _W("Create callback returns error(%d)", ret);
+ ret = __send_update_status(class_id, id,
+ WIDGET_INSTANCE_EVENT_CREATE_ABORTED, NULL);
+ __instance_drop(context);
+ } else {
+ ret = __send_update_status(class_id, id,
+ WIDGET_INSTANCE_EVENT_CREATE, NULL);
+
+ aul_widget_instance_add(class_id, id);
+ }
+
+ if (content_info)
+ bundle_free(content_info);
+}
+
+static void __stub_terminate(appcore_multiwindow_base_instance_h context, void *data)
+{
+ struct widget_class_context *class_cxt = data;
+ struct widget_extra *we;
+ bundle *b;
+ char *operation = NULL;
+ bundle *content_info;
+ widget_app_destroy_type_e reason = WIDGET_APP_DESTROY_TYPE_TEMPORARY;
+ int event = WIDGET_INSTANCE_EVENT_TERMINATE;
+ const char *id;
+ const char *class_id;
+
+ id = appcore_multiwindow_base_instance_get_id(context);
+ class_id = appcore_multiwindow_base_instance_get_class_id(context);
+ we = appcore_multiwindow_base_instance_get_extra((appcore_multiwindow_base_instance_h)context);
+ b = we->args;
+
+ if (b) {
+ bundle_get_str(b, WIDGET_K_OPERATION, &operation);
+ if (operation && strcmp(operation, "destroy") == 0)
+ reason = WIDGET_APP_DESTROY_TYPE_PERMANENT;
+ }
+
+ if (we->content)
+ content_info = bundle_decode((const bundle_raw *)we->content, strlen(we->content));
+ else
+ content_info = bundle_create();
+
+ if (class_cxt->callback.destroy)
+ class_cxt->callback.destroy(context, reason, content_info, class_cxt->data);
+ _D("%s is destroyed %d", id, reason);
+
+ if (reason == WIDGET_APP_DESTROY_TYPE_PERMANENT) {
+ event = WIDGET_INSTANCE_EVENT_DESTROY;
+ aul_widget_instance_del(class_id, id);
+ } else {
+ __send_update_status(class_id, id,
+ WIDGET_INSTANCE_EVENT_EXTRA_UPDATED, content_info);
+ }
+
+ if (content_info)
+ bundle_free(content_info);
+
+ __send_update_status(class_id, id, event, NULL);
+ appcore_multiwindow_base_class_on_terminate(context);
+}
+
+static void __stub_pause(appcore_multiwindow_base_instance_h context, void *data)
+{
+ struct widget_class_context *class_cxt = data;
+ const char *id;
+ const char *class_id;
+
+ appcore_multiwindow_base_class_on_pause(context);
+ id = appcore_multiwindow_base_instance_get_id(context);
+ class_id = appcore_multiwindow_base_instance_get_class_id(context);
+
+ if (!class_cxt) {
+ _E("class context is NULL");
+ return;
+ }
+
+ if (class_cxt->callback.pause)
+ class_cxt->callback.pause(context, class_cxt->data);
+ _D("%s is paused", id);
+ __send_update_status(class_id, id,
+ WIDGET_INSTANCE_EVENT_PAUSE, NULL);
+}
+
+static void __stub_resume(appcore_multiwindow_base_instance_h context, void *data)
+{
+ struct widget_class_context *class_cxt = data;
+ const char *id;
+ const char *class_id;
+
+ appcore_multiwindow_base_class_on_resume(context);
+ id = appcore_multiwindow_base_instance_get_id(context);
+ class_id = appcore_multiwindow_base_instance_get_class_id(context);
+
+ if (!class_cxt) {
+ _E("class context is NULL");
+ return;
}
- if (!feature) {
+ if (class_cxt->callback.resume)
+ class_cxt->callback.resume(context, class_cxt->data);
+ _D("%s is resumed", id);
+ __send_update_status(class_id, id,
+ WIDGET_INSTANCE_EVENT_RESUME, NULL);
+}
+
+EXPORT_API widget_class_h widget_app_class_add(widget_class_h widget_class,
+ const char *class_id,
+ widget_instance_lifecycle_callback_s callback, void *user_data)
+{
+ appcore_multiwindow_base_class cls;
+ struct widget_class_context *cxt;
+
+ if (!__is_widget_feature_enabled()) {
+ _E("not supported");
set_last_result(WIDGET_ERROR_NOT_SUPPORTED);
return NULL;
}
- widget_class_s *wc = (widget_class_s*)malloc(sizeof(widget_class_s));
+ if (!class_id) {
+ _E("class is is NULL");
+ set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ cxt = calloc(1, sizeof(struct widget_class_context));
- if (wc == NULL) {
- _E("failed to malloc : %s", __FUNCTION__);
+ if (!cxt) {
+ _E("failed to calloc : %s", __FUNCTION__);
set_last_result(WIDGET_ERROR_OUT_OF_MEMORY);
return NULL;
}
- wc->ops = callback;
- wc->ops_private = widget_class_tmp.ops_private;
+ cxt->callback = callback;
+ cxt->data = user_data;
+
+ cls.id = strdup(class_id);
+ cls.data = cxt;
+ cls.create = __stub_create;
+ cls.terminate = __stub_terminate;
+ cls.pause = __stub_pause;
+ cls.resume = __stub_resume;
+
+ appcore_multiwindow_base_class_add(cls);
set_last_result(WIDGET_ERROR_NONE);
- return wc;
+
+ return (widget_class_h)cxt;
}
-EXPORT_API int widget_app_context_set_tag(widget_context_h context, void *tag)
+EXPORT_API widget_class_h widget_app_class_create(
+ widget_instance_lifecycle_callback_s callback, void *user_data)
{
- int r;
- bool feature;
-
- r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
- if (r < 0)
- return WIDGET_ERROR_FAULT;
+ return widget_app_class_add(NULL, __appid, callback, user_data);
+}
- if (!feature)
- return WIDGET_ERROR_NOT_SUPPORTED;
+EXPORT_API int widget_app_context_set_tag(widget_context_h context, void *tag)
+{
+ struct widget_extra *we;
- if (context == NULL) {
- return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+ if (!__is_widget_feature_enabled()) {
+ _E("not supported"); /* LCOV_EXCL_LINE */
+ return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */
}
- context->tag = tag;
+ if (!context)
+ return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
+ __FUNCTION__, NULL);
+
+ we = appcore_multiwindow_base_instance_get_extra((appcore_multiwindow_base_instance_h)context);
+ we->extra = tag;
return WIDGET_ERROR_NONE;
}
EXPORT_API int widget_app_context_get_tag(widget_context_h context, void **tag)
{
- int r;
- bool feature;
-
- r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
- if (r < 0)
- return WIDGET_ERROR_FAULT;
+ struct widget_extra *we;
- if (!feature)
- return WIDGET_ERROR_NOT_SUPPORTED;
-
- if (context == NULL || tag == NULL) {
- return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+ if (!__is_widget_feature_enabled()) {
+ _E("not supported"); /* LCOV_EXCL_LINE */
+ return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */
}
- *tag = context->tag;
+ if (!context || !tag)
+ return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
+ __FUNCTION__, NULL);
+
+ we = appcore_multiwindow_base_instance_get_extra((appcore_multiwindow_base_instance_h)context);
+ if (we == NULL)
+ return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
+ __FUNCTION__, NULL);
+ *tag = we->extra;
return WIDGET_ERROR_NONE;
}
-EXPORT_API int widget_app_context_set_content_info(widget_context_h context, bundle *content_info)
+EXPORT_API int widget_app_context_set_content_info(widget_context_h context,
+ bundle *content_info)
{
- int r;
- bool feature;
+ int ret = 0;
+ bundle_raw *raw = NULL;
+ int len;
+ const char *id;
+ const char *class_id;
+ struct widget_extra *we;
+ appcore_multiwindow_base_instance_h cxt;
+
+ if (!__is_widget_feature_enabled()) {
+ _E("not supported"); /* LCOV_EXCL_LINE */
+ return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */
+ }
- r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
- if (r < 0)
- return WIDGET_ERROR_FAULT;
+ if (!context || !content_info)
+ return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
+ __FUNCTION__, NULL);
- if (!feature)
- return WIDGET_ERROR_NOT_SUPPORTED;
+ cxt = (appcore_multiwindow_base_instance_h)context;
+ id = appcore_multiwindow_base_instance_get_id(cxt);
+ class_id = appcore_multiwindow_base_instance_get_class_id(cxt);
+ we = appcore_multiwindow_base_instance_get_extra(cxt);
- if (content_info == NULL)
- return WIDGET_ERROR_INVALID_PARAMETER;
+ if (!class_id || !id || !we)
+ return widget_app_error(WIDGET_ERROR_FAULT, __FUNCTION__, NULL);
- bundle_raw *raw = NULL;
- int len;
- int ret = WIDGET_ERROR_FAULT;
+ ret = __send_update_status(class_id, id,
+ WIDGET_INSTANCE_EVENT_EXTRA_UPDATED, content_info);
+
+ if (we->content)
+ free(we->content);
bundle_encode(content_info, &raw, &len);
- if (raw) {
- ret = widget_provider_app_send_extra_info(context->id, (const char*)raw, NULL);
- free(raw);
+ if (raw)
+ we->content = strdup((const char *)raw);
+ else
+ we->content = NULL;
+
+ free(raw);
+ if (ret < 0) {
+ /* LCOV_EXCL_START */
+ _E("failed to send content info: %s of %s (%d)", id,
+ class_id, ret);
+ return widget_app_error(WIDGET_ERROR_IO_ERROR, __FUNCTION__,
+ NULL);
+ /* LCOV_EXCL_STOP */
}
- return ret;
+ return WIDGET_ERROR_NONE;
}
-EXPORT_API int widget_app_context_set_title(widget_context_h context, const char *title)
+EXPORT_API int widget_app_context_set_title(widget_context_h context,
+ const char *title)
{
- int r;
- bool feature;
+ appcore_multiwindow_base_instance_h cxt;
+ struct widget_extra *we;
- r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
- if (r < 0)
- return WIDGET_ERROR_FAULT;
-
- if (!feature)
- return WIDGET_ERROR_NOT_SUPPORTED;
+ if (!__is_widget_feature_enabled()) {
+ _E("not supported"); /* LCOV_EXCL_LINE */
+ return WIDGET_ERROR_NOT_SUPPORTED; /* LCOV_EXCL_LINE */
+ }
- if (context == NULL)
+ if (!context || !title) {
+ _E("Invalid parameter %p %p", context, title);
return WIDGET_ERROR_INVALID_PARAMETER;
+ }
- return widget_provider_app_send_extra_info(context->id, NULL, title);
-}
+ cxt = (appcore_multiwindow_base_instance_h)context;
+ we = appcore_multiwindow_base_instance_get_extra(cxt);
-// private API
-EXPORT_API const widget_class_factory_full_s* widget_app_get_class_factory(void)
-{
- return &factory;
+ if (we->win)
+ elm_win_title_set(we->win, title);
+
+ return WIDGET_ERROR_NONE;
}