UPDATE_ALL = 1,
};
-struct _widget_class {
- void *user_data;
- widget_instance_lifecycle_callback_s ops;
- char *classid;
- struct _widget_class *next;
- struct _widget_class *prev;
-};
-
struct app_event_handler {
app_event_type_e type;
app_event_cb cb;
void *value;
};
-struct _widget_context {
- char *id;
- struct _widget_class *provider;
- int state;
- void *tag;
- Evas_Object *win;
- int win_id;
- char *content;
- widget_instance_lifecycle_callback_s ops;
-};
-
typedef struct _widget_class widget_class_s;
-typedef struct _widget_context widget_context_s;
#define WIDGET_APP_EVENT_MAX 5
static GList *handler_list[WIDGET_APP_EVENT_MAX] = {NULL, };
static void *app_user_data;
static char *appid;
static widget_class_h class_provider;
-static GList *contexts;
-static char *viewer_endpoint;
static int exit_called;
static void _widget_core_set_appcore_event_cb(void);
static widget_context_s *__find_context_by_id(const char *id)
{
- GList *ret = g_list_find_custom(contexts, id, __comp_by_id);
+ GList *ret;
+ GList *contexts = _widget_app_get_contexts();
+
+ if (id == NULL)
+ return NULL;
+ ret = g_list_find_custom(contexts, id, __comp_by_id);
if (ret == NULL)
return NULL;
static widget_context_s *__find_context_by_win(int win)
{
+ GList *contexts = _widget_app_get_contexts();
GList *ret = g_list_find_custom(contexts, GINT_TO_POINTER(win), __comp_by_win);
if (ret == NULL)
return -1; /* LCOV_EXCL_LINE */
}
- bundle_add_str(b, WIDGET_K_ID, class_id);
- bundle_add_str(b, WIDGET_K_INSTANCE, instance_id);
- bundle_add_byte(b, WIDGET_K_STATUS, &status, sizeof(int));
+ 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));
_D("send lifecycle %s(%d)", instance_id, status);
ret = aul_app_com_send("widget.status", b);
int lifecycle = -1;
bundle_raw *raw = NULL;
int len;
+ char *viewer_endpoint = _widget_app_get_viewer_endpoint();
b = bundle_create();
if (!b) {
return -1; /* LCOV_EXCL_LINE */
}
- bundle_add_str(b, WIDGET_K_ID, class_id);
- bundle_add_str(b, WIDGET_K_INSTANCE, instance_id);
- bundle_add_byte(b, WIDGET_K_STATUS, &status, sizeof(int));
+ 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 (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);
}
_D("send update %s(%d) to %s", instance_id, status, viewer_endpoint);
}
/* LCOV_EXCL_START */
+static int __instance_update_all(widget_class_h handle, int force, const char *content)
+{
+ widget_context_s *wc;
+ int ret = 0;
+ bundle *b = NULL;
+ GList *context = _widget_app_get_contexts();
+
+ if (content)
+ b = bundle_decode((const bundle_raw *)content, strlen(content));
+
+ if (handle->ops.update) {
+ while (context) {
+ wc = (widget_context_s *)context->data;
+ handle->ops.update(wc, b, force, handle->user_data);
+ ret = __send_update_status(handle->classid, wc->id,
+ WIDGET_INSTANCE_EVENT_UPDATE, NULL);
+ _D("updated:%s", wc->id);
+ context = context->next;
+ }
+ }
+
+ if (b)
+ bundle_free(b);
+
+ return ret;
+}
+/* LCOV_EXCL_STOP */
+
+/* LCOV_EXCL_START */
static int __instance_update(widget_class_h handle, const char *id, int force, const char *content)
{
widget_context_s *wc = __find_context_by_id(id);
content_info = bundle_decode((const bundle_raw *)content, strlen(content));
}
- contexts = g_list_append(contexts, wc);
+ _widget_app_add_context(wc);
- handle->ops.create(wc, content_info, w, h, handle->user_data);
- ret = __send_update_status(handle->classid, wc->id,
+ ret = handle->ops.create(wc, content_info, w, h, handle->user_data);
+ if (ret < 0) {
+ /* TODO send abort */
+ } else {
+ ret = __send_update_status(handle->classid, wc->id,
WIDGET_INSTANCE_EVENT_CREATE, NULL);
+ if (content == NULL)
+ content = "NULL";
+
+ aul_widget_instance_add(handle->classid, id);
+ }
+
if (content_info)
bundle_free(content_info);
int event = WIDGET_INSTANCE_EVENT_TERMINATE;
bundle *content_info;
+
if (!wc) {
_E("could not find widget obj: %s", id); /* LCOV_EXCL_LINE */
return WIDGET_ERROR_INVALID_PARAMETER; /* LCOV_EXCL_LINE */
WIDGET_INSTANCE_EVENT_EXTRA_UPDATED, content_info);
}
+ aul_widget_instance_del(handle->classid, id);
+
if (content_info)
bundle_free(content_info);
ret = __send_update_status(handle->classid, id, event, NULL);
- contexts = g_list_remove(contexts, wc);
+ _widget_app_remove_context(wc);
if (wc->id)
free(wc->id);
free(wc);
- if (contexts == NULL && !exit_called) /* all instance destroyed */
+ if (_widget_app_get_contexts() == NULL && !exit_called) /* all instance destroyed */
widget_app_exit();
return ret;
if (class_id == NULL)
class_id = appid;
- bundle_get_str(b, WIDGET_K_INSTANCE, &id);
+ bundle_get_str(b, AUL_K_WIDGET_INSTANCE_ID, &id);
bundle_get_str(b, WIDGET_K_OPERATION, &operation);
handle = __find_class_handler(class_id, class_provider);
} else if (strcmp(operation, "resize") == 0) {
__resize_window(id, w, h);
} else if (strcmp(operation, "update") == 0) {
- __instance_update(handle, id, force, content);
+ if (id)
+ __instance_update(handle, id, force, content);
+ else
+ __instance_update_all(handle, force, content);
+
} else if (strcmp(operation, "destroy") == 0) {
__instance_destroy(handle, id, WIDGET_APP_DESTROY_TYPE_PERMANENT, UPDATE_ALL);
} else if (strcmp(operation, "resume") == 0) {
static void __pause_all(int send_update)
{
+ GList *contexts = _widget_app_get_contexts();
GList *iter = g_list_first(contexts);
while (iter != NULL) {
/* LCOV_EXCL_START */
static void __resume_all(int send_update)
{
+ GList *contexts = _widget_app_get_contexts();
GList *iter = g_list_first(contexts);
while (iter != NULL) {
static void __destroy_all(int reason, int send_update)
{
+ GList *contexts = _widget_app_get_contexts();
GList *iter = g_list_first(contexts);
__pause_all(send_update);
char *wayland_display = NULL;
char *xdg_runtime_dir = NULL;
char *name;
+ char *viewer_endpoint;
#if !(GLIB_CHECK_VERSION(2, 36, 0))
g_type_init();
bundle_get_str(kb, WIDGET_K_ENDPOINT, &viewer_endpoint);
if (viewer_endpoint) {
_E("viewer endpoint :%s", viewer_endpoint);
- viewer_endpoint = strdup(viewer_endpoint);
+ _widget_app_set_viewer_endpoint(viewer_endpoint);
} else {
_E("endpoint is missing");
}
if (app_ops->terminate)
app_ops->terminate(app_user_data);
- if (viewer_endpoint)
- free(viewer_endpoint);
-
+ _widget_app_free_viewer_endpoint();
_widget_core_unset_appcore_event_cb();
__free_handler_list();
elm_shutdown();
EXPORT_API int widget_app_foreach_context(widget_context_cb cb, void *data)
{
+ GList *contexts = _widget_app_get_contexts();
GList *list;
widget_context_s *wc;
return WIDGET_ERROR_NONE;
}
-