diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2017-06-09 08:11:17 +0900 |
---|---|---|
committer | Hwankyu Jhun <h.jhun@samsung.com> | 2017-06-09 08:15:51 +0900 |
commit | 43c3bb2e3ae701898a590824e66c82f35ad5ad9d (patch) | |
tree | 0d3d361eb0e106006f8377df6237532b0f0a4cb6 | |
parent | 74cc0b25fdeab2ed52c0037e50b7ab14e40671d9 (diff) | |
download | syspopup-43c3bb2e3ae701898a590824e66c82f35ad5ad9d.tar.gz syspopup-43c3bb2e3ae701898a590824e66c82f35ad5ad9d.tar.bz2 syspopup-43c3bb2e3ae701898a590824e66c82f35ad5ad9d.zip |
Add a new API to retrive syspopup information
Change-Id: Ia78164093486d3ab353d37e34e952fcb5ac9c4d7
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rwxr-xr-x | include/syspopup_caller.h | 23 | ||||
-rwxr-xr-x | include/syspopup_db.h | 2 | ||||
-rwxr-xr-x | src/syspopup_db.c | 45 | ||||
-rwxr-xr-x | syspopup-caller/syspopup_caller.c | 31 | ||||
-rwxr-xr-x | tool/test.c | 13 |
5 files changed, 113 insertions, 1 deletions
diff --git a/include/syspopup_caller.h b/include/syspopup_caller.h index d502a0a..598b9d9 100755 --- a/include/syspopup_caller.h +++ b/include/syspopup_caller.h @@ -51,6 +51,19 @@ extern "C" { */ /** + * @brief Called to get the system popup information. + * @since_tizen 4.0 + * @param[in] popup_name The name of the system popup + * @param[in] appid The application ID of the system popup + * @param[in] user_data The user data passed from the foreach function + * @return @c 0 to continue with the next iteration of the loop, + * otherwise a negative error value to break out of the loop + * @pre syspopup_foreach_info() will invoke this callback. + * @see syspopup_foreach_info() + */ +typedef int (*syspopup_info_cb)(const char *popup_name, const char *appid, void *user_data); + +/** * @brief This API launch the system popup application with given popup name. * * This API launch the system popup application. @@ -129,6 +142,16 @@ int syspopup_launch(char *popup_name, bundle *b); */ int syspopup_destroy_all(void); +/** + * @brief Retrieves the system popup information. + * @since_tizen 4.0 + * @param[in] callback The iteration callback function + * @param[in] user_data The user data to be passed to the callback function + * @return @c 0 on success, + * otherwise a negative error value + */ +int syspopup_foreach_info(syspopup_info_cb callback, void *user_data); + /** @} */ #ifdef __cplusplus diff --git a/include/syspopup_db.h b/include/syspopup_db.h index f4c07df..95b9698 100755 --- a/include/syspopup_db.h +++ b/include/syspopup_db.h @@ -56,5 +56,7 @@ typedef struct _syspopup_info_t syspopup_info_t; int _syspopup_info_add(syspopup_info_t *pinfo); syspopup_info_t *_syspopup_info_get(const char *popup_name); void _syspopup_info_free(syspopup_info_t *pinfo); +int _syspopup_info_foreach(int (*callback)(syspopup_info_t *, void *), + void *user_data); #endif diff --git a/src/syspopup_db.c b/src/syspopup_db.c index ff81499..3caa07f 100755 --- a/src/syspopup_db.c +++ b/src/syspopup_db.c @@ -144,3 +144,48 @@ void _syspopup_info_free(syspopup_info_t *pinfo) free(pinfo); } + +int _syspopup_info_foreach(int (*callback)(syspopup_info_t *, void *), + void *user_data) +{ + const char query[] = "SELECT name, prio, focus, timeout, term_act, " + "endkey_act, pkgname FROM syspopup_info;"; + sqlite3_stmt *stmt; + syspopup_info_t info; + int r; + int idx; + + if (callback == NULL) { + _E("Invalid parameter"); + return -1; + } + + if (__init() < 0) + return -1; + + r = sqlite3_prepare_v2(db, query, sizeof(query), &stmt, NULL); + if (r != SQLITE_OK) { + _E("sqlite3_prepare_v2() is failed - %d(%s)", + r, sqlite3_errmsg(db)); + __fini(); + return -1; + } + + while (sqlite3_step(stmt) == SQLITE_ROW) { + idx = 0; + info.name = (char *)sqlite3_column_text(stmt, idx++); + info.prio = sqlite3_column_int(stmt, idx++); + info.focus = sqlite3_column_int(stmt, idx++); + info.timeout = sqlite3_column_int(stmt, idx++); + info.term_act = sqlite3_column_int(stmt, idx++); + info.endkey_act = sqlite3_column_int(stmt, idx++); + info.pkgname = (char *)sqlite3_column_text(stmt, idx); + + if (callback(&info, user_data) < 0) + break; + } + sqlite3_finalize(stmt); + __fini(); + + return 0; +} diff --git a/syspopup-caller/syspopup_caller.c b/syspopup-caller/syspopup_caller.c index 663172f..2ecd8cb 100755 --- a/syspopup-caller/syspopup_caller.c +++ b/syspopup-caller/syspopup_caller.c @@ -33,9 +33,15 @@ #include "syspopup_db.h" #include "syspopup_api.h" #include "simple_util.h" +#include "syspopup_caller.h" #define REGULAR_UID_MIN 5000 +struct cb_info { + syspopup_info_cb callback; + void *user_data; +}; + API int syspopup_launch_for_uid(char *popup_name, bundle *b, uid_t uid) { syspopup_info_t *info; @@ -132,3 +138,28 @@ API int syspopup_destroy_all(void) return ret; } + +static int __foreach_cb(syspopup_info_t *sp_info, void *user_data) +{ + struct cb_info *info = (struct cb_info *)user_data; + + if (!info) + return -1; + + return info->callback(sp_info->name, sp_info->pkgname, info->user_data); +} + +API int syspopup_foreach_info(syspopup_info_cb callback, void *user_data) +{ + struct cb_info info = { + .callback = callback, + .user_data = user_data + }; + + if (!callback) { + _E("Invalid parameter"); + return -1; + } + + return _syspopup_info_foreach(__foreach_cb, &info); +} diff --git a/tool/test.c b/tool/test.c index 6a620c4..69f9e4f 100755 --- a/tool/test.c +++ b/tool/test.c @@ -27,9 +27,16 @@ #include <bundle_internal.h> #include "syspopup_caller.h" +static int __foreach_cb(const char *popup_name, const char *appid, + void *user_data) +{ + printf("system popup name [%s] appid [%s]\n", popup_name, appid); + return 0; +} + static void usage(void) { - printf("[usage] sp_test launch/destroy popup_name..." + printf("[usage] sp_test launch/destroy/foreach popup_name..." "(key1,val1,key2,val2,...)\n"); } @@ -62,6 +69,10 @@ int main(int argc, char **argv) ret = syspopup_destroy_all(); if (ret < 0) return -1; + } else if (strcmp(argv[1], "foreach") == 0) { + ret = syspopup_foreach_info(__foreach_cb, NULL); + if (ret < 0) + return -1; } else { usage(); } |