From: InHong Han Date: Mon, 16 Mar 2020 05:17:17 +0000 (+0900) Subject: Add a new API for retrieving stickers using display type X-Git-Tag: accepted/tizen/5.5/unified/20200324.134509~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d91a4a4056f29be1c68762203ccc488396adf1a4;p=platform%2Fcore%2Fuifw%2Fcapi-ui-sticker.git Add a new API for retrieving stickers using display type Change-Id: I05445d437cd89fc134da3063681fe09425937cd4 --- diff --git a/client/sticker_dbus.c b/client/sticker_dbus.c index 7bf48bf..a5190f6 100644 --- a/client/sticker_dbus.c +++ b/client/sticker_dbus.c @@ -947,4 +947,25 @@ int sticker_dbus_get_sticker_info_by_keyword(GDBusConnection *gdbus_connection, g_object_unref(reply); return ret; +} + +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 ret; + GDBusMessage *reply = NULL; + GVariant *reply_body = NULL; + + 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)); + } + + 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 52dcd02..f29d8ea 100644 --- a/client/sticker_dbus.h +++ b/client/sticker_dbus.h @@ -58,6 +58,7 @@ int sticker_dbus_get_sticker_info_by_appid(GDBusConnection *gdbus_connection, co int sticker_dbus_get_sticker_info_by_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_uri_type_e type, int offset, int count, GVariantIter **id_iter); int sticker_dbus_get_sticker_info_by_group(GDBusConnection *gdbus_connection, const char *app_id, const char *group, int offset, int count, GVariantIter **id_iter); int sticker_dbus_get_sticker_info_by_keyword(GDBusConnection *gdbus_connection, const char *app_id, const char *keyword, int offset, int count, GVariantIter **id_iter); +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); #ifdef __cplusplus } diff --git a/consumer/sticker_consumer.c b/consumer/sticker_consumer.c index aa760de..0734de1 100644 --- a/consumer/sticker_consumer.c +++ b/consumer/sticker_consumer.c @@ -367,7 +367,7 @@ EXPORT_API int sticker_consumer_data_foreach_by_type(sticker_consumer_h consumer ret = sticker_dbus_get_sticker_info_by_type(consumer_handle->gdbus_connection, consumer_handle->app_id, type, offset, count, &id_iter); if (ret != STICKER_ERROR_NONE) { - LOGE("Failed to get sticker information by group : %d", ret); + LOGE("Failed to get sticker information by uri type : %d", ret); ret = STICKER_ERROR_OPERATION_FAILED; goto cleanup; } @@ -456,3 +456,51 @@ cleanup: return ret; } + +EXPORT_API int sticker_consumer_data_foreach_by_display_type(sticker_consumer_h consumer_handle, int offset, int count, int *result, sticker_data_display_type_e type, 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 || (offset < 0) || (count <= 0) || !result || (type < 1) || !callback) + return STICKER_ERROR_INVALID_PARAMETER; + + ret = sticker_dbus_get_sticker_info_by_display_type(consumer_handle->gdbus_connection, consumer_handle->app_id, type, offset, count, &id_iter); + if (ret != STICKER_ERROR_NONE) { + LOGE("Failed to get sticker information by display type : %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 5b55d7d..f7d7533 100644 --- a/include/sticker_consumer.h +++ b/include/sticker_consumer.h @@ -239,6 +239,29 @@ int sticker_consumer_group_list_foreach_all(sticker_consumer_h consumer_handle, int sticker_consumer_keyword_list_foreach_all(sticker_consumer_h consumer_handle, sticker_consumer_keyword_list_foreach_cb callback, void *user_data); /** + * @brief Retrieves all sticker data in the sticker database using display type. + * @details If you set the @a offset as @c 10 and @a count as @c 10, then only retrieved data from @c 10 to @c 19 will be invoked. + * @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] offset The start position (Starting from zero) + * @param[in] count The number of stickers to be retrieved with respect to the offset + * @param[out] result The number of stickers retrieved (zero indicates that no data was found) + * @param[in] type The display type of the sticker for getting sticker data + * @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() + */ +int sticker_consumer_data_foreach_by_display_type(sticker_consumer_h consumer_handle, int offset, int count, int *result, sticker_data_display_type_e type, sticker_consumer_data_foreach_cb callback, void *user_data); + +/** * @} */ diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index 07f667a..4b1e479 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -139,6 +139,8 @@ static void _stickerd_client_dbus_method_call_handler(GDBusConnection *conn, con ret = stickerd_get_sticker_info_by_group(parameters, &reply_body); } else if (g_strcmp0(method_name, "get_sticker_info_by_keyword") == 0) { ret = stickerd_get_sticker_info_by_keyword(parameters, &reply_body); + } else if (g_strcmp0(method_name, "get_sticker_info_by_disp_type") == 0) { + ret = stickerd_get_sticker_info_by_display_type(parameters, &reply_body); } if (ret == STICKERD_SERVER_ERROR_NONE) { @@ -276,6 +278,14 @@ int stickerd_register_dbus_interface(void) " " " " " " + + " " + " " + " " + " " + " " + " " + " " " " " "; @@ -1351,3 +1361,39 @@ int stickerd_get_sticker_info_by_keyword(GVariant *parameters, GVariant **reply_ return ret; } + +int stickerd_get_sticker_info_by_display_type(GVariant *parameters, GVariant **reply_body) +{ + int ret; + GList *id_list = NULL; + char *app_id = NULL; + int type, offset, count; + GVariantBuilder *id_builder = NULL; + + g_variant_get(parameters, "(&siii)", &app_id, &type, &offset, &count); + + ret = stickerd_db_get_record_id(STICKER_DB_STICKER_DISP_TYPE, &id_list, &type, app_id, offset, count); + if (ret != STICKERD_SERVER_ERROR_NONE) { + LOGE("Failed to get all 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 8086dcb..246d616 100644 --- a/server/stickerd_data_manager.h +++ b/server/stickerd_data_manager.h @@ -43,6 +43,7 @@ int stickerd_get_sticker_info_by_app_id(GVariant *parameters, GVariant **reply_b int stickerd_get_sticker_info_by_type(GVariant *parameters, GVariant **reply_body); int stickerd_get_sticker_info_by_group(GVariant *parameters, GVariant **reply_body); int stickerd_get_sticker_info_by_keyword(GVariant *parameters, GVariant **reply_body); +int stickerd_get_sticker_info_by_display_type(GVariant *parameters, GVariant **reply_body); #ifdef __cplusplus } diff --git a/server/stickerd_db_manager.c b/server/stickerd_db_manager.c index e0d1a1b..dcbf279 100644 --- a/server/stickerd_db_manager.c +++ b/server/stickerd_db_manager.c @@ -81,6 +81,7 @@ #define STICKER_DB_GET_RECORD_ID_BY_TYPE "SELECT sticker_info_id FROM sticker_info WHERE 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_RECORD_ID_BY_GROUP "SELECT sticker_info_id from sticker_info WHERE group_name = ? 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_RECORD_ID_BY_KEYWORD "SELECT sticker_info_id FROM sticker_keyword_info WHERE keyword = ? INTERSECT SELECT sticker_info_id from sticker_info WHERE 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_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 ?, ?" typedef enum { @@ -135,6 +136,9 @@ static const char *_db_get_query(sticker_info_db_type sticker_type, command_type case STICKER_DB_STICKER_KEYWORD: query = STICKER_DB_GET_RECORD_ID_BY_KEYWORD; break; + case STICKER_DB_STICKER_DISP_TYPE: + query = STICKER_DB_GET_RECORD_ID_BY_DISP_TYPE; + break; default : query = ""; break; @@ -705,7 +709,7 @@ int stickerd_db_get_record_id(sticker_info_db_type type, GList **id_list, void * sqlite3_bind_int(stmt, 2, offset); sqlite3_bind_int(stmt, 3, count); } else { - if (type == STICKER_DB_STICKER_TYPE) + if (type == STICKER_DB_STICKER_TYPE || type == STICKER_DB_STICKER_DISP_TYPE) sqlite3_bind_int(stmt, 1, *(int *)data); else sqlite3_bind_text(stmt, 1, (char *)data, -1, SQLITE_TRANSIENT); diff --git a/server/stickerd_db_manager.h b/server/stickerd_db_manager.h index 9b87f81..51953bb 100644 --- a/server/stickerd_db_manager.h +++ b/server/stickerd_db_manager.h @@ -33,6 +33,7 @@ typedef enum { STICKER_DB_STICKER_DESCRIPTION, STICKER_DB_STICKER_GROUP, STICKER_DB_STICKER_KEYWORD, + STICKER_DB_STICKER_DISP_TYPE, } sticker_info_db_type; typedef struct {