summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyunho Kang <hhstark.kang@samsung.com>2016-07-20 15:21:57 +0900
committerHyunho Kang <hhstark.kang@samsung.com>2016-07-29 00:38:07 -0700
commit0e42b464e1daac16be57386b10e8c57ade7402b9 (patch)
tree4b18508566f5069d8bf41ad5029434988b573cc8
parenta8909868db87b7e6f4f151ef8ca1828d6b213712 (diff)
downloadwidget-service-0e42b464e1daac16be57386b10e8c57ade7402b9.tar.gz
widget-service-0e42b464e1daac16be57386b10e8c57ade7402b9.tar.bz2
widget-service-0e42b464e1daac16be57386b10e8c57ade7402b9.zip
Change-Id: I705fa5b45ba3809b9e61327730220c292f026139 Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
-rw-r--r--include/widget_instance.h24
-rw-r--r--include/widget_service.h10
-rw-r--r--include/widget_service_internal.h1
-rw-r--r--src/widget_instance.c112
4 files changed, 101 insertions, 46 deletions
diff --git a/include/widget_instance.h b/include/widget_instance.h
index f2fb6f4..9171caf 100644
--- a/include/widget_instance.h
+++ b/include/widget_instance.h
@@ -25,10 +25,7 @@
extern "C" {
#endif
-#define WIDGET_K_ID AUL_K_WIDGET_ID
#define WIDGET_K_CLASS AUL_K_WIDGET_ID
-#define WIDGET_K_INSTANCE AUL_K_WIDGET_INSTANCE_ID
-#define WIDGET_K_STATUS "__WIDGET_STATUS__"
#define WIDGET_K_ENDPOINT "__WIDGET_ENDPOINT__"
#define WIDGET_K_CALLER "__WIDGET_CALLER_PID__"
@@ -41,16 +38,17 @@ extern "C" {
#define WIDGET_K_CONTENT_INFO "__WIDGET_CONTENT_INFO__"
typedef enum widget_instance_event {
- WIDGET_INSTANCE_EVENT_CREATE = 0,
- WIDGET_INSTANCE_EVENT_DESTROY = 1,
- WIDGET_INSTANCE_EVENT_TERMINATE = 2,
- WIDGET_INSTANCE_EVENT_PAUSE = 3,
- WIDGET_INSTANCE_EVENT_RESUME = 4,
- WIDGET_INSTANCE_EVENT_UPDATE = 5,
- WIDGET_INSTANCE_EVENT_PERIOD_CHANGED = 6,
- WIDGET_INSTANCE_EVENT_SIZE_CHANGED = 7,
- WIDGET_INSTANCE_EVENT_EXTRA_UPDATED = 8,
- WIDGET_INSTANCE_EVENT_FAULT = 9,
+ WIDGET_INSTANCE_EVENT_CREATE = AUL_WIDGET_INSTANCE_EVENT_CREATE,
+ WIDGET_INSTANCE_EVENT_DESTROY = AUL_WIDGET_INSTANCE_EVENT_DESTROY,
+ WIDGET_INSTANCE_EVENT_TERMINATE = AUL_WIDGET_INSTANCE_EVENT_TERMINATE,
+ WIDGET_INSTANCE_EVENT_PAUSE = AUL_WIDGET_INSTANCE_EVENT_PAUSE,
+ WIDGET_INSTANCE_EVENT_RESUME = AUL_WIDGET_INSTANCE_EVENT_RESUME,
+ WIDGET_INSTANCE_EVENT_UPDATE = AUL_WIDGET_INSTANCE_EVENT_UPDATE,
+ WIDGET_INSTANCE_EVENT_PERIOD_CHANGED = AUL_WIDGET_INSTANCE_EVENT_PERIOD_CHANGED,
+ WIDGET_INSTANCE_EVENT_SIZE_CHANGED = AUL_WIDGET_INSTANCE_EVENT_SIZE_CHANGED,
+ WIDGET_INSTANCE_EVENT_EXTRA_UPDATED = AUL_WIDGET_INSTANCE_EVENT_EXTRA_UPDATED,
+ WIDGET_INSTANCE_EVENT_FAULT = AUL_WIDGET_INSTANCE_EVENT_FAULT,
+ WIDGET_INSTANCE_EVENT_APP_RESTART_REQUEST = AUL_WIDGET_INSTANCE_EVENT_APP_RESTART_REQUEST,
WIDGET_INSTANCE_EVENT_MAX,
} widget_instance_event_e;
diff --git a/include/widget_service.h b/include/widget_service.h
index 7a34b8c..6053c2a 100644
--- a/include/widget_service.h
+++ b/include/widget_service.h
@@ -19,6 +19,7 @@
#include <tizen.h>
#include <bundle.h>
+#include <aul.h>
#ifdef __cplusplus
extern "C" {
@@ -485,10 +486,11 @@ extern int widget_service_get_widget_instance_list(const char *widget_id, widget
* @see widget_lifecycle_event_cb
*/
typedef enum widget_lifecycle_event {
- WIDGET_LIFE_CYCLE_EVENT_CREATE = 1, /**< The widget is created */
- WIDGET_LIFE_CYCLE_EVENT_DESTROY = 2, /**< The widget is destroyed */
- WIDGET_LIFE_CYCLE_EVENT_PAUSE = 3, /**< The widget is paused */
- WIDGET_LIFE_CYCLE_EVENT_RESUME = 4, /**< The widget is resumed */
+ WIDGET_LIFE_CYCLE_EVENT_APP_DEAD = AUL_WIDGET_LIFE_CYCLE_EVENT_APP_DEAD,
+ WIDGET_LIFE_CYCLE_EVENT_CREATE = AUL_WIDGET_LIFE_CYCLE_EVENT_CREATE, /**< The widget is created */
+ WIDGET_LIFE_CYCLE_EVENT_DESTROY = AUL_WIDGET_LIFE_CYCLE_EVENT_DESTROY, /**< The widget is destroyed */
+ WIDGET_LIFE_CYCLE_EVENT_PAUSE = AUL_WIDGET_LIFE_CYCLE_EVENT_PAUSE, /**< The widget is paused */
+ WIDGET_LIFE_CYCLE_EVENT_RESUME = AUL_WIDGET_LIFE_CYCLE_EVENT_RESUME, /**< The widget is resumed */
WIDGET_LIFE_CYCLE_EVENT_MAX = 5
} widget_lifecycle_event_e;
diff --git a/include/widget_service_internal.h b/include/widget_service_internal.h
index 38e15e5..1047f05 100644
--- a/include/widget_service_internal.h
+++ b/include/widget_service_internal.h
@@ -62,6 +62,7 @@ extern "C" {
#define WIDGET_EVENT_WIDGET_EXTRA_BUFFER_DESTROYED 24 /**< WIDGET Extra Buffer destroyed event */
#define WIDGET_EVENT_GBAR_EXTRA_BUFFER_DESTROYED 25 /**< WIDGET Extra Buffer destroyed event */
+
/**
* @internal
* @brief specify the source of input event
diff --git a/src/widget_instance.c b/src/widget_instance.c
index 0b6e91b..6d4b09e 100644
--- a/src/widget_instance.c
+++ b/src/widget_instance.c
@@ -93,6 +93,8 @@ struct event_cb_s {
void *data;
};
+static int __fault_handler(int pid);
+
static struct _widget_instance *__pick_instance(const char *instance_id)
{
GList *instances = _widget_instances;
@@ -293,7 +295,7 @@ static int __launch(const char *widget_id, const char *instance_id, bundle *extr
b = bundle_create();
if (instance_id)
- bundle_add_str(b, WIDGET_K_INSTANCE, instance_id);
+ bundle_add_str(b, AUL_K_WIDGET_INSTANCE_ID, instance_id);
bundle_add_str(b, WIDGET_K_CLASS, classid);
bundle_add_str(b, AUL_K_WIDGET_VIEWER, viewer_appid);
@@ -596,6 +598,24 @@ static void __notify_event(int event, const char *widget_id, const char *instanc
}
}
+static int __check_valid_sender(char *widget_id, int pid)
+{
+ struct widget_app *app = NULL;
+ widget_instance_h instance;
+ GList *head = NULL;
+
+ app = __pick_app(widget_id);
+ if (app) {
+ head = app->instances;
+ if (head) {
+ instance = (widget_instance_h)head->data;
+ if (instance->pid == pid)
+ return 0;
+ }
+ }
+ return -1;
+}
+
static int __status_handler(const char *endpoint, aul_app_com_result_e e, bundle *envelope, void *user_data)
{
char *widget_id;
@@ -603,12 +623,15 @@ static int __status_handler(const char *endpoint, aul_app_com_result_e e, bundle
int *status;
size_t status_sz = 0;
struct lifecycle_local_s *cb_info;
+ char *sender_pid_str;
+ int sender_pid;
- bundle_get_str(envelope, WIDGET_K_ID, &widget_id);
- bundle_get_str(envelope, WIDGET_K_INSTANCE, &instance_id);
- bundle_get_byte(envelope, WIDGET_K_STATUS, (void **)&status, &status_sz);
+ bundle_get_str(envelope, AUL_K_WIDGET_ID, &widget_id);
+ bundle_get_str(envelope, AUL_K_WIDGET_INSTANCE_ID, &instance_id);
+ bundle_get_byte(envelope, AUL_K_WIDGET_STATUS, (void **)&status, &status_sz);
+ bundle_get_str(envelope, AUL_K_COM_SENDER_PID, &sender_pid_str);
- if (widget_id == NULL || instance_id == NULL || status == NULL) {
+ if (widget_id == NULL || status == NULL) {
_E("undefined class or instance %s of %s", instance_id, widget_id);
if (status != NULL)
_E("status: %d", *status);
@@ -616,6 +639,17 @@ static int __status_handler(const char *endpoint, aul_app_com_result_e e, bundle
return 0;
}
+ sender_pid = atoi(sender_pid_str);
+ if (__check_valid_sender(widget_id, sender_pid) == -1) {
+ _E("invalid sender, pid %d do not have widget_id %s", sender_pid, widget_id);
+ return 0;
+ }
+
+ if (*status == AUL_WIDGET_LIFE_CYCLE_EVENT_APP_DEAD) {
+ _D("handle dead widget instances");
+ __fault_handler(sender_pid);
+ }
+
cb_info = (struct lifecycle_local_s *)g_hash_table_lookup(lifecycle_tbl, "NULL");
if (cb_info)
cb_info->cb(widget_id, instance_id, *status, cb_info->data);
@@ -642,29 +676,17 @@ static int __connect_status_handler()
return 0;
}
-static int __widget_handler(const char *viewer_id, aul_app_com_result_e e, bundle *envelope, void *user_data)
+static int __widget_instance_handler(int status, char *widget_id, char *instance_id, char *content_info)
{
- char *widget_id = NULL;
- char *instance_id = NULL;
- int *status = NULL;
- size_t status_sz = 0;
- int cmd = 0;
- struct _widget_instance *instance;
- char *content_info = NULL;
- bundle_get_str(envelope, WIDGET_K_ID, &widget_id);
- bundle_get_str(envelope, WIDGET_K_INSTANCE, &instance_id);
- bundle_get_byte(envelope, WIDGET_K_STATUS, (void **)&status, &status_sz);
+ struct _widget_instance *instance;
- if (widget_id == NULL || instance_id == NULL || status == NULL) {
+ if (instance_id == NULL) {
_E("undefined class or instance %s of %s", instance_id, widget_id);
- if (status != NULL)
- _E("cmd: %d", *status);
-
return 0;
}
- _D("update status %s on %d", instance_id, *status);
+ _D("update status %s on %d", instance_id, status);
instance = __pick_instance(instance_id);
@@ -673,9 +695,7 @@ static int __widget_handler(const char *viewer_id, aul_app_com_result_e e, bundl
return 0;
}
- cmd = *status;
-
- switch (cmd) {
+ switch (status) {
case WIDGET_INSTANCE_EVENT_CREATE:
instance->status = WIDGET_INSTANCE_RUNNING;
break;
@@ -692,7 +712,6 @@ static int __widget_handler(const char *viewer_id, aul_app_com_result_e e, bundl
case WIDGET_INSTANCE_EVENT_UPDATE:
break;
case WIDGET_INSTANCE_EVENT_EXTRA_UPDATED:
- bundle_get_str(envelope, WIDGET_K_CONTENT_INFO, &content_info);
if (content_info) {
if (instance->content_info)
free(instance->content_info);
@@ -704,11 +723,11 @@ static int __widget_handler(const char *viewer_id, aul_app_com_result_e e, bundl
break;
default:
- _E("unknown command: %d", cmd);
+ _E("unknown status: %d", status);
break;
}
- __notify_event(cmd, widget_id, instance_id);
+ __notify_event(status, widget_id, instance_id);
if (instance->status == WIDGET_INSTANCE_DELETED)
widget_instance_unref(instance);
@@ -716,8 +735,43 @@ static int __widget_handler(const char *viewer_id, aul_app_com_result_e e, bundl
return 0;
}
+static int __widget_handler(const char *viewer_id, aul_app_com_result_e e, bundle *envelope, void *user_data)
+{
+ char *widget_id = NULL;
+ char *instance_id = NULL;
+ int *status = NULL;
+ size_t status_sz = 0;
+ char *content_info = NULL;
+ char *sender_pid_str = NULL;
+ int sender_pid;
+ int ret;
+
+ bundle_get_str(envelope, AUL_K_WIDGET_ID, &widget_id);
+ bundle_get_byte(envelope, AUL_K_WIDGET_STATUS, (void **)&status, &status_sz);
+
+ if (widget_id == NULL) {
+ _E("undefined widget_id %s", widget_id);
+ return 0;
+ }
+
+ if (*status == WIDGET_INSTANCE_EVENT_APP_RESTART_REQUEST) {
+ _D("WIDGET_INSTANCE_EVENT_APP_RESTART_REQUEST notify");
+ bundle_get_str(envelope, AUL_K_COM_SENDER_PID, &sender_pid_str);
+ sender_pid = atoi(sender_pid_str);
+ ret = __check_valid_sender(widget_id, sender_pid);
+ if (ret == 0)
+ __notify_event(*status, widget_id, "");
+ } else {
+ bundle_get_str(envelope, AUL_K_WIDGET_INSTANCE_ID, &instance_id);
+ bundle_get_str(envelope, WIDGET_K_CONTENT_INFO, &content_info);
+ __widget_instance_handler(*status, widget_id, instance_id, content_info);
+ }
+
+ return 0;
+}
+
/* LCOV_EXCL_START */
-static int __fault_handler(int pid, void *data)
+static int __fault_handler(int pid)
{
GList *iter;
struct _widget_instance *instance;
@@ -746,8 +800,8 @@ EAPI int widget_instance_init(const char *viewer_id)
viewer_appid = strdup(viewer_id);
__connect_status_handler();
- aul_listen_app_dead_signal(__fault_handler, NULL);
+ _D("widget_instance_init %s", viewer_id);
if (aul_app_com_create(viewer_id, NULL, __widget_handler, NULL, &conn_viewer) < 0) {
_E("failed to create app com endpoint");
return -1;