upload tizen1.0 source
[pkgs/o/oma-ds-service.git] / src / ServiceEngine / SE_Notification.c
1 /*
2  * oma-ds-service
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: JuHak Park <juhaki.park@samsung.com>,
7  *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
8  *          SunBong Ha <sunbong.ha@samsung.com>
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */
23
24
25
26
27 /*
28  * For any sort of issue you concern as to this software,
29  * you may use following point of contact.
30  * All resources contributed on this software
31  * are orinigally written by S-Core Inc., a member of Samsung Group.
32  *
33  * SeongWon Shim <seongwon.shim@samsung.com>
34  */
35
36 /**
37  *   @SE_Notification.c
38  *   @version                                                                   0.1
39  *   @brief                                                                             This file is the source file of implementation of notify to ui
40  */
41
42 #include "agent-framework/Event/Event_Handler.h"
43 #include "agent-framework/Utility/fw_log.h"
44 #include "ServiceEngine/SE_Notification.h"
45 #include "ServiceEngine/SE_Sync.h"
46
47 #define LOG_TAG "OMA_DS_SE"
48
49 #define NOTI_KEY        "OMADS"
50
51 SE_ErrorType send_noti_auto_configure(char *profileDirName, GList *configure)
52 {
53         FW_LOGV("start");
54
55         SE_ErrorType err = SE_INTERNAL_OK;
56
57         if (!profileDirName) {
58                 FW_LOGE("Not Defined profileDirName");
59                 err = SE_INTERNAL_NOT_DEFINED;
60                 goto error;
61         }
62
63         int notiType = 1;
64         Event_Data *noti = create_Noti(notiType);
65         if (noti == NULL) {
66                 FW_LOGE("failed to create_Noti");
67                 err = SE_INTERNAL_NO_MEMORY;
68                 goto error;
69         }
70
71         append_eventdata_param(noti, STRING, (void *)profileDirName);
72
73         GList *iter = NULL;
74         GList *inIter = NULL;
75         char *config = NULL;
76         int count;
77         for (iter = configure; iter != NULL; iter = g_list_next(iter)) {
78
79                 inIter = iter->data;
80                 count = g_list_length(inIter);
81                 FW_LOGV("count =%d", count);
82                 append_eventdata_param(noti, INTEGER, &count);
83
84                 for (inIter = iter->data; inIter != NULL; inIter = g_list_next(inIter)) {
85                         config = inIter->data;
86                         FW_LOGV("config = %s", config);
87                         append_eventdata_param(noti, STRING, (void *)config);
88                 }
89         }
90
91         EVENT_ERROR event_err;
92         send_Noti(NOTI_KEY, noti, NULL, NULL, &event_err);
93
94         if (event_err != EVENT_SUCCESS) {
95                 FW_LOGE("failed to send_Noti");
96                 err = SE_INTERNAL_EVENT_ERROR;
97                 goto error;
98         }
99
100         FW_LOGV("end");
101
102 error:
103
104         return err;
105 }
106
107 SE_ErrorType send_noti_sync_status(char *profileDirName)
108 {
109         FW_LOGV("start");
110
111         SE_ErrorType err = SE_INTERNAL_OK;
112
113         int notiType = 2;
114         Event_Data *noti = create_Noti(notiType);
115         if (noti == NULL) {
116                 FW_LOGE("failed to create_Noti");
117                 err = SE_INTERNAL_NO_MEMORY;
118                 goto error;
119         }
120
121         FW_LOGV("synchronising profile is : %s", profileDirName);
122
123         append_eventdata_param(noti, STRING, (void *)profileDirName);
124
125         EVENT_ERROR event_err;
126         send_Noti(NOTI_KEY, noti, NULL, NULL, &event_err);
127
128         if (event_err != EVENT_SUCCESS) {
129                 FW_LOGE("failed to send_Noti");
130                 err = SE_INTERNAL_EVENT_ERROR;
131                 goto error;
132         }
133
134         FW_LOGV("end");
135
136 error:
137
138         return err;
139 }
140
141 SE_ErrorType send_noti_session_process(char *profile, char *progress, char *error)
142 {
143         FW_LOGV("start");
144
145         SE_ErrorType err = SE_INTERNAL_OK;
146
147         if (!profile) {
148                 FW_LOGE("Not Defined profile");
149                 err = SE_INTERNAL_NOT_DEFINED;
150                 goto error;
151         }
152
153         int notiType = 3;
154         Event_Data *noti = create_Noti(notiType);
155         if (noti == NULL) {
156                 FW_LOGE("failed to create_Noti");
157                 err = SE_INTERNAL_NO_MEMORY;
158                 goto error;
159         }
160
161         append_eventdata_param(noti, STRING, (void *)profile);
162         append_eventdata_param(noti, STRING, (void *)progress);
163         append_eventdata_param(noti, STRING, (void *)error);
164
165         EVENT_ERROR event_err;
166         send_Noti(NOTI_KEY, noti, NULL, NULL, &event_err);
167
168         if (event_err != EVENT_SUCCESS) {
169                 FW_LOGE("failed to send_Noti");
170                 err = SE_INTERNAL_EVENT_ERROR;
171                 goto error;
172         }
173
174         FW_LOGV("end");
175
176 error:
177
178         return err;
179 }
180
181 SE_ErrorType send_noti_process_update(char *profileDirName, char *uri, char *progressStatus,
182                                                                                                 char *operationType, int isFromServer, int totalPerOperation,
183                                                                                                 int syncedPerOperation, int totalPerDb, int syncedPerDb)
184 {
185         FW_LOGV("start");
186
187         SE_ErrorType err = SE_INTERNAL_OK;
188
189         if (!profileDirName) {
190                 FW_LOGE("Not Defined profileDirName");
191                 err = SE_INTERNAL_NOT_DEFINED;
192                 goto error;
193         }
194
195         int notiType = 4;
196         Event_Data *noti = create_Noti(notiType);
197         if (noti == NULL) {
198                 FW_LOGE("failed to create_Noti");
199                 err = SE_INTERNAL_NO_MEMORY;
200                 goto error;
201         }
202
203         append_eventdata_param(noti, STRING, (void *)profileDirName);
204         append_eventdata_param(noti, STRING, (void *)uri);
205         append_eventdata_param(noti, STRING, (void *)progressStatus);
206         append_eventdata_param(noti, STRING, (void *)operationType);
207         append_eventdata_param(noti, INTEGER, &isFromServer);
208         append_eventdata_param(noti, INTEGER, &totalPerOperation);
209         append_eventdata_param(noti, INTEGER, &syncedPerOperation);
210         append_eventdata_param(noti, INTEGER, &totalPerDb);
211         append_eventdata_param(noti, INTEGER, &syncedPerDb);
212
213         EVENT_ERROR event_err;
214         send_Noti(NOTI_KEY, noti, NULL, NULL, &event_err);
215
216         if (event_err != EVENT_SUCCESS) {
217                 FW_LOGE("failed to send_Noti");
218                 err = SE_INTERNAL_EVENT_ERROR;
219                 goto error;
220         }
221
222         FW_LOGV("end");
223
224 error:
225
226         return err;
227 }