upload tizen1.0 source
[pkgs/o/oma-ds-service.git] / src / Framework / Event / OMA_DS_Platform_Event_Handler.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  *   @OMA_DS_Platform_Event_Handler.c
38  *   @version                                                                   0.1
39  *   @brief                                                                             This file is the source file of implementation of event callback function(from platform)
40  */
41
42 #include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
43 #include "Framework/Event/OMA_DS_Platform_Event_Handler.h"
44 #include "Framework/Task/OMA_DS_Engine_Controller_Task.h"
45 #include "Framework/SAN_parser/PM_SanParser.h"
46 #include "agent-framework/Utility/fw_log.h"
47 #include "Common/Common_Define_Internal.h"
48 #include "Common/Common_Util.h"
49
50 #define LOG_TAG "OMA_DS_COMMON"
51
52 static void __request_periodic_sync_task_finish_callback(task_error_t task_error,
53                                                                                         unsigned int out_param_cnt, param_t **out_param_spec_array, void *usr_data);
54
55 static void __request_san_sync_task_finish_callback(task_error_t task_error,
56                                                                                         unsigned int out_param_cnt, param_t **out_param_spec_array, void *usr_data);
57
58 static void __request_periodic_sync_task_finish_callback(task_error_t task_error,
59                                                                                                                         unsigned int out_param_cnt,
60                                                                                                                         param_t **out_param_spec_array,
61                                                                                                                         void *usr_data)
62 {
63         unsigned int request_msg_id_to_cancel = 0;
64         get_periodic_sync_request_id(&request_msg_id_to_cancel);
65
66 }
67
68 static void __request_san_sync_task_finish_callback(task_error_t task_error,
69                                                                                                                         unsigned int out_param_cnt,
70                                                                                                                         param_t **out_param_spec_array,
71                                                                                                                         void *usr_data)
72 {
73         unsigned int request_msg_id_to_cancel = 0;
74         get_san_sync_request_id(&request_msg_id_to_cancel);
75 }
76
77 int SAN_callback_parse(const char *msgBody, unsigned int msgSize, int version)
78 {
79         FW_LOGV("start");
80         SanPackage  *pSanPackage = NULL;
81         int accountID = -1;
82         char *sync_mode = NULL;
83         char *server_id = NULL;
84         int *account_list = 0;
85
86         switch (version) {
87         case 11:
88         {
89                 pSanPackage = sanPackage11Parser(msgBody, msgSize) ;
90         }
91                 break;
92         case 12:
93         {
94                 pSanPackage = sanPackage12Parser(msgBody, msgSize) ;
95         }
96                 break;
97         default:
98                 break;
99         }
100
101         DACI_RETURN da_err = DACI_Open_Agent();
102         if (da_err != DACI_SUCCESS)
103                 return 0;
104
105         if (!pSanPackage)
106                 goto return_part;
107
108
109         int account_list_count = 0;
110         account_list = DACI_Get_Account_Account_Id_List(&account_list_count);
111         bool result;
112
113         int i;
114         for (i = 0 ; i < account_list_count ; i++) {
115                 result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, &sync_mode);
116                 if (result == true) {
117                         /*One device MUST NOT register multi account at same server...*/
118                         if (strcmp(sync_mode, DEFINE_SYNC_MODE_PUSH) == 0) {
119                                 result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, &server_id);
120                                 if (result == true) {
121                                         /*One device MUST NOT register multi account at same server...*/
122                                         if (strcmp(pSanPackage->serverID, server_id) == 0) {
123                                                 accountID = account_list[i];
124                                                 break;
125                                         }
126                                 } else{
127                                         FW_LOGE("failed in get_Config");
128                                         goto return_part;
129                                 }
130                         }
131                 } else{
132                         FW_LOGE("failed in get_Config");
133                         goto return_part;
134                 }
135
136         }
137
138         if (accountID < 0)
139                 goto return_part;
140
141         char *syncMode = strdup(DEFINE_SYNC_MODE_PUSH) ;
142
143         void *in_param_value_array[3] = {&accountID, &syncMode, &pSanPackage};
144         int in_param_index_array[3] = {0, 1, 2};
145         ECValueType in_param_type[3] = {EC_VALUE_TYPE_INT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
146         unsigned int request_msg_id = 0;
147         engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_REQUEST, 0,
148                                                                                                                         3, in_param_index_array, in_param_type, in_param_value_array,
149                                                                                                                         __request_san_sync_task_finish_callback, NULL,
150                                                                                                                         (int *)&request_msg_id);
151
152         insert_request_msg_info(SYNC_MODE_SAN, request_msg_id);
153
154         return 1;
155
156 return_part:
157
158         if (account_list_count > 0)
159                 free(account_list);
160
161         if (sync_mode)
162                 free(sync_mode);
163
164         if (server_id)
165                 free(server_id);
166
167         DACI_Close_Agent();
168
169         FW_LOGV("end");
170         return 0;
171 }
172
173 void send_periodic_sync_msg(int schedulerId, void *data)
174 {
175         FW_LOGV("#######Scheduler Send Msg Success!!!!!##########");
176         FW_LOGV("schedulerId = %d", schedulerId);
177
178         int *account_list = 0;
179         int account_list_count = 0;
180         int accountId = -1;
181         int alarmId = 0;
182         char *alarmId_str = NULL;
183         bool result;
184
185         DACI_RETURN da_err = DACI_Open_Agent();
186         if (da_err != DACI_SUCCESS) {
187                 FW_LOGE("failed in DACI_Open_Agent");
188                 goto error;
189         }
190
191         account_list = DACI_Get_Account_Account_Id_List(&account_list_count);
192
193         FW_LOGV("account_list_count = %d", account_list_count);
194
195         int i;
196         for (i = 0; i < account_list_count; i++) {
197                 if (alarmId_str != NULL)
198                         free(alarmId_str);
199
200                 result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &alarmId_str);
201                 if (result == false) {
202                         FW_LOGE("failed in get_Config");
203                         goto error;
204                 }
205                 alarmId = atoi(alarmId_str);
206                 FW_LOGV("alarm id = %d", alarmId);
207                 if (alarmId == schedulerId) {
208                         FW_LOGV("account_list[i] = %d", account_list[i]);
209                         accountId = account_list[i];
210                         break;
211                 }
212         }
213
214         if (accountId != -1) {
215                 int in_param_index_array[3] = {0, 1, 2};
216                 ECValueType in_param_value_type_array[3] = {EC_VALUE_TYPE_INT,
217                                                                                         EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
218                 char *syncMode = strdup(DEFINE_SYNC_MODE_PERIODIC);
219
220                 void *in_param_value_array[3] = {&accountId, &syncMode, NULL};
221
222                 unsigned int request_msg_id = 0;
223                 engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_REQUEST, 0,
224                                                                                                                                         3, in_param_index_array, in_param_value_type_array, in_param_value_array,
225                                                                                                                                         __request_periodic_sync_task_finish_callback, NULL,
226                                                                                                                                         (int *)&request_msg_id);
227
228                 insert_request_msg_info(SYNC_MODE_PERIODIC, request_msg_id);
229         }
230
231 error:
232
233         if (account_list_count > 0)
234                 free(account_list);
235
236         if (alarmId_str != NULL)
237                 free(alarmId_str);
238
239         DACI_Close_Agent();
240 }