From 0e7c92077e14d8fff12384077db979b33611927f Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 12 Mar 2020 21:25:57 +0900 Subject: [PATCH 01/16] Update package version to 0.1.21 Change-Id: I27e93064365f1c900e470cae8005c07461566733 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 c562a85..cedf01b 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.20 +Version: 0.1.21 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index cbd4cfe..db360d0 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4 From b7bb55fa84f79bf5696df1f48169d201fcc404b3 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Wed, 11 Mar 2020 19:43:43 +0900 Subject: [PATCH 02/16] Remove temporary code to handle wrong member name in json Change-Id: I6cfaefb93eaa51ff0fd0f784f124295ceeda4b42 Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 4e26d73..7e8926b 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -495,9 +495,6 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in JsonObject *file_obj = json_array_get_object_element(file_list, i); int file_len = json_object_get_int_member(file_obj, "size"); const char *json_filename = json_object_get_string_member(file_obj, "fileName"); - if (!json_filename) { - json_filename = json_object_get_string_member(file_obj, "filename"); - } string file_name = string(json_filename ? json_filename : ""); if (file_len > 0) { -- 2.7.4 From cea833b0fd6219441950055b3782a29b4f30de4d Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 13 Mar 2020 16:44:04 +0900 Subject: [PATCH 03/16] Remove unused code Change-Id: I3498174ececa2b2f0f14accbd63298d02f549e4f Signed-off-by: Jihoon Kim --- receiver/inc/ft.h | 1 - receiver/src/ft.cpp | 5 ----- 2 files changed, 6 deletions(-) diff --git a/receiver/inc/ft.h b/receiver/inc/ft.h index c6cbb63..a95204c 100644 --- a/receiver/inc/ft.h +++ b/receiver/inc/ft.h @@ -29,7 +29,6 @@ void accept_file(void); gboolean initialize_sap(void); void deinitialize_sap(void); -void sap_file_transfer_get_receive_filepath(char **filepath); void request_sticker_data(const char *mode, const char *category, const char *type); void request_sticker_feature(); diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 7e8926b..02ee53f 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -286,11 +286,6 @@ void accept_file() file_on_progress = 1; } -void sap_file_transfer_get_receive_filepath(char **filepath) -{ - *filepath = strdup(sticker_data.file_path.c_str()); -} - void request_sticker_data(const char *mode, const char *category, const char *type) { JsonObject *j_object = json_object_new(); -- 2.7.4 From 853ebb4e2fdf7641a07540403b28ec9d31640e42 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Tue, 17 Mar 2020 17:48:02 +0900 Subject: [PATCH 04/16] Add boilerplate Change-Id: I9ef5ed62a4461b34cb38c5bc302a24d2d0bb58cf Signed-off-by: Jihoon Kim --- receiver/inc/log.h | 15 +++++++++++++++ receiver/inc/main.h | 15 +++++++++++++++ receiver/inc/sticker_info.h | 15 +++++++++++++++ receiver/src/main.cpp | 15 +++++++++++++++ receiver/src/sticker_info.cpp | 15 +++++++++++++++ 5 files changed, 75 insertions(+) diff --git a/receiver/inc/log.h b/receiver/inc/log.h index 3749cad..07ee738 100644 --- a/receiver/inc/log.h +++ b/receiver/inc/log.h @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef __debug_H__ #define __debug_H__ diff --git a/receiver/inc/main.h b/receiver/inc/main.h index b6fac02..e32a820 100644 --- a/receiver/inc/main.h +++ b/receiver/inc/main.h @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include #include #include diff --git a/receiver/inc/sticker_info.h b/receiver/inc/sticker_info.h index bda6616..86b6c88 100644 --- a/receiver/inc/sticker_info.h +++ b/receiver/inc/sticker_info.h @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef __STICKER_INFO_H__ #define __STICKER_INFO_H__ diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index 3799557..9968b91 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include #include #include diff --git a/receiver/src/sticker_info.cpp b/receiver/src/sticker_info.cpp index 1ac2247..89aedfb 100644 --- a/receiver/src/sticker_info.cpp +++ b/receiver/src/sticker_info.cpp @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include "sticker_info.h" #include #include -- 2.7.4 From 1811c4ec1666ad81d786195238416a2cfb742566 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Tue, 17 Mar 2020 19:03:04 +0900 Subject: [PATCH 05/16] Terminate sticker-receiver after sending result Change-Id: I27f5f04e2cc964cfcc29925800f6d47070f051a5 Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 02ee53f..f471b55 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -60,8 +60,7 @@ typedef enum { enum { SYNC_START_RSP_SUCCESS = 1000, - SYNC_START_RSP_NO_STICKER = 1001, - SYNC_START_RSP_EXIST_STICKER = 1002 + SYNC_START_RSP_NO_STICKER = 1001 }; struct sap_info_s { @@ -466,7 +465,6 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in string response_to_app; switch (result_code) { case SYNC_START_RSP_SUCCESS: - case SYNC_START_RSP_EXIST_STICKER: response_to_app = "success"; break; case SYNC_START_RSP_NO_STICKER: @@ -478,6 +476,9 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in } send_message("sync_start_response", response_to_app.c_str()); + + if (result_code != SYNC_START_RSP_SUCCESS) + service_app_exit(); } else if (msg_id == STICKER_SEND_START_REQ) { LOGD("msg : %s", msg_id.c_str()); total_file_count = 0; @@ -586,6 +587,8 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in current_request.mode.clear(); current_request.category.clear(); current_request.type.clear(); + + service_app_exit(); } else LOGW("unknown msg id : %s", msg_id.c_str()); -- 2.7.4 From a5b9e3c2154ac5673199a866cd0a3b5db48569f8 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Tue, 17 Mar 2020 19:10:17 +0900 Subject: [PATCH 06/16] Fix json parsing error due to trailing trash character Change-Id: I3bce228b55b0ef16828783f15e3bc1c89af78dfa Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index f471b55..3f56506 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -406,7 +406,8 @@ 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) */ { - LOGI("received data: %s, len:%d", (char *)buffer, payload_length); + unsigned int buf_len = strlen((char *)buffer); + LOGI("received data: %s, len: %d, buffer len : %d", (char *)buffer, payload_length, buf_len); JsonParser *parser = json_parser_new(); GError *err_msg = NULL; @@ -415,7 +416,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in string msg_id; const char *json_msgid = NULL; - json_parser_load_from_data(parser, (char *)buffer, -1, &err_msg); + json_parser_load_from_data(parser, (char *)buffer, payload_length, &err_msg); if (err_msg) { LOGE("failed to load json file. error message: %s", err_msg->message); goto cleanup; -- 2.7.4 From dfd48fd5ee154781ce88b2c1e3f575a40ff8b89b Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Tue, 17 Mar 2020 20:04:03 +0900 Subject: [PATCH 07/16] Add vconf define temporarily Change-Id: I2d63113a8523ca0dbebb3d93e001568023a6078d Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 3f56506..9d42623 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -51,6 +51,16 @@ #define STICKER_SEND_STOP_REQ "sticker-send-stop-req" #define STICKER_SEND_STOP_RSP "sticker-send-stop-rsp" +#ifndef VCONFKEY_STICKER_SUPPORTED_FEATURE +#define VCONFKEY_STICKER_SUPPORTED_FEATURE "db/sticker/supported_feature" + +enum { + VCONFKEY_STICKER_FEATURE_NONE = 0x00, + VCONFKEY_STICKER_FEATURE_AREMOJI = 0x01, + VCONFKEY_STICKER_FEATURE_BITMOJI = 0x02 +}; +#endif + using namespace std; typedef enum { -- 2.7.4 From 918c619c21da07219f8be47554ca118a9d47f62e Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Tue, 17 Mar 2020 19:52:18 +0900 Subject: [PATCH 08/16] Update package version to 0.1.22 Change-Id: Iafe24998ee5ac3fff6a12734e8b7ac44e5b7a1e9 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 cedf01b..d36c513 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.21 +Version: 0.1.22 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index db360d0..6726d6d 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4 From 1103a02281292296c671363d44fc13fffd9003c8 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Wed, 18 Mar 2020 09:43:06 +0900 Subject: [PATCH 09/16] Revert "Add vconf define temporarily" This reverts commit dfd48fd5ee154781ce88b2c1e3f575a40ff8b89b. Change-Id: Ifd945d7e422ea73ffeaed176d44c5177d3aa962b --- receiver/src/ft.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 9d42623..3f56506 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -51,16 +51,6 @@ #define STICKER_SEND_STOP_REQ "sticker-send-stop-req" #define STICKER_SEND_STOP_RSP "sticker-send-stop-rsp" -#ifndef VCONFKEY_STICKER_SUPPORTED_FEATURE -#define VCONFKEY_STICKER_SUPPORTED_FEATURE "db/sticker/supported_feature" - -enum { - VCONFKEY_STICKER_FEATURE_NONE = 0x00, - VCONFKEY_STICKER_FEATURE_AREMOJI = 0x01, - VCONFKEY_STICKER_FEATURE_BITMOJI = 0x02 -}; -#endif - using namespace std; typedef enum { -- 2.7.4 From 9416b763017a9617c334efd5f0e11a32ef920b47 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Wed, 18 Mar 2020 09:52:12 +0900 Subject: [PATCH 10/16] Avoid build error due to vconf key Change-Id: I496e4a871fa9bf571b10fd9cd233e2e7b8b16637 Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 3f56506..61afdc0 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -438,6 +438,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in msg_id = string(json_msgid ? json_msgid : ""); if (msg_id == STICKER_SYNC_FEATURE_RSP) { LOGD("msg : %s", msg_id.c_str()); +#ifdef VCONFKEY_STICKER_SUPPORTED_FEATURE const char *json_aremoji = json_object_get_string_member(root_obj, "arEmoji"); const char *json_bitmoji = json_object_get_string_member(root_obj, "bitmoji"); string support_aremoji = string(json_aremoji ? json_aremoji : ""); @@ -454,6 +455,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in LOGD("Succeed to set supported feature"); else LOGW("Fail to set supported feature"); +#endif service_app_exit(); } else if (msg_id == STICKER_SYNC_START_RSP) { -- 2.7.4 From 050335661a4f1c10681d66c895b8219817057699 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Fri, 13 Mar 2020 09:52:19 +0900 Subject: [PATCH 11/16] Support display_type Change-Id: I84a9ee0230c8d0da38236edde726eb74abcd66a8 --- client/sticker_data.c | 26 ++++++++++++++++++++++++++ client/sticker_data_main.h | 1 + client/sticker_dbus.c | 4 ++++ client/sticker_defs.h | 1 + include/sticker_data.h | 37 +++++++++++++++++++++++++++++++++++++ include/sticker_provider.h | 10 ++++++---- server/stickerd_data_manager.c | 5 +++++ server/stickerd_db_manager.c | 17 ++++++++++------- server/stickerd_db_manager.h | 1 + sticker-parser/sticker-parser.c | 14 ++++++++------ 10 files changed, 99 insertions(+), 17 deletions(-) diff --git a/client/sticker_data.c b/client/sticker_data.c index decbfe3..b76e7a8 100644 --- a/client/sticker_data.c +++ b/client/sticker_data.c @@ -208,6 +208,8 @@ EXPORT_API int sticker_data_clone(sticker_data_h origin_handle, sticker_data_h * if (origin_handle->date) handle->date = strdup(origin_handle->date); + handle->disp_type = origin_handle->disp_type; + *target_handle = handle; return STICKER_ERROR_NONE; @@ -444,3 +446,27 @@ EXPORT_API int sticker_data_get_date(sticker_data_h data_handle, char **date) return STICKER_ERROR_NONE; } + +EXPORT_API int sticker_data_set_display_type(sticker_data_h data_handle, sticker_data_display_type_e type) +{ + CHECK_STICKER_FEATURE(); + + if (!data_handle || !type || type < STICKER_DATA_DISP_EMOJI || type > STICKER_DATA_DISP_WALLPAPER) + return STICKER_ERROR_INVALID_PARAMETER; + + data_handle->disp_type = type; + + return STICKER_ERROR_NONE; +} + +EXPORT_API int sticker_data_get_display_type(sticker_data_h data_handle, sticker_data_display_type_e *type) +{ + CHECK_STICKER_FEATURE(); + + if (!data_handle || !type) + return STICKER_ERROR_INVALID_PARAMETER; + + *type = data_handle->disp_type; + + return STICKER_ERROR_NONE; +} \ No newline at end of file diff --git a/client/sticker_data_main.h b/client/sticker_data_main.h index 058de9c..463216e 100644 --- a/client/sticker_data_main.h +++ b/client/sticker_data_main.h @@ -39,6 +39,7 @@ struct sticker_data_s{ char *group; char *description; char *date; + sticker_data_display_type_e disp_type; }; #ifdef __cplusplus diff --git a/client/sticker_dbus.c b/client/sticker_dbus.c index debfc5f..7bf48bf 100644 --- a/client/sticker_dbus.c +++ b/client/sticker_dbus.c @@ -110,6 +110,9 @@ static void _get_sticker_info_from_gvariant(GVariant *body, sticker_data_h stick case STICKER_DATA_TYPE_DATE: sticker_data->date = g_variant_dup_string(value, NULL); break; + case STICKER_DATA_TYPE_DISP_TYPE: + sticker_data->disp_type = g_variant_get_int32(value); + break; default: break; } @@ -585,6 +588,7 @@ int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_ if (sticker_data->description) g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DESCRIPTION, g_variant_new_string((const gchar *)sticker_data->description)); g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_GROUP, g_variant_new_string((const gchar *)sticker_data->group)); + g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DISP_TYPE, g_variant_new_int32(sticker_data->disp_type)); keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)")); g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder); diff --git a/client/sticker_defs.h b/client/sticker_defs.h index ce56260..01cae60 100644 --- a/client/sticker_defs.h +++ b/client/sticker_defs.h @@ -66,6 +66,7 @@ typedef enum { STICKER_DATA_TYPE_GROUP, STICKER_DATA_TYPE_KEYWORD, STICKER_DATA_TYPE_DATE, + STICKER_DATA_TYPE_DISP_TYPE, } STICKER_DAT_TYPE; #ifdef __cplusplus diff --git a/include/sticker_data.h b/include/sticker_data.h index 16c8753..fc1f8c3 100644 --- a/include/sticker_data.h +++ b/include/sticker_data.h @@ -44,6 +44,16 @@ typedef enum { } sticker_data_uri_type_e; /** + * @brief Enumeration for sticker display type. + * + * @since_tizen 5.5 + */ +typedef enum { + STICKER_DATA_DISP_EMOJI = 1, /**< Emoji type */ + STICKER_DATA_DISP_WALLPAPER, /**< Wallpaper type */ +} sticker_data_display_type_e; + +/** * @brief The sticker data handle. * @since_tizen 5.5 */ @@ -304,6 +314,33 @@ int sticker_data_get_description(sticker_data_h data_handle, char **description) int sticker_data_get_date(sticker_data_h data_handle, char **date); /** + * @brief Sets the display type of the sticker. + * @since_tizen 5.5 + * @param[in] data_handle The sticker data handle + * @param[in] type The display type to be saved + * @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 + * @see sticker_data_get_display_type() + */ +int sticker_data_set_display_type(sticker_data_h data_handle, sticker_data_display_type_e type); + +/** + * @brief Gets the display type from sticker data handle. + * @details If the display type is empty, the result will be a zero. + * @since_tizen 5.5 + * @param[in] data_handle The sticker data handle + * @param[out] type The display type of the sticker + * @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 + * @see sticker_data_set_display_type() + */ +int sticker_data_get_display_type(sticker_data_h data_handle, sticker_data_display_type_e *type); + +/** * @} */ diff --git a/include/sticker_provider.h b/include/sticker_provider.h index 8ab7758..6ea0234 100644 --- a/include/sticker_provider.h +++ b/include/sticker_provider.h @@ -97,7 +97,7 @@ int sticker_provider_destroy(sticker_provider_h provider_handle); /** * @brief Inserts a sticker data to the sticker database. * @since_tizen 5.5 - * @remarks All data except thumbnail and description must be set in the @a data_handle to insert the sticker data. + * @remarks All data except thumbnail, description, display_type must be set in the @a data_handle to insert the sticker data. * If the uri type is #STICKER_DATA_URI_LOCAL_PATH, the sticker file is copied to a sticker directory. * It is recommended to delete your sticker file after inserting a sticker data. * @param[in] provider_handle The sticker provider handle @@ -116,7 +116,7 @@ int sticker_provider_insert_data(sticker_provider_h provider_handle, sticker_dat * @brief Inserts a sticker data using json file. * @details @a json_path must be a relative path like '/data/message_sticker.json'. * @since_tizen 5.5 - * @remarks All data except thumbnail and description must be set in the json file to insert the sticker data. + * @remarks All data except thumbnail, description, display_type must be set in the json file to insert the sticker data. * @a json_path must have a non-null value and must be an existing file. If not, the error as invalid parameter will be returned. * If the uri type is #STICKER_DATA_URI_LOCAL_PATH, the sticker file is copied to a sticker directory. * It is recommended to delete your sticker files after inserting a sticker data. @@ -143,7 +143,8 @@ int sticker_provider_insert_data(sticker_provider_h provider_handle, sticker_dat "keyword" : ["heart eyes", "love", "cute"], "group" : "face", "thumbnail" : "/res/face/thumbnail/heart_eyes.png", - "description" : "Smiling face with heart eyes emoji." + "description" : "Smiling face with heart eyes emoji.", + "display_type" : 1 }, { "type" : 2, @@ -151,7 +152,8 @@ int sticker_provider_insert_data(sticker_provider_h provider_handle, sticker_dat "keyword" : ["smile", "high five"], "group" : "face", "thumbnail" : "", - "description" : "Smiling face with high five emoji." + "description" : "Smiling face with high five emoji.", + "display_type" : null }, ..... { diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index f0dc8d2..07f667a 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -531,6 +531,8 @@ int stickerd_insert_sticker_info(GVariant *parameters, GVariant **reply_body) case STICKER_DATA_TYPE_GROUP: sticker_info->group = (char *) g_variant_get_string(value, NULL); break; + case STICKER_DATA_TYPE_DISP_TYPE: + sticker_info->display_type = g_variant_get_int32(value); default: break; } @@ -701,6 +703,8 @@ int stickerd_insert_sticker_info_by_json(GVariant *parameters, GVariant **reply_ sticker_info->description = _get_string_from_object(info_object, "description"); + sticker_info->display_type = _get_int_from_object(info_object, "display_type"); + JsonArray *keyword_arr = json_object_get_array_member(info_object, "keyword"); int keyword_arr_len = json_array_get_length(keyword_arr); if (keyword_arr_len < 1) @@ -986,6 +990,7 @@ int stickerd_get_sticker_info(GVariant *parameters, GVariant **reply_body) 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); diff --git a/server/stickerd_db_manager.c b/server/stickerd_db_manager.c index ab68092..e0d1a1b 100644 --- a/server/stickerd_db_manager.c +++ b/server/stickerd_db_manager.c @@ -31,11 +31,11 @@ * Table Information * * sticker_info - * +-----------------+--------+------+------+-----------+-------------+------------+------+ - * | INT | TEXT | INT | TEXT | TEXT | TEXT | TEXT | TEXT | - * +-----------------+--------+------+------+-----------+-------------+------------+------+ - * | sticker_info_id | app_id | type | uri | thumbnail | description | group_name | date | - * +-----------------+--------+------+------+-----------+-------------+------------+------+ + * +-----------------+--------+------+------+-----------+-------------+------------+------+--------------+ + * | INT | TEXT | INT | TEXT | TEXT | TEXT | TEXT | TEXT | INT | + * +-----------------+--------+------+------+-----------+-------------+------------+------+--------------+ + * | sticker_info_id | app_id | type | uri | thumbnail | description | group_name | date | display_type | + * +-----------------+--------+------+------+-----------+-------------+------------+------+--------------+ * * sticker_keyword_info * +------------+-----------------+---------+ @@ -54,11 +54,11 @@ */ #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)" +#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_DB_INSERT_STICKER_INFO "INSERT INTO sticker_info (app_id, type, uri, thumbnail, description, group_name, date) VALUES (?, ?, ?, ?, ?, ?, DateTime('now','localtime'))" +#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_DELETE_STICKER_INFO "DELETE FROM sticker_info WHERE sticker_info_id = ?" @@ -311,6 +311,7 @@ int stickerd_db_insert_sticker_info(int *record_id, sticker_info_db *sticker_inf sqlite3_bind_text(stmt, 4, sticker_info->thumbnail, -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 5, sticker_info->description, -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 6, sticker_info->group, -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 7, sticker_info->display_type); ret = sqlite3_step(stmt); if (ret != SQLITE_OK && ret != SQLITE_DONE) { @@ -541,6 +542,8 @@ int stickerd_db_get_sticker_info_by_record_id(int record_id, sticker_info_db *st 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; diff --git a/server/stickerd_db_manager.h b/server/stickerd_db_manager.h index b2ff9bb..9b87f81 100644 --- a/server/stickerd_db_manager.h +++ b/server/stickerd_db_manager.h @@ -44,6 +44,7 @@ typedef struct { char *group; GList *keyword; char *date; + int display_type; } sticker_info_db; int stickerd_db_init(void); diff --git a/sticker-parser/sticker-parser.c b/sticker-parser/sticker-parser.c index 11e7e91..6910d6b 100644 --- a/sticker-parser/sticker-parser.c +++ b/sticker-parser/sticker-parser.c @@ -41,7 +41,7 @@ #define LOG_TAG "STICKER_PARSER" #define STICKER_DIRECTORY tzplatform_mkpath(TZ_SYS_SHARE, "sticker-data") -#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)" +#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 UIFW_ID 502 @@ -405,7 +405,7 @@ cleanup: } } -static void __insert_sticker_info(const char *app_id, int type, const char *uri, const char *group, const char *thumbnail, const char *description) +static void __insert_sticker_info(const char *app_id, int type, const char *uri, const char *group, const char *thumbnail, const char *description, int disp_type) { int ret; sqlite3 *db = NULL; @@ -417,7 +417,7 @@ static void __insert_sticker_info(const char *app_id, int type, const char *uri, if (!db) return; - ret = sqlite3_prepare_v2(db, "INSERT INTO sticker_info (app_id, type, uri, thumbnail, description, group_name, date) VALUES (?, ?, ?, ?, ?, ?, DateTime('now','localtime'))",-1, &stmt, NULL); + ret = sqlite3_prepare_v2(db, "INSERT INTO sticker_info (app_id, type, uri, thumbnail, description, group_name, date, display_type) VALUES (?, ?, ?, ?, ?, ?, DateTime('now','localtime'), ?)",-1, &stmt, NULL); if (ret == SQLITE_OK) { sqlite3_bind_text(stmt, 1, app_id, -1, SQLITE_TRANSIENT); sqlite3_bind_int(stmt, 2, type); @@ -425,6 +425,7 @@ static void __insert_sticker_info(const char *app_id, int type, const char *uri, sqlite3_bind_text(stmt, 4, thumbnail, -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 5, description, -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 6, group, -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 7, disp_type); ret = sqlite3_step(stmt); if (ret != SQLITE_OK && ret != SQLITE_DONE) @@ -599,6 +600,7 @@ static int __get_sticker_info_from_json(const char *appid, const char *file_path thumbnail = __get_string_from_object(info_object, "thumbnail"); description = __get_string_from_object(info_object, "description"); + int disp_type = __get_int_from_object(info_object, "display_type"); JsonArray *keyword_arr = json_object_get_array_member(info_object, "keyword"); int keyword_arr_len = json_array_get_length(keyword_arr); @@ -610,7 +612,7 @@ static int __get_sticker_info_from_json(const char *appid, const char *file_path char *new_uri = __convert_sticker_uri(uri, appid, app_path); if (!new_uri) goto free_memory; - __insert_sticker_info(appid, type, new_uri, group, thumbnail, description); + __insert_sticker_info(appid, type, new_uri, group, thumbnail, description, disp_type); if (new_uri) { free(new_uri); @@ -636,7 +638,7 @@ static int __get_sticker_info_from_json(const char *appid, const char *file_path uri_path = NULL; goto free_memory; } - __insert_sticker_info(appid, type, new_uri, group, thumbnail, description); + __insert_sticker_info(appid, type, new_uri, group, thumbnail, description, disp_type); free(new_uri); new_uri = NULL; @@ -651,7 +653,7 @@ static int __get_sticker_info_from_json(const char *appid, const char *file_path } } } else { - __insert_sticker_info(appid, type, uri, group, thumbnail, description); + __insert_sticker_info(appid, type, uri, group, thumbnail, description, disp_type); } for (int j = 0; j < keyword_arr_len; j++) { -- 2.7.4 From d91a4a4056f29be1c68762203ccc488396adf1a4 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 16 Mar 2020 14:17:17 +0900 Subject: [PATCH 12/16] Add a new API for retrieving stickers using display type Change-Id: I05445d437cd89fc134da3063681fe09425937cd4 --- client/sticker_dbus.c | 21 ++++++++++++++++++ client/sticker_dbus.h | 1 + consumer/sticker_consumer.c | 50 +++++++++++++++++++++++++++++++++++++++++- include/sticker_consumer.h | 23 +++++++++++++++++++ server/stickerd_data_manager.c | 46 ++++++++++++++++++++++++++++++++++++++ server/stickerd_data_manager.h | 1 + server/stickerd_db_manager.c | 6 ++++- server/stickerd_db_manager.h | 1 + 8 files changed, 147 insertions(+), 2 deletions(-) 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 { -- 2.7.4 From f5c7d980281eef0eb91c1f3ba5b9991e848e19fa Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 16 Mar 2020 17:15:11 +0900 Subject: [PATCH 13/16] Add a new API for retrieving group list using display type Change-Id: Ib6f92eff0014daad1b427e4e8a194dc4d9a54cf7 --- client/sticker_dbus.c | 39 +++++++++++++++++++++++++++++++++++++++ client/sticker_dbus.h | 1 + consumer/sticker_consumer.c | 28 ++++++++++++++++++++++++++++ include/sticker_consumer.h | 17 +++++++++++++++++ server/stickerd_data_manager.c | 36 ++++++++++++++++++++++++++++++++++++ server/stickerd_data_manager.h | 1 + server/stickerd_db_manager.c | 38 ++++++++++++++++++++++++++++++++++++++ server/stickerd_db_manager.h | 1 + 8 files changed, 161 insertions(+) diff --git a/client/sticker_dbus.c b/client/sticker_dbus.c index a5190f6..cef8b8c 100644 --- a/client/sticker_dbus.c +++ b/client/sticker_dbus.c @@ -968,4 +968,43 @@ int sticker_dbus_get_sticker_info_by_display_type(GDBusConnection *gdbus_connect g_object_unref(reply); return ret; +} + +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 ret; + GDBusMessage *reply = NULL; + GVariantIter *iter = NULL; + GVariant *reply_body = NULL; + char *group = NULL; + + if (group_list == NULL) { + LOGE("group_list is invalid"); + return STICKER_CLIENT_ERROR_INVALID_PARAMETER; + } + + ret = _send_sync_message(gdbus_connection, g_variant_new("(si)", app_id, (int)type), &reply, "get_group_list_by_disp_type"); + if (ret == STICKER_CLIENT_ERROR_NONE) { + reply_body = g_dbus_message_get_body(reply); + g_variant_get(reply_body, "(a(s))", &iter); + + if (!iter) { + LOGD("failed to get iter"); + return STICKER_CLIENT_ERROR_OPERATION_FAILED; + } + + while (g_variant_iter_loop (iter, "(s)", &group)) { + *group_list = g_list_append(*group_list, strdup((const char *)group)); + } + + g_variant_iter_free(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 f29d8ea..4ef7234 100644 --- a/client/sticker_dbus.h +++ b/client/sticker_dbus.h @@ -59,6 +59,7 @@ int sticker_dbus_get_sticker_info_by_type(GDBusConnection *gdbus_connection, con 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); +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); #ifdef __cplusplus } diff --git a/consumer/sticker_consumer.c b/consumer/sticker_consumer.c index 0734de1..5211f36 100644 --- a/consumer/sticker_consumer.c +++ b/consumer/sticker_consumer.c @@ -503,4 +503,32 @@ cleanup: g_variant_iter_free(id_iter); return ret; +} + +EXPORT_API 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) +{ + CHECK_STICKER_FEATURE(); + + int ret; + GList *list = NULL; + + if (!consumer_handle || (type < 1) || !callback) + return STICKER_ERROR_INVALID_PARAMETER; + + ret = sticker_dbus_get_group_list_by_display_type(consumer_handle->gdbus_connection, consumer_handle->app_id, type, &list); + if (ret != STICKER_ERROR_NONE) { + LOGE("Failed to get group list : %d", ret); + ret = STICKER_ERROR_OPERATION_FAILED; + goto cleanup; + } + + for(GList *tmp = g_list_first(list); tmp != NULL; tmp=tmp->next) { + callback((const char *)tmp->data, user_data); + } + +cleanup: + if (list) + g_list_free_full(list, free); + + return ret; } \ No newline at end of file diff --git a/include/sticker_consumer.h b/include/sticker_consumer.h index f7d7533..ac2428e 100644 --- a/include/sticker_consumer.h +++ b/include/sticker_consumer.h @@ -262,6 +262,23 @@ int sticker_consumer_keyword_list_foreach_all(sticker_consumer_h consumer_handle 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); /** + * @brief Retrieves all group name in the sticker database using display type. + * @since_tizen 5.5 + * @param[in] consumer_handle The sticker consumer handle + * @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_OPERATION_FAILED Operation failed + * @post This function invokes sticker_consumer_group_list_foreach_cb() repeatedly for getting data. + * @see sticker_consumer_group_list_foreach_cb() + */ +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); + +/** * @} */ diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index 4b1e479..9b344d4 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -141,6 +141,8 @@ static void _stickerd_client_dbus_method_call_handler(GDBusConnection *conn, con 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); + } else if (g_strcmp0(method_name, "get_group_list_by_disp_type") == 0) { + ret = stickerd_get_group_list_by_disp_type(parameters, &reply_body); } if (ret == STICKERD_SERVER_ERROR_NONE) { @@ -286,6 +288,12 @@ int stickerd_register_dbus_interface(void) " " " " " " + + " " + " " + " " + " " + " " " " " "; @@ -1396,4 +1404,32 @@ int stickerd_get_sticker_info_by_display_type(GVariant *parameters, GVariant **r g_variant_builder_unref(id_builder); return ret; +} + +int stickerd_get_group_list_by_disp_type(GVariant *parameters, GVariant **reply_body) +{ + int ret; + GVariantBuilder *builder = NULL; + char *app_id = NULL; + int disp_type; + + g_variant_get(parameters, "(&si)", &app_id, &disp_type); + + builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)")); + ret = stickerd_db_get_group_list_by_display_type(builder, app_id, disp_type); + if (ret != STICKERD_SERVER_ERROR_NONE) { + LOGE("Failed to get sticker group list"); + g_variant_builder_unref(builder); + return STICKERD_SERVER_ERROR_OPERATION_FAILED; + } + + *reply_body = g_variant_new("(a(s))", builder); + g_variant_builder_unref(builder); + + if (*reply_body == NULL) { + LOGE("Failed to create reply_body"); + return STICKERD_SERVER_ERROR_OPERATION_FAILED; + } + + return ret; } \ No newline at end of file diff --git a/server/stickerd_data_manager.h b/server/stickerd_data_manager.h index 246d616..0c4c979 100644 --- a/server/stickerd_data_manager.h +++ b/server/stickerd_data_manager.h @@ -44,6 +44,7 @@ int stickerd_get_sticker_info_by_type(GVariant *parameters, GVariant **reply_bod 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); +int stickerd_get_group_list_by_disp_type(GVariant *parameters, GVariant **reply_body); #ifdef __cplusplus } diff --git a/server/stickerd_db_manager.c b/server/stickerd_db_manager.c index dcbf279..bc172e2 100644 --- a/server/stickerd_db_manager.c +++ b/server/stickerd_db_manager.c @@ -82,6 +82,7 @@ #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 ?, ?" +#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 = ?))" typedef enum { @@ -735,4 +736,41 @@ cleanup: sqlite3_close(db); return STICKERD_SERVER_ERROR_DB_FAILED; +} + +int stickerd_db_get_group_list_by_display_type(GVariantBuilder *builder, char *app_id, int disp_type) +{ + 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_GET_GROUP_LIST_BY_DISP_TYPE, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + LOGE("fail to get group list : %s", sqlite3_errmsg(db)); + goto cleanup; + } + + sqlite3_bind_int(stmt, 1, disp_type); + sqlite3_bind_text(stmt, 2, app_id, -1, SQLITE_TRANSIENT); + + while (sqlite3_step(stmt) == SQLITE_ROW) { + const unsigned char *group = sqlite3_column_text(stmt, 0); + if (group) + g_variant_builder_add(builder, "(s)", strdup((const char *)group)); + } + + 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 51953bb..2ef2fd5 100644 --- a/server/stickerd_db_manager.h +++ b/server/stickerd_db_manager.h @@ -57,6 +57,7 @@ int stickerd_db_get_group_list(GVariantBuilder *builder, char *app_id); int stickerd_db_get_keyword_list(GVariantBuilder *builder, char *app_id); 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); #ifdef __cplusplus } -- 2.7.4 From 41ef7c1f28f248b4cb015c7df6f32104b8408c75 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 16 Mar 2020 19:29:11 +0900 Subject: [PATCH 14/16] Add interface to update sticker display type Change-Id: I34f96920bc8acb6aab9c76395732dfa084297e8c --- client/sticker_dbus.c | 7 +++++++ server/stickerd_data_manager.c | 30 ++++++++++++++++++++++++++++++ server/stickerd_data_manager.h | 1 + server/stickerd_db_manager.c | 6 +++++- 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/client/sticker_dbus.c b/client/sticker_dbus.c index cef8b8c..242e978 100644 --- a/client/sticker_dbus.c +++ b/client/sticker_dbus.c @@ -702,6 +702,13 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ LOGE("failed to update sticker group"); } + if (sticker_data->disp_type != 0 && sticker_data->disp_type != origin_data->disp_type) { + LOGD("origin_disp_type : %d, new_disp_type : %d", origin_data->disp_type, sticker_data->disp_type); + ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->disp_type), &reply, "update_sticker_disp_type"); + if (ret != STICKER_CLIENT_ERROR_NONE) + LOGE("failed to update sticker display type"); + } + if (sticker_data->keyword) { GVariantBuilder *keyword_builder; keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)")); diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index 9b344d4..414fc12 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -143,6 +143,8 @@ static void _stickerd_client_dbus_method_call_handler(GDBusConnection *conn, con ret = stickerd_get_sticker_info_by_display_type(parameters, &reply_body); } else if (g_strcmp0(method_name, "get_group_list_by_disp_type") == 0) { ret = stickerd_get_group_list_by_disp_type(parameters, &reply_body); + } else if (g_strcmp0(method_name, "update_sticker_disp_type") == 0) { + ret = stickerd_update_sticker_disp_type(parameters, &reply_body); } if (ret == STICKERD_SERVER_ERROR_NONE) { @@ -294,6 +296,11 @@ int stickerd_register_dbus_interface(void) " " " " " " + + " " + " " + " " + " " " " " "; @@ -1432,4 +1439,27 @@ int stickerd_get_group_list_by_disp_type(GVariant *parameters, GVariant **reply_ } return ret; +} + +int stickerd_update_sticker_disp_type(GVariant *parameters, GVariant **reply_body) +{ + int ret; + int record_id; + int disp_type; + + *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, "(ii)", &record_id, &disp_type); + + ret = stickerd_db_update_sticker_info(record_id, STICKER_DB_STICKER_DISP_TYPE, &disp_type); + if (ret != STICKERD_SERVER_ERROR_NONE) { + LOGE("Failed to update sticker disp_type"); + return STICKERD_SERVER_ERROR_OPERATION_FAILED; + } + + return ret; } \ No newline at end of file diff --git a/server/stickerd_data_manager.h b/server/stickerd_data_manager.h index 0c4c979..e8e3a9e 100644 --- a/server/stickerd_data_manager.h +++ b/server/stickerd_data_manager.h @@ -45,6 +45,7 @@ int stickerd_get_sticker_info_by_group(GVariant *parameters, GVariant **reply_bo 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); int stickerd_get_group_list_by_disp_type(GVariant *parameters, GVariant **reply_body); +int stickerd_update_sticker_disp_type(GVariant *parameters, GVariant **reply_body); #ifdef __cplusplus } diff --git a/server/stickerd_db_manager.c b/server/stickerd_db_manager.c index bc172e2..3b54fb4 100644 --- a/server/stickerd_db_manager.c +++ b/server/stickerd_db_manager.c @@ -69,6 +69,7 @@ #define STICKER_DB_UPDATE_STICKER_THUMBNAIL "UPDATE sticker_info SET thumbnail = ?, date = DateTime('now','localtime') WHERE sticker_info_id = ?" #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_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 = ?" @@ -116,6 +117,9 @@ static const char *_db_get_query(sticker_info_db_type sticker_type, command_type case STICKER_DB_STICKER_KEYWORD: query = STICKER_DB_DELETE_STICKER_KEYWORD_INFO; break; + case STICKER_DB_STICKER_DISP_TYPE: + query = STICKER_DB_UPDATE_STICKER_DISP_TYPE; + break; default : query = ""; break; @@ -438,7 +442,7 @@ int stickerd_db_update_sticker_info(int record_id, sticker_info_db_type type, vo goto cleanup; } - 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 if (type == STICKER_DB_STICKER_KEYWORD) { sqlite3_bind_int(stmt, 1, record_id); -- 2.7.4 From b6a60aea32fb77a347eeee9be430b444f2c2a8f5 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 16 Mar 2020 19:53:59 +0900 Subject: [PATCH 15/16] Add error codes Change-Id: Ibdde0b8c7ed6f1068bc80ccb950e05e3b0925d50 --- client/sticker_data.c | 10 +++++----- client/sticker_dbus.c | 37 +++++++++++++++++++++++++------------ client/sticker_dbus.h | 3 +++ include/sticker_data.h | 11 +++++------ include/sticker_error.h | 3 +++ include/sticker_provider.h | 4 ++++ provider/sticker_provider.c | 14 ++++++++++++-- server/stickerd_data_manager.c | 10 +++++++--- server/stickerd_error.h | 4 +++- 9 files changed, 67 insertions(+), 29 deletions(-) diff --git a/client/sticker_data.c b/client/sticker_data.c index b76e7a8..555a23a 100644 --- a/client/sticker_data.c +++ b/client/sticker_data.c @@ -223,7 +223,7 @@ EXPORT_API int sticker_data_get_app_id(sticker_data_h data_handle, char **app_id return STICKER_ERROR_INVALID_PARAMETER; if (!data_handle->app_id) - return STICKER_ERROR_OPERATION_FAILED; + return STICKER_ERROR_NO_DATA; *app_id = strdup(data_handle->app_id); @@ -268,7 +268,7 @@ EXPORT_API int sticker_data_get_uri(sticker_data_h data_handle, sticker_data_uri return STICKER_ERROR_INVALID_PARAMETER; if (!data_handle->type || !data_handle->uri) - return STICKER_ERROR_OPERATION_FAILED; + return STICKER_ERROR_NO_DATA; *type = data_handle->type; *uri = strdup(data_handle->uri); @@ -284,7 +284,7 @@ EXPORT_API int sticker_data_foreach_keyword(sticker_data_h data_handle, sticker_ return STICKER_ERROR_INVALID_PARAMETER; if (!data_handle->keyword) - return STICKER_ERROR_OPERATION_FAILED; + return STICKER_ERROR_NO_DATA; GList *list = NULL; for(list = g_list_first(data_handle->keyword); list != NULL; list=list->next) { @@ -357,7 +357,7 @@ EXPORT_API int sticker_data_get_group_name(sticker_data_h data_handle, char **gr return STICKER_ERROR_INVALID_PARAMETER; if (!data_handle->group) - return STICKER_ERROR_OPERATION_FAILED; + return STICKER_ERROR_NO_DATA; *group = strdup(data_handle->group); @@ -440,7 +440,7 @@ EXPORT_API int sticker_data_get_date(sticker_data_h data_handle, char **date) return STICKER_ERROR_INVALID_PARAMETER; if (!data_handle->date) - return STICKER_ERROR_OPERATION_FAILED; + return STICKER_ERROR_NO_DATA; *date = strdup(data_handle->date); diff --git a/client/sticker_dbus.c b/client/sticker_dbus.c index 242e978..8902922 100644 --- a/client/sticker_dbus.c +++ b/client/sticker_dbus.c @@ -667,46 +667,58 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ return ret; } - if (sticker_data->type != 0 && sticker_data->type != origin_data->type) { - LOGD("origin_type : %d, new_type : %d", origin_data->type, sticker_data->type); - ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->type), &reply, "update_sticker_type"); - if (ret != STICKER_CLIENT_ERROR_NONE) - LOGE("failed to update sticker type"); - } - if (sticker_data->uri && strcmp(sticker_data->uri, origin_data->uri) != 0) { LOGD("origin_uri : %s, new_uri : %s", origin_data->uri, sticker_data->uri); ret = _send_sync_message(gdbus_connection, g_variant_new("(isis)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->type, sticker_data->uri), &reply, "update_sticker_uri"); - if (ret != STICKER_CLIENT_ERROR_NONE) + if (ret != STICKER_CLIENT_ERROR_NONE) { LOGE("failed to update sticker uri"); + goto cleanup; + } + } + + if (sticker_data->type != 0 && sticker_data->type != origin_data->type) { + LOGD("origin_type : %d, new_type : %d", origin_data->type, sticker_data->type); + ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->type), &reply, "update_sticker_type"); + if (ret != STICKER_CLIENT_ERROR_NONE) { + LOGE("failed to update sticker type"); + goto cleanup; + } } if (sticker_data->thumbnail && strcmp(sticker_data->thumbnail, origin_data->thumbnail) != 0) { LOGD("origin_thumbnail : %s, new_thumbnail : %s", origin_data->thumbnail, sticker_data->thumbnail); ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->thumbnail), &reply, "update_sticker_thumbnail"); - if (ret != STICKER_CLIENT_ERROR_NONE) + if (ret != STICKER_CLIENT_ERROR_NONE) { LOGE("failed to update sticker thumbnail"); + goto cleanup; + } } if (sticker_data->description && strcmp(sticker_data->description, origin_data->description) != 0) { LOGD("origin_description : %s, new_description : %s", origin_data->description, sticker_data->description); ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->description), &reply, "update_sticker_description"); - if (ret != STICKER_CLIENT_ERROR_NONE) + if (ret != STICKER_CLIENT_ERROR_NONE) { LOGE("failed to update sticker description"); + goto cleanup; + } } if (sticker_data->group && strcmp(sticker_data->group, origin_data->group) != 0) { LOGD("origin_group : %s, new_group : %s", origin_data->group, sticker_data->group); ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->group), &reply, "update_sticker_group"); - if (ret != STICKER_CLIENT_ERROR_NONE) + if (ret != STICKER_CLIENT_ERROR_NONE) { LOGE("failed to update sticker group"); + goto cleanup; + } } if (sticker_data->disp_type != 0 && sticker_data->disp_type != origin_data->disp_type) { LOGD("origin_disp_type : %d, new_disp_type : %d", origin_data->disp_type, sticker_data->disp_type); ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->disp_type), &reply, "update_sticker_disp_type"); - if (ret != STICKER_CLIENT_ERROR_NONE) + if (ret != STICKER_CLIENT_ERROR_NONE) { LOGE("failed to update sticker display type"); + goto cleanup; + } } if (sticker_data->keyword) { @@ -719,6 +731,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ g_variant_builder_unref(keyword_builder); } +cleanup: _free_sticker_data(origin_data); if (reply_body) diff --git a/client/sticker_dbus.h b/client/sticker_dbus.h index 4ef7234..7640435 100644 --- a/client/sticker_dbus.h +++ b/client/sticker_dbus.h @@ -40,6 +40,9 @@ enum sticker_client_error { STICKER_CLIENT_ERROR_SERVICE_NOT_READY, STICKER_CLIENT_ERROR_OPERATION_FAILED, STICKER_CLIENT_ERROR_IO_ERROR, + STICKER_CLIENT_ERROR_DB_FAILED, + STICKER_CLIENT_ERROR_FILE_EXISTS, + STICKER_CLIENT_ERROR_NO_SUCH_FILE, }; int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id, diff --git a/include/sticker_data.h b/include/sticker_data.h index fc1f8c3..e27197c 100644 --- a/include/sticker_data.h +++ b/include/sticker_data.h @@ -123,7 +123,7 @@ int sticker_data_clone(sticker_data_h origin_handle, sticker_data_h *target_hand * @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 + * @retval #STICKER_ERROR_NO_DATA No data available */ int sticker_data_get_app_id(sticker_data_h data_handle, char **app_id); @@ -139,7 +139,6 @@ int sticker_data_get_app_id(sticker_data_h data_handle, char **app_id); * @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_data_get_uri() */ int sticker_data_set_uri(sticker_data_h data_handle, sticker_data_uri_type_e type, const char *uri); @@ -155,7 +154,7 @@ int sticker_data_set_uri(sticker_data_h data_handle, sticker_data_uri_type_e typ * @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 + * @retval #STICKER_ERROR_NO_DATA No data available * @see sticker_data_set_uri() */ int sticker_data_get_uri(sticker_data_h data_handle, sticker_data_uri_type_e *type, char **uri); @@ -170,7 +169,7 @@ int sticker_data_get_uri(sticker_data_h data_handle, sticker_data_uri_type_e *ty * @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 + * @retval #STICKER_ERROR_NO_DATA No data available * @post This function invokes sticker_data_keyword_foreach_cb() repeatedly for getting keywords. * @see sticker_data_keyword_foreach_cb() * @see sticker_data_add_keyword() @@ -234,7 +233,7 @@ int sticker_data_set_group_name(sticker_data_h data_handle, const char *group); * @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 + * @retval #STICKER_ERROR_NO_DATA No data available * @see sticker_data_set_group() */ int sticker_data_get_group_name(sticker_data_h data_handle, char **group); @@ -309,7 +308,7 @@ int sticker_data_get_description(sticker_data_h data_handle, char **description) * @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 + * @retval #STICKER_ERROR_NO_DATA No data available */ int sticker_data_get_date(sticker_data_h data_handle, char **date); diff --git a/include/sticker_error.h b/include/sticker_error.h index a38b9c6..fea1302 100644 --- a/include/sticker_error.h +++ b/include/sticker_error.h @@ -45,6 +45,9 @@ typedef enum { STICKER_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ STICKER_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ STICKER_ERROR_OPERATION_FAILED = TIZEN_ERROR_STICKER | 0x0001, /**< Operation failed */ + STICKER_ERROR_FILE_EXISTS = TIZEN_ERROR_FILE_EXISTS, /**< File exists */ + STICKER_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No data available */ + STICKER_ERROR_NO_SUCH_FILE = TIZEN_ERROR_FILE_EXISTS, /**< No such file */ } sticker_error_e; /** diff --git a/include/sticker_provider.h b/include/sticker_provider.h index 6ea0234..e7367b3 100644 --- a/include/sticker_provider.h +++ b/include/sticker_provider.h @@ -107,6 +107,8 @@ int sticker_provider_destroy(sticker_provider_h provider_handle); * @retval #STICKER_ERROR_NOT_SUPPORTED Not supported * @retval #STICKER_ERROR_INVALID_PARAMETER Invalid parameter * @retval #STICKER_ERROR_OPERATION_FAILED Operation failed + * @retval #STICKER_ERROR_FILE_EXISTS File exists + * @retval #STICKER_ERROR_NO_SUCH_FILE No such file * @see sticker_provider_update_data() * @see sticker_provider_delete_data() */ @@ -175,6 +177,8 @@ int sticker_provider_insert_data_by_json_file(sticker_provider_h provider_handle * @retval #STICKER_ERROR_NOT_SUPPORTED Not supported * @retval #STICKER_ERROR_INVALID_PARAMETER Invalid parameter * @retval #STICKER_ERROR_OPERATION_FAILED Operation failed + * @retval #STICKER_ERROR_FILE_EXISTS File exists + * @retval #STICKER_ERROR_NO_SUCH_FILE No such file * @see sticker_provider_insert_data() * @see sticker_provider_delete_data() */ diff --git a/provider/sticker_provider.c b/provider/sticker_provider.c index a271ca6..9ef5b60 100644 --- a/provider/sticker_provider.c +++ b/provider/sticker_provider.c @@ -133,7 +133,12 @@ EXPORT_API int sticker_provider_insert_data(sticker_provider_h provider_handle, ret = sticker_dbus_insert_sticker_info(provider_handle->gdbus_connection, data_handle); if (ret != STICKER_ERROR_NONE) { LOGE("Failed to insert sticker information : %d", ret); - return STICKER_ERROR_OPERATION_FAILED; + if (ret == STICKER_CLIENT_ERROR_FILE_EXISTS) + return STICKER_ERROR_FILE_EXISTS; + else if (ret == STICKER_CLIENT_ERROR_NO_SUCH_FILE) + return STICKER_ERROR_NO_SUCH_FILE; + else + return STICKER_ERROR_OPERATION_FAILED; } return STICKER_ERROR_NONE; @@ -233,7 +238,12 @@ EXPORT_API int sticker_provider_update_data(sticker_provider_h provider_handle, ret = sticker_dbus_update_sticker_info(provider_handle->gdbus_connection, data_handle); if (ret != STICKER_ERROR_NONE) { LOGE("Failed to update sticker information : %d", ret); - return STICKER_ERROR_OPERATION_FAILED; + if (ret == STICKER_CLIENT_ERROR_FILE_EXISTS) + return STICKER_ERROR_FILE_EXISTS; + else if (ret == STICKER_CLIENT_ERROR_NO_SUCH_FILE) + return STICKER_ERROR_NO_SUCH_FILE; + 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 414fc12..f30cd8e 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -572,12 +572,12 @@ int stickerd_insert_sticker_info(GVariant *parameters, GVariant **reply_body) sticker_info->uri = _convert_sticker_uri(sticker_info->uri, sticker_info->app_id); if (!sticker_info->uri) { LOGE("failed to copy sticker file"); - ret = STICKERD_SERVER_ERROR_OPERATION_FAILED; + ret = STICKERD_SERVER_ERROR_FILE_EXISTS; goto cleanup; } } else { LOGE("sticker file does not exist"); - ret = STICKERD_SERVER_ERROR_OPERATION_FAILED; + ret = STICKERD_SERVER_ERROR_NO_SUCH_FILE; goto cleanup; } } @@ -715,6 +715,8 @@ int stickerd_insert_sticker_info_by_json(GVariant *parameters, GVariant **reply_ sticker_info->uri = _convert_sticker_uri(sticker_info->uri, sticker_info->app_id); if (!sticker_info->uri) goto free_memory; + } else { + goto free_memory; } } @@ -835,8 +837,10 @@ int stickerd_update_sticker_uri(GVariant *parameters, GVariant **reply_body) uri = _convert_sticker_uri(uri, app_id); if (!uri) { LOGE("failed to copy sticker file"); - return STICKERD_SERVER_ERROR_OPERATION_FAILED; + return STICKERD_SERVER_ERROR_FILE_EXISTS; } + } else { + return STICKERD_SERVER_ERROR_NO_SUCH_FILE; } } diff --git a/server/stickerd_error.h b/server/stickerd_error.h index 2afea16..6d1b444 100644 --- a/server/stickerd_error.h +++ b/server/stickerd_error.h @@ -31,13 +31,15 @@ extern "C" { */ enum stickerd_server_error { STICKERD_SERVER_ERROR_NONE, - STICKERD_SERVER_ERROR_IO_ERROR, STICKERD_SERVER_ERROR_INVALID_PARAMETER, STICKERD_SERVER_ERROR_PERMISSION_DENIED, STICKERD_SERVER_ERROR_OUT_OF_MEMORY, STICKERD_SERVER_ERROR_SERVICE_NOT_READY, STICKERD_SERVER_ERROR_OPERATION_FAILED, + STICKERD_SERVER_ERROR_IO_ERROR, STICKERD_SERVER_ERROR_DB_FAILED, + STICKERD_SERVER_ERROR_FILE_EXISTS, + STICKERD_SERVER_ERROR_NO_SUCH_FILE, }; /** -- 2.7.4 From 002014050cc15255d4334685f94462c89d6b51d6 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Wed, 18 Mar 2020 16:50:30 +0900 Subject: [PATCH 16/16] Split sticker data into another file Change-Id: I3c23542e657757e0250fea67effb196677ae08c7 Signed-off-by: Jihoon Kim --- receiver/CMakeLists.txt | 1 + receiver/inc/sticker_data.h | 37 +++++++++++++++++++++++++++++++++++++ receiver/inc/sticker_info.h | 2 +- receiver/src/ft.cpp | 26 ++------------------------ receiver/src/sticker_data.cpp | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 25 deletions(-) create mode 100644 receiver/inc/sticker_data.h create mode 100644 receiver/src/sticker_data.cpp diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt index 73d4503..4a875d9 100644 --- a/receiver/CMakeLists.txt +++ b/receiver/CMakeLists.txt @@ -3,6 +3,7 @@ PROJECT(sticker-receiver CXX) SET(SRCS src/main.cpp + src/sticker_data.cpp src/ft.cpp src/sticker_info.cpp src/message.cpp diff --git a/receiver/inc/sticker_data.h b/receiver/inc/sticker_data.h new file mode 100644 index 0000000..97f82cc --- /dev/null +++ b/receiver/inc/sticker_data.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __STICKER_DATA_H__ +#define __STICKER_DATA_H__ + +#include + +using namespace std; + +struct sticker_info { + sticker_info(); + ~sticker_info(); + + void reset(); + + string file_path; + string group; + string keyword; + string disp_type; + string description; +}; + +#endif /* __STICKER_DATA_H__ */ diff --git a/receiver/inc/sticker_info.h b/receiver/inc/sticker_info.h index 86b6c88..8231585 100644 --- a/receiver/inc/sticker_info.h +++ b/receiver/inc/sticker_info.h @@ -21,4 +21,4 @@ int create_sticker_provider_handle(void); void destroy_sticker_provider_handle(void); void delete_sticker_data(const char *fileName); -#endif /* __STICKER_INF_H__ */ +#endif /* __STICKER_INFO_H__ */ diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 61afdc0..4a2ec79 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -35,6 +35,7 @@ #include "ft.h" #include "log.h" #include "sticker_info.h" +#include "../inc/sticker_data.h" #include "message.h" #include "sync_alarm.h" @@ -77,21 +78,6 @@ struct request { string type; }; -static void _reset_sticker_data(); - -struct sticker_info { - string file_path; - string group; - string keyword; - string disp_type; - string description; - - sticker_info() - { - _reset_sticker_data(); - } -}; - static struct sap_info_s priv_data = { 0 }; static struct sticker_info sticker_data; static struct request pending_request, current_request; @@ -393,14 +379,6 @@ void conn_terminated(sap_peer_agent_h peer_agent, service_app_exit(); } -static void _reset_sticker_data() -{ - sticker_data.file_path.clear(); - sticker_data.group.clear(); - sticker_data.keyword.clear(); - sticker_data.disp_type.clear(); - sticker_data.description.clear(); -} void on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned int payload_length, void *buffer, @@ -525,7 +503,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in json_object_unref(j_object); } else if (msg_id == STICKER_SEND_FACE_DATA) { LOGD("msg : %s", msg_id.c_str()); - _reset_sticker_data(); + sticker_data.reset(); const char *type_data = json_object_get_string_member(root_obj, "type"); if (type_data) diff --git a/receiver/src/sticker_data.cpp b/receiver/src/sticker_data.cpp new file mode 100644 index 0000000..bd94ee5 --- /dev/null +++ b/receiver/src/sticker_data.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "../inc/sticker_data.h" + +sticker_info::sticker_info() +{ + reset(); +} + +sticker_info::~sticker_info() +{ + +} + +void sticker_info::reset() +{ + file_path.clear(); + group.clear(); + keyword.clear(); + disp_type.clear(); + description.clear(); +} \ No newline at end of file -- 2.7.4