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_APP_ID:
92 sticker_data->app_id = g_variant_dup_string(value, NULL);
94 case STICKER_DATA_TYPE_URI_TYPE:
95 sticker_data->type = g_variant_get_int32(value);
97 case STICKER_DATA_TYPE_URI:
98 sticker_data->uri = g_variant_dup_string(value, NULL);
100 case STICKER_DATA_TYPE_THUMBNAIL:
101 sticker_data->thumbnail = g_variant_dup_string(value, NULL);
103 case STICKER_DATA_TYPE_DESCRIPTION:
104 sticker_data->description = g_variant_dup_string(value, NULL);
106 case STICKER_DATA_TYPE_GROUP:
107 sticker_data->group = g_variant_dup_string(value, NULL);
109 case STICKER_DATA_TYPE_DATE:
110 sticker_data->date = g_variant_dup_string(value, NULL);
112 case STICKER_DATA_TYPE_DISP_TYPE:
113 sticker_data->disp_type = g_variant_get_int32(value);
120 while (g_variant_iter_loop (keyword_iter, "(s)", &keyword)) {
121 sticker_data->keyword = g_list_append(sticker_data->keyword, strdup((const char *)keyword));
125 g_variant_unref(value);
127 g_variant_iter_free(info_iter);
128 g_variant_iter_free(keyword_iter);
131 static void _free_sticker_data(sticker_data_h sticker_data)
133 if (sticker_data->app_id) {
134 free(sticker_data->app_id);
135 sticker_data->app_id = NULL;
138 if (sticker_data->uri) {
139 free(sticker_data->uri);
140 sticker_data->uri = NULL;
143 if (sticker_data->thumbnail) {
144 free(sticker_data->thumbnail);
145 sticker_data->thumbnail = NULL;
148 if (sticker_data->keyword) {
149 g_list_free_full(sticker_data->keyword, free);
150 sticker_data->keyword = NULL;
153 if (sticker_data->group) {
154 free(sticker_data->group);
155 sticker_data->group = NULL;
158 if (sticker_data->description) {
159 free(sticker_data->description);
160 sticker_data->description = NULL;
163 if (sticker_data->date) {
164 free(sticker_data->date);
165 sticker_data->date = NULL;
172 static void _call_insert_finished_cb(sticker_provider_h provider_handle, GVariant *body)
175 g_variant_get(body, "(i)", &ret);
178 provider_handle->insert_finished_cb(STICKER_ERROR_NONE, provider_handle->insert_finished_cb_user_data);
180 provider_handle->insert_finished_cb(STICKER_ERROR_OPERATION_FAILED, provider_handle->insert_finished_cb_user_data);
185 static void _handle_sticker_consumer_cb(GDBusConnection *connection,
186 const gchar *sender_name,
187 const gchar *object_path,
188 const gchar *interface_name,
189 const gchar *signal_name,
190 GVariant *parameters,
193 LOGD("own_name : %s, signal_name : %s", g_dbus_connection_get_unique_name(connection), signal_name);
194 sticker_consumer_h consumer_handle = (sticker_consumer_h)user_data;
196 if (consumer_handle == NULL) {
197 LOGE("consumer handle is not available");
201 if (parameters == NULL) {
202 LOGE("failed to get sticker info");
206 if (g_strcmp0(signal_name, "send_sticker_changed_event") == 0) {
207 if (consumer_handle->event_cb != NULL) {
208 sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
211 GVariantIter *info_iter = NULL;
212 GVariantIter *keyword_iter = NULL;
214 g_variant_get(parameters, "(ia{iv}a(s))", &event_type, &info_iter, &keyword_iter);
215 _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
216 consumer_handle->event_cb((sticker_consumer_event_type_e)event_type, sticker_data, consumer_handle->event_cb_user_data);
219 g_variant_iter_free(info_iter);
222 g_variant_iter_free(keyword_iter);
224 _free_sticker_data(sticker_data);
229 #if 0 // Receive the sticker information by asynchronous communication.
230 if (g_strcmp0(signal_name, "send_group_list") == 0) {
231 if (consumer_handle->group_foreach_cb != NULL)
232 _call_sticker_list_cb(consumer_handle, parameters, signal_name);
234 } else if (g_strcmp0(signal_name, "send_keyword_list") == 0) {
235 if (consumer_handle->keyword_foreach_cb != NULL)
236 _call_sticker_list_cb(consumer_handle, parameters, signal_name);
240 sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
243 LOGE("failed to allocate memory");
247 _get_sticker_info_from_gvariant(parameters, sticker_data);
249 if (g_strcmp0(signal_name, "send_all_sticker_info") == 0) {
250 if (consumer_handle->data_foreach_cb != NULL)
251 consumer_handle->data_foreach_cb(sticker_data, consumer_handle->data_foreach_cb_user_data);
253 LOGW("No registered callback function");
254 } else if (g_strcmp0(signal_name, "send_sticker_info_by_keyword") == 0) {
255 if (consumer_handle->data_foreach_by_keyword_cb != NULL)
256 consumer_handle->data_foreach_by_keyword_cb(sticker_data, consumer_handle->data_foreach_by_keyword_cb_user_data);
258 LOGW("No registered callback function");
259 } else if (g_strcmp0(signal_name, "send_sticker_info_by_group") == 0) {
260 if (consumer_handle->data_foreach_by_group_cb != NULL)
261 consumer_handle->data_foreach_by_group_cb(sticker_data, consumer_handle->data_foreach_by_group_cb_user_data);
263 LOGW("No registered callback function");
264 } else if (g_strcmp0(signal_name, "send_sticker_info_by_type") == 0) {
265 if (consumer_handle->data_foreach_by_type_cb != NULL)
266 consumer_handle->data_foreach_by_type_cb(sticker_data, consumer_handle->data_foreach_by_type_cb_user_data);
268 LOGW("No registered callback function");
271 _free_sticker_data(sticker_data);
276 static void _handle_sticker_provider_cb(GDBusConnection *connection,
277 const gchar *sender_name,
278 const gchar *object_path,
279 const gchar *interface_name,
280 const gchar *signal_name,
281 GVariant *parameters,
284 LOGD("own_name : %s, signal_name : %s", g_dbus_connection_get_unique_name(connection), signal_name);
285 sticker_provider_h provider_handle = (sticker_provider_h)user_data;
287 if (provider_handle == NULL) {
288 LOGE("provider handle is not available");
292 if (parameters == NULL) {
293 LOGE("failed to get sticker info");
297 if (g_strcmp0(signal_name, "send_insert_result") == 0) {
298 if (provider_handle->insert_finished_cb != NULL)
299 _call_insert_finished_cb(provider_handle, parameters);
302 #if 0 // Receive the sticker information by asynchronous communication.
303 sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
306 LOGE("failed to allocate memory");
310 _get_sticker_info_from_gvariant(parameters, sticker_data);
312 if (g_strcmp0(signal_name, "send_sticker_info_by_appid") == 0) {
313 if (provider_handle->data_foreach_cb != NULL)
314 provider_handle->data_foreach_cb(sticker_data, provider_handle->data_foreach_cb_user_data);
316 LOGW("No registered callback function");
319 _free_sticker_data(sticker_data);
323 static int _dbus_signal_init(GDBusConnection *gdbus_connection, int *monitor_id, CLIENT_LIB lib, void *data)
325 int ret = STICKER_CLIENT_ERROR_NONE;
326 if (*monitor_id == 0) {
328 if (lib == STICKER_CLIENT_LIB_CONSUMER)
329 id = g_dbus_connection_signal_subscribe(gdbus_connection,
331 STICKER_CONSUMER_INTERFACE_NAME,
335 G_DBUS_SIGNAL_FLAGS_NONE,
336 _handle_sticker_consumer_cb,
339 else if (lib == STICKER_CLIENT_LIB_PROVIDER)
340 id = g_dbus_connection_signal_subscribe(gdbus_connection,
342 STICKER_PROVIDER_INTERFACE_NAME,
346 G_DBUS_SIGNAL_FLAGS_NONE,
347 _handle_sticker_provider_cb,
352 ret = STICKER_CLIENT_ERROR_IO_ERROR;
353 LOGE("g_dbus_connection_signal_subscribe() failed");
362 static GDBusMessage *_get_gbus_message(GVariant *body, const char *cmd)
364 GDBusMessage *message = NULL;
365 message = g_dbus_message_new_method_call(
368 STICKER_INTERFACE_NAME,
372 LOGE("Failed to create a new gdbus message");
374 g_variant_unref(body);
379 g_dbus_message_set_body(message, body);
384 static int _send_gdbus_sync_message(GDBusConnection *gdbus_connection, GDBusMessage *msg, GDBusMessage **reply, const char *cmd)
386 int ret = STICKER_CLIENT_ERROR_NONE;
389 *reply = g_dbus_connection_send_message_with_reply_sync(
392 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
399 ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY;
401 LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
402 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
403 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
409 if (g_dbus_message_to_gerror(*reply, &err)) {
410 LOGE("error message = %s, code = %d", err->message, err->code);
411 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
412 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
419 LOGD("Send a message to server(cmd : %s)", cmd);
420 return STICKER_CLIENT_ERROR_NONE;
423 static int _send_sync_message(GDBusConnection *gdbus_connection, GVariant *body, GDBusMessage **reply, char *cmd)
425 int ret = STICKER_CLIENT_ERROR_NONE;
426 GDBusMessage *msg = NULL;
428 msg = _get_gbus_message(body, cmd);
430 return STICKER_CLIENT_ERROR_IO_ERROR;
432 ret = _send_gdbus_sync_message(gdbus_connection, msg, reply, cmd);
440 static int _send_async_message(GDBusConnection *gdbus_connection, GVariant *body, char *cmd)
442 int ret = STICKER_CLIENT_ERROR_NONE;
443 GDBusMessage *msg = NULL;
446 msg = _get_gbus_message(body, cmd);
448 return STICKER_CLIENT_ERROR_IO_ERROR;
450 g_dbus_connection_send_message(gdbus_connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &err);
456 ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY;
457 LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
459 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
460 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
469 static int _monitor_register(GDBusConnection *gdbus_connection, int *server_watcher_id, CLIENT_LIB lib)
472 GDBusMessage *reply = NULL;
473 GVariant *reply_body = NULL;
475 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", (int)lib), &reply, "sticker_service_register");
476 if (ret != STICKER_CLIENT_ERROR_NONE) {
477 LOGE("_send_sync_message() failed : %d", ret);
481 reply_body = g_dbus_message_get_body(reply);
482 g_variant_get(reply_body, "(i)", server_watcher_id);
485 g_object_unref(reply);
487 is_server_started = 1;
491 static void _on_name_appeared(GDBusConnection *connection,
493 const gchar *name_owner,
496 if (is_server_started == 0) {
497 int *watcher_id = (int *)user_data;
498 _monitor_register(connection, watcher_id, last_req_lib);
503 static void _on_name_vanished(GDBusConnection *connection,
507 is_server_started = 0;
511 int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id,
512 int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data)
517 ret = _dbus_init(gdbus_connection);
518 if (ret != STICKER_CLIENT_ERROR_NONE) {
519 LOGE("_dbus_init() failed : %d", ret);
523 ret = _dbus_signal_init(*gdbus_connection, monitor_id, lib, data);
524 if (ret != STICKER_CLIENT_ERROR_NONE) {
525 LOGE("_dbus_signal_init() failed : %d", ret);
529 ret = _monitor_register(*gdbus_connection, server_watcher_id, lib);
530 if (ret != STICKER_CLIENT_ERROR_NONE) {
531 LOGE("_monitor_register() failed : %d", ret);
535 if (*server_monitor_id == 0) {
536 *server_monitor_id = g_bus_watch_name_on_connection(
539 G_BUS_NAME_WATCHER_FLAGS_NONE,
544 if (*server_monitor_id == 0) {
545 g_dbus_connection_signal_unsubscribe(*gdbus_connection, *monitor_id);
547 LOGE("Failed to get identifier");
548 return STICKER_CLIENT_ERROR_IO_ERROR;
552 return STICKER_CLIENT_ERROR_NONE;
555 int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id, CLIENT_LIB lib)
559 if (server_watcher_id) {
560 ret = _send_async_message(gdbus_connection, g_variant_new("(ii)", (int)lib, *server_watcher_id), "sticker_service_unregister");
561 if (ret != STICKER_CLIENT_ERROR_NONE) {
562 LOGE("Failed to unregister sticker service");
566 *server_watcher_id = 0;
569 if (*server_monitor_id) {
570 g_bus_unwatch_name(*server_monitor_id);
571 *server_monitor_id = 0;
575 g_dbus_connection_signal_unsubscribe(gdbus_connection, *monitor_id);
579 return STICKER_CLIENT_ERROR_NONE;
582 static void _set_keyword_builder(char *keyword, GVariantBuilder *keyword_builder)
585 LOGE("keyword doesn't exist");
589 g_variant_builder_add(keyword_builder, "(s)", (const char *)keyword);
592 int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
596 GDBusMessage *reply = NULL;
597 GVariant *reply_body = NULL;
598 GVariantBuilder *info_builder;
599 GVariantBuilder *keyword_builder;
601 if (!sticker_data->app_id || (sticker_data->type < 1) || !sticker_data->uri || !sticker_data->group || !sticker_data->keyword)
602 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
604 info_builder = g_variant_builder_new(G_VARIANT_TYPE("a{iv}"));
605 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_APP_ID, g_variant_new_string((const gchar *)sticker_data->app_id));
606 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI_TYPE, g_variant_new_int32(sticker_data->type));
607 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI, g_variant_new_string((const gchar *)sticker_data->uri));
608 if (sticker_data->thumbnail)
609 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_THUMBNAIL, g_variant_new_string((const gchar *)sticker_data->thumbnail));
610 if (sticker_data->description)
611 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DESCRIPTION, g_variant_new_string((const gchar *)sticker_data->description));
612 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_GROUP, g_variant_new_string((const gchar *)sticker_data->group));
613 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DISP_TYPE, g_variant_new_int32(sticker_data->disp_type));
615 keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
616 g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
618 ret = _send_sync_message(gdbus_connection, g_variant_new("(a{iv}a(s))", info_builder, keyword_builder), &reply, "insert_sticker_info");
619 if (ret != STICKER_CLIENT_ERROR_NONE) {
620 LOGW("Failed to save sticker info");
624 reply_body = g_dbus_message_get_body(reply);
625 g_variant_get(reply_body, "(i)", &ret_id);
626 sticker_data->sticker_info_id = ret_id;
628 LOGD("ret_id : %d", ret_id);
630 g_variant_builder_unref(info_builder);
631 g_variant_builder_unref(keyword_builder);
634 g_variant_unref(reply_body);
637 g_object_unref(reply);
642 int sticker_dbus_insert_sticker_info_by_json(GDBusConnection *gdbus_connection, const char *app_id, const char *json_path)
646 ret = _send_async_message(gdbus_connection, g_variant_new("(ss)", app_id, json_path), "update_sticker_info_by_json");
647 if (ret != STICKER_CLIENT_ERROR_NONE)
648 LOGE("failed to send json path");
653 int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int record_id)
656 GDBusMessage *reply = NULL;
658 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "delete_sticker_info");
659 if (ret != STICKER_CLIENT_ERROR_NONE)
660 LOGE("failed to delete sticker info");
663 g_object_unref(reply);
668 int sticker_dbus_delete_sticker_info_by_uri(GDBusConnection *gdbus_connection, const char *uri)
671 GDBusMessage *reply = NULL;
673 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "delete_sticker_info_by_uri");
674 if (ret != STICKER_CLIENT_ERROR_NONE)
675 LOGE("failed to delete sticker info");
678 g_object_unref(reply);
683 int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
686 bool is_updated = false;
687 GDBusMessage *reply = NULL;
688 GVariant *reply_body = NULL;
689 sticker_data_h origin_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
692 LOGE("failed to allocate memory");
693 return STICKER_CLIENT_ERROR_OUT_OF_MEMORY;
696 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "get_sticker_info");
697 if (ret == STICKER_CLIENT_ERROR_NONE) {
698 reply_body = g_dbus_message_get_body(reply);
699 GVariantIter *info_iter = NULL;
700 GVariantIter *keyword_iter = NULL;
702 g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
703 _get_sticker_info_from_gvariant(info_iter, keyword_iter, origin_data);
706 g_variant_iter_free(info_iter);
709 g_variant_iter_free(keyword_iter);
711 LOGW("failed to get sticker info");
714 g_object_unref(reply);
718 if (sticker_data->uri) {
720 char *conv_path = NULL;
721 if (sticker_data->type == STICKER_DATA_URI_LOCAL_PATH) {
722 len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->uri) + 2;
723 conv_path = (char *)calloc(len, sizeof(char));
725 snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->uri);
727 conv_path = strdup(sticker_data->uri);
729 if (conv_path && (strcmp(conv_path, origin_data->uri) != 0)) {
730 LOGD("origin_uri : %s, new_uri : %s", origin_data->uri, conv_path);
732 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", sticker_data->uri), &reply, "check_file_exists");
733 if (ret == STICKER_CLIENT_ERROR_NONE) {
734 reply_body = g_dbus_message_get_body(reply);
735 g_variant_get(reply_body, "(i)", &is_exist);
738 LOGE("file already exists");
739 ret = STICKER_CLIENT_ERROR_FILE_EXISTS;
744 LOGE("failed to check file exists");
749 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");
750 if (ret != STICKER_CLIENT_ERROR_NONE) {
751 LOGE("failed to update sticker uri");
760 if (sticker_data->type != 0 && sticker_data->type != origin_data->type) {
761 LOGD("origin_type : %d, new_type : %d", origin_data->type, sticker_data->type);
762 ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->type), &reply, "update_sticker_type");
763 if (ret != STICKER_CLIENT_ERROR_NONE) {
764 LOGE("failed to update sticker type");
770 if (sticker_data->thumbnail) {
771 int len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->thumbnail) + 2;
772 char *conv_path = (char *)calloc(len, sizeof(char));
774 snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->thumbnail);
775 if (strcmp(conv_path, origin_data->thumbnail) != 0)
777 LOGD("origin_thumbnail : %s, new_thumbnail : %s", origin_data->thumbnail, conv_path);
778 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");
779 if (ret != STICKER_CLIENT_ERROR_NONE)
781 LOGE("failed to update sticker thumbnail");
791 if (sticker_data->description && strcmp(sticker_data->description, origin_data->description) != 0) {
792 LOGD("origin_description : %s, new_description : %s", origin_data->description, sticker_data->description);
793 ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->description), &reply, "update_sticker_description");
794 if (ret != STICKER_CLIENT_ERROR_NONE) {
795 LOGE("failed to update sticker description");
801 if (sticker_data->group && strcmp(sticker_data->group, origin_data->group) != 0) {
802 LOGD("origin_group : %s, new_group : %s", origin_data->group, sticker_data->group);
803 ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->group), &reply, "update_sticker_group");
804 if (ret != STICKER_CLIENT_ERROR_NONE) {
805 LOGE("failed to update sticker group");
811 if (sticker_data->disp_type != 0 && sticker_data->disp_type != origin_data->disp_type) {
812 LOGD("origin_disp_type : %d, new_disp_type : %d", origin_data->disp_type, sticker_data->disp_type);
813 ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->disp_type), &reply, "update_sticker_disp_type");
814 if (ret != STICKER_CLIENT_ERROR_NONE) {
815 LOGE("failed to update sticker display type");
821 if (sticker_data->keyword) {
822 GVariantBuilder *keyword_builder;
823 keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
824 g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
825 ret = _send_sync_message(gdbus_connection, g_variant_new("(ia(s))", sticker_data->sticker_info_id, keyword_builder), &reply, "update_sticker_keyword");
826 if (ret != STICKER_CLIENT_ERROR_NONE)
827 LOGE("failed to update sticker keyword");
830 g_variant_builder_unref(keyword_builder);
834 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "send_update_event");
837 _free_sticker_data(origin_data);
840 g_variant_unref(reply_body);
843 g_object_unref(reply);
848 int sticker_dbus_get_sticker_info_by_record_id(GDBusConnection *gdbus_connection, sticker_data_h sticker_data, int record_id)
851 GDBusMessage *reply = NULL;
852 GVariant *reply_body = NULL;
853 GVariantIter *info_iter = NULL;
854 GVariantIter *keyword_iter = NULL;
856 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "get_sticker_info");
857 if (ret == STICKER_CLIENT_ERROR_NONE) {
858 reply_body = g_dbus_message_get_body(reply);
859 sticker_data->sticker_info_id = record_id;
861 g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
862 _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
865 g_variant_unref(reply_body);
868 g_variant_iter_free(info_iter);
871 g_variant_iter_free(keyword_iter);
875 g_object_unref(reply);
880 int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, const char *app_id, GList **group_list)
883 GDBusMessage *reply = NULL;
884 GVariantIter *iter = NULL;
885 GVariant *reply_body = NULL;
888 if (group_list == NULL) {
889 LOGE("group_list is invalid");
890 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
893 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_group_list");
894 if (ret == STICKER_CLIENT_ERROR_NONE) {
895 reply_body = g_dbus_message_get_body(reply);
896 g_variant_get(reply_body, "(a(s))", &iter);
899 LOGD("failed to get iter");
900 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
903 while (g_variant_iter_loop (iter, "(s)", &group)) {
904 *group_list = g_list_append(*group_list, strdup((const char *)group));
907 g_variant_iter_free(iter);
911 g_variant_unref(reply_body);
914 g_object_unref(reply);
919 int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, const char *app_id, GList **keyword_list)
922 GDBusMessage *reply = NULL;
923 GVariantIter *iter = NULL;
924 GVariant *reply_body = NULL;
925 char *keyword = NULL;
927 if (keyword_list == NULL) {
928 LOGE("keyword_list is invalid");
929 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
932 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_keyword_list");
933 if (ret == STICKER_CLIENT_ERROR_NONE) {
934 reply_body = g_dbus_message_get_body(reply);
935 g_variant_get(reply_body, "(a(s))", &iter);
938 LOGD("failed to get iter");
939 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
942 while (g_variant_iter_loop (iter, "(s)", &keyword)) {
943 *keyword_list = g_list_append(*keyword_list, strdup((const char *)keyword));
946 g_variant_iter_free(iter);
950 g_variant_unref(reply_body);
953 g_object_unref(reply);
958 int sticker_dbus_get_sticker_count(GDBusConnection *gdbus_connection, const char *app_id, int *count)
961 GDBusMessage *reply = NULL;
962 GVariant *reply_body = NULL;
964 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_sticker_count");
965 if (ret == STICKER_CLIENT_ERROR_NONE) {
966 reply_body = g_dbus_message_get_body(reply);
967 g_variant_get(reply_body, "(i)", count);
971 g_variant_unref(reply_body);
974 g_object_unref(reply);
979 int sticker_dbus_get_all_sticker_info(GDBusConnection *gdbus_connection, const char *app_id, int offset, int count, GVariantIter **id_iter)
982 GDBusMessage *reply = NULL;
983 GVariant *reply_body = NULL;
985 ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_all_sticker_info");
986 if (ret == STICKER_CLIENT_ERROR_NONE) {
987 reply_body = g_dbus_message_get_body(reply);
988 g_variant_get(reply_body, "(a(i))", id_iter);
992 g_variant_unref(reply_body);
995 g_object_unref(reply);
1000 int sticker_dbus_get_sticker_info_by_appid(GDBusConnection *gdbus_connection, const char *app_id, int offset, int count, GVariantIter **id_iter)
1003 GDBusMessage *reply = NULL;
1004 GVariant *reply_body = NULL;
1006 ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_sticker_info_by_appid");
1007 if (ret == STICKER_CLIENT_ERROR_NONE) {
1008 reply_body = g_dbus_message_get_body(reply);
1009 g_variant_get(reply_body, "(a(i))", id_iter);
1013 g_variant_unref(reply_body);
1016 g_object_unref(reply);
1021 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)
1024 GDBusMessage *reply = NULL;
1025 GVariant *reply_body = NULL;
1027 ret = _send_sync_message(gdbus_connection, g_variant_new("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_type");
1028 if (ret == STICKER_CLIENT_ERROR_NONE) {
1029 reply_body = g_dbus_message_get_body(reply);
1030 g_variant_get(reply_body, "(a(i))", id_iter);
1034 g_variant_unref(reply_body);
1037 g_object_unref(reply);
1042 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)
1045 GDBusMessage *reply = NULL;
1046 GVariant *reply_body = NULL;
1048 ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, group, offset, count), &reply, "get_sticker_info_by_group");
1049 if (ret == STICKER_CLIENT_ERROR_NONE) {
1050 reply_body = g_dbus_message_get_body(reply);
1051 g_variant_get(reply_body, "(a(i))", id_iter);
1055 g_variant_unref(reply_body);
1058 g_object_unref(reply);
1063 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)
1066 GDBusMessage *reply = NULL;
1067 GVariant *reply_body = NULL;
1069 ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, keyword, offset, count), &reply, "get_sticker_info_by_keyword");
1070 if (ret == STICKER_CLIENT_ERROR_NONE) {
1071 reply_body = g_dbus_message_get_body(reply);
1072 g_variant_get(reply_body, "(a(i))", id_iter);
1076 g_variant_unref(reply_body);
1079 g_object_unref(reply);
1084 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)
1087 GDBusMessage *reply = NULL;
1088 GVariant *reply_body = NULL;
1090 ret = _send_sync_message(gdbus_connection, g_variant_new("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_disp_type");
1091 if (ret == STICKER_CLIENT_ERROR_NONE) {
1092 reply_body = g_dbus_message_get_body(reply);
1093 g_variant_get(reply_body, "(a(i))", id_iter);
1097 g_variant_unref(reply_body);
1100 g_object_unref(reply);
1105 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)
1108 GDBusMessage *reply = NULL;
1109 GVariantIter *iter = NULL;
1110 GVariant *reply_body = NULL;
1113 if (group_list == NULL) {
1114 LOGE("group_list is invalid");
1115 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
1118 ret = _send_sync_message(gdbus_connection, g_variant_new("(si)", app_id, (int)type), &reply, "get_group_list_by_disp_type");
1119 if (ret == STICKER_CLIENT_ERROR_NONE) {
1120 reply_body = g_dbus_message_get_body(reply);
1121 g_variant_get(reply_body, "(a(s))", &iter);
1124 LOGD("failed to get iter");
1125 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
1128 while (g_variant_iter_loop (iter, "(s)", &group)) {
1129 *group_list = g_list_append(*group_list, strdup((const char *)group));
1132 g_variant_iter_free(iter);
1136 g_variant_unref(reply_body);
1139 g_object_unref(reply);
1144 int sticker_dbus_check_file_exists(GDBusConnection *gdbus_connection, const char *uri, int *result)
1147 GDBusMessage *reply = NULL;
1148 GVariant *reply_body = NULL;
1150 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "check_file_exists");
1151 if (ret == STICKER_CLIENT_ERROR_NONE) {
1152 reply_body = g_dbus_message_get_body(reply);
1153 g_variant_get(reply_body, "(i)", result);
1157 g_variant_unref(reply_body);
1160 g_object_unref(reply);
1165 int sticker_dbus_insert_recent_sticker_info(GDBusConnection *gdbus_connection, int record_id)
1168 GDBusMessage *reply = NULL;
1170 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "insert_recent_sticker_info");
1171 if (ret != STICKER_CLIENT_ERROR_NONE)
1172 LOGE("failed to insert recent sticker info");
1175 g_object_unref(reply);
1180 int sticker_dbus_get_recent_sticker_list(GDBusConnection *gdbus_connection, int count, GVariantIter **id_iter)
1183 GDBusMessage *reply = NULL;
1184 GVariant *reply_body = NULL;
1186 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", count), &reply, "get_recent_sticker_info");
1187 if (ret == STICKER_CLIENT_ERROR_NONE) {
1188 reply_body = g_dbus_message_get_body(reply);
1189 g_variant_get(reply_body, "(a(i))", id_iter);
1193 g_variant_unref(reply_body);
1196 g_object_unref(reply);