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