upload tizen1.0 source
[pkgs/o/oma-ds-service.git] / 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_part:
155
156         if (account_list_count > 0)
157                 free(account_list);
158
159         if (sync_mode)
160                 free(sync_mode);
161
162         if (server_id)
163                 free(server_id);
164
165         DACI_Close_Agent();
166
167         FW_LOGV("end");
168         return 0;
169 }
170
171 void send_periodic_sync_msg(int schedulerId, void *data)
172 {
173         FW_LOGV("#######Scheduler Send Msg Success!!!!!##########");
174         FW_LOGV("schedulerId = %d", schedulerId);
175
176         int *account_list = 0;
177         int account_list_count = 0;
178         int accountId = -1;
179         int alarmId = 0;
180         char *alarmId_str = NULL;
181         bool result;
182
183         DACI_RETURN da_err = DACI_Open_Agent();
184         if (da_err != DACI_SUCCESS) {
185                 FW_LOGE("failed in DACI_Open_Agent");
186                 goto error;
187         }
188
189         account_list = DACI_Get_Account_Account_Id_List(&account_list_count);
190
191         FW_LOGV("account_list_count = %d", account_list_count);
192
193         int i;
194         for (i = 0; i < account_list_count; i++) {
195                 if (alarmId_str != NULL)
196                         free(alarmId_str);
197
198                 result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &alarmId_str);
199                 if (result == false) {
200                         FW_LOGE("failed in get_Config");
201                         goto error;
202                 }
203                 alarmId = atoi(alarmId_str);
204                 FW_LOGV("alarm id = %d", alarmId);
205                 if (alarmId == schedulerId) {
206                         FW_LOGV("account_list[i] = %d", account_list[i]);
207                         accountId = account_list[i];
208                         break;
209                 }
210         }
211
212         if (accountId != -1) {
213                 int in_param_index_array[3] = {0, 1, 2};
214                 ECValueType in_param_value_type_array[3] = {EC_VALUE_TYPE_INT,
215                                                                                         EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
216                 char *syncMode = strdup(DEFINE_SYNC_MODE_PERIODIC);
217
218                 void *in_param_value_array[3] = {&accountId, &syncMode, NULL};
219
220                 unsigned int request_msg_id = 0;
221                 engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_REQUEST, 0,
222                                                                                                                                         3, in_param_index_array, in_param_value_type_array, in_param_value_array,
223                                                                                                                                         __request_periodic_sync_task_finish_callback, NULL,
224                                                                                                                                         (int *)&request_msg_id);
225
226                 insert_request_msg_info(SYNC_MODE_PERIODIC, request_msg_id);
227         }
228
229 error:
230
231         if (account_list_count > 0)
232                 free(account_list);
233
234         if (alarmId_str != NULL)
235                 free(alarmId_str);
236
237         DACI_Close_Agent();
238 }