upload tizen1.0 source
[pkgs/o/oma-ds-service.git] / src / Framework / Event / OMA_DS_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_Event_Handler.c
38  *   @version                                                                   0.1
39  *   @brief                                                                             This file is the source file of implementation of event callback function(from ui)
40  */
41
42 #include <glib.h>
43 #include <stdlib.h>
44 #include <string.h>
45 #include "Framework/Event/OMA_DS_Event_Handler.h"
46 #include "Framework/Event/OMA_DS_Platform_Event_Handler.h"
47 #include "Framework/Task/OMA_DS_Engine_Controller_Task.h"
48 #include "Common/Common_Define.h"
49 #include "Common/Common_Vconf.h"
50 #include "Common/Common_Util.h"
51 #include "agent-framework/Utility/fw_log.h"
52
53 #define LOG_TAG "OMA_DS_COMMON"
54
55 static void __request_manual_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 __auto_configure_task_finish_callback(task_error_t task_error,
59                                                                                                                 unsigned int out_param_cnt, param_t **out_param_spec_array, void *usr_data);
60
61
62 static void __request_manual_sync_task_finish_callback(task_error_t task_error,
63                                                                                                                         unsigned int out_param_cnt,
64                                                                                                                         param_t **out_param_spec_array,
65                                                                                                                         void *usr_data)
66 {
67         unsigned int request_msg_id_to_cancel = 0;
68         get_manual_sync_request_id(&request_msg_id_to_cancel);
69 }
70
71 static void __auto_configure_task_finish_callback(task_error_t task_error,
72                                                                                                                         unsigned int out_param_cnt,
73                                                                                                                         param_t **out_param_spec_array,
74                                                                                                                         void *usr_data)
75 {
76         unsigned int request_msg_id_to_cancel = 0;
77         get_auto_configure_request_id(&request_msg_id_to_cancel);
78 }
79
80 /*TODO have to be removed after removing vconf*/
81 int event_callback_add_account(Event_Data *request, Event_Data *response)
82 {
83         FW_LOGV("start");
84
85         int result;
86         char *profile = NULL;
87         get_eventdata_param(request, &profile);
88
89         if (!profile) {
90                 FW_LOGE("profile is not defined");
91                 goto error;
92         }
93         FW_LOGV("request param : %s", profile);
94
95         /* send to engine controller */
96         void *in_param_value_array[1] = {&profile};
97         int in_param_index_array[1] = {0};
98         ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_STRUCT};
99         unsigned int request_msg_id = 0;
100
101         unsigned int out_param_count;
102         task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
103         param_t **param_array = NULL;
104
105         engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_ADD_ACCOUNT, 0,
106                                                                                                                         1, in_param_index_array, in_param_value_type_array, in_param_value_array,
107                                                                                                                         (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
108
109         param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
110
111         append_eventdata_param(response, INTEGER, &result);
112
113         FW_LOGV("end");
114
115 error:
116
117         return 0;
118 }
119
120 /*TODO have to be removed after removing vconf*/
121 int event_callback_edit_account(Event_Data *request, Event_Data *response)
122 {
123         FW_LOGV("start");
124
125         int result;
126         char *profile = NULL;
127         get_eventdata_param(request, &profile);
128
129         if (!profile) {
130                 FW_LOGE("profile is not defined");
131                 goto error;
132         }
133         FW_LOGV("request param : %s", profile);
134
135         /* send to engine controller */
136         void *in_param_value_array[1] = {&profile};
137         int in_param_index_array[1] = {0};
138         ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_STRUCT};
139         unsigned int request_msg_id = 0;
140
141         unsigned int out_param_count;
142         task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
143         param_t **param_array = NULL;
144
145         engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_EDIT_ACCOUNT, 0,
146                                                                                                                                 1, in_param_index_array, in_param_value_type_array, in_param_value_array,
147                                                                                                                                 (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
148
149         param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
150
151         append_eventdata_param(response, INTEGER, &result);
152
153         FW_LOGV("end");
154
155 error:
156
157         return 0;
158 }
159
160 /*TODO have to be removed after removing vconf*/
161 int event_callback_auto_configure(Event_Data *request, Event_Data *response)
162 {
163         FW_LOGV("start");
164
165         char *profile = NULL;
166         get_eventdata_param(request, &profile);
167
168         if (!profile) {
169                 FW_LOGE("profile is not defined");
170                 goto error;
171         }
172
173         FW_LOGV("request param : %s", profile);
174
175         void *in_param_value_array[1] = {&profile};
176         int in_param_index_array[1] = {0};
177         ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_STRUCT};
178         unsigned int request_msg_id = 0;
179         engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_AUTOCONFIGURE, 0,
180                                                                                                                                 1, in_param_index_array, in_param_value_type_array, in_param_value_array,
181                                                                                                                                 __auto_configure_task_finish_callback, NULL, (int *)&request_msg_id);
182
183         insert_request_msg_info(SYNC_MODE_AUTOCONFIG, request_msg_id);
184
185         FW_LOGV("end");
186
187 error:
188
189         return 0;
190 }
191
192 int event_callback_add_profile_sync(Event_Data *request, Event_Data *response)
193 {
194         FW_LOGV("start");
195
196         char *profileDirName = NULL;
197         char *profileName = NULL;
198         char *addr = NULL;
199         char *id = NULL;
200         char *password = NULL;
201         char *syncMode = NULL;
202         char *syncType = NULL;
203         char *interval = NULL;
204         int category_count;
205         int result;
206         int accountId;
207
208         get_eventdata_param(request, &profileDirName);
209         get_eventdata_param(request, &profileName);
210         get_eventdata_param(request, &addr);
211         get_eventdata_param(request, &id);
212         get_eventdata_param(request, &password);
213         get_eventdata_param(request, &syncMode);
214         get_eventdata_param(request, &syncType);
215         get_eventdata_param(request, &interval);
216         get_eventdata_param(request, &category_count);
217
218         /*
219         FW_LOGV("request param : %s", profileDirName);
220         FW_LOGV("request param : %s", profileName);
221         FW_LOGV("request param : %s", addr);
222         FW_LOGV("request param : %s", id);
223         FW_LOGV("request param : %s", password);
224         FW_LOGV("request param : %s", syncMode);
225         FW_LOGV("request param : %s", syncType);
226         FW_LOGV("request param : %s", interval);
227         FW_LOGV("request param : %d", category_count);
228         */
229
230         GList *categorys = NULL;
231         sync_category *category = (sync_category *)calloc(1, sizeof(sync_category));
232
233         int i = 0;
234         for (; i < category_count ; i++) {
235                 get_eventdata_param(request, &(category->enabled));
236                 get_eventdata_param(request, &(category->srcURI));
237                 get_eventdata_param(request, &(category->tgtURI));
238                 get_eventdata_param(request, &(category->id));
239                 get_eventdata_param(request, &(category->password));
240
241                 categorys = g_list_append(categorys, category);
242
243                 /*
244                 FW_LOGV("category[i]->enabled : %d", category->enabled);
245                 FW_LOGV("category[i]->srcURI : %s", category->srcURI);
246                 FW_LOGV("category[i]->tgtURI : %s", category->tgtURI);
247                 FW_LOGV("category[i]->id : %s", category->id);
248                 FW_LOGV("category[i]->password : %s", category->password);
249                 */
250         }
251
252         /* send to engine controller */
253         void *in_param_value_array[9] = {&profileDirName, &profileName, &addr, &id, &password, &syncMode, &syncType, &interval, &categorys};
254         int in_param_index_array[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
255         ECValueType in_param_value_type_array[9] = {EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT,
256                                                                                                 EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT,
257                                                                                                 EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
258         unsigned int request_msg_id = 0;
259
260         unsigned int out_param_count;
261         task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
262         param_t **param_array = NULL;
263
264         engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE, 0,
265                                                                                                                         9, in_param_index_array, in_param_value_type_array, in_param_value_array,
266                                                                                                                         (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
267
268         param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
269         param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &accountId);
270
271         append_eventdata_param(response, INTEGER, &result);
272         append_eventdata_param(response, INTEGER, &accountId);
273
274
275         FW_LOGV("end");
276
277         return 0;
278 }
279
280 int event_callback_edit_profile_sync(Event_Data *request, Event_Data *response)
281 {
282         FW_LOGV("start");
283
284         char *profileDirName = NULL;
285         char *profileName = NULL;
286         char *addr = NULL;
287         char *id = NULL;
288         char *password = NULL;
289         char *syncMode = NULL;
290         char *syncType = NULL;
291         char *interval = NULL;
292         int category_count;
293         int result;
294
295         get_eventdata_param(request, &profileDirName);
296
297         if (!profileDirName) {
298                 FW_LOGE("profileDirName is not defined");
299                 goto error;
300         }
301         FW_LOGV("request param : %s", profileDirName);
302
303         int accountId =  get_accountid(profileDirName, false);
304
305         get_eventdata_param(request, &profileName);
306         get_eventdata_param(request, &addr);
307         get_eventdata_param(request, &id);
308         get_eventdata_param(request, &password);
309         get_eventdata_param(request, &syncMode);
310         get_eventdata_param(request, &syncType);
311         get_eventdata_param(request, &interval);
312         get_eventdata_param(request, &category_count);
313
314         /*
315         FW_LOGV("request param : %s", profileName);
316         FW_LOGV("request param : %s", addr);
317         FW_LOGV("request param : %s", id);
318         FW_LOGV("request param : %s", password);
319         FW_LOGV("request param : %s", syncMode);
320         FW_LOGV("request param : %s", syncType);
321         FW_LOGV("request param : %s", interval);
322         FW_LOGV("request param : %d", category_count);
323         */
324
325         GList *categorys = NULL;
326         sync_category *category = (sync_category *)calloc(1, sizeof(sync_category));
327
328         int i = 0;
329         for (; i < category_count ; i++) {
330                 get_eventdata_param(request, &(category->enabled));
331                 get_eventdata_param(request, &(category->srcURI));
332                 get_eventdata_param(request, &(category->tgtURI));
333                 get_eventdata_param(request, &(category->id));
334                 get_eventdata_param(request, &(category->password));
335
336                 categorys = g_list_append(categorys, category);
337
338                 /*
339                 FW_LOGV("category[i]->enabled : %d", category->enabled);
340                 FW_LOGV("category[i]->srcURI : %s", category->srcURI);
341                 FW_LOGV("category[i]->tgtURI : %s", category->tgtURI);
342                 FW_LOGV("category[i]->id : %s", category->id);
343                 FW_LOGV("category[i]->password : %s", category->password);
344                 */
345         }
346
347         /* send to engine controller */
348         void *in_param_value_array[9] = {&accountId, &profileName, &addr, &id, &password, &syncMode, &syncType, &interval, &categorys};
349         int in_param_index_array[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
350         ECValueType in_param_value_type_array[9] = {EC_VALUE_TYPE_INT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT,
351                                                                                                 EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT,
352                                                                                                 EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
353         unsigned int request_msg_id = 0;
354
355         unsigned int out_param_count;
356         task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
357         param_t **param_array = NULL;
358
359         engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_EDIT_PROFILE, 0,
360                                                                                                                         9, in_param_index_array, in_param_value_type_array, in_param_value_array,
361                                                                                                                         (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
362
363         param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
364
365         append_eventdata_param(response, INTEGER, &result);
366
367         FW_LOGV("end");
368
369 error:
370
371         return 0;
372 }
373
374 int event_callback_delete_profile_sync(Event_Data *request, Event_Data *response)
375 {
376         FW_LOGV("start");
377
378         int result;
379         int count;
380         get_eventdata_param(request, &count);
381         GList *profiles = NULL;
382         int *accountId = 0;
383
384         int i;
385         char *profile = NULL;
386         for (i = 0; i < count; i++) {
387                 if (profile != NULL) {
388                         free(profile);
389                         profile = NULL;
390                 }
391
392                 get_eventdata_param(request, &profile);
393                 if (!profile) {
394                         FW_LOGE("profile is not defined");
395                         goto error;
396                 }
397                 FW_LOGV("request param : %s", profile);
398
399                 accountId = (int *)calloc(1, sizeof(int));
400                 *accountId = get_accountid(profile, false);
401
402                 profiles = g_list_append(profiles, accountId);
403         }
404
405         /* send to engine controller */
406         void *in_param_value_array[1] = {&profiles};
407         int in_param_index_array[1] = {0};
408         ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_STRUCT};
409         unsigned int request_msg_id = 0;
410
411         unsigned int out_param_count;
412         task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
413         param_t **param_array = NULL;
414
415         engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_DELETE_PROFILE, 0,
416                                                                                                                                         1, in_param_index_array, in_param_value_type_array, in_param_value_array,
417                                                                                                                                         (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
418
419         param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
420
421         append_eventdata_param(response, INTEGER, &result);
422
423         FW_LOGV("end");
424
425 error:
426         if (profile != NULL)
427                 free(profile);
428
429         return 0;
430 }
431
432 int event_callback_request_sync_async(Event_Data *request, Event_Data *response)
433 {
434         FW_LOGV("start");
435         char *profile = NULL;
436         get_eventdata_param(request, &profile);
437
438         if (!profile) {
439                 FW_LOGE("profile is not defined");
440                 goto error;
441         }
442         FW_LOGV("request param : %s", profile);
443
444         int accountId =  get_accountid(profile, false);
445         char *syncMode = strdup(DEFINE_SYNC_MODE_MANUAL);
446
447         void *in_param_value_array[3] = {&accountId, &syncMode, NULL};
448         int in_param_index_array[3] = {0, 1, 2};
449         ECValueType in_param_value_type_array[3] = {EC_VALUE_TYPE_INT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
450         unsigned int request_msg_id = 0;
451         engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_REQUEST, 0,
452                                                                                                                                 3, in_param_index_array, in_param_value_type_array, in_param_value_array,
453                                                                                                                                 __request_manual_sync_task_finish_callback, NULL, (int *)&request_msg_id);
454
455         insert_request_msg_info(SYNC_MODE_MANUAL, request_msg_id);
456
457
458         FW_LOGV("end");
459
460 error:
461
462         if (profile != NULL)
463                 free(profile);
464
465         return 0;
466 }
467
468 int event_callback_auto_configure_async(Event_Data *request, Event_Data *response)
469 {
470         FW_LOGV("start");
471
472         char *profileDirName = NULL;
473         char *addr = NULL;
474         char *id = NULL;
475         char *password = NULL;
476
477         get_eventdata_param(request, &profileDirName);
478         get_eventdata_param(request, &addr);
479         get_eventdata_param(request, &id);
480         get_eventdata_param(request, &password);
481
482         /*
483         FW_LOGV("request param : %s", profileDirName);
484         FW_LOGV("request param : %s", addr);
485         FW_LOGV("request param : %s", id);
486         FW_LOGV("request param : %s", password);
487         */
488
489         void *in_param_value_array[4] = {&profileDirName, &addr, &id, &password};
490         int in_param_index_array[4] = {0, 1, 2, 3};
491         ECValueType in_param_value_type_array[4] = {EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
492         unsigned int request_msg_id = 0;
493         engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_AUTO_CONFIGURE, 0,
494                                                                                                                                 4, in_param_index_array, in_param_value_type_array, in_param_value_array,
495                                                                                                                                 __auto_configure_task_finish_callback, NULL, (int *)&request_msg_id);
496
497         insert_request_msg_info(SYNC_MODE_AUTOCONFIG, request_msg_id);
498
499         FW_LOGV("end");
500
501         return 0;
502 }
503
504 int event_callback_cancel_sync_async(Event_Data *request, Event_Data *response)
505 {
506         FW_LOGV("start");
507         char *profile = NULL;
508         get_eventdata_param(request, &profile);
509
510         if (!profile) {
511                 FW_LOGE("profile is not defined");
512                 goto error;
513         }
514
515         FW_LOGV("request param : %s", profile);
516
517         unsigned int request_msg_id_to_cancel =  0;
518         bool has_autoconfig = get_auto_configure_request_id(&request_msg_id_to_cancel);
519         if (has_autoconfig) {
520                 FW_LOGV("has_autoconfig [%d] ", request_msg_id_to_cancel);
521                 engine_controller_cancel_task(request_msg_id_to_cancel);
522         } else{
523                 bool has_sync = get_synchronizing_request_id(&request_msg_id_to_cancel);
524                 if (has_sync) {
525                         FW_LOGV("has_manual_sync [%d] ", request_msg_id_to_cancel);
526                         engine_controller_cancel_task(request_msg_id_to_cancel);
527
528                         /*request network session cancel*/
529                         /*engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_CANCEL_SYNC_REQUEST, 0,
530                                                                                                                                 0, NULL, NULL, NULL, NULL, NULL, &request_msg_id);*/
531                 } else {
532                         /* nothing to do */
533                 }
534         }
535
536
537         FW_LOGV("end");
538
539 error:
540
541         if (profile != NULL)
542                 free(profile);
543
544         return 0;
545 }
546
547 int event_callback_query_sync_status_async(Event_Data *request, Event_Data *response)
548 {
549         FW_LOGV("start");
550
551         unsigned int request_msg_id = 0;
552         engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_SYNCSTATUS, 0,
553                                                                                                                         0, NULL, NULL, NULL, NULL, NULL, (int *)&request_msg_id);
554
555         FW_LOGV("end");
556         return 0;
557 }
558
559 int event_callback_get_profile_name_sync(Event_Data *request, Event_Data *response)
560 {
561         FW_LOGV("start");
562         char *profile = NULL;
563         char *profileName = NULL;
564         int result;
565
566         get_eventdata_param(request, &profile);
567         if (!profile) {
568                 FW_LOGE("profile is not defined");
569                 goto error;
570         }
571
572         FW_LOGV("request param : %s", profile);
573
574         int accountId =  get_accountid(profile, false);
575
576         int in_param_index_array[1] = {0};
577         void *in_param_value_array[1] = {&accountId};
578         ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_INT};
579
580         unsigned int out_param_count;
581         task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
582         param_t **param_array = NULL;
583
584
585         unsigned int request_msg_id = 0;
586         engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_NAME, 0,
587                                                                                                                         1, in_param_index_array, in_param_value_type_array, in_param_value_array,
588                                                                                                                         (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
589
590         param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
591         param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &profileName);
592
593         /*
594         FW_LOGV("result = %d", result);
595         FW_LOGV("profileName = %s", profileName);
596         */
597
598         append_eventdata_param(response, INTEGER, &result);
599         append_eventdata_param(response, STRING, (void *)profileName);
600
601
602         FW_LOGV("end");
603 error:
604
605         if (profile != NULL)
606                 free(profile);
607
608         return 0;
609 }
610
611 int event_callback_get_profile_server_info_sync(Event_Data *request, Event_Data *response)
612 {
613         FW_LOGV("start");
614         char *profile = NULL;
615         char *addr = NULL;
616         char *id = NULL;
617         char *password = NULL;
618         int result;
619
620         get_eventdata_param(request, &profile);
621         if (!profile) {
622                 FW_LOGE("profile is not defined");
623                 goto error;
624         }
625
626         FW_LOGV("request param : %s", profile);
627
628         int accountId =  get_accountid(profile, false);
629
630         int in_param_index_array[1] = {0};
631         void *in_param_value_array[1] = {&accountId};
632         ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_INT};
633
634         unsigned int out_param_count;
635         task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
636         param_t **param_array = NULL;
637
638         unsigned int request_msg_id = 0;
639         engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SERVER_INFO, 0,
640                                                                                                                         1, in_param_index_array, in_param_value_type_array, in_param_value_array,
641                                                                                                                         (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
642
643         param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
644         param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &addr);
645         param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &id);
646         param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &password);
647
648         /*
649         FW_LOGV("result = %d", result);
650         FW_LOGV("addr = %s", addr);
651         FW_LOGV("id = %s", id);
652         FW_LOGV("password = %s", password);
653         */
654
655         append_eventdata_param(response, INTEGER, &result);
656         append_eventdata_param(response, STRING, (void *)addr);
657         append_eventdata_param(response, STRING, (void *)id);
658         append_eventdata_param(response, STRING, (void *)password);
659
660         FW_LOGV("end");
661
662 error:
663
664         if (profile != NULL)
665                 free(profile);
666
667         return 0;
668 }
669
670 int event_callback_get_profile_sync_mode_sync(Event_Data *request, Event_Data *response)
671 {
672         FW_LOGV("start");
673         char *profile = NULL;
674         char *syncMode = NULL;
675         char *syncType = NULL;
676         char *interval = NULL;
677         int result;
678
679         get_eventdata_param(request, &profile);
680         if (!profile) {
681                 FW_LOGE("profile is not defined");
682                 goto error;
683         }
684         FW_LOGV("request param : %s", profile);
685
686         int accountId =  get_accountid(profile, false);
687
688         int in_param_index_array[1] = {0};
689         void *in_param_value_array[1] = {&accountId};
690         ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_INT};
691
692         unsigned int out_param_count;
693         task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
694         param_t **param_array = NULL;
695
696
697         unsigned int request_msg_id = 0;
698         engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_MODE, 0,
699                                                                                                                         1, in_param_index_array, in_param_value_type_array, in_param_value_array,
700                                                                                                                         (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
701
702         param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
703         param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &syncMode);
704         param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &syncType);
705         param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &interval);
706
707         /*
708         FW_LOGV("result = %d", result);
709         FW_LOGV("syncMode = %s", syncMode);
710         FW_LOGV("syncType = %s", syncType);
711         FW_LOGV("interval = %s", interval);
712         */
713
714         append_eventdata_param(response, INTEGER, &result);
715         append_eventdata_param(response, STRING, (void *)syncMode);
716         append_eventdata_param(response, STRING, (void *)syncType);
717         append_eventdata_param(response, STRING, (void *)interval);
718
719
720         FW_LOGV("end");
721
722 error:
723
724         if (profile != NULL)
725                 free(profile);
726
727         return 0;
728 }
729
730 int event_callback_get_profile_sync_category_sync(Event_Data *request, Event_Data *response)
731 {
732         FW_LOGV("start");
733         char *profile = NULL;
734         int content_type;
735         int enabled;
736         char *srcURI = NULL;
737         char *tgtURI = NULL;
738         char *id = NULL;
739         char *password = NULL;
740         int result;
741
742         get_eventdata_param(request, &profile);
743         if (!profile) {
744                 FW_LOGE("profile is not defined");
745                 goto error;
746         }
747
748         get_eventdata_param(request, &content_type);
749
750         FW_LOGV("request param : %s", profile);
751         FW_LOGV("request param : %d", content_type);
752
753         int accountId =  get_accountid(profile, false);
754         FW_LOGV(" accountId: %d", accountId);
755
756         int in_param_index_array[2] = {0, 1};
757         void *in_param_value_array[2] = {&accountId, &content_type};
758         ECValueType in_param_value_type_array[2] = {EC_VALUE_TYPE_INT, EC_VALUE_TYPE_INT};
759
760         unsigned int out_param_count;
761         task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
762         param_t **param_array = NULL;
763
764         unsigned int request_msg_id = 0;
765         engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_CATEGORY, 0,
766                                                                                                                         2, in_param_index_array, in_param_value_type_array, in_param_value_array,
767                                                                                                                         (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
768
769         param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
770         param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &enabled);
771         param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &srcURI);
772         param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &tgtURI);
773         param_value_get_value(&(param_array[4]->param_value), EC_VALUE_TYPE_STRUCT, &id);
774         param_value_get_value(&(param_array[5]->param_value), EC_VALUE_TYPE_STRUCT, &password);
775
776         /*
777         FW_LOGV("result = %d", result);
778         FW_LOGV("enabled = %d", enabled);
779         FW_LOGV("srcURI = %s", srcURI);
780         FW_LOGV("tgtURI = %s", tgtURI);
781         FW_LOGV("id = %s", id);
782         FW_LOGV("password = %s", password);
783         */
784
785         append_eventdata_param(response, INTEGER, &result);
786         append_eventdata_param(response, INTEGER, &enabled);
787         append_eventdata_param(response, STRING, (void *)srcURI);
788         append_eventdata_param(response, STRING, (void *)tgtURI);
789         append_eventdata_param(response, STRING, (void *)id);
790         append_eventdata_param(response, STRING, (void *)password);
791
792
793         FW_LOGV("end");
794
795 error:
796
797         if (profile != NULL)
798                 free(profile);
799
800         return 0;
801 }
802
803 int event_callback_get_profile_last_session_sync(Event_Data *request, Event_Data *response)
804 {
805         FW_LOGV("start");
806         char *profile = NULL;
807         int result;
808         int lastSessionStatus;
809         int lastSessionTime;
810
811         get_eventdata_param(request, &profile);
812         if (!profile) {
813                 FW_LOGE("profile is not defined");
814                 goto error;
815         }
816         FW_LOGV("request param : %s", profile);
817
818         int accountId =  get_accountid(profile, false);
819
820         int in_param_index_array[1] = {0};
821         void *in_param_value_array[1] = {&accountId};
822         ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_INT};
823
824         unsigned int out_param_count;
825         task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
826         param_t **param_array = NULL;
827
828
829         unsigned int request_msg_id = 0;
830         engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_LAST_SESSION, 0,
831                                                                                                                         1, in_param_index_array, in_param_value_type_array, in_param_value_array,
832                                                                                                                         (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
833
834         param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
835         param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &lastSessionStatus);
836         param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_INT, &lastSessionTime);
837
838         /*
839         FW_LOGV("result = %d", result);
840         FW_LOGV("lastSessionStatus = %d", lastSessionStatus);
841         FW_LOGV("lastSessionTime = %d", lastSessionTime);
842         */
843
844         append_eventdata_param(response, INTEGER, &result);
845         append_eventdata_param(response, INTEGER, &lastSessionStatus);
846         append_eventdata_param(response, INTEGER, &lastSessionTime);
847
848         FW_LOGV("end");
849
850 error:
851
852         if (profile != NULL)
853                 free(profile);
854
855         return 0;
856 }
857
858 int event_callback_get_profile_last_statistics_sync(Event_Data *request, Event_Data *response)
859 {
860         FW_LOGV("start");
861
862         char *profile = NULL;
863         int content_type;
864         char *dbSynced = NULL;
865         int lastSessionTime;
866         int server2Client_Total;
867         int server2Client_NrOfAdd;
868         int server2Client_NrOfDelete;
869         int server2Client_NrOfReplace;
870         int client2Server_Total;
871         int client2Server_NrOfAdd;
872         int client2Server_NrOrDelete;
873         int client2Server_NrOfReplace;
874         int result;
875
876         get_eventdata_param(request, &profile);
877         if (!profile) {
878                 FW_LOGE("profile is not defined");
879                 goto error;
880         }
881
882         get_eventdata_param(request, &content_type);
883
884         FW_LOGV("request param : %s", profile);
885         FW_LOGV("request param : %d", content_type);
886
887         int accountId =  get_accountid(profile, false);
888
889         int in_param_index_array[2] = {0, 1};
890         void *in_param_value_array[2] = {&accountId, &content_type};
891         ECValueType in_param_value_type_array[2] = {EC_VALUE_TYPE_INT, EC_VALUE_TYPE_INT};
892
893         unsigned int out_param_count;
894         task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
895         param_t **param_array = NULL;
896
897
898         unsigned int request_msg_id = 0;
899         engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_STATISTICS, 0,
900                                                                                                                         2, in_param_index_array, in_param_value_type_array, in_param_value_array,
901                                                                                                                         (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
902
903
904         param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
905         param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &dbSynced);
906         param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_INT, &lastSessionTime);
907         param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_INT, &server2Client_Total);
908         param_value_get_value(&(param_array[4]->param_value), EC_VALUE_TYPE_INT, &server2Client_NrOfAdd);
909         param_value_get_value(&(param_array[5]->param_value), EC_VALUE_TYPE_INT, &server2Client_NrOfDelete);
910         param_value_get_value(&(param_array[6]->param_value), EC_VALUE_TYPE_INT, &server2Client_NrOfReplace);
911         param_value_get_value(&(param_array[7]->param_value), EC_VALUE_TYPE_INT, &client2Server_Total);
912         param_value_get_value(&(param_array[8]->param_value), EC_VALUE_TYPE_INT, &client2Server_NrOfAdd);
913         param_value_get_value(&(param_array[9]->param_value), EC_VALUE_TYPE_INT, &client2Server_NrOrDelete);
914         param_value_get_value(&(param_array[10]->param_value), EC_VALUE_TYPE_INT, &client2Server_NrOfReplace);
915
916         /*
917         FW_LOGV("result = %d", result);
918         FW_LOGV("dbSynced = %s\n", dbSynced);
919         FW_LOGV("lastSessionTime = %d\n", lastSessionTime);
920         FW_LOGV("server2Client_Total = %d\n", server2Client_Total);
921         FW_LOGV("server2Client_NrOfAdd = %d\n", server2Client_NrOfAdd);
922         FW_LOGV("server2Client_NrOfDelete = %d\n", server2Client_NrOfDelete);
923         FW_LOGV("server2Client_NrOfReplace = %d\n", server2Client_NrOfReplace);
924         FW_LOGV("client2Server_Total = %d\n", client2Server_Total);
925         FW_LOGV("client2Server_NrOfAdd = %d\n", client2Server_NrOfAdd);
926         FW_LOGV("client2Server_NrOrDelete = %d\n", client2Server_NrOrDelete);
927         FW_LOGV("client2Server_NrOfReplace = %d\n", client2Server_NrOfReplace);
928         */
929
930         append_eventdata_param(response, INTEGER, &result);
931         append_eventdata_param(response, STRING, (void *)dbSynced);
932         append_eventdata_param(response, INTEGER, &lastSessionTime);
933         append_eventdata_param(response, INTEGER, &server2Client_Total);
934         append_eventdata_param(response, INTEGER, &server2Client_NrOfAdd);
935         append_eventdata_param(response, INTEGER, &server2Client_NrOfDelete);
936         append_eventdata_param(response, INTEGER, &server2Client_NrOfReplace);
937         append_eventdata_param(response, INTEGER, &client2Server_Total);
938         append_eventdata_param(response, INTEGER, &client2Server_NrOfAdd);
939         append_eventdata_param(response, INTEGER, &client2Server_NrOrDelete);
940         append_eventdata_param(response, INTEGER, &client2Server_NrOfReplace);
941
942         FW_LOGV("end");
943
944 error:
945
946         if (profile != NULL)
947                 free(profile);
948
949         return 0;
950 }
951
952
953 int event_callback_add_profile_cp_sync(Event_Data *request, Event_Data *response)
954 {
955         FW_LOGV("start");
956
957         char *profileName = NULL;
958         char *addr = NULL;
959         char *id = NULL;
960         char *password = NULL;
961         int category_count;
962         int result;
963         int accountId;
964
965         get_eventdata_param(request, &profileName);
966         get_eventdata_param(request, &addr);
967         get_eventdata_param(request, &id);
968         get_eventdata_param(request, &password);
969         get_eventdata_param(request, &category_count);
970
971         /*
972         FW_LOGV("request param : %s", profileName);
973         FW_LOGV("request param : %s", addr);
974         FW_LOGV("request param : %s", id);
975         FW_LOGV("request param : %s", password);
976         FW_LOGV("request param : %d", category_count);
977         */
978
979         GList *categorys = NULL;
980         int i = 0;
981         for (; i < category_count ; i++) {
982                 resource_cp *category = (resource_cp *)calloc(1, sizeof(resource_cp));
983
984                 get_eventdata_param(request, &(category->name));
985                 get_eventdata_param(request, &(category->accept));
986                 get_eventdata_param(request, &(category->id));
987                 get_eventdata_param(request, &(category->password));
988                 get_eventdata_param(request, &(category->authType));
989                 get_eventdata_param(request, &(category->authData));
990
991                 categorys = g_list_append(categorys, category);
992
993                 /*
994                 FW_LOGV("category[%d]->name : %s", i, category->name);
995                 FW_LOGV("category[%d]->accept : %s", i, category->accept);
996                 FW_LOGV("category[%d]->id : %s", i, category->id);
997                 FW_LOGV("category[%d]->password : %s", i, category->password);
998                 FW_LOGV("category[%d]->authType : %s", i, category->authType);
999                 FW_LOGV("category[%d]->authData : %s\n", i, category->authData);
1000                 */
1001         }
1002
1003         /* send to engine controller */
1004         void *in_param_value_array[5] = {&profileName, &addr, &id, &password, &categorys};
1005         int in_param_index_array[5] = {0, 1, 2, 3, 4};
1006         ECValueType in_param_value_type_array[5] = {EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT,
1007                                                                                 EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
1008         unsigned int request_msg_id = 0;
1009
1010         unsigned int out_param_count;
1011         task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
1012         param_t **param_array = NULL;
1013
1014         engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE_CP, 0,
1015                                                                                                                         5, in_param_index_array, in_param_value_type_array, in_param_value_array,
1016                                                                                                                         (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
1017
1018         param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
1019         param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &accountId);
1020
1021         append_eventdata_param(response, INTEGER, &result);
1022         append_eventdata_param(response, INTEGER, &accountId);
1023
1024
1025         FW_LOGV("end");
1026
1027         return 0;
1028 }