Add a new API to retrive syspopup information 98/132998/2
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 8 Jun 2017 23:11:17 +0000 (08:11 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 8 Jun 2017 23:15:51 +0000 (08:15 +0900)
Change-Id: Ia78164093486d3ab353d37e34e952fcb5ac9c4d7
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/syspopup_caller.h
include/syspopup_db.h
src/syspopup_db.c
syspopup-caller/syspopup_caller.c
tool/test.c

index d502a0a..598b9d9 100755 (executable)
@@ -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
index f4c07df..95b9698 100755 (executable)
@@ -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
index ff81499..3caa07f 100755 (executable)
@@ -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;
+}
index 663172f..2ecd8cb 100755 (executable)
 #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);
+}
index 6a620c4..69f9e4f 100755 (executable)
 #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();
        }