upload tizen1.0 source
[pkgs/o/oma-ds-service.git] / src / main / main.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  *   @main.c
38  *   @version                                                                   0.1
39  *   @brief                                                                             This file is the source file of implementation of main function
40  */
41
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <unistd.h>
45 #include "agent-framework/Initialization/initialize.h"
46 #include "agent-framework/Utility/fw_log.h"
47 #include "agent-framework/PlatformMonitor/EXT_PMCI_Struct.h"
48 #include "agent-framework/PlatformMonitor/EXT_PMCI.h"
49 #include "agent-framework/FSAPI/FSAPI_operation.h"
50 #include "Framework/Event/OMA_DS_Platform_Event_Handler.h"
51 #include "Framework/Event/OMA_DS_Event_Handler.h"
52 #include "Framework/Task/OMA_DS_Engine_Controller_Task.h"
53 #include "Common/CscKeys.h"
54 #include "Common/Common_Define_Internal.h"
55 #include "Common/Common_Vconf.h"
56 #include "ServiceEngine/SE_Account.h"
57
58 #define LOG_TAG "OMA_DS_MAIN"
59
60 static void __request_reset_synchronizing_profiles();
61 static void __check_csc();
62 static void __update_csc();
63
64 int main()
65 {
66         FW_LOGV("start");
67
68         EVENT_ERROR error  = EVENT_SUCCESS;
69
70         INIT_ERROR init_error = Init_Framework("/opt/data/oma-ds/omads_fw_config.xml");
71         if (init_error != INIT_SUCCESS) {
72                 FW_LOGE("Failed to Init_Framework() : %d", init_error);
73         } else {
74                 FW_LOGV("done init_Framework");
75         }
76
77         /*TODO have to be removed after removing vconf*/
78         task_spec_t *pAddAccountTaskSpec = make_add_account_task();
79         task_spec_t *pEditAccountTaskSpec = make_edit_account_task();
80         /*task_spec_t *pDeleteAccountTaskSpec = make_delete_account_task();*/
81         task_spec_t *pAutoConfTaskSpec = make_autoconfigure_task();
82
83
84         task_spec_t *pSyncTaskSpec = make_synchronize_task();
85         /*task_spec_t *pAddProfileTaskSpec = make_add_profile_task();*/
86         /*task_spec_t *pEditProfileTaskSpec = make_edit_profile_task();*/
87         task_spec_t *pDeleteProfileTaskSpec = make_delete_profile_task();
88         /*task_spec_t *pAutoConfTaskSpec = make_auto_configure_task();*/
89         task_spec_t *pSyncStatusTaskSpec = make_sync_status_task();
90         task_spec_t *pGetProfileNameTaskSpec = make_get_profile_name_task();
91         task_spec_t *pGetProfileServerInfoTaskSpec = make_get_profile_server_info_task();
92         task_spec_t *pGetProfileSyncModeTaskSpec = make_get_profile_sync_mode_task();
93         task_spec_t *pGetProfileSyncCategoryTaskSpec = make_get_profile_sync_category_task();
94         task_spec_t *pGetProfileLastSessionTaskSpec = make_get_profile_last_session_task();
95         task_spec_t *pGetProfileStatisticsTaskSpec = make_get_profile_statistics_task();
96         task_spec_t *pResetSynchronizingProfilesTaskSpec = make_reset_synchronizing_profiles_task();
97         task_spec_t *pAddProfileCPTaskSpec = make_add_profile_cp_task();
98         task_spec_t *pRefreshFromServiceTaskSpec = make_refresh_from_service_task();
99
100         /*FIXME cancel request to NA */
101         /*task_spec_t *pCancelSyncRequestTaskSpec = make_cancel_sync_request();*/
102
103
104
105         /*TODO have to be removed after removing vconf*/
106         engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_ADD_ACCOUNT,
107                                                                                                                 EC_MSG_TYPE_NAME_SYNC_TASK_ADD_ACCOUNT,
108                                                                                                                 pAddAccountTaskSpec, NULL);
109
110         engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_EDIT_ACCOUNT,
111                                                                                                                 EC_MSG_TYPE_NAME_SYNC_TASK_EDIT_ACCOUNT,
112                                                                                                                 pEditAccountTaskSpec, NULL);
113
114         engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_AUTOCONFIGURE,
115                                                                                                                         EC_MSG_TYPE_NAME_SYNC_TASK_AUTOCONFIGURE,
116                                                                                                                         pAutoConfTaskSpec, NULL);
117 /*******************************************************/
118
119
120         engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_REQUEST,
121                                                                                                                         EC_MSG_TYPE_NAME_SYNC_TASK_REQUEST,
122                                                                                                                         pSyncTaskSpec, NULL);
123
124         /*engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE,
125                                                                                                                 EC_MSG_TYPE_NAME_SYNC_TASK_ADD_PROFILE,
126                                                                                                                 pAddProfileTaskSpec, NULL);*/
127
128         /*engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_EDIT_PROFILE,
129                                                                                                                 EC_MSG_TYPE_NAME_SYNC_TASK_EDIT_PROFILE,
130                                                                                                                 pEditProfileTaskSpec, NULL);*/
131
132         engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_DELETE_PROFILE,
133                                                                                                                 EC_MSG_TYPE_NAME_SYNC_TASK_DELETE_PROFILE,
134                                                                                                                 pDeleteProfileTaskSpec, NULL);
135
136
137         /*engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_AUTO_CONFIGURE,
138                                                                                                                 EC_MSG_TYPE_NAME_SYNC_TASK_AUTO_CONFIGURE,
139                                                                                                                         pAutoConfTaskSpec, NULL);*/
140
141         engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_SYNCSTATUS,
142                                                                                                                         EC_MSG_TYPE_NAME_SYNC_TASK_SYNCSTATUS,
143                                                                                                                         pSyncStatusTaskSpec, NULL);
144
145         engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_NAME,
146                                                                                                                         EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_NAME,
147                                                                                                                         pGetProfileNameTaskSpec, NULL);
148
149         engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SERVER_INFO,
150                                                                                                                         EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_SERVER_INFO,
151                                                                                                                         pGetProfileServerInfoTaskSpec, NULL);
152
153         engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_MODE,
154                                                                                                                         EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_SYNC_MODE,
155                                                                                                                         pGetProfileSyncModeTaskSpec, NULL);
156
157         engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_CATEGORY,
158                                                                                                                         EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_SYNC_CATEGORY,
159                                                                                                                         pGetProfileSyncCategoryTaskSpec, NULL);
160
161         engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_LAST_SESSION,
162                                                                                                                         EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_LAST_SESSION,
163                                                                                                                         pGetProfileLastSessionTaskSpec, NULL);
164
165         engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_STATISTICS,
166                                                                                                                         EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_STATISTICS,
167                                                                                                                         pGetProfileStatisticsTaskSpec, NULL);
168
169         engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_RESET_SYNCHRONIZING_PROFILES,
170                                                                                                                         EC_MSG_TYPE_NAME_SYNC_TASK_RESET_SYNCHRONIZING_PROFILES,
171                                                                                                                         pResetSynchronizingProfilesTaskSpec, NULL);
172
173         engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE_CP,
174                                                                                                                         EC_MSG_TYPE_NAME_SYNC_TASK_ADD_PROFILE_CP,
175                                                                                                                         pAddProfileCPTaskSpec, NULL);
176
177         engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_REFRESH_FROM_SERVICE,
178                                                                                                                         EC_MSG_TYPE_NAME_SYNC_TASK_REFRESH_FROM_SERVICE,
179                                                                                                                         pRefreshFromServiceTaskSpec, NULL);
180
181         /*FIXME cancel request to NA */
182         /*engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_CANCEL_SYNC_REQUEST,
183                                                                                                                         EC_MSG_TYPE_NAME_SYNC_TASK_CANCEL_SYNC_REQUEST,
184                                                                                                                         pCancelSyncRequestTaskSpec, NULL);*/
185
186         queuing_rule_spec_t *pQueuing_rule = queuing_rule_spec_create_queuing_rule_spec_outline("sync_queueing_rule");
187
188         queuing_rule_spec_add_progress_blocking_element(pQueuing_rule, EC_MSG_TYPE_SYNC_TASK_REFRESH_FROM_SERVICE,
189                                                                                                                                                                         pSyncTaskSpec, 0);
190
191         queuing_rule_spec_add_progress_blocking_element(pQueuing_rule, EC_MSG_TYPE_SYNC_TASK_REQUEST,
192                                                                                                                                                                 pSyncTaskSpec, 0);
193
194         engine_controller_async_register_queuing_rule_spec(pQueuing_rule, NULL, NULL);
195
196         queuing_rule_spec_unref(pQueuing_rule);
197
198         __request_reset_synchronizing_profiles();                       /*reset synchronizing flag 0 every account & construct item tbl*/
199
200         /*TODO have to be removed after removing vconf*/
201         error = set_EventCallback(1,  event_callback_add_account);
202         if (error != EVENT_SUCCESS)
203                 FW_LOGE("failed set_EventCallback()");
204
205         error = set_EventCallback(3,  event_callback_edit_account);
206         if (error != EVENT_SUCCESS)
207                 FW_LOGE("failed set_EventCallback()");
208
209         error = set_EventCallback(5,  event_callback_auto_configure);
210         if (error != EVENT_SUCCESS)
211                 FW_LOGE("failed set_EventCallback()");
212 /************************************************/
213
214
215
216         /*error = set_EventCallback(1,  event_callback_add_profile_sync);
217         if (error != EVENT_SUCCESS)
218                 FW_LOGE("failed set_EventCallback()");*/
219
220         error = set_EventCallback(2,  event_callback_request_sync_async);
221         if (error != EVENT_SUCCESS)
222                 FW_LOGE("failed set_EventCallback()");
223
224         /*error = set_EventCallback(3,  event_callback_edit_profile_sync);
225         if (error != EVENT_SUCCESS)
226                 FW_LOGE("failed set_EventCallback()");*/
227
228         error = set_EventCallback(4,  event_callback_delete_profile_sync);
229         if (error != EVENT_SUCCESS)
230                 FW_LOGE("failed set_EventCallback()");
231
232         /*error = set_EventCallback(5,  event_callback_auto_configure_async);
233         if (error != EVENT_SUCCESS)
234                 FW_LOGE("failed set_EventCallback()");*/
235
236         error = set_EventCallback(6,  event_callback_cancel_sync_async);
237         if (error != EVENT_SUCCESS)
238                 FW_LOGE("failed set_EventCallback()");
239
240         error = set_EventCallback(7,  event_callback_query_sync_status_async);
241         if (error != EVENT_SUCCESS)
242                 FW_LOGE("failed set_EventCallback()");
243
244         error = set_EventCallback(8,  event_callback_get_profile_name_sync);
245         if (error != EVENT_SUCCESS)
246                 FW_LOGE("failed set_EventCallback()");
247
248         error = set_EventCallback(9,  event_callback_get_profile_server_info_sync);
249         if (error != EVENT_SUCCESS)
250                 FW_LOGE("failed set_EventCallback()");
251
252         error = set_EventCallback(10,  event_callback_get_profile_sync_mode_sync);
253         if (error != EVENT_SUCCESS)
254                 FW_LOGE("failed set_EventCallback()");
255
256         error = set_EventCallback(11,  event_callback_get_profile_sync_category_sync);
257         if (error != EVENT_SUCCESS)
258                 FW_LOGE("failed set_EventCallback()");
259
260         error = set_EventCallback(12,  event_callback_get_profile_last_session_sync);
261         if (error != EVENT_SUCCESS)
262                 FW_LOGE("failed set_EventCallback()");
263
264         error = set_EventCallback(13,  event_callback_get_profile_last_statistics_sync);
265         if (error != EVENT_SUCCESS)
266                 FW_LOGE("failed set_EventCallback()");
267
268         error = set_EventCallback(14,  event_callback_add_profile_cp_sync);
269         if (error != EVENT_SUCCESS)
270                 FW_LOGE("failed set_EventCallback()");
271
272         PMCI_RETURN san_err = PMCI_Init_Specific_Type(DEFINE_PLATFORM, SAN, PKG_NAME, NULL, 1, SAN_callback_parse);
273         if (san_err != PMCI_SUCCESS)
274                 FW_LOGE("failed in PMCI_Init_Specific_Type");
275
276         PMCI_RETURN scheduler_err = PMCI_Init_Specific_Type(DEFINE_PLATFORM, ALARM, PKG_NAME, NULL, 1, send_periodic_sync_msg);
277         if (scheduler_err != PMCI_SUCCESS)
278                 FW_LOGE("failed in PMCI_Init_Specific_Type");
279
280         /*register profiles from csc*/
281         __check_csc();
282
283         while (1) {
284                 sleep(1);
285         }
286         return 0;
287 }
288
289 static void __request_reset_synchronizing_profiles()
290 {
291         FW_LOGV("start");
292         unsigned int request_msg_id = 0;
293         engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_RESET_SYNCHRONIZING_PROFILES, 0,
294                                                                                                                         0, NULL, NULL, NULL, NULL, NULL, (int *)&request_msg_id);
295         FW_LOGV("end");
296 }
297 static void __check_csc()
298 {
299         FW_LOGV("start");
300
301         bool exist = false;
302
303         /*FIXME(temporary do not process csc for ui reason)
304         check csc_check file is existed
305         if false do csc update
306         if true check csc xml file has been changed*/
307
308         /*exist = FSAPI_isExisting(OMA_DS_CSC_CHECK_PATH);*/
309         exist = true;
310         FW_LOGV("update = %d", exist);
311
312         if (exist == false)
313                 __update_csc();
314
315         FW_LOGV("end");
316 }
317
318 static void __update_csc()
319 {
320         FW_LOGV("start");
321
322         char profile[128];
323         int numberOfProfiles = 0;
324         char *contents = "check";
325
326         bool result = get_vconf_Int_key(CSC_VCONF_KEY_SYNCMLDS_NBDATASYNC, &numberOfProfiles);
327         if (result == false) {
328                 FW_LOGE("failed in get_vconf_Int_key");
329                 goto error;
330         }
331
332         int i;
333         for (i = 1; i <= numberOfProfiles; i++) {
334                 sprintf(profile, "Sync%d", i);
335                 add_profile_csc(i);
336         }
337
338         FSAPI_fileWriteWhole(OMA_DS_CSC_CHECK_PATH, contents, sizeof(contents), false);
339
340 error:
341
342         FW_LOGV("end");
343 }