From 3c5c87061e6c614f1e3eadd07af87cab341c8761 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Wed, 8 Apr 2020 21:56:58 +0900 Subject: [PATCH 01/16] Modified to set VCONFKEY_STICKER_SYNC_STATE when bitmoji sync is finished Change-Id: Ia2c2e65bc0e78fdd7d819f329eb1ff345cf40300 --- receiver/src/ft.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index ef2b771..9288b72 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -775,6 +775,10 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in send_message("sync_stop_result", reason.c_str()); + current_request.mode.clear(); + current_request.category.clear(); + current_request.type.clear(); + if (!process_request_queue()) { sync_success_cnt = 0; @@ -782,10 +786,6 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in send_disconnect_message(); service_app_exit(); } - - current_request.mode.clear(); - current_request.category.clear(); - current_request.type.clear(); } else LOGW("unknown msg id : %s", msg_id.c_str()); -- 2.7.4 From 9a8bfc673c34838f14393f1f003411fa850b3ed9 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Wed, 8 Apr 2020 21:58:46 +0900 Subject: [PATCH 02/16] Update package version to 0.1.31 Change-Id: Idcd893834e1eaf5fc2c0024033b2096092b23ab2 --- packaging/capi-ui-sticker.spec | 2 +- receiver/tizen-manifest.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 7d6cc1d..faae811 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.30 +Version: 0.1.31 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index 402974f..cf0b55e 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4 From a7ac397bc9415d1fcb91e445fc2a0eabe702075f Mon Sep 17 00:00:00 2001 From: InHong Han Date: Tue, 7 Apr 2020 18:21:24 +0900 Subject: [PATCH 03/16] Add a new table into DB for checking recent history Change-Id: I78725d047ab6b5e1c24a4c49b63ab69bde6d17d7 --- server/stickerd_db_manager.c | 21 +++++++++++++++++++++ sticker-parser/sticker-parser.c | 13 +++++++++++++ 2 files changed, 34 insertions(+) diff --git a/server/stickerd_db_manager.c b/server/stickerd_db_manager.c index 3adda1b..7e6c8e1 100644 --- a/server/stickerd_db_manager.c +++ b/server/stickerd_db_manager.c @@ -51,12 +51,20 @@ * | whitelist_id | provider_id | consumer_id | * +------------+---------------+-------------+ * + * sticker_recent_history_info + * +------------+-----------------+-------+-----------+ + * | INT | INT | INT | TEXT | + * +------------+-----------------+-------+-----------+ + * | history_id | sticker_info_id | count | timestamp | + * +------------+-----------------+-------+-----------+ + * */ #define STICKER_DB_PATH tzplatform_mkpath(TZ_SYS_DB, ".sticker_info.db") #define STICKER_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_info(sticker_info_id INTEGER PRIMARY KEY AUTOINCREMENT, app_id TEXT NOT NULL, type INTEGER NOT NULL, uri TEXT NOT NULL, thumbnail TEXT, description TEXT, group_name TEXT NOT NULL, date TEXT NOT NULL, display_type INTEGER)" #define STICKER_KEYWORD_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_keyword_info(keyword_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, keyword TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)" #define STICKER_WHITELIST_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_whitelist_info(whitelist_id INTEGER PRIMARY KEY AUTOINCREMENT, provider_id TEXT NOT NULL, consumer_id TEXT NOT NULL)" +#define STICKER_RECENT_HISTORY_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_recent_history_info(history_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, count INTEGER NOT NULL, timestamp TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)" #define STICKER_DB_INSERT_STICKER_INFO "INSERT INTO sticker_info (app_id, type, uri, thumbnail, description, group_name, date, display_type) VALUES (?, ?, ?, ?, ?, ?, DateTime('now','localtime'), ?)" #define STICKER_DB_INSERT_STICKER_KEYWORD_INFO "INSERT INTO sticker_keyword_info (sticker_info_id, keyword) VALUES (?, ?)" @@ -197,6 +205,12 @@ static int _recover_db(void) ret = STICKERD_SERVER_ERROR_DB_FAILED; } + ret = sqlite3_exec(db, STICKER_RECENT_HISTORY_INFO_CREATE_TABLE, NULL, NULL, &err); + if (ret != SQLITE_OK) { + LOGE("Failed to create sticker_recent_history_info table : %s", err); + ret = STICKERD_SERVER_ERROR_DB_FAILED; + } + is_corrupted = FALSE; cleanup: @@ -255,6 +269,13 @@ int stickerd_db_init(void) goto cleanup; } + ret = sqlite3_exec(db, STICKER_RECENT_HISTORY_INFO_CREATE_TABLE, NULL, NULL, &err); + if (ret != SQLITE_OK) { + LOGE("Failed to create sticker_recent_history_info table : %s", err); + ret = STICKERD_SERVER_ERROR_DB_FAILED; + goto cleanup; + } + ret = sqlite3_exec(db, "PRAGMA journal_mode = WAL", NULL, NULL, &err); if (ret != SQLITE_OK) { LOGE("Failed to set journal_mode : %s", err); diff --git a/sticker-parser/sticker-parser.c b/sticker-parser/sticker-parser.c index 86ebd3e..a3f96b5 100644 --- a/sticker-parser/sticker-parser.c +++ b/sticker-parser/sticker-parser.c @@ -44,6 +44,7 @@ #define STICKER_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_info(sticker_info_id INTEGER PRIMARY KEY AUTOINCREMENT, app_id TEXT NOT NULL, type INTEGER NOT NULL, uri TEXT NOT NULL, thumbnail TEXT, description TEXT, group_name TEXT NOT NULL, date TEXT NOT NULL, display_type INTEGER)" #define STICKER_KEYWORD_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_keyword_info(keyword_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, keyword TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)" #define STICKER_WHITELIST_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_whitelist_info(whitelist_id INTEGER PRIMARY KEY AUTOINCREMENT, provider_id TEXT NOT NULL, consumer_id TEXT NOT NULL)" +#define STICKER_RECENT_HISTORY_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_recent_history_info(history_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, count INTEGER NOT NULL, timestamp TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)" #define UIFW_ID 502 #define APPFW_ID 301 #define MAX_ERROR_BUFFER 256 @@ -130,6 +131,12 @@ static void __recover_db() goto cleanup; } + ret = sqlite3_exec(db, STICKER_RECENT_HISTORY_INFO_CREATE_TABLE, NULL, NULL, &err); + if (ret != SQLITE_OK) { + LOGE("Failed to create sticker_recent_history_info table : %s", err); + goto cleanup; + } + is_corrupted = FALSE; cleanup: @@ -186,6 +193,12 @@ static void __db_init() goto cleanup; } + ret = sqlite3_exec(db, STICKER_RECENT_HISTORY_INFO_CREATE_TABLE, NULL, NULL, &err); + if (ret != SQLITE_OK) { + LOGE("Failed to create sticker_recent_history_info table : %s", err); + goto cleanup; + } + ret = sqlite3_exec(db, "PRAGMA journal_mode = WAL", NULL, NULL, &err); if (ret != SQLITE_OK) { LOGE("Failed to set journal_mode : %s", err); -- 2.7.4 From 152404a751b572f8d2777ad72ba8cca201e62aff Mon Sep 17 00:00:00 2001 From: InHong Han Date: Tue, 7 Apr 2020 18:36:03 +0900 Subject: [PATCH 04/16] Add APIs for managing recent stickers history Change-Id: I9f1ae1c9bf066822e497bc5a4c03eaefb12f58d4 --- client/sticker_dbus.c | 36 ++++++++++++++++++++++ client/sticker_dbus.h | 2 ++ consumer/sticker_consumer.c | 66 +++++++++++++++++++++++++++++++++++++++ include/sticker_consumer.h | 37 ++++++++++++++++++++++ server/stickerd_data_manager.c | 70 ++++++++++++++++++++++++++++++++++++++++++ server/stickerd_data_manager.h | 2 ++ server/stickerd_db_manager.c | 70 ++++++++++++++++++++++++++++++++++++++++++ server/stickerd_db_manager.h | 2 ++ 8 files changed, 285 insertions(+) diff --git a/client/sticker_dbus.c b/client/sticker_dbus.c index 5460c71..c6aaaea 100644 --- a/client/sticker_dbus.c +++ b/client/sticker_dbus.c @@ -1108,4 +1108,40 @@ int sticker_dbus_check_file_exists(GDBusConnection *gdbus_connection, const char g_object_unref(reply); return ret; +} + +int sticker_dbus_insert_recent_sticker_info(GDBusConnection *gdbus_connection, int record_id) +{ + int ret; + GDBusMessage *reply = NULL; + + ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "insert_recent_sticker_info"); + if (ret != STICKER_CLIENT_ERROR_NONE) + LOGE("failed to insert recent sticker info"); + + if (reply) + g_object_unref(reply); + + return ret; +} + +int sticker_dbus_get_recent_sticker_list(GDBusConnection *gdbus_connection, int count, GVariantIter **id_iter) +{ + int ret; + GDBusMessage *reply = NULL; + GVariant *reply_body = NULL; + + ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", count), &reply, "get_recent_sticker_info"); + if (ret == STICKER_CLIENT_ERROR_NONE) { + reply_body = g_dbus_message_get_body(reply); + g_variant_get(reply_body, "(a(i))", &(*id_iter)); + } + + if (reply_body) + g_variant_unref(reply_body); + + if (reply) + g_object_unref(reply); + + return ret; } \ No newline at end of file diff --git a/client/sticker_dbus.h b/client/sticker_dbus.h index 610cfe1..a6d5437 100644 --- a/client/sticker_dbus.h +++ b/client/sticker_dbus.h @@ -65,6 +65,8 @@ int sticker_dbus_get_sticker_info_by_keyword(GDBusConnection *gdbus_connection, int sticker_dbus_get_sticker_info_by_display_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_display_type_e type, int offset, int count, GVariantIter **id_iter); int sticker_dbus_get_group_list_by_display_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_display_type_e type, GList **group_list); int sticker_dbus_check_file_exists(GDBusConnection *gdbus_connection, const char *uri, int *result); +int sticker_dbus_insert_recent_sticker_info(GDBusConnection *gdbus_connection, int record_id); +int sticker_dbus_get_recent_sticker_list(GDBusConnection *gdbus_connection, int count, GVariantIter **id_iter); #ifdef __cplusplus } diff --git a/consumer/sticker_consumer.c b/consumer/sticker_consumer.c index 5211f36..15ea7fc 100644 --- a/consumer/sticker_consumer.c +++ b/consumer/sticker_consumer.c @@ -531,4 +531,70 @@ cleanup: g_list_free_full(list, free); return ret; +} + +EXPORT_API int sticker_consumer_add_recent_data(sticker_consumer_h consumer_handle, sticker_data_h data_handle) +{ + CHECK_STICKER_FEATURE(); + + int ret; + + if (!consumer_handle || !data_handle || (data_handle->sticker_info_id > 0) || !data_handle->uri) + return STICKER_ERROR_INVALID_PARAMETER; + + ret = sticker_dbus_insert_recent_sticker_info(consumer_handle->gdbus_connection, data_handle->sticker_info_id); + if (ret != STICKER_ERROR_NONE) { + LOGE("Failed to add recent sticker information : %d", ret); + return STICKER_ERROR_OPERATION_FAILED; + } + + return STICKER_ERROR_NONE; +} + +EXPORT_API int sticker_consumer_get_recent_data_list(sticker_consumer_h consumer_handle, int count, int *result, sticker_consumer_data_foreach_cb callback, void *user_data) +{ + CHECK_STICKER_FEATURE(); + + int ret; + int info_id; + int sticker_count = 0; + GVariantIter *id_iter = NULL; + + if (!consumer_handle || (count <= 0) || !result || !callback) + return STICKER_ERROR_INVALID_PARAMETER; + + ret = sticker_dbus_get_recent_sticker_list(consumer_handle->gdbus_connection, count, &id_iter); + if (ret != STICKER_ERROR_NONE) { + LOGE("Failed to get recent sticker information : %d", ret); + ret = STICKER_ERROR_OPERATION_FAILED; + goto cleanup; + } + + if (id_iter) { + while (g_variant_iter_loop (id_iter, "(i)", &info_id)) { + sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s)); + if (!sticker_data) { + ret = STICKER_ERROR_OUT_OF_MEMORY; + goto cleanup; + } + + ret = sticker_dbus_get_sticker_info_by_record_id(consumer_handle->gdbus_connection, sticker_data, info_id); + if (ret == STICKER_ERROR_NONE) { + sticker_count++; + callback(sticker_data, user_data); + _free_sticker_data(sticker_data); + } else { + _free_sticker_data(sticker_data); + goto cleanup; + } + } + } + + *result = sticker_count; + +cleanup: + if (id_iter) + g_variant_iter_free(id_iter); + + return ret; } \ No newline at end of file diff --git a/include/sticker_consumer.h b/include/sticker_consumer.h index ac2428e..a143e00 100644 --- a/include/sticker_consumer.h +++ b/include/sticker_consumer.h @@ -279,6 +279,43 @@ int sticker_consumer_data_foreach_by_display_type(sticker_consumer_h consumer_ha int sticker_consumer_group_list_foreach_by_display_type(sticker_consumer_h consumer_handle, sticker_data_display_type_e type, sticker_consumer_group_list_foreach_cb callback, void *user_data); /** + * @brief Add history to recently used stickers list + * @since_tizen 5.5 + * @param[in] consumer_handle The sticker consumer handle + * @param[in] data_handle The sticker data handle + * @return 0 on success, otherwise a negative error value + * @retval #STICKER_ERROR_NONE Successful + * @retval #STICKER_ERROR_NOT_SUPPORTED Not supported + * @retval #STICKER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STICKER_ERROR_OPERATION_FAILED Operation failed + * @see sticker_consumer_get_recent_list() + */ +int sticker_consumer_add_recent_data(sticker_consumer_h consumer_handle, sticker_data_h data_handle); + +/** + * @brief Gets recently used stickers list. + * @details The most recently used stickers are delivered in order. + * @since_tizen 5.5 + * @remarks It is not an error if @a result is smaller than @a count. + * @param[in] consumer_handle The sticker consumer handle + * @param[in] count The number of stickers that you want to receive. + * If -1, the number of stickers is not restricted + * @param[out] result The number of stickers received (zero indicates that no data was found) + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value + * @retval #STICKER_ERROR_NONE Successful + * @retval #STICKER_ERROR_NOT_SUPPORTED Not supported + * @retval #STICKER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STICKER_ERROR_OUT_OF_MEMORY Out of memory + * @retval #STICKER_ERROR_OPERATION_FAILED Operation failed + * @post This function invokes sticker_consumer_data_foreach_cb() repeatedly for getting data. + * @see sticker_consumer_data_foreach_cb() + * @see sticker_consumer_add_recent_data() + */ +int sticker_consumer_get_recent_data_list(sticker_consumer_h consumer_handle, int count, int *result, sticker_consumer_data_foreach_cb callback, void *user_data); + +/** * @} */ diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index 3585b8d..251e9c0 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -149,6 +149,10 @@ static void _stickerd_client_dbus_method_call_handler(GDBusConnection *conn, con ret = stickerd_update_sticker_disp_type(parameters, &reply_body); } else if (g_strcmp0(method_name, "check_file_exists") == 0) { ret = stickerd_check_file_exists(parameters, &reply_body); + } else if (g_strcmp0(method_name, "insert_recent_sticker_info") == 0) { + ret = stickerd_insert_recent_sticker_info(parameters, &reply_body); + } else if (g_strcmp0(method_name, "get_recent_sticker_info") == 0) { + ret = stickerd_get_recent_sticker_info(parameters, &reply_body); } if (ret == STICKERD_SERVER_ERROR_NONE) { @@ -315,6 +319,15 @@ int stickerd_register_dbus_interface(void) " " " " " " + + " " + " " + " " + + " " + " " + " " + " " " " " "; @@ -1558,4 +1571,61 @@ int stickerd_check_file_exists(GVariant *parameters, GVariant **reply_body) } return ret; +} + +int stickerd_insert_recent_sticker_info(GVariant *parameters, GVariant **reply_body) +{ + int ret; + int record_id; + + *reply_body = g_variant_new("()"); + if (*reply_body == NULL) { + LOGE("Failed to create reply_body"); + return STICKERD_SERVER_ERROR_OPERATION_FAILED; + } + + g_variant_get(parameters, "(i)", &record_id); + + ret = stickerd_db_insert_recent_sticker_info(record_id); + if (ret != STICKERD_SERVER_ERROR_NONE) { + LOGE("Failed to insert recent sticker info"); + return STICKERD_SERVER_ERROR_OPERATION_FAILED; + } + + return ret; +} + +int stickerd_get_recent_sticker_info(GVariant *parameters, GVariant **reply_body) +{ + int ret; + int count; + GList *id_list = NULL; + GVariantBuilder *id_builder = NULL; + + g_variant_get(parameters, "(i)", &count); + + ret = stickerd_db_get_record_id(STICKER_DB_STICKER_RECENT_HISTORY, &id_list, NULL, NULL, 0, count); + if (ret != STICKERD_SERVER_ERROR_NONE) { + LOGE("Failed to get recent sticker id"); + if(id_list) + g_list_free_full(id_list, free); + return STICKERD_SERVER_ERROR_OPERATION_FAILED; + } + + id_builder = g_variant_builder_new(G_VARIANT_TYPE("a(i)")); + g_list_foreach(id_list, (GFunc) _set_id_builder, id_builder); + + *reply_body = g_variant_new("(a(i))", id_builder); + if (*reply_body == NULL) { + LOGE("Failed to create reply_body"); + ret = STICKERD_SERVER_ERROR_OPERATION_FAILED; + } + + if (id_list) + g_list_free_full(id_list, free); + + if (id_builder) + g_variant_builder_unref(id_builder); + + return ret; } \ No newline at end of file diff --git a/server/stickerd_data_manager.h b/server/stickerd_data_manager.h index e09e91d..ea90752 100644 --- a/server/stickerd_data_manager.h +++ b/server/stickerd_data_manager.h @@ -48,6 +48,8 @@ int stickerd_get_sticker_info_by_display_type(GVariant *parameters, GVariant **r int stickerd_get_group_list_by_disp_type(GVariant *parameters, GVariant **reply_body); int stickerd_update_sticker_disp_type(GVariant *parameters, GVariant **reply_body); int stickerd_check_file_exists(GVariant *parameters, GVariant **reply_body); +int stickerd_insert_recent_sticker_info(GVariant *parameters, GVariant **reply_body); +int stickerd_get_recent_sticker_info(GVariant *parameters, GVariant **reply_body); #ifdef __cplusplus } diff --git a/server/stickerd_db_manager.c b/server/stickerd_db_manager.c index 3adda1b..79d4c61 100644 --- a/server/stickerd_db_manager.c +++ b/server/stickerd_db_manager.c @@ -60,6 +60,7 @@ #define STICKER_DB_INSERT_STICKER_INFO "INSERT INTO sticker_info (app_id, type, uri, thumbnail, description, group_name, date, display_type) VALUES (?, ?, ?, ?, ?, ?, DateTime('now','localtime'), ?)" #define STICKER_DB_INSERT_STICKER_KEYWORD_INFO "INSERT INTO sticker_keyword_info (sticker_info_id, keyword) VALUES (?, ?)" +#define STICKER_DB_INSERT_RECENT_HISTORY "INSERT INTO sticker_recent_history_info (sticker_info_id, count, timestamp) VALUES (?, 1, DateTime('now','localtime'))" #define STICKER_DB_DELETE_STICKER_INFO "DELETE FROM sticker_info WHERE sticker_info_id = ?" #define STICKER_DB_DELETE_STICKER_KEYWORD_INFO "DELETE FROM sticker_keyword_info WHERE sticker_info_id = ?" @@ -71,6 +72,7 @@ #define STICKER_DB_UPDATE_STICKER_DESCRIPTION "UPDATE sticker_info SET description = ?, date = DateTime('now','localtime') WHERE sticker_info_id = ?" #define STICKER_DB_UPDATE_STICKER_GROUP "UPDATE sticker_info SET group_name = ?, date = DateTime('now','localtime') WHERE sticker_info_id = ?" #define STICKER_DB_UPDATE_STICKER_DISP_TYPE "UPDATE sticker_info SET display_type = ?, date = DateTime('now','localtime') WHERE sticker_info_id = ?" +#define STICKER_DB_UPDATE_RECENT_HISTORY "UPDATE sticker_recent_history_info SET count = count + 1, timestamp = DateTime('now','localtime') WHERE sticker_info_id = ?" #define STICKER_DB_GET_LATEST_RECORD_ID "SELECT sticker_info_id FROM sticker_info ORDER BY sticker_info_id DESC LIMIT 1" #define STICKER_DB_GET_STICKER_INFO_BY_RECORD_ID "SELECT * FROM sticker_info WHERE sticker_info_id = ?" @@ -88,6 +90,8 @@ #define STICKER_DB_GET_RECORD_ID_BY_DISP_TYPE "SELECT sticker_info_id FROM sticker_info WHERE display_type = ? AND app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?)) LIMIT ?, ?" #define STICKER_DB_GET_GROUP_LIST_BY_DISP_TYPE "SELECT DISTINCT group_name FROM sticker_info WHERE display_type = ? AND app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?))" #define STICKER_DB_CHECK_FILE_EXISTS "SELECT EXISTS(SELECT 1 FROM sticker_info WHERE uri = ? LIMIT 1)" +#define STICKER_DB_CHECK_RECENT_HISTORY_EXISTS "SELECT EXISTS(SELECT 1 FROM sticker_recent_history_info WHERE sticker_info_id = ? LIMIT 1)" +#define STICKER_DB_GET_RECENT_HISTORY "SELECT sticker_info_id FROM sticker_recent_history_info ORDER BY datetime(timestamp) DESC LIMIT ?" typedef enum { @@ -147,6 +151,8 @@ static const char *_db_get_query(sticker_info_db_type sticker_type, command_type break; case STICKER_DB_STICKER_DISP_TYPE: query = STICKER_DB_GET_RECORD_ID_BY_DISP_TYPE; + case STICKER_DB_STICKER_RECENT_HISTORY: + query = STICKER_DB_GET_RECENT_HISTORY; break; default : query = ""; @@ -811,6 +817,8 @@ int stickerd_db_get_record_id(sticker_info_db_type type, GList **id_list, void * sqlite3_bind_text(stmt, 1, app_id, -1, SQLITE_TRANSIENT); sqlite3_bind_int(stmt, 2, offset); sqlite3_bind_int(stmt, 3, count); + } else if (type == STICKER_DB_STICKER_RECENT_HISTORY) { + sqlite3_bind_int(stmt, 1, count); } else { if (type == STICKER_DB_STICKER_TYPE || type == STICKER_DB_STICKER_DISP_TYPE) sqlite3_bind_int(stmt, 1, *(int *)data); @@ -913,4 +921,66 @@ cleanup: sqlite3_close(db); return STICKERD_SERVER_ERROR_DB_FAILED; +} + +int stickerd_db_insert_recent_sticker_info(int record_id) +{ + int ret; + sqlite3 *db = NULL; + sqlite3_stmt *stmt = NULL; + + db = _db_open(); + if (!db) + return STICKERD_SERVER_ERROR_DB_FAILED; + + ret = sqlite3_prepare_v2(db, STICKER_DB_CHECK_RECENT_HISTORY_EXISTS, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + LOGE("fail to check recent sticker exists : %s", sqlite3_errmsg(db)); + goto cleanup; + } + + sqlite3_bind_int(stmt, 1, record_id); + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ERROR) { + LOGE("sqlite3_step() failed : ret(%d)", ret); + goto cleanup; + } + + int result = sqlite3_column_int(stmt, 0); + + sqlite3_finalize(stmt); + stmt = NULL; + + if (result) + ret = sqlite3_prepare_v2(db, STICKER_DB_UPDATE_RECENT_HISTORY, -1, &stmt, NULL); + else + ret = sqlite3_prepare_v2(db, STICKER_DB_INSERT_RECENT_HISTORY, -1, &stmt, NULL); + + if (ret != SQLITE_OK) { + LOGE("fail to update recent history : %s", sqlite3_errmsg(db)); + goto cleanup; + } + + sqlite3_bind_int(stmt, 1, record_id); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_OK && ret != SQLITE_DONE) { + LOGE("sqlite3_step() failed : ret(%d)", ret); + goto cleanup; + } else if (sqlite3_changes(db) == 0) { + LOGE("No changes to DB"); + goto cleanup; + } + + sqlite3_finalize(stmt); + sqlite3_close(db); + + return STICKERD_SERVER_ERROR_NONE; + +cleanup: + sqlite3_finalize(stmt); + sqlite3_close(db); + + return STICKERD_SERVER_ERROR_DB_FAILED; } \ No newline at end of file diff --git a/server/stickerd_db_manager.h b/server/stickerd_db_manager.h index 4a14e50..38e13b5 100644 --- a/server/stickerd_db_manager.h +++ b/server/stickerd_db_manager.h @@ -34,6 +34,7 @@ typedef enum { STICKER_DB_STICKER_GROUP, STICKER_DB_STICKER_KEYWORD, STICKER_DB_STICKER_DISP_TYPE, + STICKER_DB_STICKER_RECENT_HISTORY, } sticker_info_db_type; typedef struct { @@ -60,6 +61,7 @@ int stickerd_db_get_sticker_count(int *count, char *app_id); int stickerd_db_get_record_id(sticker_info_db_type type, GList **id_list, void *data, char *app_id, int offset, int count); int stickerd_db_get_group_list_by_display_type(GVariantBuilder *builder, char *app_id, int disp_type); int stickerd_db_check_file_exists(int *result, char *uri); +int stickerd_db_insert_recent_sticker_info(int record_id); #ifdef __cplusplus } -- 2.7.4 From de8ad13fcbd9716bb2fa1189c9c152afdaf7cf68 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Fri, 10 Apr 2020 12:07:42 +0900 Subject: [PATCH 05/16] Add a new API for sending whether sticker DB is changed Change-Id: I6cf48055fbdc83bfe564f11146c20f69e243b2a4 --- consumer/sticker_consumer.c | 26 ++++++++++++++++++++ consumer/sticker_consumer_main.h | 2 ++ include/sticker_consumer.h | 52 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/consumer/sticker_consumer.c b/consumer/sticker_consumer.c index 15ea7fc..1c9de90 100644 --- a/consumer/sticker_consumer.c +++ b/consumer/sticker_consumer.c @@ -597,4 +597,30 @@ cleanup: g_variant_iter_free(id_iter); return ret; +} + +EXPORT_API int sticker_consumer_set_event_callback(sticker_consumer_h consumer_handle, sticker_consumer_event_cb callback, void *user_data) +{ + CHECK_STICKER_FEATURE(); + + if (!consumer_handle || !callback) + return STICKER_ERROR_INVALID_PARAMETER; + + consumer_handle->event_cb = callback; + consumer_handle->event_cb_user_data = user_data; + + return STICKER_ERROR_NONE; +} + +EXPORT_API int sticker_consumer_unset_event_callback(sticker_consumer_h consumer_handle) +{ + CHECK_STICKER_FEATURE(); + + if (!consumer_handle) + return STICKER_ERROR_INVALID_PARAMETER; + + consumer_handle->event_cb = NULL; + consumer_handle->event_cb_user_data = NULL; + + return STICKER_ERROR_NONE; } \ No newline at end of file diff --git a/consumer/sticker_consumer_main.h b/consumer/sticker_consumer_main.h index 5f72eaf..f830204 100644 --- a/consumer/sticker_consumer_main.h +++ b/consumer/sticker_consumer_main.h @@ -32,6 +32,8 @@ struct sticker_consumer_s { int monitor_id; int server_monitor_id; char *app_id; + sticker_consumer_event_cb event_cb; + void *event_cb_user_data; }; #ifdef __cplusplus diff --git a/include/sticker_consumer.h b/include/sticker_consumer.h index a143e00..fb6985d 100644 --- a/include/sticker_consumer.h +++ b/include/sticker_consumer.h @@ -35,6 +35,17 @@ extern "C" { */ /** + * @brief Enumeration for event type. + * + * @since_tizen 5.5 + */ +typedef enum { + STICKER_CONSUMER_EVENT_TYPE_INSERT, /**< Insert event type */ + STICKER_CONSUMER_EVENT_TYPE_DELETE, /**< Delete event type */ + STICKER_CONSUMER_EVENT_TYPE_UPDATE, /**< Update event type */ +} sticker_consumer_event_type_e; + +/** * @brief The sticker consumer handle. * @since_tizen 5.5 */ @@ -85,6 +96,17 @@ typedef void (*sticker_consumer_group_list_foreach_cb)(const char *group, void * typedef void (*sticker_consumer_keyword_list_foreach_cb)(const char *keyword, void *user_data); /** + * @brief Called when the stickers are inserted, deleted, or updated. + * @since_tizen 5.5 + * @param[in] event_type The event type of sticker + * @param[in] user_data The user data passed from sticker_consumer_set_event_callback() + * @pre The callback can be registered using sticker_consumer_set_event_callback() + * @see sticker_consumer_set_event_callback() + * @see sticker_consumer_unset_event_callback() + */ +typedef void (*sticker_consumer_event_cb)(sticker_consumer_event_type_e event_type, void *user_data); + +/** * @brief Creates a sticker consumer handle. * @since_tizen 5.5 * @privlevel public @@ -316,6 +338,36 @@ int sticker_consumer_add_recent_data(sticker_consumer_h consumer_handle, sticker int sticker_consumer_get_recent_data_list(sticker_consumer_h consumer_handle, int count, int *result, sticker_consumer_data_foreach_cb callback, void *user_data); /** + * @brief Registers a callback function to be invoked when the stickers are inserted, deleted, or updated. + * @since_tizen 5.5 + * @param[in] consumer_handle The sticker consumer handle + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value + * @retval #STICKER_ERROR_NONE Successful + * @retval #STICKER_ERROR_NOT_SUPPORTED Not supported + * @retval #STICKER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STICKER_ERROR_OPERATION_FAILED Operation failed + * @see sticker_consumer_event_cb() + * @see sticker_consumer_unset_event_callback() + */ +int sticker_consumer_set_event_callback(sticker_consumer_h consumer_handle, sticker_consumer_event_cb callback, void *user_data); + +/** + * @brief Unregisters a callback function. + * @since_tizen 5.5 + * @param[in] consumer_handle The sticker consumer handle + * @return 0 on success, otherwise a negative error value + * @retval #STICKER_ERROR_NONE Successful + * @retval #STICKER_ERROR_NOT_SUPPORTED Not supported + * @retval #STICKER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STICKER_ERROR_OPERATION_FAILED Operation failed + * @see sticker_consumer_event_cb() + * @see sticker_consumer_set_event_callback() + */ +int sticker_consumer_unset_event_callback(sticker_consumer_h consumer_handle); + +/** * @} */ -- 2.7.4 From 6f1b4554bc68c9c33e09ea290e09a6429bcf94c1 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Fri, 10 Apr 2020 15:06:08 +0900 Subject: [PATCH 06/16] Fix invalid pointer casting Change-Id: Ib6eec53220eb03bd4a561b62e6ab03f2cbb641d6 --- client/sticker_dbus.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/client/sticker_dbus.c b/client/sticker_dbus.c index c6aaaea..f8a4b72 100644 --- a/client/sticker_dbus.c +++ b/client/sticker_dbus.c @@ -933,7 +933,7 @@ int sticker_dbus_get_all_sticker_info(GDBusConnection *gdbus_connection, const c ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_all_sticker_info"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); - g_variant_get(reply_body, "(a(i))", &(*id_iter)); + g_variant_get(reply_body, "(a(i))", id_iter); } if (reply_body) @@ -954,7 +954,7 @@ int sticker_dbus_get_sticker_info_by_appid(GDBusConnection *gdbus_connection, co ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_sticker_info_by_appid"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); - g_variant_get(reply_body, "(a(i))", &(*id_iter)); + g_variant_get(reply_body, "(a(i))", id_iter); } if (reply_body) @@ -975,7 +975,7 @@ int sticker_dbus_get_sticker_info_by_type(GDBusConnection *gdbus_connection, con ret = _send_sync_message(gdbus_connection, g_variant_new("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_type"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); - g_variant_get(reply_body, "(a(i))", &(*id_iter)); + g_variant_get(reply_body, "(a(i))", id_iter); } if (reply_body) @@ -996,7 +996,7 @@ int sticker_dbus_get_sticker_info_by_group(GDBusConnection *gdbus_connection, co ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, group, offset, count), &reply, "get_sticker_info_by_group"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); - g_variant_get(reply_body, "(a(i))", &(*id_iter)); + g_variant_get(reply_body, "(a(i))", id_iter); } if (reply_body) @@ -1017,7 +1017,7 @@ int sticker_dbus_get_sticker_info_by_keyword(GDBusConnection *gdbus_connection, ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, keyword, offset, count), &reply, "get_sticker_info_by_keyword"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); - g_variant_get(reply_body, "(a(i))", &(*id_iter)); + g_variant_get(reply_body, "(a(i))", id_iter); } if (reply_body) @@ -1038,7 +1038,7 @@ int sticker_dbus_get_sticker_info_by_display_type(GDBusConnection *gdbus_connect ret = _send_sync_message(gdbus_connection, g_variant_new("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_disp_type"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); - g_variant_get(reply_body, "(a(i))", &(*id_iter)); + g_variant_get(reply_body, "(a(i))", id_iter); } if (reply_body) @@ -1134,7 +1134,7 @@ int sticker_dbus_get_recent_sticker_list(GDBusConnection *gdbus_connection, int ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", count), &reply, "get_recent_sticker_info"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); - g_variant_get(reply_body, "(a(i))", &(*id_iter)); + g_variant_get(reply_body, "(a(i))", id_iter); } if (reply_body) -- 2.7.4 From e5359c85b9ea99ef5c0c4530cce887742f25498c Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 9 Apr 2020 20:00:00 +0900 Subject: [PATCH 07/16] Reduce duplicated code Change-Id: I60e2527d5c3ecb325988a00f1be3ea8a7e88d4f0 Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 9288b72..34763da 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -566,6 +566,13 @@ static bool process_request_queue() return true; } +static void quit() +{ + job_progress = FALSE; + send_disconnect_message(); + service_app_exit(); +} + void on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned int payload_length, void *buffer, void *user_data) /* message exchange on_receive callback (sap_agent_data_received_cb) */ @@ -626,9 +633,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in #endif if (!process_request_queue()) { - job_progress = FALSE; - send_disconnect_message(); - service_app_exit(); + quit(); } } else if (msg_id == STICKER_SYNC_START_RSP) { LOGD("msg : %s", msg_id.c_str()); @@ -658,9 +663,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in if (result_code == SYNC_START_RSP_NO_STICKER) save_last_sync_time(); - job_progress = FALSE; - send_disconnect_message(); - service_app_exit(); + quit(); } } } else if (msg_id == STICKER_SEND_START_REQ) { @@ -782,9 +785,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in if (!process_request_queue()) { sync_success_cnt = 0; - job_progress = FALSE; - send_disconnect_message(); - service_app_exit(); + quit(); } } else LOGW("unknown msg id : %s", msg_id.c_str()); -- 2.7.4 From 76dbba6c38b81d1f9bda5c4e4a2f1ce444f6a83a Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 10 Apr 2020 13:32:03 +0900 Subject: [PATCH 08/16] Add sticker-receiver log dump feature Change-Id: Id37806ed564cc45f8b318dea4b26768d73a1017b Signed-off-by: Jihoon Kim --- dump/sticker_log_dump.sh | 15 ++++++++++++ packaging/capi-ui-sticker.spec | 4 ++++ receiver/CMakeLists.txt | 1 + receiver/inc/log.h | 34 +++++++++++++-------------- receiver/src/main.cpp | 14 ++++++++++++ receiver/src/sticker_log.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 102 insertions(+), 18 deletions(-) create mode 100755 dump/sticker_log_dump.sh create mode 100644 receiver/src/sticker_log.cpp diff --git a/dump/sticker_log_dump.sh b/dump/sticker_log_dump.sh new file mode 100755 index 0000000..2d0f875 --- /dev/null +++ b/dump/sticker_log_dump.sh @@ -0,0 +1,15 @@ +#!/bin/sh +PATH=/bin:/usr/bin:/sbin:/usr/sbin + +#-------------------------------------- +# sticker +#-------------------------------------- +STICKER_DEBUG=$1/sticker +STICKER_HOME=/opt/usr/home/owner/apps_rw/.shared/org.tizen.sticker-receiver/data/log +STICKER_DB=/opt/dbspace/.sticker_info.db +/bin/mkdir -p ${STICKER_DEBUG} +/bin/cat ${STICKER_HOME}/sticker.log > ${STICKER_DEBUG}/sticker.log +/bin/cp ${STICKER_DB}/.sticker_info.db* ${STICKER_DEBUG}/ +/bin/sync + +##UEP330x4988b0767795e32b117da2c8c810260b9f03a2808cd45af44f4584cde4d17be8149fd2921bdbcf4b0d6c08ef97453b983cb72e238c6c64b33e8286148e7b377f906f66407eec37edd6fd431d93a217109003fa0ebc99560a67954fe2910fe35a02523c131fd0ab36de45f140db756fdda71f58e1d9d46575d0c2f5453575aaa08d47e6f13a657420020353981fb8e5998b29c9af70272613dffd33a97502e51ea926a258c6de56cc21d951d28b1e44f1e33ed5a530c5dfb9a72714a56d30894f02bf98fb9cfd1521102abbf46f50d38dc079321850685808ae0fd05a22822592bec5a1883d7937d990cbd59947829ea7c2c0d43333a2f0d72d53c6bcef426bb7AAACAg==:UEP diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index faae811..eb79cd5 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -114,6 +114,9 @@ find . -name '*.gcno' -exec cp '{}' gcov-obj ';' rm -rf %{buildroot} %make_install +mkdir -p %{buildroot}/%{TZ_SYS_ETC}/dump.d/module.d +cp -af dump/sticker_log_dump.sh %{buildroot}/%{TZ_SYS_ETC}/dump.d/module.d + mkdir -p %{buildroot}%{_prefix}/lib/systemd/system install -m 0644 %SOURCE1 %{buildroot}%{_unitdir}/capi-ui-sticker.service @@ -157,6 +160,7 @@ chsmack -a "System::Shared" %{TZ_SYS_SHARE}/sticker-data %{TZ_SYS_RO_SHARE}/parser-plugins/capi-ui-sticker.info %{TZ_SYS_RO_ETC}/package-manager/parserlib/category/libcapi-ui-sticker-parser.so* %{TZ_SYS_RO_ETC}/package-manager/parserlib/metadata/libcapi-ui-sticker-parser.so* +%{TZ_SYS_ETC}/dump.d/module.d/* %files devel %manifest %{name}-devel.manifest diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt index c9f9fc4..90c3837 100644 --- a/receiver/CMakeLists.txt +++ b/receiver/CMakeLists.txt @@ -7,6 +7,7 @@ SET(SRCS src/ft.cpp src/sticker_info.cpp src/message.cpp + src/sticker_log.cpp ) INCLUDE(FindPkgConfig) diff --git a/receiver/inc/log.h b/receiver/inc/log.h index 763f6cb..43a3aa6 100644 --- a/receiver/inc/log.h +++ b/receiver/inc/log.h @@ -18,34 +18,32 @@ #define __debug_H__ #include +#include +#include #undef LOG_TAG #define LOG_TAG "STICKER_RECEIVER" -#ifndef _LOG -#define _LOG(logLevel, fmt, ...) do { \ +void sticker_save_log (const char *fmt, ...); + +#define _STICKER_RECEIVER_LOG(logLevel, fmt, ...) do { \ dlog_print(logLevel, LOG_TAG, "%s : %s(%d) > " fmt, rindex(__FILE__, '/')+1, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + sticker_save_log("pid(%d) %s : %s(%d) > " fmt, getpid(), rindex(__FILE__, '/')+1, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ } while (0) -#endif -#ifndef LOGD -#define LOGD(format, arg...) _LOG(DLOG_DEBUG, format, ##arg) -#endif +#undef LOGD +#define LOGD(format, arg...) _STICKER_RECEIVER_LOG(DLOG_DEBUG, format, ##arg) -#ifndef LOGI -#define LOGI(format, arg...) _LOG(DLOG_INFO, format, ##arg) -#endif +#undef LOGI +#define LOGI(format, arg...) _STICKER_RECEIVER_LOG(DLOG_INFO, format, ##arg) -#ifndef LOGW -#define LOGW(format, arg...) _LOG(DLOG_WARN, format, ##arg) -#endif +#undef LOGW +#define LOGW(format, arg...) _STICKER_RECEIVER_LOG(DLOG_WARN, format, ##arg) -#ifndef LOGE -#define LOGE(format, arg...) _LOG(DLOG_ERROR, format, ##arg) -#endif +#undef LOGE +#define LOGE(format, arg...) _STICKER_RECEIVER_LOG(DLOG_ERROR, format, ##arg) -#ifndef LOGF -#define LOGF(format, arg...) _LOG(DLOG_FATAL, format, ##arg) -#endif +#undef LOGF +#define LOGF(format, arg...) _STICKER_RECEIVER_LOG(DLOG_FATAL, format, ##arg) #endif /* __debug_H__ */ \ No newline at end of file diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index 2006985..0de1ef9 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -41,6 +41,20 @@ static bool app_create(void *data) LOGD(""); + char log_path[PATH_MAX]; + char *data_path = NULL; + data_path = app_get_shared_data_path(); + snprintf(log_path, sizeof(log_path), "%s/log", data_path); + + if (data_path) + free(data_path); + + if (access(log_path, F_OK) != 0) { + if (mkdir(log_path, 0755) == -1) { + LOGE("directory create error"); + } + } + return true; } diff --git a/receiver/src/sticker_log.cpp b/receiver/src/sticker_log.cpp new file mode 100644 index 0000000..8954a28 --- /dev/null +++ b/receiver/src/sticker_log.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "log.h" + +using namespace std; + +void sticker_save_log(const char *fmt, ...) +{ + char buf[4000] = {0}; + char time_buf[96] = {0}; + char full_buf[4096] = {0}; + char log_path[PATH_MAX]; + char strLogFile[PATH_MAX]; + va_list ap; + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + const time_t tt = ts.tv_sec; + const long int real_millisec = ts.tv_nsec / 1000000; + + struct tm *const ptm = localtime(&tt); + strftime(time_buf, sizeof(time_buf), "%m-%d %H:%M:%S", ptm); + + va_start(ap, fmt); + vsnprintf(buf, sizeof (buf), fmt, ap); + va_end(ap); + + snprintf(full_buf, sizeof(full_buf), "%s.%03ld %s", time_buf, real_millisec, buf); + + char *data_path = NULL; + data_path = app_get_shared_data_path(); + snprintf(log_path, sizeof(log_path), "%s/log", data_path); + + if (data_path) + free(data_path); + + snprintf(strLogFile, sizeof(strLogFile), "%s/sticker.log", log_path); + + std::ofstream sticker_log_file (strLogFile, std::ios::app); + sticker_log_file << full_buf << std::endl; + sticker_log_file.flush (); +} -- 2.7.4 From 04404d91a21104a5abe8d048a739425775475795 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 10 Apr 2020 19:36:23 +0900 Subject: [PATCH 09/16] Update package version to 0.1.32 Change-Id: I630b6ac296dcaad0ff47e7d69981091fd7ebac5e Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 2 +- receiver/tizen-manifest.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index eb79cd5..6c728fa 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.31 +Version: 0.1.32 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index cf0b55e..efed9ad 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4 From eb8901c263076a7e36eb9822fb9f595900c14aaf Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Mon, 13 Apr 2020 11:14:20 +0900 Subject: [PATCH 10/16] Remove unnecessary error logs Change-Id: Ib1333d15087741edc3155e9be7efb3312149fba7 Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 34763da..55c3f38 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -415,12 +415,10 @@ void request_all_sticker_data(const char *mode, const char *type) if (vconf_get_int(VCONFKEY_STICKER_SUPPORTED_FEATURE, &feature_flag) == 0) { if (feature_flag & VCONFKEY_STICKER_FEATURE_AREMOJI) - if (!request_sticker_data(mode, "arsticker", type)) - LOGW("Failed to request ar_sticker sync"); + request_sticker_data(mode, "arsticker", type); if (feature_flag & VCONFKEY_STICKER_FEATURE_BITMOJI) - if (!request_sticker_data(mode, "bitmoji", type)) - LOGW("Failed to request bitmoji sync"); + request_sticker_data(mode, "bitmoji", type); } else LOGW("Failed to get value of VCONFKEY_STICKER_SUPPORTED_FEATURE"); -- 2.7.4 From 483b8e05c9c4b67e26ee552defac632c109b02fc Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 10 Apr 2020 20:29:47 +0900 Subject: [PATCH 11/16] Fixed an issue sending errors during synchronization Change-Id: I24d6009d2bf039b42780ff62c0f1dcf423a0af16 Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 16 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 55c3f38..eb4e297 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -87,6 +87,7 @@ static int rec_file_cnt_in_group = 0; static int total_file_count_in_group = 0; static int sync_success_cnt = 0; static gboolean job_progress = FALSE; +static int sync_complete_flags = 0; static void save_last_sync_time() { @@ -100,7 +101,7 @@ static void save_last_sync_time() } } -static void set_sync_complete() +static void set_sync_first_complete() { int complete_flags = 0; if (vconf_get_int(VCONFKEY_STICKER_SYNC_COMPLETE, &complete_flags) == 0 && complete_flags == 0) { @@ -110,7 +111,11 @@ static void set_sync_complete() else LOGW("Fail to set sync complete"); } +} +static void set_sync_complete() +{ + set_sync_first_complete(); save_last_sync_time(); } @@ -571,6 +576,60 @@ static void quit() service_app_exit(); } +static void send_sync_start_response(int result_code) +{ + int feature_flag = 0; + string response_to_app; + switch (result_code) { + case SYNC_START_RSP_SUCCESS: + { + response_to_app = "success"; + if (current_request.category == string("arsticker")) + sync_complete_flags |= VCONFKEY_STICKER_FEATURE_AREMOJI; + else if (current_request.category == string("bitmoji")) + sync_complete_flags |= VCONFKEY_STICKER_FEATURE_BITMOJI; + } + break; + case SYNC_START_RSP_NO_STICKER: + response_to_app = "no_sticker"; + break; + default: + response_to_app = "unknown_error"; + break; + } + + LOGD("result code : %d, sync complete flag : %d", result_code, sync_complete_flags); + +#ifdef VCONFKEY_STICKER_SUPPORTED_FEATURE + if (vconf_get_int(VCONFKEY_STICKER_SUPPORTED_FEATURE, &feature_flag) != 0) + { + LOGW("Failed to read support feature"); + return; + } + + LOGD("feature : %d, current request category : %s", feature_flag, current_request.category.c_str()); + if (feature_flag == VCONFKEY_STICKER_FEATURE_AREMOJI || + feature_flag == VCONFKEY_STICKER_FEATURE_BITMOJI) + { + LOGD("only standalone sync mode"); + send_message("sync_start_response", response_to_app.c_str()); + } + else { + if (current_request.category == string("arsticker")) + { + if (result_code == SYNC_START_RSP_SUCCESS) + send_message("sync_start_response", response_to_app.c_str()); + } + else if (current_request.category == string("bitmoji")) + { + if (sync_complete_flags == 0 || + sync_complete_flags == VCONFKEY_STICKER_FEATURE_BITMOJI) + send_message("sync_start_response", response_to_app.c_str()); + } + } +#endif +} + void on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned int payload_length, void *buffer, void *user_data) /* message exchange on_receive callback (sap_agent_data_received_cb) */ @@ -640,24 +699,11 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in int result_code = json_object_get_int_member(root_obj, "resultCode"); LOGD("result : %s, resultCode : %d", result.c_str(), result_code); - string response_to_app; - switch (result_code) { - case SYNC_START_RSP_SUCCESS: - response_to_app = "success"; - break; - case SYNC_START_RSP_NO_STICKER: - response_to_app = "no_sticker"; - break; - default: - response_to_app = "unknown_error"; - break; - } - - send_message("sync_start_response", response_to_app.c_str()); + send_sync_start_response(result_code); if (result_code != SYNC_START_RSP_SUCCESS) { - set_sync_progressing(FALSE); if (!process_request_queue()) { + set_sync_progressing(FALSE); if (result_code == SYNC_START_RSP_NO_STICKER) save_last_sync_time(); -- 2.7.4 From 49de48fbff52178b3582d7912c336068da18f239 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Mon, 13 Apr 2020 14:39:36 +0900 Subject: [PATCH 12/16] Update package version to 0.1.33 Change-Id: Iccd3988c52eb94f0984f4e2996b37e0acbf9543b Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 2 +- receiver/tizen-manifest.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 6c728fa..1bfd88b 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.32 +Version: 0.1.33 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index efed9ad..624126f 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4 From a0ad6afd4cd651b848ef2b8a8c5bc9f3db6f05d4 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 13 Apr 2020 19:26:45 +0900 Subject: [PATCH 13/16] Add missing condition check code Change-Id: I736566ac02f1c70b8ae302a93228a236bb3005a9 --- server/stickerd_data_manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index 251e9c0..d82b2cf 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -767,7 +767,7 @@ int stickerd_insert_sticker_info_by_json(GVariant *parameters, GVariant **reply_ goto free_memory; sticker_info->thumbnail = _get_string_from_object(info_object, "thumbnail"); - if (sticker_info->thumbnail) { + if (sticker_info->thumbnail && sticker_info->thumbnail[0] != '\0') { if (_check_file_exist(sticker_info->app_id, sticker_info->thumbnail) == 0) { sticker_info->thumbnail = _convert_sticker_uri(sticker_info->thumbnail, sticker_info->app_id); if (!sticker_info->thumbnail) -- 2.7.4 From 32bd8d402850917ee150661c0e03a29f35ecb75e Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 13 Apr 2020 10:25:56 +0900 Subject: [PATCH 14/16] Add missing parameter to event callback Change-Id: I2fcad31c0c17dacc8703f83c82c5a574a2608ca1 --- include/sticker_consumer.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/sticker_consumer.h b/include/sticker_consumer.h index fb6985d..7231f26 100644 --- a/include/sticker_consumer.h +++ b/include/sticker_consumer.h @@ -98,13 +98,18 @@ typedef void (*sticker_consumer_keyword_list_foreach_cb)(const char *keyword, vo /** * @brief Called when the stickers are inserted, deleted, or updated. * @since_tizen 5.5 + * @remarks @a data_handle should not be freed and can be used only in the callback. + * If you want to use it outside of the callback, you need to use a clone which can be obtained sticker_data_clone(). + * When the @a event_type is STICKER_CONSUMER_EVENT_TYPE_DELETE, sticker data can be obtained using @a data_handle, + * but unable to access file because it has been deleted. * @param[in] event_type The event type of sticker + * @param[in] data_handle The sticker data handle * @param[in] user_data The user data passed from sticker_consumer_set_event_callback() * @pre The callback can be registered using sticker_consumer_set_event_callback() * @see sticker_consumer_set_event_callback() * @see sticker_consumer_unset_event_callback() */ -typedef void (*sticker_consumer_event_cb)(sticker_consumer_event_type_e event_type, void *user_data); +typedef void (*sticker_consumer_event_cb)(sticker_consumer_event_type_e event_type, sticker_data_h data_handle, void *user_data); /** * @brief Creates a sticker consumer handle. -- 2.7.4 From f31d31c3cb45b89edf4d743026b0e0c24fb52777 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 13 Apr 2020 14:24:08 +0900 Subject: [PATCH 15/16] Support the event callback to send sticker DB changes Change-Id: I43d08448b3d67794f2ea7f7ccfdd4b8a9a9d3508 --- client/sticker_dbus.c | 82 ++++++++++++++++++----- client/sticker_dbus.h | 3 +- client/sticker_defs.h | 6 ++ consumer/sticker_consumer.c | 2 +- provider/sticker_provider.c | 3 +- server/stickerd_data_manager.c | 147 +++++++++++++++++++++++++++++++++++++---- server/stickerd_data_manager.h | 1 + server/stickerd_db_manager.c | 85 ++++++++++++++++++++++++ server/stickerd_db_manager.h | 1 + server/stickerd_dbus.c | 16 ++++- server/stickerd_dbus.h | 4 +- 11 files changed, 312 insertions(+), 38 deletions(-) diff --git a/client/sticker_dbus.c b/client/sticker_dbus.c index f8a4b72..412a143 100644 --- a/client/sticker_dbus.c +++ b/client/sticker_dbus.c @@ -26,6 +26,7 @@ #define STICKER_DIRECTORY tzplatform_mkpath(TZ_SYS_SHARE, "sticker-data") static int is_server_started = 0; +static CLIENT_LIB last_req_lib = STICKER_CLIENT_LIB_NONE; static void _server_appeared_cb(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data) { @@ -74,18 +75,14 @@ static int _dbus_init(GDBusConnection **gdbus_connection) return STICKER_CLIENT_ERROR_NONE; } -static void _get_sticker_info_from_gvariant(GVariant *body, sticker_data_h sticker_data) +static void _get_sticker_info_from_gvariant(GVariantIter *info_iter, GVariantIter *keyword_iter, sticker_data_h sticker_data) { STICKER_DAT_TYPE key; GVariant *value = NULL; - GVariantIter *info_iter = NULL; - GVariantIter *keyword_iter = NULL; char *keyword = NULL; - g_variant_get(body, "(a{iv}a(s))", &info_iter, &keyword_iter); - if (!info_iter || !keyword_iter) { - LOGD("failed to get iter"); + LOGW("failed to get iter"); return; } @@ -206,6 +203,29 @@ static void _handle_sticker_consumer_cb(GDBusConnection *connection, return; } + if (g_strcmp0(signal_name, "send_sticker_changed_event") == 0) { + if (consumer_handle->event_cb != NULL) { + sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s)); + if (sticker_data) { + int event_type; + GVariantIter *info_iter = NULL; + GVariantIter *keyword_iter = NULL; + + g_variant_get(parameters, "(ia{iv}a(s))", &event_type, &info_iter, &keyword_iter); + _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data); + consumer_handle->event_cb((sticker_consumer_event_type_e)event_type, sticker_data, consumer_handle->event_cb_user_data); + + if (info_iter) + g_variant_iter_free(info_iter); + + if (keyword_iter) + g_variant_iter_free(keyword_iter); + + _free_sticker_data(sticker_data); + } + } + } + #if 0 // Receive the sticker information by asynchronous communication. if (g_strcmp0(signal_name, "send_group_list") == 0) { if (consumer_handle->group_foreach_cb != NULL) @@ -446,14 +466,13 @@ static int _send_async_message(GDBusConnection *gdbus_connection, GVariant *body return ret; } -static int _monitor_register(GDBusConnection *gdbus_connection, int *server_watcher_id) +static int _monitor_register(GDBusConnection *gdbus_connection, int *server_watcher_id, CLIENT_LIB lib) { int ret; GDBusMessage *reply = NULL; GVariant *reply_body = NULL; - ret = _send_sync_message(gdbus_connection, g_variant_new("()"), &reply, "sticker_service_register"); - + ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", (int)lib), &reply, "sticker_service_register"); if (ret != STICKER_CLIENT_ERROR_NONE) { LOGE("_send_sync_message() failed : %d", ret); return ret; @@ -476,7 +495,7 @@ static void _on_name_appeared(GDBusConnection *connection, { if (is_server_started == 0) { int *watcher_id = (int *)user_data; - _monitor_register(connection, watcher_id); + _monitor_register(connection, watcher_id, last_req_lib); } } @@ -493,6 +512,7 @@ int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data) { int ret; + last_req_lib = lib; ret = _dbus_init(gdbus_connection); if (ret != STICKER_CLIENT_ERROR_NONE) { @@ -506,7 +526,7 @@ int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id return ret; } - ret = _monitor_register(*gdbus_connection, server_watcher_id); + ret = _monitor_register(*gdbus_connection, server_watcher_id, lib); if (ret != STICKER_CLIENT_ERROR_NONE) { LOGE("_monitor_register() failed : %d", ret); return ret; @@ -532,12 +552,12 @@ int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id return STICKER_CLIENT_ERROR_NONE; } -int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id) +int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id, CLIENT_LIB lib) { int ret; if (server_watcher_id) { - ret = _send_async_message(gdbus_connection, g_variant_new("(i)", *server_watcher_id), "sticker_service_unregister"); + ret = _send_async_message(gdbus_connection, g_variant_new("(ii)", (int)lib, *server_watcher_id), "sticker_service_unregister"); if (ret != STICKER_CLIENT_ERROR_NONE) { LOGE("Failed to unregister sticker service"); return ret; @@ -663,6 +683,7 @@ int sticker_dbus_delete_sticker_info_by_uri(GDBusConnection *gdbus_connection, c int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data) { int ret; + bool is_updated = false; GDBusMessage *reply = NULL; GVariant *reply_body = NULL; sticker_data_h origin_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s)); @@ -675,7 +696,17 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "get_sticker_info"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); - _get_sticker_info_from_gvariant(reply_body, origin_data); + GVariantIter *info_iter = NULL; + GVariantIter *keyword_iter = NULL; + + g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter); + _get_sticker_info_from_gvariant(info_iter, keyword_iter, origin_data); + + if (info_iter) + g_variant_iter_free(info_iter); + + if (keyword_iter) + g_variant_iter_free(keyword_iter); } else { LOGW("failed to get sticker info"); free(origin_data); @@ -721,6 +752,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ free(conv_path); goto cleanup; } + is_updated = true; } free(conv_path); } @@ -732,6 +764,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ LOGE("failed to update sticker type"); goto cleanup; } + is_updated = true; } if (sticker_data->thumbnail) { @@ -749,6 +782,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ free(conv_path); goto cleanup; } + is_updated = true; } free(conv_path); } @@ -761,6 +795,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ LOGE("failed to update sticker description"); goto cleanup; } + is_updated = true; } if (sticker_data->group && strcmp(sticker_data->group, origin_data->group) != 0) { @@ -770,6 +805,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ LOGE("failed to update sticker group"); goto cleanup; } + is_updated = true; } if (sticker_data->disp_type != 0 && sticker_data->disp_type != origin_data->disp_type) { @@ -779,6 +815,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ LOGE("failed to update sticker display type"); goto cleanup; } + is_updated = true; } if (sticker_data->keyword) { @@ -788,9 +825,14 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ ret = _send_sync_message(gdbus_connection, g_variant_new("(ia(s))", sticker_data->sticker_info_id, keyword_builder), &reply, "update_sticker_keyword"); if (ret != STICKER_CLIENT_ERROR_NONE) LOGE("failed to update sticker keyword"); + else + is_updated = true; g_variant_builder_unref(keyword_builder); } + if (is_updated) + ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "send_update_event"); + cleanup: _free_sticker_data(origin_data); @@ -808,15 +850,25 @@ int sticker_dbus_get_sticker_info_by_record_id(GDBusConnection *gdbus_connection int ret; GDBusMessage *reply = NULL; GVariant *reply_body = NULL; + GVariantIter *info_iter = NULL; + GVariantIter *keyword_iter = NULL; ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "get_sticker_info"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); sticker_data->sticker_info_id = record_id; - _get_sticker_info_from_gvariant(reply_body, sticker_data); + + g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter); + _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data); if (reply_body) g_variant_unref(reply_body); + + if (info_iter) + g_variant_iter_free(info_iter); + + if (keyword_iter) + g_variant_iter_free(keyword_iter); } if (reply) diff --git a/client/sticker_dbus.h b/client/sticker_dbus.h index a6d5437..4115e1d 100644 --- a/client/sticker_dbus.h +++ b/client/sticker_dbus.h @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -47,7 +48,7 @@ enum sticker_client_error { int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id, int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data); -int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id); +int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id, CLIENT_LIB lib); int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data); int sticker_dbus_insert_sticker_info_by_json(GDBusConnection *gdbus_connection, const char *app_id, const char *json_path); int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int record_id); diff --git a/client/sticker_defs.h b/client/sticker_defs.h index 01cae60..69167ec 100644 --- a/client/sticker_defs.h +++ b/client/sticker_defs.h @@ -69,6 +69,12 @@ typedef enum { STICKER_DATA_TYPE_DISP_TYPE, } STICKER_DAT_TYPE; +typedef enum { + STICKER_EVENT_TYPE_INSERT, + STICKER_EVENT_TYPE_DELETE, + STICKER_EVENT_TYPE_UPDATE, +} STICKER_EVENT_TYPE; + #ifdef __cplusplus } #endif diff --git a/consumer/sticker_consumer.c b/consumer/sticker_consumer.c index 1c9de90..91de924 100644 --- a/consumer/sticker_consumer.c +++ b/consumer/sticker_consumer.c @@ -189,7 +189,7 @@ EXPORT_API int sticker_consumer_destroy(sticker_consumer_h consumer_handle) LOGD("consumer_handle : %p", consumer_handle); ret = sticker_dbus_shutdown(consumer_handle->gdbus_connection, &consumer_handle->server_watcher_id, - &consumer_handle->server_monitor_id, &consumer_handle->monitor_id); + &consumer_handle->server_monitor_id, &consumer_handle->monitor_id, STICKER_CLIENT_LIB_CONSUMER); if (ret != STICKER_ERROR_NONE) { LOGE("Failed to finalize dbus : %d", ret); free(consumer_handle); diff --git a/provider/sticker_provider.c b/provider/sticker_provider.c index 98f1005..b16db5e 100644 --- a/provider/sticker_provider.c +++ b/provider/sticker_provider.c @@ -107,7 +107,7 @@ EXPORT_API int sticker_provider_destroy(sticker_provider_h provider_handle) LOGD("provider_handle : %p", provider_handle); ret = sticker_dbus_shutdown(provider_handle->gdbus_connection, &provider_handle->server_watcher_id, - &provider_handle->server_monitor_id, &provider_handle->monitor_id); + &provider_handle->server_monitor_id, &provider_handle->monitor_id, STICKER_CLIENT_LIB_PROVIDER); if (ret != STICKER_ERROR_NONE) { LOGE("Failed to finalize dbus : %d", ret); free(provider_handle); @@ -151,7 +151,6 @@ EXPORT_API int sticker_provider_insert_data(sticker_provider_h provider_handle, else return STICKER_ERROR_OPERATION_FAILED; } - return STICKER_ERROR_NONE; } diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index d82b2cf..23c09e0 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -44,6 +44,7 @@ static GHashTable *_monitoring_hash = NULL; static char error_buffer[MAX_ERROR_BUFFER]; +static GList *consumer_list = NULL; extern GMainLoop *main_loop; static void _check_watcher_exist() @@ -52,6 +53,8 @@ static void _check_watcher_exist() LOGD("Terminate sticker daemon"); g_hash_table_destroy(_monitoring_hash); _monitoring_hash = NULL; + g_list_free_full(consumer_list, free); + consumer_list = NULL; g_main_loop_quit(main_loop); } } @@ -77,6 +80,9 @@ static void _on_name_vanished(GDBusConnection *connection, delete_monitoring_list(&_monitoring_hash, info->bus_name, info->watcher_id); } + if (g_list_find(consumer_list, info->bus_name)) + consumer_list = g_list_remove(consumer_list, info->bus_name); + if (info->bus_name) free(info->bus_name); free(info); @@ -95,14 +101,17 @@ static void _stickerd_client_dbus_method_call_handler(GDBusConnection *conn, con if (_monitoring_hash == NULL) _monitoring_hash = g_hash_table_new(g_direct_hash, g_direct_equal); + if (consumer_list == NULL) + consumer_list = g_list_alloc(); + GVariant *reply_body = NULL; int ret = STICKERD_SERVER_ERROR_OPERATION_FAILED; if (g_strcmp0(method_name, "sticker_service_register") == 0) { ret = stickerd_server_register(parameters, &reply_body, sender, - _on_name_appeared, _on_name_vanished, &_monitoring_hash); + _on_name_appeared, _on_name_vanished, &_monitoring_hash, &consumer_list); } else if (g_strcmp0(method_name, "sticker_service_unregister") == 0) { - ret = stickerd_server_unregister(parameters, &reply_body, sender, &_monitoring_hash); + ret = stickerd_server_unregister(parameters, &reply_body, sender, &_monitoring_hash, &consumer_list); } else if (g_strcmp0(method_name, "insert_sticker_info") == 0) { ret = stickerd_insert_sticker_info(parameters, &reply_body); } else if (g_strcmp0(method_name, "update_sticker_info_by_json") == 0) { @@ -153,6 +162,8 @@ static void _stickerd_client_dbus_method_call_handler(GDBusConnection *conn, con ret = stickerd_insert_recent_sticker_info(parameters, &reply_body); } else if (g_strcmp0(method_name, "get_recent_sticker_info") == 0) { ret = stickerd_get_recent_sticker_info(parameters, &reply_body); + } else if (g_strcmp0(method_name, "send_update_event") == 0) { + ret = stickerd_send_update_event(parameters, &reply_body); } if (ret == STICKERD_SERVER_ERROR_NONE) { @@ -178,10 +189,12 @@ int stickerd_register_dbus_interface(void) " " " " " " + " " " " " " " " + " " " " " " @@ -328,6 +341,10 @@ int stickerd_register_dbus_interface(void) " " " " " " + + " " + " " + " " " " " "; @@ -538,6 +555,70 @@ cleanup: } } +static void _set_keyword_builder(char *keyword, GVariantBuilder *keyword_builder) +{ + if (!keyword) { + LOGE("keyword doesn't exist"); + return; + } + + g_variant_builder_add(keyword_builder, "(s)", (const char *)keyword); +} + +static GVariant* _get_sticker_g_variant(STICKER_EVENT_TYPE type, sticker_info_db *sticker_info) +{ + GVariantBuilder *info_builder; + GVariantBuilder *keyword_builder; + + info_builder = g_variant_builder_new(G_VARIANT_TYPE("a{iv}")); + g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_APP_ID, g_variant_new_string((const gchar *)sticker_info->app_id)); + g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI_TYPE, g_variant_new_int32(sticker_info->type)); + g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI, g_variant_new_string((const gchar *)sticker_info->uri)); + g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_THUMBNAIL, g_variant_new_string((const gchar *)sticker_info->thumbnail)); + g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DESCRIPTION, g_variant_new_string((const gchar *)sticker_info->description)); + g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_GROUP, g_variant_new_string((const gchar *)sticker_info->group)); + g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DATE, g_variant_new_string((const gchar *)sticker_info->date)); + g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DISP_TYPE, g_variant_new_int32(sticker_info->display_type)); + + keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)")); + g_list_foreach(sticker_info->keyword, (GFunc) _set_keyword_builder, keyword_builder); + + GVariant *body = g_variant_new("(ia{iv}a(s))", (int)type, info_builder, keyword_builder); + g_variant_builder_unref(info_builder); + g_variant_builder_unref(keyword_builder); + + if (body) + return body; + else + return NULL; +} + +void _get_consumer_busname(gpointer data, gpointer user_data) +{ + if (data == NULL) + return; + + int ret; + char *cmd = "send_sticker_changed_event"; + char *sender = (char *)data; + GVariant *body = (GVariant *)user_data; + + ret = stickerd_send_dbus_message(body, sender, cmd, STICKER_CLIENT_LIB_CONSUMER); + if (ret != STICKERD_SERVER_ERROR_NONE) + LOGE("Failed to send sticker changed event"); +} + +static void _send_sticker_changed_event(STICKER_EVENT_TYPE type, sticker_info_db *sticker_info) +{ + GVariant *body = _get_sticker_g_variant(type, sticker_info); + + if (body) + g_list_foreach(consumer_list, _get_consumer_busname, body); + + if (body) + g_variant_unref(body); +} + int stickerd_insert_sticker_info(GVariant *parameters, GVariant **reply_body) { int ret; @@ -635,7 +716,8 @@ int stickerd_insert_sticker_info(GVariant *parameters, GVariant **reply_body) if (*reply_body == NULL) { LOGE("Failed to create reply_body"); ret = STICKERD_SERVER_ERROR_OPERATION_FAILED; - } + } else + _send_sticker_changed_event(STICKER_EVENT_TYPE_INSERT, sticker_info); cleanup: if (value) @@ -794,7 +876,8 @@ int stickerd_insert_sticker_info_by_json(GVariant *parameters, GVariant **reply_ if (ret != STICKERD_SERVER_ERROR_NONE) { LOGE("Failed to insert sticker info"); ret = STICKERD_SERVER_ERROR_OPERATION_FAILED; - } + } else + _send_sticker_changed_event(STICKER_EVENT_TYPE_INSERT, sticker_info); free_memory: free(sticker_info); @@ -833,10 +916,20 @@ int stickerd_del_sticker_info(GVariant *parameters, GVariant **reply_body) g_variant_get(parameters, "(i)", &record_id); + sticker_info_db *sticker_info = (sticker_info_db *)calloc(1, sizeof(sticker_info_db)); + if (sticker_info) + stickerd_db_get_sticker_info_by_record_id(record_id, sticker_info); + ret = stickerd_db_delete_sticker_info(record_id); if (ret != STICKERD_SERVER_ERROR_NONE) { LOGE("Failed to delete sticker info"); return STICKERD_SERVER_ERROR_OPERATION_FAILED; + } else { + if (sticker_info && sticker_info->uri) { + _send_sticker_changed_event(STICKER_EVENT_TYPE_DELETE, sticker_info); + free(sticker_info); + sticker_info = NULL; + } } return ret; @@ -855,10 +948,20 @@ int stickerd_del_sticker_info_by_uri(GVariant *parameters, GVariant **reply_body g_variant_get(parameters, "(&s)", &uri); + sticker_info_db *sticker_info = (sticker_info_db *)calloc(1, sizeof(sticker_info_db)); + if (sticker_info) + stickerd_db_get_sticker_info_by_uri(uri, sticker_info); + ret = stickerd_db_delete_sticker_info_by_uri(uri); if (ret != STICKERD_SERVER_ERROR_NONE) { LOGE("Failed to delete sticker info"); return STICKERD_SERVER_ERROR_OPERATION_FAILED; + } else { + if (sticker_info && sticker_info->uri) { + _send_sticker_changed_event(STICKER_EVENT_TYPE_DELETE, sticker_info); + free(sticker_info); + sticker_info = NULL; + } } return ret; @@ -1040,16 +1143,6 @@ int stickerd_update_sticker_keyword(GVariant *parameters, GVariant **reply_body) return ret; } -static void _set_keyword_builder(char *keyword, GVariantBuilder *keyword_builder) -{ - if (!keyword) { - LOGE("keyword doesn't exist"); - return; - } - - g_variant_builder_add(keyword_builder, "(s)", (const char *)keyword); -} - int stickerd_get_sticker_info(GVariant *parameters, GVariant **reply_body) { int ret; @@ -1628,4 +1721,30 @@ int stickerd_get_recent_sticker_info(GVariant *parameters, GVariant **reply_body g_variant_builder_unref(id_builder); return ret; +} + +int stickerd_send_update_event(GVariant *parameters, GVariant **reply_body) +{ + int ret = STICKERD_SERVER_ERROR_NONE; + int record_id; + + *reply_body = g_variant_new("()"); + if (*reply_body == NULL) { + LOGE("Failed to create reply_body"); + return STICKERD_SERVER_ERROR_OPERATION_FAILED; + } + + g_variant_get(parameters, "(i)", &record_id); + + sticker_info_db *sticker_info = (sticker_info_db *)calloc(1, sizeof(sticker_info_db)); + if (sticker_info) { + ret = stickerd_db_get_sticker_info_by_record_id(record_id, sticker_info); + if (ret == STICKERD_SERVER_ERROR_NONE) { + _send_sticker_changed_event(STICKER_EVENT_TYPE_UPDATE, sticker_info); + free(sticker_info); + sticker_info = NULL; + } + } + + return ret; } \ No newline at end of file diff --git a/server/stickerd_data_manager.h b/server/stickerd_data_manager.h index ea90752..6b54c68 100644 --- a/server/stickerd_data_manager.h +++ b/server/stickerd_data_manager.h @@ -50,6 +50,7 @@ int stickerd_update_sticker_disp_type(GVariant *parameters, GVariant **reply_bod int stickerd_check_file_exists(GVariant *parameters, GVariant **reply_body); int stickerd_insert_recent_sticker_info(GVariant *parameters, GVariant **reply_body); int stickerd_get_recent_sticker_info(GVariant *parameters, GVariant **reply_body); +int stickerd_send_update_event(GVariant *parameters, GVariant **reply_body); #ifdef __cplusplus } diff --git a/server/stickerd_db_manager.c b/server/stickerd_db_manager.c index 9536c65..ecf8f33 100644 --- a/server/stickerd_db_manager.c +++ b/server/stickerd_db_manager.c @@ -100,6 +100,7 @@ #define STICKER_DB_CHECK_FILE_EXISTS "SELECT EXISTS(SELECT 1 FROM sticker_info WHERE uri = ? LIMIT 1)" #define STICKER_DB_CHECK_RECENT_HISTORY_EXISTS "SELECT EXISTS(SELECT 1 FROM sticker_recent_history_info WHERE sticker_info_id = ? LIMIT 1)" #define STICKER_DB_GET_RECENT_HISTORY "SELECT sticker_info_id FROM sticker_recent_history_info ORDER BY datetime(timestamp) DESC LIMIT ?" +#define STICKER_DB_GET_STICKER_INFO_BY_URI "SELECT * FROM sticker_info WHERE uri = ?" typedef enum { @@ -1004,4 +1005,88 @@ cleanup: sqlite3_close(db); return STICKERD_SERVER_ERROR_DB_FAILED; +} + +int stickerd_db_get_sticker_info_by_uri(char *uri, sticker_info_db *sticker_info) +{ + int ret; + int record_id; + sqlite3 *db = NULL; + sqlite3_stmt *stmt = NULL; + + db = _db_open(); + if (!db) + return STICKERD_SERVER_ERROR_DB_FAILED; + + ret = sqlite3_prepare_v2(db, STICKER_DB_GET_STICKER_INFO_BY_URI, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + LOGE("fail to get sticker information : %s", sqlite3_errmsg(db)); + goto cleanup; + } + + sqlite3_bind_text(stmt, 1, uri, -1, SQLITE_TRANSIENT); + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ERROR) { + LOGE("sqlite3_step() failed : ret(%d)", ret); + goto cleanup; + } + + record_id = sticker_info->display_type = sqlite3_column_int(stmt, 0); + + const unsigned char *tmp_app_id = sqlite3_column_text(stmt, 1); + if (tmp_app_id) + sticker_info->app_id = strdup((const char *)tmp_app_id); + + sticker_info->type = sqlite3_column_int(stmt, 2); + + const unsigned char *tmp_uri = sqlite3_column_text(stmt, 3); + if (tmp_uri) + sticker_info->uri = strdup((const char *)tmp_uri); + + const unsigned char *tmp_thumbnail = sqlite3_column_text(stmt, 4); + if (tmp_thumbnail) + sticker_info->thumbnail = strdup((const char *)tmp_thumbnail); + + const unsigned char *tmp_description = sqlite3_column_text(stmt, 5); + if (tmp_description) + sticker_info->description = strdup((const char *)tmp_description); + + const unsigned char *tmp_group = sqlite3_column_text(stmt, 6); + if (tmp_group) + sticker_info->group = strdup((const char *)tmp_group); + + const unsigned char *tmp_date = sqlite3_column_text(stmt, 7); + if (tmp_date) + sticker_info->date = strdup((const char *)tmp_date); + + sticker_info->display_type = sqlite3_column_int(stmt, 8); + + sqlite3_finalize(stmt); + stmt = NULL; + + ret = sqlite3_prepare_v2(db, STICKER_DB_GET_KEYWORD_INFO_BY_RECORD_ID, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + LOGE("fail to get sticker keyword : %s", sqlite3_errmsg(db)); + goto cleanup; + } + + sqlite3_bind_int(stmt, 1, record_id); + + while (sqlite3_step(stmt) == SQLITE_ROW) { + const unsigned char *keyword = sqlite3_column_text(stmt, 0); + if (keyword) + sticker_info->keyword = g_list_append(sticker_info->keyword, strdup((const char *)keyword)); + } + + sqlite3_finalize(stmt); + sqlite3_close(db); + + return STICKERD_SERVER_ERROR_NONE; + +cleanup: + sqlite3_finalize(stmt); + sqlite3_close(db); + + return STICKERD_SERVER_ERROR_DB_FAILED; } \ No newline at end of file diff --git a/server/stickerd_db_manager.h b/server/stickerd_db_manager.h index 38e13b5..83bf132 100644 --- a/server/stickerd_db_manager.h +++ b/server/stickerd_db_manager.h @@ -62,6 +62,7 @@ int stickerd_db_get_record_id(sticker_info_db_type type, GList **id_list, void * int stickerd_db_get_group_list_by_display_type(GVariantBuilder *builder, char *app_id, int disp_type); int stickerd_db_check_file_exists(int *result, char *uri); int stickerd_db_insert_recent_sticker_info(int record_id); +int stickerd_db_get_sticker_info_by_uri(char *uri, sticker_info_db *sticker_info); #ifdef __cplusplus } diff --git a/server/stickerd_dbus.c b/server/stickerd_dbus.c index 6184033..d125daf 100644 --- a/server/stickerd_dbus.c +++ b/server/stickerd_dbus.c @@ -32,13 +32,16 @@ static GDBusConnection *_gdbus_connection; extern GMainLoop *main_loop; int stickerd_server_register(GVariant *parameters, GVariant **reply_body, const gchar *sender, GBusNameAppearedCallback name_appeared_handler, - GBusNameVanishedCallback name_vanished_handler, GHashTable **monitoring_hash) + GBusNameVanishedCallback name_vanished_handler, GHashTable **monitoring_hash, GList **consumer_list) { int ret = STICKERD_SERVER_ERROR_NONE; char *m_info_bus_name = NULL; char *list_bus_name = NULL; monitoring_info_s *m_info = NULL; GList *monitoring_list = NULL; + int c_lib; + + g_variant_get(parameters, "(i)", &c_lib); if (reply_body == NULL) return STICKERD_SERVER_ERROR_INVALID_PARAMETER; @@ -80,6 +83,9 @@ int stickerd_server_register(GVariant *parameters, GVariant **reply_body, const goto cleanup; } + if ((CLIENT_LIB)c_lib == STICKER_CLIENT_LIB_CONSUMER) + *consumer_list = g_list_append(*consumer_list, strdup((const char *)sender)); + LOGD("sender: %s, watcher: %d", sender, m_info->watcher_id); monitoring_list = g_list_append(monitoring_list, list_bus_name); if (g_hash_table_lookup(*monitoring_hash, GUINT_TO_POINTER(m_info->watcher_id)) == NULL) @@ -104,11 +110,15 @@ cleanup: return ret; } -int stickerd_server_unregister(GVariant *parameters, GVariant **reply_body, const gchar *sender, GHashTable **monitoring_hash) +int stickerd_server_unregister(GVariant *parameters, GVariant **reply_body, const gchar *sender, GHashTable **monitoring_hash, GList **consumer_list) { int watcher_id = 0; + int c_lib; + + g_variant_get(parameters, "(ii)", &c_lib, &watcher_id); - g_variant_get(parameters, "(i)", &watcher_id); + if ((CLIENT_LIB)c_lib == STICKER_CLIENT_LIB_CONSUMER) + *consumer_list = g_list_remove(*consumer_list, sender); if (g_hash_table_lookup(*monitoring_hash, GUINT_TO_POINTER(watcher_id)) != NULL) { g_bus_unwatch_name(watcher_id); diff --git a/server/stickerd_dbus.h b/server/stickerd_dbus.h index e8ad143..2f684ae 100644 --- a/server/stickerd_dbus.h +++ b/server/stickerd_dbus.h @@ -31,8 +31,8 @@ typedef struct monitoring_info { } monitoring_info_s; int stickerd_server_register(GVariant *parameters, GVariant **reply_body, const gchar *sender, GBusNameAppearedCallback name_appeared_handler, - GBusNameVanishedCallback name_vanished_handler, GHashTable **monitoring_hash); -int stickerd_server_unregister(GVariant *parameters, GVariant **reply_body, const gchar *sender, GHashTable **monitoring_hash); + GBusNameVanishedCallback name_vanished_handler, GHashTable **monitoring_hash, GList **consumer_list); +int stickerd_server_unregister(GVariant *parameters, GVariant **reply_body, const gchar *sender, GHashTable **monitoring_hash, GList **consumer_list); int stickerd_server_register_dbus_interface(char *introspection_xml, GDBusInterfaceVTable interface_vtable); int delete_monitoring_list(GHashTable **monitoring_hash, const char *sender, int monitoring_id); int stickerd_send_dbus_message(GVariant *body, const char *dest, char *cmd, CLIENT_LIB lib); -- 2.7.4 From 39e1a8004a118977a91af8aaed7b3c717bf6db36 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Tue, 14 Apr 2020 13:59:18 +0900 Subject: [PATCH 16/16] Update package version to 0.1.34 Change-Id: Ic4db1fc0d5cb8389b728b7d3cc88985eaa596bcf --- packaging/capi-ui-sticker.spec | 2 +- receiver/tizen-manifest.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 1bfd88b..4df16d5 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.33 +Version: 0.1.34 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index 624126f..124cd9c 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4