2 * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "sticker_dbus.h"
24 #define LOG_TAG "STICKER_DBUS"
26 #define STICKER_DIRECTORY tzplatform_mkpath(TZ_SYS_SHARE, "sticker-data")
28 static int is_server_started = 0;
29 static CLIENT_LIB last_req_lib = STICKER_CLIENT_LIB_NONE;
31 static void _server_appeared_cb(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data)
33 LOGD("name : %s, name_owner : %s", name, name_owner);
37 static void _server_vanished_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
39 LOGD("name : %s", name);
43 static int _dbus_init(GDBusConnection **gdbus_connection)
48 if (*gdbus_connection == NULL) {
49 GDBusConnection *conn = NULL;
50 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
53 LOGE("g_bus_get_sync error message = %s", error->message);
56 return STICKER_CLIENT_ERROR_IO_ERROR;
58 *gdbus_connection = conn;
61 LOGD("Connected bus name : %s", g_dbus_connection_get_unique_name(*gdbus_connection));
62 watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
64 G_BUS_NAME_WATCHER_FLAGS_NONE,
69 LOGD("watch_id : %d", watch_id);
71 LOGE("Failed to get identifier");
72 return STICKER_CLIENT_ERROR_IO_ERROR;
75 return STICKER_CLIENT_ERROR_NONE;
78 static void _get_sticker_info_from_gvariant(GVariantIter *info_iter, GVariantIter *keyword_iter, sticker_data_h sticker_data)
81 GVariant *value = NULL;
84 if (!info_iter || !keyword_iter) {
85 LOGW("failed to get iter");
89 while (g_variant_iter_loop (info_iter, "{iv}", &key, &value)) {
91 case STICKER_DATA_TYPE_INFO_ID:
92 sticker_data->sticker_info_id = g_variant_get_int32(value);
94 case STICKER_DATA_TYPE_APP_ID:
95 sticker_data->app_id = g_variant_dup_string(value, NULL);
97 case STICKER_DATA_TYPE_URI_TYPE:
98 sticker_data->type = g_variant_get_int32(value);
100 case STICKER_DATA_TYPE_URI:
101 sticker_data->uri = g_variant_dup_string(value, NULL);
103 case STICKER_DATA_TYPE_THUMBNAIL:
104 sticker_data->thumbnail = g_variant_dup_string(value, NULL);
106 case STICKER_DATA_TYPE_DESCRIPTION:
107 sticker_data->description = g_variant_dup_string(value, NULL);
109 case STICKER_DATA_TYPE_GROUP:
110 sticker_data->group = g_variant_dup_string(value, NULL);
112 case STICKER_DATA_TYPE_DATE:
113 sticker_data->date = g_variant_dup_string(value, NULL);
115 case STICKER_DATA_TYPE_DISP_TYPE:
116 sticker_data->disp_type = g_variant_get_int32(value);
123 while (g_variant_iter_loop (keyword_iter, "(s)", &keyword)) {
124 sticker_data->keyword = g_list_append(sticker_data->keyword, strdup((const char *)keyword));
128 g_variant_unref(value);
130 g_variant_iter_free(info_iter);
131 g_variant_iter_free(keyword_iter);
134 static void _free_sticker_data(sticker_data_h sticker_data)
136 if (sticker_data->app_id) {
137 free(sticker_data->app_id);
138 sticker_data->app_id = NULL;
141 if (sticker_data->uri) {
142 free(sticker_data->uri);
143 sticker_data->uri = NULL;
146 if (sticker_data->thumbnail) {
147 free(sticker_data->thumbnail);
148 sticker_data->thumbnail = NULL;
151 if (sticker_data->keyword) {
152 g_list_free_full(sticker_data->keyword, free);
153 sticker_data->keyword = NULL;
156 if (sticker_data->group) {
157 free(sticker_data->group);
158 sticker_data->group = NULL;
161 if (sticker_data->description) {
162 free(sticker_data->description);
163 sticker_data->description = NULL;
166 if (sticker_data->date) {
167 free(sticker_data->date);
168 sticker_data->date = NULL;
175 static void _call_insert_finished_cb(sticker_provider_h provider_handle, GVariant *body)
178 g_variant_get(body, "(i)", &ret);
181 provider_handle->insert_finished_cb(STICKER_ERROR_NONE, provider_handle->insert_finished_cb_user_data);
183 provider_handle->insert_finished_cb(STICKER_ERROR_OPERATION_FAILED, provider_handle->insert_finished_cb_user_data);
188 static void _handle_sticker_consumer_cb(GDBusConnection *connection,
189 const gchar *sender_name,
190 const gchar *object_path,
191 const gchar *interface_name,
192 const gchar *signal_name,
193 GVariant *parameters,
196 LOGD("own_name : %s, signal_name : %s", g_dbus_connection_get_unique_name(connection), signal_name);
197 sticker_consumer_h consumer_handle = (sticker_consumer_h)user_data;
199 if (consumer_handle == NULL) {
200 LOGE("consumer handle is not available");
204 if (parameters == NULL) {
205 LOGE("failed to get sticker info");
209 if (g_strcmp0(signal_name, "send_sticker_changed_event") == 0) {
210 if (consumer_handle->event_cb != NULL) {
211 sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
214 GVariantIter *info_iter = NULL;
215 GVariantIter *keyword_iter = NULL;
217 g_variant_get(parameters, "(ia{iv}a(s))", &event_type, &info_iter, &keyword_iter);
218 _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
219 consumer_handle->event_cb((sticker_consumer_event_type_e)event_type, sticker_data, consumer_handle->event_cb_user_data);
222 g_variant_iter_free(info_iter);
225 g_variant_iter_free(keyword_iter);
227 _free_sticker_data(sticker_data);
232 #if 0 // Receive the sticker information by asynchronous communication.
233 if (g_strcmp0(signal_name, "send_group_list") == 0) {
234 if (consumer_handle->group_foreach_cb != NULL)
235 _call_sticker_list_cb(consumer_handle, parameters, signal_name);
237 } else if (g_strcmp0(signal_name, "send_keyword_list") == 0) {
238 if (consumer_handle->keyword_foreach_cb != NULL)
239 _call_sticker_list_cb(consumer_handle, parameters, signal_name);
243 sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
246 LOGE("failed to allocate memory");
250 _get_sticker_info_from_gvariant(parameters, sticker_data);
252 if (g_strcmp0(signal_name, "send_all_sticker_info") == 0) {
253 if (consumer_handle->data_foreach_cb != NULL)
254 consumer_handle->data_foreach_cb(sticker_data, consumer_handle->data_foreach_cb_user_data);
256 LOGW("No registered callback function");
257 } else if (g_strcmp0(signal_name, "send_sticker_info_by_keyword") == 0) {
258 if (consumer_handle->data_foreach_by_keyword_cb != NULL)
259 consumer_handle->data_foreach_by_keyword_cb(sticker_data, consumer_handle->data_foreach_by_keyword_cb_user_data);
261 LOGW("No registered callback function");
262 } else if (g_strcmp0(signal_name, "send_sticker_info_by_group") == 0) {
263 if (consumer_handle->data_foreach_by_group_cb != NULL)
264 consumer_handle->data_foreach_by_group_cb(sticker_data, consumer_handle->data_foreach_by_group_cb_user_data);
266 LOGW("No registered callback function");
267 } else if (g_strcmp0(signal_name, "send_sticker_info_by_type") == 0) {
268 if (consumer_handle->data_foreach_by_type_cb != NULL)
269 consumer_handle->data_foreach_by_type_cb(sticker_data, consumer_handle->data_foreach_by_type_cb_user_data);
271 LOGW("No registered callback function");
274 _free_sticker_data(sticker_data);
279 static void _handle_sticker_provider_cb(GDBusConnection *connection,
280 const gchar *sender_name,
281 const gchar *object_path,
282 const gchar *interface_name,
283 const gchar *signal_name,
284 GVariant *parameters,
287 LOGD("own_name : %s, signal_name : %s", g_dbus_connection_get_unique_name(connection), signal_name);
288 sticker_provider_h provider_handle = (sticker_provider_h)user_data;
290 if (provider_handle == NULL) {
291 LOGE("provider handle is not available");
295 if (parameters == NULL) {
296 LOGE("failed to get sticker info");
300 if (g_strcmp0(signal_name, "send_insert_result") == 0) {
301 if (provider_handle->insert_finished_cb != NULL)
302 _call_insert_finished_cb(provider_handle, parameters);
305 #if 0 // Receive the sticker information by asynchronous communication.
306 sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
309 LOGE("failed to allocate memory");
313 _get_sticker_info_from_gvariant(parameters, sticker_data);
315 if (g_strcmp0(signal_name, "send_sticker_info_by_appid") == 0) {
316 if (provider_handle->data_foreach_cb != NULL)
317 provider_handle->data_foreach_cb(sticker_data, provider_handle->data_foreach_cb_user_data);
319 LOGW("No registered callback function");
322 _free_sticker_data(sticker_data);
326 static int _dbus_signal_init(GDBusConnection *gdbus_connection, int *monitor_id, CLIENT_LIB lib, void *data)
328 int ret = STICKER_CLIENT_ERROR_NONE;
329 if (*monitor_id == 0) {
331 if (lib == STICKER_CLIENT_LIB_CONSUMER)
332 id = g_dbus_connection_signal_subscribe(gdbus_connection,
334 STICKER_CONSUMER_INTERFACE_NAME,
338 G_DBUS_SIGNAL_FLAGS_NONE,
339 _handle_sticker_consumer_cb,
342 else if (lib == STICKER_CLIENT_LIB_PROVIDER)
343 id = g_dbus_connection_signal_subscribe(gdbus_connection,
345 STICKER_PROVIDER_INTERFACE_NAME,
349 G_DBUS_SIGNAL_FLAGS_NONE,
350 _handle_sticker_provider_cb,
355 ret = STICKER_CLIENT_ERROR_IO_ERROR;
356 LOGE("g_dbus_connection_signal_subscribe() failed");
365 static GDBusMessage *_get_gbus_message(GVariant *body, const char *cmd)
367 GDBusMessage *message = NULL;
368 message = g_dbus_message_new_method_call(
371 STICKER_INTERFACE_NAME,
375 LOGE("Failed to create a new gdbus message");
377 g_variant_unref(body);
382 g_dbus_message_set_body(message, body);
387 static int _send_gdbus_sync_message(GDBusConnection *gdbus_connection, GDBusMessage *msg, GDBusMessage **reply, const char *cmd)
389 int ret = STICKER_CLIENT_ERROR_NONE;
392 *reply = g_dbus_connection_send_message_with_reply_sync(
395 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
402 ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY;
404 LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
405 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
406 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
412 if (g_dbus_message_to_gerror(*reply, &err)) {
413 LOGE("error message = %s, code = %d", err->message, err->code);
414 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
415 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
422 LOGD("Send a message to server(cmd : %s)", cmd);
423 return STICKER_CLIENT_ERROR_NONE;
426 static int _send_sync_message(GDBusConnection *gdbus_connection, GVariant *body, GDBusMessage **reply, char *cmd)
428 int ret = STICKER_CLIENT_ERROR_NONE;
429 GDBusMessage *msg = NULL;
431 msg = _get_gbus_message(body, cmd);
433 return STICKER_CLIENT_ERROR_IO_ERROR;
435 ret = _send_gdbus_sync_message(gdbus_connection, msg, reply, cmd);
443 static int _send_async_message(GDBusConnection *gdbus_connection, GVariant *body, char *cmd)
445 int ret = STICKER_CLIENT_ERROR_NONE;
446 GDBusMessage *msg = NULL;
449 msg = _get_gbus_message(body, cmd);
451 return STICKER_CLIENT_ERROR_IO_ERROR;
453 g_dbus_connection_send_message(gdbus_connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &err);
459 ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY;
460 LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
462 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
463 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
472 static int _monitor_register(GDBusConnection *gdbus_connection, int *server_watcher_id, CLIENT_LIB lib)
475 GDBusMessage *reply = NULL;
476 GVariant *reply_body = NULL;
478 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", (int)lib), &reply, "sticker_service_register");
479 if (ret != STICKER_CLIENT_ERROR_NONE) {
480 LOGE("_send_sync_message() failed : %d", ret);
484 reply_body = g_dbus_message_get_body(reply);
485 g_variant_get(reply_body, "(i)", server_watcher_id);
488 g_object_unref(reply);
490 is_server_started = 1;
494 static void _on_name_appeared(GDBusConnection *connection,
496 const gchar *name_owner,
499 if (is_server_started == 0) {
500 int *watcher_id = (int *)user_data;
501 _monitor_register(connection, watcher_id, last_req_lib);
506 static void _on_name_vanished(GDBusConnection *connection,
510 is_server_started = 0;
514 int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id,
515 int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data)
520 ret = _dbus_init(gdbus_connection);
521 if (ret != STICKER_CLIENT_ERROR_NONE) {
522 LOGE("_dbus_init() failed : %d", ret);
526 ret = _dbus_signal_init(*gdbus_connection, monitor_id, lib, data);
527 if (ret != STICKER_CLIENT_ERROR_NONE) {
528 LOGE("_dbus_signal_init() failed : %d", ret);
532 ret = _monitor_register(*gdbus_connection, server_watcher_id, lib);
533 if (ret != STICKER_CLIENT_ERROR_NONE) {
534 LOGE("_monitor_register() failed : %d", ret);
538 if (*server_monitor_id == 0) {
539 *server_monitor_id = g_bus_watch_name_on_connection(
542 G_BUS_NAME_WATCHER_FLAGS_NONE,
547 if (*server_monitor_id == 0) {
548 g_dbus_connection_signal_unsubscribe(*gdbus_connection, *monitor_id);
550 LOGE("Failed to get identifier");
551 return STICKER_CLIENT_ERROR_IO_ERROR;
555 return STICKER_CLIENT_ERROR_NONE;
558 int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id, CLIENT_LIB lib)
562 if (server_watcher_id) {
563 ret = _send_async_message(gdbus_connection, g_variant_new("(ii)", (int)lib, *server_watcher_id), "sticker_service_unregister");
564 if (ret != STICKER_CLIENT_ERROR_NONE) {
565 LOGE("Failed to unregister sticker service");
569 *server_watcher_id = 0;
572 if (*server_monitor_id) {
573 g_bus_unwatch_name(*server_monitor_id);
574 *server_monitor_id = 0;
578 g_dbus_connection_signal_unsubscribe(gdbus_connection, *monitor_id);
582 return STICKER_CLIENT_ERROR_NONE;
585 static void _set_keyword_builder(char *keyword, GVariantBuilder *keyword_builder)
588 LOGE("keyword doesn't exist");
592 g_variant_builder_add(keyword_builder, "(s)", (const char *)keyword);
595 int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
599 GDBusMessage *reply = NULL;
600 GVariant *reply_body = NULL;
601 GVariantBuilder *info_builder;
602 GVariantBuilder *keyword_builder;
604 if (!sticker_data->app_id || (sticker_data->type < 1) || !sticker_data->uri || !sticker_data->group || !sticker_data->keyword)
605 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
607 info_builder = g_variant_builder_new(G_VARIANT_TYPE("a{iv}"));
608 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_APP_ID, g_variant_new_string((const gchar *)sticker_data->app_id));
609 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI_TYPE, g_variant_new_int32(sticker_data->type));
610 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI, g_variant_new_string((const gchar *)sticker_data->uri));
611 if (sticker_data->thumbnail)
612 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_THUMBNAIL, g_variant_new_string((const gchar *)sticker_data->thumbnail));
613 if (sticker_data->description)
614 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DESCRIPTION, g_variant_new_string((const gchar *)sticker_data->description));
615 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_GROUP, g_variant_new_string((const gchar *)sticker_data->group));
616 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DISP_TYPE, g_variant_new_int32(sticker_data->disp_type));
618 keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
619 g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
621 ret = _send_sync_message(gdbus_connection, g_variant_new("(a{iv}a(s))", info_builder, keyword_builder), &reply, "insert_sticker_info");
622 if (ret != STICKER_CLIENT_ERROR_NONE) {
623 LOGW("Failed to save sticker info");
627 reply_body = g_dbus_message_get_body(reply);
628 g_variant_get(reply_body, "(i)", &ret_id);
629 sticker_data->sticker_info_id = ret_id;
631 LOGD("ret_id : %d", ret_id);
633 g_variant_builder_unref(info_builder);
634 g_variant_builder_unref(keyword_builder);
637 g_variant_unref(reply_body);
640 g_object_unref(reply);
645 int sticker_dbus_insert_sticker_info_by_json(GDBusConnection *gdbus_connection, const char *app_id, const char *json_path)
649 ret = _send_async_message(gdbus_connection, g_variant_new("(ss)", app_id, json_path), "update_sticker_info_by_json");
650 if (ret != STICKER_CLIENT_ERROR_NONE)
651 LOGE("failed to send json path");
656 int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int record_id)
659 GDBusMessage *reply = NULL;
661 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "delete_sticker_info");
662 if (ret != STICKER_CLIENT_ERROR_NONE)
663 LOGE("failed to delete sticker info");
666 g_object_unref(reply);
671 int sticker_dbus_delete_sticker_info_by_uri(GDBusConnection *gdbus_connection, const char *uri)
674 GDBusMessage *reply = NULL;
676 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "delete_sticker_info_by_uri");
677 if (ret != STICKER_CLIENT_ERROR_NONE)
678 LOGE("failed to delete sticker info");
681 g_object_unref(reply);
686 int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
689 bool is_updated = false;
690 GDBusMessage *reply = NULL;
691 GVariant *reply_body = NULL;
692 sticker_data_h origin_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
695 LOGE("failed to allocate memory");
696 return STICKER_CLIENT_ERROR_OUT_OF_MEMORY;
699 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "get_sticker_info");
700 if (ret == STICKER_CLIENT_ERROR_NONE) {
701 reply_body = g_dbus_message_get_body(reply);
702 GVariantIter *info_iter = NULL;
703 GVariantIter *keyword_iter = NULL;
705 g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
706 _get_sticker_info_from_gvariant(info_iter, keyword_iter, origin_data);
709 g_variant_iter_free(info_iter);
712 g_variant_iter_free(keyword_iter);
714 LOGW("failed to get sticker info");
717 g_object_unref(reply);
721 if (sticker_data->uri) {
723 char *conv_path = NULL;
724 if (sticker_data->type == STICKER_DATA_URI_LOCAL_PATH) {
725 len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->uri) + 2;
726 conv_path = (char *)calloc(len, sizeof(char));
728 snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->uri);
730 conv_path = strdup(sticker_data->uri);
732 if (conv_path && (strcmp(conv_path, origin_data->uri) != 0)) {
733 LOGD("origin_uri : %s, new_uri : %s", origin_data->uri, conv_path);
735 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", sticker_data->uri), &reply, "check_file_exists");
736 if (ret == STICKER_CLIENT_ERROR_NONE) {
737 reply_body = g_dbus_message_get_body(reply);
738 g_variant_get(reply_body, "(i)", &is_exist);
741 LOGE("file already exists");
742 ret = STICKER_CLIENT_ERROR_FILE_EXISTS;
747 LOGE("failed to check file exists");
752 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");
753 if (ret != STICKER_CLIENT_ERROR_NONE) {
754 LOGE("failed to update sticker uri");
763 if (sticker_data->type != 0 && sticker_data->type != origin_data->type) {
764 LOGD("origin_type : %d, new_type : %d", origin_data->type, sticker_data->type);
765 ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->type), &reply, "update_sticker_type");
766 if (ret != STICKER_CLIENT_ERROR_NONE) {
767 LOGE("failed to update sticker type");
773 if (sticker_data->thumbnail) {
774 int len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->thumbnail) + 2;
775 char *conv_path = (char *)calloc(len, sizeof(char));
777 snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->thumbnail);
778 if (strcmp(conv_path, origin_data->thumbnail) != 0)
780 LOGD("origin_thumbnail : %s, new_thumbnail : %s", origin_data->thumbnail, conv_path);
781 ret = _send_sync_message(gdbus_connection, g_variant_new("(iss)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->thumbnail), &reply, "update_sticker_thumbnail");
782 if (ret != STICKER_CLIENT_ERROR_NONE)
784 LOGE("failed to update sticker thumbnail");
794 if (sticker_data->description && strcmp(sticker_data->description, origin_data->description) != 0) {
795 LOGD("origin_description : %s, new_description : %s", origin_data->description, sticker_data->description);
796 ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->description), &reply, "update_sticker_description");
797 if (ret != STICKER_CLIENT_ERROR_NONE) {
798 LOGE("failed to update sticker description");
804 if (sticker_data->group && strcmp(sticker_data->group, origin_data->group) != 0) {
805 LOGD("origin_group : %s, new_group : %s", origin_data->group, sticker_data->group);
806 ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->group), &reply, "update_sticker_group");
807 if (ret != STICKER_CLIENT_ERROR_NONE) {
808 LOGE("failed to update sticker group");
814 if (sticker_data->disp_type != 0 && sticker_data->disp_type != origin_data->disp_type) {
815 LOGD("origin_disp_type : %d, new_disp_type : %d", origin_data->disp_type, sticker_data->disp_type);
816 ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->disp_type), &reply, "update_sticker_disp_type");
817 if (ret != STICKER_CLIENT_ERROR_NONE) {
818 LOGE("failed to update sticker display type");
824 if (sticker_data->keyword) {
825 GVariantBuilder *keyword_builder;
826 keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
827 g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
828 ret = _send_sync_message(gdbus_connection, g_variant_new("(ia(s))", sticker_data->sticker_info_id, keyword_builder), &reply, "update_sticker_keyword");
829 if (ret != STICKER_CLIENT_ERROR_NONE)
830 LOGE("failed to update sticker keyword");
833 g_variant_builder_unref(keyword_builder);
837 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "send_update_event");
840 _free_sticker_data(origin_data);
843 g_variant_unref(reply_body);
846 g_object_unref(reply);
851 int sticker_dbus_get_sticker_info_by_record_id(GDBusConnection *gdbus_connection, sticker_data_h sticker_data, int record_id)
854 GDBusMessage *reply = NULL;
855 GVariant *reply_body = NULL;
856 GVariantIter *info_iter = NULL;
857 GVariantIter *keyword_iter = NULL;
859 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "get_sticker_info");
860 if (ret == STICKER_CLIENT_ERROR_NONE) {
861 reply_body = g_dbus_message_get_body(reply);
862 sticker_data->sticker_info_id = record_id;
864 g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
865 _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
868 g_variant_unref(reply_body);
871 g_variant_iter_free(info_iter);
874 g_variant_iter_free(keyword_iter);
878 g_object_unref(reply);
883 int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, const char *app_id, GList **group_list)
886 GDBusMessage *reply = NULL;
887 GVariantIter *iter = NULL;
888 GVariant *reply_body = NULL;
891 if (group_list == NULL) {
892 LOGE("group_list is invalid");
893 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
896 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_group_list");
897 if (ret == STICKER_CLIENT_ERROR_NONE) {
898 reply_body = g_dbus_message_get_body(reply);
899 g_variant_get(reply_body, "(a(s))", &iter);
902 LOGD("failed to get iter");
903 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
906 while (g_variant_iter_loop (iter, "(s)", &group)) {
907 *group_list = g_list_append(*group_list, strdup((const char *)group));
910 g_variant_iter_free(iter);
914 g_variant_unref(reply_body);
917 g_object_unref(reply);
922 int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, const char *app_id, GList **keyword_list)
925 GDBusMessage *reply = NULL;
926 GVariantIter *iter = NULL;
927 GVariant *reply_body = NULL;
928 char *keyword = NULL;
930 if (keyword_list == NULL) {
931 LOGE("keyword_list is invalid");
932 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
935 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_keyword_list");
936 if (ret == STICKER_CLIENT_ERROR_NONE) {
937 reply_body = g_dbus_message_get_body(reply);
938 g_variant_get(reply_body, "(a(s))", &iter);
941 LOGD("failed to get iter");
942 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
945 while (g_variant_iter_loop (iter, "(s)", &keyword)) {
946 *keyword_list = g_list_append(*keyword_list, strdup((const char *)keyword));
949 g_variant_iter_free(iter);
953 g_variant_unref(reply_body);
956 g_object_unref(reply);
961 int sticker_dbus_get_sticker_count(GDBusConnection *gdbus_connection, const char *app_id, int *count)
964 GDBusMessage *reply = NULL;
965 GVariant *reply_body = NULL;
967 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_sticker_count");
968 if (ret == STICKER_CLIENT_ERROR_NONE) {
969 reply_body = g_dbus_message_get_body(reply);
970 g_variant_get(reply_body, "(i)", count);
974 g_variant_unref(reply_body);
977 g_object_unref(reply);
982 int sticker_dbus_get_all_sticker_info(GDBusConnection *gdbus_connection, const char *app_id, int offset, int count, GVariantIter **id_iter)
985 GDBusMessage *reply = NULL;
986 GVariant *reply_body = NULL;
988 ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_all_sticker_info");
989 if (ret == STICKER_CLIENT_ERROR_NONE) {
990 reply_body = g_dbus_message_get_body(reply);
991 g_variant_get(reply_body, "(a(i))", id_iter);
995 g_variant_unref(reply_body);
998 g_object_unref(reply);
1003 int sticker_dbus_get_sticker_info_by_appid(GDBusConnection *gdbus_connection, const char *app_id, int offset, int count, GVariantIter **id_iter)
1006 GDBusMessage *reply = NULL;
1007 GVariant *reply_body = NULL;
1009 ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_sticker_info_by_appid");
1010 if (ret == STICKER_CLIENT_ERROR_NONE) {
1011 reply_body = g_dbus_message_get_body(reply);
1012 g_variant_get(reply_body, "(a(i))", id_iter);
1016 g_variant_unref(reply_body);
1019 g_object_unref(reply);
1024 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)
1027 GDBusMessage *reply = NULL;
1028 GVariant *reply_body = NULL;
1030 ret = _send_sync_message(gdbus_connection, g_variant_new("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_type");
1031 if (ret == STICKER_CLIENT_ERROR_NONE) {
1032 reply_body = g_dbus_message_get_body(reply);
1033 g_variant_get(reply_body, "(a(i))", id_iter);
1037 g_variant_unref(reply_body);
1040 g_object_unref(reply);
1045 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)
1048 GDBusMessage *reply = NULL;
1049 GVariant *reply_body = NULL;
1051 ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, group, offset, count), &reply, "get_sticker_info_by_group");
1052 if (ret == STICKER_CLIENT_ERROR_NONE) {
1053 reply_body = g_dbus_message_get_body(reply);
1054 g_variant_get(reply_body, "(a(i))", id_iter);
1058 g_variant_unref(reply_body);
1061 g_object_unref(reply);
1066 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)
1069 GDBusMessage *reply = NULL;
1070 GVariant *reply_body = NULL;
1072 ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, keyword, offset, count), &reply, "get_sticker_info_by_keyword");
1073 if (ret == STICKER_CLIENT_ERROR_NONE) {
1074 reply_body = g_dbus_message_get_body(reply);
1075 g_variant_get(reply_body, "(a(i))", id_iter);
1079 g_variant_unref(reply_body);
1082 g_object_unref(reply);
1087 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)
1090 GDBusMessage *reply = NULL;
1091 GVariant *reply_body = NULL;
1093 ret = _send_sync_message(gdbus_connection, g_variant_new("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_disp_type");
1094 if (ret == STICKER_CLIENT_ERROR_NONE) {
1095 reply_body = g_dbus_message_get_body(reply);
1096 g_variant_get(reply_body, "(a(i))", id_iter);
1100 g_variant_unref(reply_body);
1103 g_object_unref(reply);
1108 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)
1111 GDBusMessage *reply = NULL;
1112 GVariantIter *iter = NULL;
1113 GVariant *reply_body = NULL;
1116 if (group_list == NULL) {
1117 LOGE("group_list is invalid");
1118 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
1121 ret = _send_sync_message(gdbus_connection, g_variant_new("(si)", app_id, (int)type), &reply, "get_group_list_by_disp_type");
1122 if (ret == STICKER_CLIENT_ERROR_NONE) {
1123 reply_body = g_dbus_message_get_body(reply);
1124 g_variant_get(reply_body, "(a(s))", &iter);
1127 LOGD("failed to get iter");
1128 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
1131 while (g_variant_iter_loop (iter, "(s)", &group)) {
1132 *group_list = g_list_append(*group_list, strdup((const char *)group));
1135 g_variant_iter_free(iter);
1139 g_variant_unref(reply_body);
1142 g_object_unref(reply);
1147 int sticker_dbus_check_file_exists(GDBusConnection *gdbus_connection, const char *uri, int *result)
1150 GDBusMessage *reply = NULL;
1151 GVariant *reply_body = NULL;
1153 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "check_file_exists");
1154 if (ret == STICKER_CLIENT_ERROR_NONE) {
1155 reply_body = g_dbus_message_get_body(reply);
1156 g_variant_get(reply_body, "(i)", result);
1160 g_variant_unref(reply_body);
1163 g_object_unref(reply);
1168 int sticker_dbus_insert_recent_sticker_info(GDBusConnection *gdbus_connection, int record_id)
1171 GDBusMessage *reply = NULL;
1173 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "insert_recent_sticker_info");
1174 if (ret != STICKER_CLIENT_ERROR_NONE)
1175 LOGE("failed to insert recent sticker info");
1178 g_object_unref(reply);
1183 int sticker_dbus_get_recent_sticker_list(GDBusConnection *gdbus_connection, int count, GVariantIter **id_iter)
1186 GDBusMessage *reply = NULL;
1187 GVariant *reply_body = NULL;
1189 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", count), &reply, "get_recent_sticker_info");
1190 if (ret == STICKER_CLIENT_ERROR_NONE) {
1191 reply_body = g_dbus_message_get_body(reply);
1192 g_variant_get(reply_body, "(a(i))", id_iter);
1196 g_variant_unref(reply_body);
1199 g_object_unref(reply);
1204 int sticker_dbus_get_sticker_info_by_uri(GDBusConnection *gdbus_connection, sticker_data_h sticker_data, const char *uri)
1207 GDBusMessage *reply = NULL;
1208 GVariant *reply_body = NULL;
1209 GVariantIter *info_iter = NULL;
1210 GVariantIter *keyword_iter = NULL;
1212 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "get_sticker_info_by_uri");
1213 if (ret == STICKER_CLIENT_ERROR_NONE) {
1214 reply_body = g_dbus_message_get_body(reply);
1215 g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
1216 _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
1219 g_variant_unref(reply_body);
1222 g_variant_iter_free(info_iter);
1225 g_variant_iter_free(keyword_iter);
1229 g_object_unref(reply);