Release notification lib for Tizen2.0 beta(tagging)
[apps/home/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                 NOTIFICATION_INFO("Send progress info : %s(%d) %.2f",
74                                   caller_pkgname, priv_id, progress);
75                 return NOTIFICATION_ERROR_NONE;
76         }
77
78         return NOTIFICATION_ERROR_FROM_DBUS;
79 }
80
81 notification_error_e notification_ongoing_update_size(const char *caller_pkgname,
82                                                       int priv_id, double size)
83 {
84         DBusConnection *connection = NULL;
85         DBusMessage *signal = NULL;
86         DBusError err;
87         dbus_bool_t ret;
88
89         dbus_error_init(&err);
90         connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
91         if (!connection) {
92                 NOTIFICATION_ERR("Fail to dbus_bus_get");
93                 return NOTIFICATION_ERROR_FROM_DBUS;
94         }
95
96         signal =
97             dbus_message_new_signal("/dbus/signal", "notification.ongoing",
98                                     "update_size");
99         if (!signal) {
100                 NOTIFICATION_ERR("Fail to dbus_message_new_signal");
101                 return NOTIFICATION_ERROR_FROM_DBUS;
102         }
103
104         ret = dbus_message_append_args(signal,
105                                        DBUS_TYPE_STRING, &caller_pkgname,
106                                        DBUS_TYPE_INT32, &priv_id,
107                                        DBUS_TYPE_DOUBLE, &size,
108                                        DBUS_TYPE_INVALID);
109         NOTIFICATION_INFO("arg...");
110         if (ret) {
111                 ret = dbus_connection_send(connection, signal, NULL);
112                 NOTIFICATION_INFO("Send size info : %s(%d) %.2f",
113                                   caller_pkgname, priv_id, size);
114
115                 if (ret) {
116                         dbus_connection_flush(connection);
117                 }
118         }
119
120         dbus_message_unref(signal);
121
122         if (ret) {
123                 NOTIFICATION_INFO("Send size info : %s(%d) %.2f",
124                                   caller_pkgname, priv_id, size);
125                 return NOTIFICATION_ERROR_NONE;
126         }
127
128         return NOTIFICATION_ERROR_FROM_DBUS;
129 }
130
131 notification_error_e notification_ongoing_update_content(const char *caller_pkgname,
132                                                       int priv_id, const char *content)
133 {
134         DBusConnection *connection = NULL;
135         DBusMessage *signal = NULL;
136         DBusError err;
137         dbus_bool_t ret;
138
139         dbus_error_init(&err);
140         connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
141         if (!connection) {
142                 NOTIFICATION_ERR("Fail to dbus_bus_get");
143                 return NOTIFICATION_ERROR_FROM_DBUS;
144         }
145
146         signal =
147             dbus_message_new_signal("/dbus/signal", "notification.ongoing",
148                                     "update_content");
149         if (!signal) {
150                 NOTIFICATION_ERR("Fail to dbus_message_new_signal");
151                 return NOTIFICATION_ERROR_FROM_DBUS;
152         }
153
154         if(content == NULL) {
155                 ret = dbus_message_append_args(signal,
156                                                    DBUS_TYPE_STRING, &caller_pkgname,
157                                                    DBUS_TYPE_INT32, &priv_id,
158                                                    DBUS_TYPE_INVALID);
159         } else {
160                 ret = dbus_message_append_args(signal,
161                                                    DBUS_TYPE_STRING, &caller_pkgname,
162                                                    DBUS_TYPE_INT32, &priv_id,
163                                                    DBUS_TYPE_STRING, &content,
164                                                    DBUS_TYPE_INVALID);
165         }
166         if (ret) {
167                 ret = dbus_connection_send(connection, signal, NULL);
168                 NOTIFICATION_INFO("Send content : %s(%d) %s",
169                                   caller_pkgname, priv_id, content);
170
171                 if (ret) {
172                         dbus_connection_flush(connection);
173                 }
174         }
175
176         dbus_message_unref(signal);
177
178         if (ret) {
179                 return NOTIFICATION_ERROR_NONE;
180         }
181
182         return NOTIFICATION_ERROR_FROM_DBUS;
183 }
184