summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorInkyun Kil <inkyun.kil@samsung.com>2017-01-10 16:42:22 +0900
committerInkyun Kil <inkyun.kil@samsung.com>2017-02-06 14:52:59 +0900
commit4259894fde81136eca754812738695dc6871fe74 (patch)
tree6e83440b844eb51951c21e5803bc01a3b84cbae5 /test
parent99befe4b26696342cca67bd2b3cbbebb3f6f2e84 (diff)
downloadlibrua-4259894fde81136eca754812738695dc6871fe74.tar.gz
librua-4259894fde81136eca754812738695dc6871fe74.tar.bz2
librua-4259894fde81136eca754812738695dc6871fe74.zip
Add new api for subscribing db update callback
- To inform task-manager of updated rua list. Change-Id: Ia7e8cb28221e21bd383a5171dd97dc2bf9b78737 Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
Diffstat (limited to 'test')
-rw-r--r--test/rua-test.c150
1 files changed, 127 insertions, 23 deletions
diff --git a/test/rua-test.c b/test/rua-test.c
index 2d85442..1dd6bf3 100644
--- a/test/rua-test.c
+++ b/test/rua-test.c
@@ -22,6 +22,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <glib.h>
+#include <pthread.h>
/* For multi-user support */
#include <tzplatform_config.h>
@@ -31,6 +32,54 @@
#include "rua_stat.h"
#include "rua_stat_internal.h"
+static GMainLoop *mainloop = NULL;
+static pthread_t g_thread;
+
+static int callback_id_table[10] = { 0, };
+
+static gboolean run_test(int selected_number);
+static void __print_menu()
+{
+ int test_num = 0;
+ int run_next = 1;
+
+ while(run_next) {
+ printf("==========================================\n");
+ printf(" Basic test menu \n");
+ printf("==========================================\n");
+ printf(" 0. EXIT\n");
+ printf(" 1. Add rua history to DEFAULT USER(5001)\n");
+ printf(" 2. Delete history with pkgname\n");
+ printf(" 3. Load RUA history\n");
+ printf(" 4. Update RUA stat\n");
+ printf(" 5. Get RUA stat tags\n");
+ printf(" 6. Register update callback (MAX 10)\n");
+ printf(" 7. Unregister update callback\n");
+ printf("------------------------------------------\n");
+ int ret = scanf("%d", &test_num);
+ if (ret < 0) {
+ printf("scanf fail %d", ret);
+ break;
+ }
+
+ run_next = run_test(test_num);
+ }
+
+}
+
+static void __update_cb(char **table, int rows, int cols)
+{
+ struct rua_rec record;
+
+ printf("update_cb");
+ int row;
+ for (row = 0; row < rows; ++row) {
+ rua_history_get_rec(&record, table, rows, cols, row);
+ printf("pkgname : %s, time : %d \n", record.pkg_name, (int)record.launch_time);
+ }
+
+}
+
static int __add_history()
{
int ret;
@@ -95,13 +144,62 @@ static int __get_stat_tags()
return ret;
}
-static gboolean run_test(int selected_number)
+static int __register_callback()
+{
+ int ret;
+
+ int i = 0;
+ for (i = 0; i < 10; i++) {
+ if (callback_id_table[i] == 0) {
+ int output = 0;
+ ret = rua_register_update_cb(__update_cb, NULL, &output);
+ if (ret == -1) {
+ printf("__register_callback error : %d \n", ret);
+ return -1;
+ }
+
+ printf("callback id : %d \n", output);
+ callback_id_table[i] = output;
+
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+static int __unregister_callback()
{
- gboolean go_to_loop = TRUE;
+ int ret;
+
+ int i = 0;
+ int id = 0;
+ printf("Enter callback_id (The number from register_callback) : ");
+ scanf("%d", &id);
+
+ for (i = 0; i < 10; i++) {
+ if (callback_id_table[i] == id) {
+ ret = rua_unregister_update_cb(callback_id_table[i]);
+ if (ret == -1)
+ printf("__unregister_callback : %d \n", ret);
+ callback_id_table[i] = 0;
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+
+static gboolean run_test(int selected_number)
+{
+ int r = 0;
+ gboolean loop = TRUE;
switch (selected_number) {
case 0:
- go_to_loop = FALSE;
+ g_main_loop_quit(mainloop);
+ loop = FALSE;
break;
case 1:
@@ -124,38 +222,44 @@ static gboolean run_test(int selected_number)
__get_stat_tags();
break;
+ case 6:
+ r = __register_callback();
+ if (r == -1)
+ printf("table is full");
+ break;
+
+ case 7:
+ r = __unregister_callback();
+ if (r == -1)
+ printf("id is wrong");
+
+ break;
+
default:
break;
}
- return go_to_loop;
+
+ return loop;
}
int main()
{
int ret = 0;
- int test_num;
- gboolean run_next = TRUE;
- while(run_next) {
- printf("==========================================\n");
- printf(" Basic test menu \n");
- printf("==========================================\n");
- printf(" 0. EXIT\n");
- printf(" 1. Add rua history to DEFAULT USER(5001)\n");
- printf(" 2. Delete history with pkgname\n");
- printf(" 3. Load RUA history\n");
- printf(" 4. Update RUA stat\n");
- printf(" 5. Get RUA stat tags\n");
- printf("------------------------------------------\n");
- ret = scanf("%d", &test_num);
- if (ret < 0) {
- printf("scanf fail %d", ret);
- break;
- }
+ mainloop = g_main_loop_new(NULL, FALSE);
- run_next = run_test(test_num);
+ int result = pthread_create(&g_thread, NULL, __print_menu, (void *)NULL);
+ if (result < 0)
+ {
+ printf("pthread_create failed in initialize\n");
+ return 0;
}
+
+ g_main_loop_run(mainloop);
+ g_main_loop_unref(mainloop);
+ mainloop = NULL;
+
return ret;
}