diff options
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | include/widget_instance.h | 8 | ||||
-rw-r--r-- | packaging/libwidget_service.spec | 1 | ||||
-rw-r--r-- | src/widget_instance.c | 88 | ||||
-rw-r--r-- | src/widget_service.c | 195 | ||||
-rw-r--r-- | tool/widget_test.c | 61 |
6 files changed, 337 insertions, 20 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d4171db..7ff419b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,10 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_I CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}.pc") +ADD_EXECUTABLE(widget_test tool/widget_test.c) +TARGET_LINK_LIBRARIES(widget_test ${pkgs_LDFLAGS} ${pkg_extra_LDFLAGS} widget_service) +INSTALL(TARGETS widget_test DESTINATION bin) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/widget_service.h DESTINATION include/${PROJECT_NAME}) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/widget_service_internal.h DESTINATION include/${PROJECT_NAME}) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/widget_errno.h DESTINATION include/${PROJECT_NAME}) diff --git a/include/widget_instance.h b/include/widget_instance.h index 24ae27c..ef885e1 100644 --- a/include/widget_instance.h +++ b/include/widget_instance.h @@ -65,6 +65,14 @@ int widget_instance_destroy(const char *widget_id, const char *instance_id); int widget_instance_init(const char *viewer_id); int widget_instance_fini(); +widget_instance_h widget_instance_get_instance(const char *widget_id, const char *instance_id); +int widget_instance_get_instance_list(const char *widget_id, int (*cb)(const char *widget_id, const char *instance_id, void *data), void *data); +void widget_instance_unref(widget_instance_h instance); +widget_instance_h widget_instance_ref(widget_instance_h instance); +int widget_instance_change_period(widget_instance_h instance, double period); +int widget_instance_trigger_update(widget_instance_h instance, bundle *b, int force); +int widget_instance_listen_status(const char *widget_id, int (*cb)(const char *widget_id, int status, const char *instance_id, void *data), void *data); + #ifdef __cplusplus } #endif diff --git a/packaging/libwidget_service.spec b/packaging/libwidget_service.spec index 788c158..aaf5bf5 100644 --- a/packaging/libwidget_service.spec +++ b/packaging/libwidget_service.spec @@ -77,6 +77,7 @@ chsmack -a "User::Home" %{_sysconfdir}/skel/.applications/dbspace/.widget.db %{_sysconfdir}/package-manager/parserlib/libwidget-application.so %{_sysconfdir}/skel/.applications/dbspace/.widget.db %{TZ_SYS_DB}/.widget.db +%{_bindir}/widget_test %files devel %manifest %{name}.manifest diff --git a/src/widget_instance.c b/src/widget_instance.c index c11eea3..0580411 100644 --- a/src/widget_instance.c +++ b/src/widget_instance.c @@ -59,6 +59,7 @@ struct _widget_instance { bundle *content_info; int status; int stored; + int ref; }; struct widget_app { @@ -77,6 +78,7 @@ static sqlite3 *_widget_db = NULL; static char *viewer_appid = NULL; static aul_app_com_connection_h conn = NULL; + #define QUERY_CREATE_TABLE_WIDGET \ "create table if not exists widget_instance" \ "(widget_id text, " \ @@ -248,6 +250,7 @@ static struct _widget_instance *__add_instance(const char *id, const char *widge instance->stored = 0; instance->widget_id = g_strdup(widget_id); instance->content_info = NULL; + instance->ref = 0; _widget_instances = g_list_append(_widget_instances, instance); @@ -446,10 +449,9 @@ static int __update_instance_info(struct _widget_instance *instance) rc = sqlite3_step(p_statement); if (rc == SQLITE_DONE) { - if (instance->status == WIDGET_INSTANCE_DELETED) { - __remove_instance(instance); - instance = NULL; - } else + if (instance->status == WIDGET_INSTANCE_DELETED) + widget_instance_unref(instance); + else instance->stored = 1; } @@ -690,7 +692,6 @@ EAPI int widget_instance_foreach(const char *widget_id, widget_instance_foreach_ 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; @@ -841,3 +842,80 @@ EAPI int widget_instance_get_period(widget_instance_h instance, double *period) *period = instance->period; return 0; } + +EAPI int widget_instance_change_period(widget_instance_h instance, double period) +{ + return 0; +} + +EAPI int widget_instance_trigger_update(widget_instance_h instance, bundle *b, int force) +{ + return 0; +} + +EAPI widget_instance_h widget_instance_get_instance(const char *widget_id, const char *instance_id) +{ + widget_instance_h instance; + + if (widget_id == NULL || instance_id == NULL) + return NULL; + + if (_widget_apps && _widget_instances) { + instance = __pick_instance(widget_id, instance_id); + return widget_instance_ref(instance); + } + + return NULL; +} + +EAPI int widget_instance_get_instance_list(const char *widget_id, widget_instance_list_cb cb, void *data) +{ + widget_instance_h instance; + struct widget_app *app; + GList *head = NULL; + + if (widget_id == NULL) + return -1; + + if (_widget_apps) + app = __pick_app(widget_id); + else + return -2; + + if (app) { + head = app->instances; + + while (head) { + instance = (widget_instance_h)head->data; + if (cb(instance->widget_id, instance->id, data) != 0) + break; + + head = head->next; + } + } + + return 0; +} + +EAPI void widget_instance_unref(widget_instance_h instance) +{ + if (instance == NULL) + return; + + instance->ref--; + + if (instance->ref > -1) + return; + + __remove_instance(instance); +} + +EAPI widget_instance_h widget_instance_ref(widget_instance_h instance) +{ + if (instance) + instance->ref++; + + return instance; +} + + diff --git a/src/widget_service.c b/src/widget_service.c index 344363d..91bb143 100644 --- a/src/widget_service.c +++ b/src/widget_service.c @@ -30,6 +30,7 @@ #include "widget_errno.h" #include "debug.h" #include "widget_conf.h" +#include "widget_instance.h" #include "widget_service.h" static inline bool _is_widget_feature_enabled(void) @@ -261,14 +262,59 @@ static int _get_widget_supported_sizes(const char *widget_id, int *cnt, EAPI int widget_service_change_period(const char *pkgname, const char *id, double period) { - _E("not supported"); - return WIDGET_ERROR_NOT_SUPPORTED; + if (!_is_widget_feature_enabled()) { + _E("not supported"); + return WIDGET_ERROR_NOT_SUPPORTED; + } + + if (!pkgname || !id || period < 0.0f) { + _E("invalid parameter"); + return WIDGET_ERROR_INVALID_PARAMETER; + } + + widget_instance_h instance; + int ret; + + instance = widget_instance_get_instance(pkgname, id); + + if (!instance) { + _E("instance not exists or out of bound(package)"); + return WIDGET_ERROR_PERMISSION_DENIED; + } + + ret = widget_instance_change_period(instance, period); + + widget_instance_unref(instance); + + return ret; } EAPI int widget_service_trigger_update(const char *widget_id, const char *id, bundle *b, int force) { - _E("not supported"); - return WIDGET_ERROR_NOT_SUPPORTED; + if (!_is_widget_feature_enabled()) { + _E("not supported"); + return WIDGET_ERROR_NOT_SUPPORTED; + } + + if (!widget_id || !id || !b) { + _E("invalid parameter"); + return WIDGET_ERROR_INVALID_PARAMETER; + } + + widget_instance_h instance; + int ret; + + instance = widget_instance_get_instance(widget_id, id); + if (!instance) { + _E("instance not exists or out of bound(package)"); + return WIDGET_ERROR_PERMISSION_DENIED; + } + + ret = widget_instance_trigger_update(instance, b, force); + + widget_instance_unref(instance); + + return ret; } EAPI int widget_service_get_widget_list(widget_list_cb cb, void *data) @@ -626,26 +672,60 @@ EAPI int widget_service_get_nodisplay(const char *widget_id) } set_last_result(WIDGET_ERROR_NONE); - return (int)nodisplay; } +/* deprecated, always return need_of_frame as false */ EAPI int widget_service_get_need_of_frame(const char *pkgid, widget_size_type_e size_type, bool *need_of_frame) { - /* deprecated */ - return WIDGET_ERROR_NOT_SUPPORTED; + if (!_is_widget_feature_enabled()) { + _E("not supported"); + return WIDGET_ERROR_NOT_SUPPORTED; + } + + if (!pkgid) { + _E("invalid parameter"); + return WIDGET_ERROR_INVALID_PARAMETER; + } + + *need_of_frame = false; + + return WIDGET_ERROR_NONE; } +/* deprecated, always return need_of_touch_event as false */ EAPI int widget_service_get_need_of_touch_effect(const char *pkgid, widget_size_type_e size_type, bool *need_of_touch_event) { - /* deprecated */ - return WIDGET_ERROR_NOT_SUPPORTED; + if (!_is_widget_feature_enabled()) { + _E("not supported"); + return WIDGET_ERROR_NOT_SUPPORTED; + } + + if (!pkgid) { + _E("invalid parameter"); + return WIDGET_ERROR_INVALID_PARAMETER; + } + + *need_of_touch_event = false; + + return WIDGET_ERROR_NONE; } +/* deprecated, always return need_of_mouse_event as false */ EAPI int widget_service_get_need_of_mouse_event(const char *pkgid, widget_size_type_e size_type, bool *need_of_mouse_event) { - /* deprecated */ - return WIDGET_ERROR_NOT_SUPPORTED; + if (!_is_widget_feature_enabled()) { + _E("not supported"); + return WIDGET_ERROR_NOT_SUPPORTED; + } + + if (!pkgid) { + _E("invalid parameter"); + return WIDGET_ERROR_INVALID_PARAMETER; + } + + *need_of_mouse_event = false; + return WIDGET_ERROR_NONE; } EAPI char *widget_service_get_preview_image_path(const char *widget_id, @@ -1032,20 +1112,105 @@ EAPI int widget_service_get_size_type(int width, int height, EAPI int widget_service_get_content_of_widget_instance(const char *widget_id, const char *widget_instance_id, bundle **b) { - return WIDGET_ERROR_NOT_SUPPORTED; + widget_instance_h instance; + bundle *kb = NULL; + + if (!_is_widget_feature_enabled()) { + _E("not supported"); + return WIDGET_ERROR_NOT_SUPPORTED; + } + + if (widget_id == NULL || widget_instance_id == NULL || b == NULL) { + _E("invalid parameter"); + return WIDGET_ERROR_INVALID_PARAMETER; + } + + instance = widget_instance_get_instance(widget_id, widget_instance_id); + + if (instance) { + widget_instance_get_content(instance, &kb); + if (kb) { + *b = bundle_dup(kb); + widget_instance_unref(instance); + return WIDGET_ERROR_NONE; + } + } + + return WIDGET_ERROR_INVALID_PARAMETER; +} + +struct instance_cb { + widget_instance_list_cb cb; + void *data; +}; + +static int __instance_list_cb(const char *widget_id, const char *instance_id, void *data) +{ + struct instance_cb *cb_data = (struct instance_cb *)data; + + if (cb_data && cb_data->cb) + return cb_data->cb(widget_id, instance_id, cb_data->data); + + return -1; } EAPI int widget_service_get_widget_instance_list(const char *widget_id, widget_instance_list_cb cb, void *data) { - return WIDGET_ERROR_NOT_SUPPORTED; + struct instance_cb cb_data; + int ret = WIDGET_ERROR_NONE; + + cb_data.cb = cb; + cb_data.data = data; + + if (!_is_widget_feature_enabled()) { + _E("not supported"); + return WIDGET_ERROR_NOT_SUPPORTED; + } + + if (widget_id == NULL || cb == NULL) { + _E("inavlid parameter"); + return WIDGET_ERROR_INVALID_PARAMETER; + } + + ret = widget_instance_get_instance_list(widget_id, __instance_list_cb, &cb_data); + + return ret < 0 ? (ret == -2 ? WIDGET_ERROR_PERMISSION_DENIED : WIDGET_ERROR_NOT_EXIST) : WIDGET_ERROR_NONE; } EAPI int widget_service_set_lifecycle_event_cb(const char *widget_id, widget_lifecycle_event_cb cb, void *data) { - return WIDGET_ERROR_NOT_SUPPORTED; + int ret = WIDGET_ERROR_NONE; + + if (!_is_widget_feature_enabled()) { + _E("not supported"); + return WIDGET_ERROR_NOT_SUPPORTED; + } + + if (widget_id == NULL || cb == NULL) { + _E("invalid parameter"); + return WIDGET_ERROR_INVALID_PARAMETER; + } + + /* TODO */ + + return ret; } EAPI int widget_service_unset_lifecycle_event_cb(const char *widget_id, void **user_data) { - return WIDGET_ERROR_NOT_SUPPORTED; + int ret = WIDGET_ERROR_NONE; + + if (!_is_widget_feature_enabled()) { + _E("not supported"); + return WIDGET_ERROR_NOT_SUPPORTED; + } + + if (widget_id == NULL) { + _E("invalid parameter"); + return WIDGET_ERROR_INVALID_PARAMETER; + } + + /* TODO */ + + return ret; } diff --git a/tool/widget_test.c b/tool/widget_test.c new file mode 100644 index 0000000..fe4d8ee --- /dev/null +++ b/tool/widget_test.c @@ -0,0 +1,61 @@ +#include <stdio.h> +#include <stdlib.h> +#include <widget_service.h> +#include <string.h> + +typedef int (*test_fn)(int argc, char **argv); + +typedef struct _test_func_t { + const char *cmd; + test_fn fn; + const char *usage; +} test_func_t; + +int get_pkg_id(int argc, char **argv) +{ + char *pkg_id; + + if (argc < 1) + return -1; + + pkg_id = widget_service_get_package_id(argv[2]); + printf("pkg id: %s", pkg_id); + + return 0; +} + +test_func_t test_func[] = { + {"get_pkg_id", get_pkg_id, "<widget_id>"} +}; + +static void print_usage(char *pname) +{ + int i = 0; + printf("[usage] %s <cmd> ...\n", pname); + printf(" - available cmd list \n"); + + for (i = 0; i < sizeof(test_func) / sizeof(test_func_t); i++) { + printf("%s %s %s\n\n", pname, test_func[i].cmd, test_func[i].usage); + } + printf(" - end cmd list\n"); +} + +int main(int argc, char **argv) +{ + int i = 0; + + if (argc < 2) { + print_usage(argv[0]); + exit(0); + } + + for (i = 0; i < (sizeof(test_func) / sizeof(test_func_t)); i++) { + if (strcmp(test_func[i].cmd, argv[1]) == 0) { + return test_func[i].fn(argc, argv); + } + } + + print_usage(argv[0]); + + return 0; +} |