f67665a7db439b67f40e56ae36ee322377f78a0c
[platform/core/api/notification.git] / src / notification_ongoing.c
1 /*
2  *  libnotification
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
25
26 #include <dbus/dbus.h>
27
28 #include <notification_db.h>
29 #include <notification_debug.h>
30 #include <notification_ongoing.h>
31 #include <notification_private.h>
32
33 int notification_ongoing_update_progress(const char *caller_pkgname,
34                                                           int priv_id,
35                                                           double progress)
36 {
37         DBusConnection *connection = NULL;
38         DBusMessage *signal = NULL;
39         DBusError err;
40         dbus_bool_t ret;
41
42         dbus_error_init(&err);
43         connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
44         if (!connection) {
45                 NOTIFICATION_ERR("Fail to dbus_bus_get");
46                 return NOTIFICATION_ERROR_FROM_DBUS;
47         }
48
49         signal =
50             dbus_message_new_signal("/dbus/signal", "notification.ongoing",
51                                     "update_progress");
52         if (!signal) {
53                 NOTIFICATION_ERR("Fail to dbus_message_new_signal");
54                 return NOTIFICATION_ERROR_FROM_DBUS;
55         }
56
57         ret = dbus_message_append_args(signal,
58                                        DBUS_TYPE_STRING, &caller_pkgname,
59                                        DBUS_TYPE_INT32, &priv_id,
60                                        DBUS_TYPE_DOUBLE, &progress,
61                                        DBUS_TYPE_INVALID);
62
63         if (ret) {
64                 ret = dbus_connection_send(connection, signal, NULL);
65                 if (ret) {
66                         dbus_connection_flush(connection);
67                 }
68         }
69
70         dbus_message_unref(signal);
71
72         if (ret) {
73                 return NOTIFICATION_ERROR_NONE;
74         }
75
76         return NOTIFICATION_ERROR_FROM_DBUS;
77 }
78
79 int notification_ongoing_update_size(const char *caller_pkgname,
80                                                       int priv_id, double size)
81 {
82         DBusConnection *connection = NULL;
83         DBusMessage *signal = NULL;
84         DBusError err;
85         dbus_bool_t ret;
86
87         dbus_error_init(&err);
88         connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
89         if (!connection) {
90                 NOTIFICATION_ERR("Fail to dbus_bus_get");
91                 return NOTIFICATION_ERROR_FROM_DBUS;
92         }
93
94         signal =
95             dbus_message_new_signal("/dbus/signal", "notification.ongoing",
96                                     "update_size");
97         if (!signal) {
98                 NOTIFICATION_ERR("Fail to dbus_message_new_signal");
99                 return NOTIFICATION_ERROR_FROM_DBUS;
100         }
101
102         ret = dbus_message_append_args(signal,
103                                        DBUS_TYPE_STRING, &caller_pkgname,
104                                        DBUS_TYPE_INT32, &priv_id,
105                                        DBUS_TYPE_DOUBLE, &size,
106                                        DBUS_TYPE_INVALID);
107         if (ret) {
108                 ret = dbus_connection_send(connection, signal, NULL);
109
110                 if (ret) {
111                         dbus_connection_flush(connection);
112                 }
113         }
114
115         dbus_message_unref(signal);
116
117         if (ret) {
118                 return NOTIFICATION_ERROR_NONE;
119         }
120
121         return NOTIFICATION_ERROR_FROM_DBUS;
122 }
123
124 int notification_ongoing_update_content(const char *caller_pkgname,
125                                                       int priv_id, const char *content)
126 {
127         DBusConnection *connection = NULL;
128         DBusMessage *signal = NULL;
129         DBusError err;
130         dbus_bool_t ret;
131
132         dbus_error_init(&err);
133         connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
134         if (!connection) {
135                 NOTIFICATION_ERR("Fail to dbus_bus_get");
136                 return NOTIFICATION_ERROR_FROM_DBUS;
137         }
138
139         signal =
140             dbus_message_new_signal("/dbus/signal", "notification.ongoing",
141                                     "update_content");
142         if (!signal) {
143                 NOTIFICATION_ERR("Fail to dbus_message_new_signal");
144                 return NOTIFICATION_ERROR_FROM_DBUS;
145         }
146
147         if(content == NULL) {
148                 ret = dbus_message_append_args(signal,
149                                                    DBUS_TYPE_STRING, &caller_pkgname,
150                                                    DBUS_TYPE_INT32, &priv_id,
151                                                    DBUS_TYPE_INVALID);
152         } else {
153                 ret = dbus_message_append_args(signal,
154                                                    DBUS_TYPE_STRING, &caller_pkgname,
155                                                    DBUS_TYPE_INT32, &priv_id,
156                                                    DBUS_TYPE_STRING, &content,
157                                                    DBUS_TYPE_INVALID);
158         }
159         if (ret) {
160                 ret = dbus_connection_send(connection, signal, NULL);
161
162                 if (ret) {
163                         dbus_connection_flush(connection);
164                 }
165         }
166
167         dbus_message_unref(signal);
168
169         if (ret) {
170                 return NOTIFICATION_ERROR_NONE;
171         }
172
173         return NOTIFICATION_ERROR_FROM_DBUS;
174 }
175