sync with private git
[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>, Youngsub Ko <ys4610.ko@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_internal.h>
32
33 notification_error_e 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 notification_error_e 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                 NOTIFICATION_INFO("Send size info : %s(%d) %.2f",
119                                   caller_pkgname, priv_id, size);
120                 return NOTIFICATION_ERROR_NONE;
121         }
122
123         return NOTIFICATION_ERROR_FROM_DBUS;
124 }
125
126 notification_error_e notification_ongoing_update_content(const char *caller_pkgname,
127                                                       int priv_id, const char *content)
128 {
129         DBusConnection *connection = NULL;
130         DBusMessage *signal = NULL;
131         DBusError err;
132         dbus_bool_t ret;
133
134         dbus_error_init(&err);
135         connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
136         if (!connection) {
137                 NOTIFICATION_ERR("Fail to dbus_bus_get");
138                 return NOTIFICATION_ERROR_FROM_DBUS;
139         }
140
141         signal =
142             dbus_message_new_signal("/dbus/signal", "notification.ongoing",
143                                     "update_content");
144         if (!signal) {
145                 NOTIFICATION_ERR("Fail to dbus_message_new_signal");
146                 return NOTIFICATION_ERROR_FROM_DBUS;
147         }
148
149         if(content == NULL) {
150                 ret = dbus_message_append_args(signal,
151                                                    DBUS_TYPE_STRING, &caller_pkgname,
152                                                    DBUS_TYPE_INT32, &priv_id,
153                                                    DBUS_TYPE_INVALID);
154         } else {
155                 ret = dbus_message_append_args(signal,
156                                                    DBUS_TYPE_STRING, &caller_pkgname,
157                                                    DBUS_TYPE_INT32, &priv_id,
158                                                    DBUS_TYPE_STRING, &content,
159                                                    DBUS_TYPE_INVALID);
160         }
161         if (ret) {
162                 ret = dbus_connection_send(connection, signal, NULL);
163
164                 if (ret) {
165                         dbus_connection_flush(connection);
166                 }
167         }
168
169         dbus_message_unref(signal);
170
171         if (ret) {
172                 return NOTIFICATION_ERROR_NONE;
173         }
174
175         return NOTIFICATION_ERROR_FROM_DBUS;
176 }
177