2 * Copyright (c) 2000 - 2016 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.
24 #include <notification_db.h>
25 #include <notification_debug.h>
26 #include <notification_ongoing.h>
27 #include <notification_private.h>
29 #define PATH_NAME "/dbus/signal"
30 #define INTERFACE_NAME "notification.ongoing"
31 #define MEMBER_PROGRESS "update_progress"
32 #define MEMBER_SIZE "update_size"
33 #define MEMBER_CONTENT "update_content"
35 struct _ongoing_update_cb_data {
36 notification_ongoing_update_cb callback;
38 GDBusConnection *conn;
42 static struct _ongoing_update_cb_data od;
44 static void __notification_ongoing_update_callback(GDBusConnection *connection,
45 const gchar *sender_name,
46 const gchar *object_path,
47 const gchar *interface_name,
48 const gchar *signal_name,
52 struct ongoing_info_s *info;
59 info = calloc(1, sizeof(struct ongoing_info_s));
62 NOTIFICATION_ERR("Out of memory");
67 if (g_strcmp0(signal_name, MEMBER_PROGRESS) == 0) {
68 g_variant_get(parameters, "(&sid)", &pkgname, &priv_id, &progress);
69 info->type = ONGOING_TYPE_PROGRESS;
70 } else if (g_strcmp0(signal_name, MEMBER_SIZE) == 0) {
71 g_variant_get(parameters, "(&sid)", &pkgname, &priv_id, &size);
72 info->type = ONGOING_TYPE_SIZE;
74 } else if (g_strcmp0(signal_name, MEMBER_CONTENT) == 0) {
75 g_variant_get(parameters, "(&si&s)", &pkgname, &priv_id, &content);
76 info->type = ONGOING_TYPE_CONTENT;
79 if (pkgname == NULL) {
81 NOTIFICATION_ERR("pkgname is null");
87 info->pkgname = pkgname;
88 info->priv_id = priv_id;
89 info->progress = progress;
91 info->content = content;
93 od.callback(info, od.data);
98 static int __send_ongoing_update_signal(const char *signal_name, GVariant *param)
101 GDBusConnection *conn;
102 int ret = NOTIFICATION_ERROR_NONE;
104 if (signal_name == NULL)
105 return NOTIFICATION_ERROR_INVALID_PARAMETER;
107 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
109 /* LCOV_EXCL_START */
110 NOTIFICATION_ERR("g_bus_get_sync() failed: %s", err->message);
111 ret = NOTIFICATION_ERROR_FROM_DBUS;
116 if (g_dbus_connection_emit_signal(conn,
123 /* LCOV_EXCL_START */
124 NOTIFICATION_ERR("g_dbus_connection_emit_signal() failed: %s",
126 ret = NOTIFICATION_ERROR_FROM_DBUS;
131 if (g_dbus_connection_flush_sync(conn, NULL, &err) == FALSE) {
132 /* LCOV_EXCL_START */
133 NOTIFICATION_ERR("g_dbus_connection_flush_sync() failed: %s",
135 ret = NOTIFICATION_ERROR_FROM_DBUS;
146 g_object_unref(conn);
153 int notification_ongoing_update_cb_set(notification_ongoing_update_cb callback,
156 GError *error = NULL;
159 return NOTIFICATION_ERROR_INVALID_PARAMETER;
161 if (od.conn == NULL) {
162 od.conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
163 if (od.conn == NULL) {
164 /* LCOV_EXCL_START */
165 NOTIFICATION_ERR("Failed to connect to the D-BUS Daemon: %s",
168 return NOTIFICATION_ERROR_FROM_DBUS;
173 if (!od.subscribe_id) {
174 od.subscribe_id = g_dbus_connection_signal_subscribe(od.conn,
180 G_DBUS_SIGNAL_FLAGS_NONE,
181 __notification_ongoing_update_callback,
184 if (od.subscribe_id == 0) {
185 /* LCOV_EXCL_START */
186 NOTIFICATION_ERR("g_dbus_connection_signal_subscribe() failed");
187 g_object_unref(od.conn);
188 return NOTIFICATION_ERROR_FROM_DBUS;
193 od.callback = callback;
196 return NOTIFICATION_ERROR_NONE;
200 int notification_ongoing_update_cb_unset(void)
202 if (od.subscribe_id) {
203 g_dbus_connection_signal_unsubscribe(od.conn, od.subscribe_id);
208 g_object_unref(od.conn);
215 return NOTIFICATION_ERROR_NONE;
218 int notification_ongoing_update_progress(const char *caller_pkgname,
219 int priv_id, double progress)
224 param = g_variant_new("(sid)", caller_pkgname, priv_id, progress);
226 ret = __send_ongoing_update_signal(MEMBER_PROGRESS, param);
227 if (ret != NOTIFICATION_ERROR_NONE) {
228 /* LCOV_EXCL_START */
229 NOTIFICATION_ERR("notification_ongoing_update_progress failed %d",
235 return NOTIFICATION_ERROR_NONE;
238 int notification_ongoing_update_size(const char *caller_pkgname,
239 int priv_id, double size)
244 param = g_variant_new("(sid)", caller_pkgname, priv_id, size);
246 ret = __send_ongoing_update_signal(MEMBER_SIZE, param);
247 if (ret != NOTIFICATION_ERROR_NONE) {
248 /* LCOV_EXCL_START */
249 NOTIFICATION_ERR("notification_ongoing_update_size failed %d",
255 return NOTIFICATION_ERROR_NONE;
258 int notification_ongoing_update_content(const char *caller_pkgname,
259 int priv_id, const char *content)
264 param = g_variant_new("(sis)", caller_pkgname, priv_id, content);
266 ret = __send_ongoing_update_signal(MEMBER_CONTENT, param);
267 if (ret != NOTIFICATION_ERROR_NONE) {
268 /* LCOV_EXCL_START */
269 NOTIFICATION_ERR("notification_ongoing_update_content failed %d",
274 return NOTIFICATION_ERROR_NONE;