3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
24 #ifndef SYNC_AGENT_LOG
26 #define LOG_TAG "OMADS_CLIENT"
29 //#include <sync_agent.h>
30 #include "event/event.h"
31 #include "utility/sync_util.h"
32 #include "initialization/initialization.h"
35 #define EXPORT_API __attribute__ ((visibility("default")))
38 #define OMA_DS_CONFIG_FILE "/usr/share/oma-ds-cfg/omadsUI_fw_config.xml"
40 #define SYNC_AGENT_DS_API_RESULT_FAILURE 0
41 #define SYNC_AGENT_DS_API_RESULT_SUCCESS 1
44 SYNC_AGENT_DS_ADD_PROFILE = 1,
45 SYNC_AGENT_DS_UPDATE_PROFILE = 2,
46 SYNC_AGENT_DS_DELETE_PROFILE = 3,
47 SYNC_AGENT_DS_START_SYNC = 4,
48 SYNC_AGENT_DS_STOP_SYNC = 5,
49 SYNC_AGENT_DS_GET_PROFILE = 6,
50 SYNC_AGENT_DS_GET_SYNC_CATEGORY = 7,
51 SYNC_AGENT_DS_GET_SYNC_STATISTICS = 8,
52 SYNC_AGENT_DS_GET_ALL_PROFILES = 9
53 } sync_agent_ds_event_e;
56 SYNC_AGENT_DS_SYNC_CONTACTS = 0,
57 SYNC_AGENT_DS_SYNC_SCHEDULE = 1,
58 SYNC_AGENT_DS_SYNC_MEMO = 2
59 } sync_agent_ds_sync_e;
61 static gboolean _get_sync_category(char *profile_dir_name, int service_type, sync_agent_ds_service_info ** service)
65 int event_type = SYNC_AGENT_DS_GET_SYNC_CATEGORY;
66 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
68 // check mandatory parameter
69 retvm_if(profile_dir_name == NULL, FALSE, "profile_dir_name is null!!");
70 retvm_if(service_type < 0, FALSE, "service_type is wrong!!");
72 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
73 sync_agent_event_data_s *request_event = NULL;
74 sync_agent_event_data_s *response_event = NULL;
76 /* create empty event packet */
77 request_event = sync_agent_create_event(event_type);
78 if (request_event == NULL) {
79 _DEBUG_ERROR("event is NULL");
84 /* add request parameter to event packet */
85 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
86 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &service_type);
88 /* send event request to ds agent daemon, waiting for response */
89 response_event = sync_agent_send_event(request_event, &error);
90 if (error != SYNC_AGENT_EVENT_SUCCESS) {
91 _DEBUG_ERROR("error = %d", error);
92 sync_agent_free_event(request_event);
96 if (response_event == NULL) {
97 _DEBUG_ERROR("response_event is null!!");
98 sync_agent_free_event(request_event);
103 *service = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
104 if (*service == NULL) {
105 _DEBUG_ERROR("calloc failed");
106 sync_agent_free_event(request_event);
107 sync_agent_free_event_data(response_event);
111 /* get response parameter from event packet */
113 sync_agent_get_event_data_param(response_event, &api_result);
114 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
115 _DEBUG_ERROR("api_result = failed");
116 sync_agent_free_event(request_event);
117 sync_agent_free_event_data(response_event);
119 return SYNC_AGENT_DS_FAIL;
122 sync_agent_get_event_data_param(response_event, &((*service)->enabled));
123 sync_agent_get_event_data_param(response_event, &((*service)->src_uri));
124 sync_agent_get_event_data_param(response_event, &((*service)->tgt_uri));
125 sync_agent_get_event_data_param(response_event, &((*service)->id));
126 sync_agent_get_event_data_param(response_event, &((*service)->password));
128 _DEBUG_TRACE("enabled = %d", (*service)->enabled);
129 _DEBUG_TRACE("src_uri = %s", (*service)->src_uri);
130 _DEBUG_TRACE("tgt_uri = %s", (*service)->tgt_uri);
131 _DEBUG_TRACE("id = %s", (*service)->id);
132 _DEBUG_TRACE("password = %s", (*service)->password);
134 /* free request & response event */
135 sync_agent_free_event(request_event);
136 sync_agent_free_event_data(response_event);
143 static gboolean _get_sync_statistics(char *profile_dir_name, int service_type, sync_agent_ds_statistics_info ** statistics)
147 int event_type = SYNC_AGENT_DS_GET_SYNC_STATISTICS;
148 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
150 // check mandatory parameter
151 retvm_if(profile_dir_name == NULL, FALSE, "profile_dir_name is null!!");
152 retvm_if(service_type < 0, FALSE, "service_type is wrong!!");
154 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
155 sync_agent_event_data_s *request_event = NULL;
156 sync_agent_event_data_s *response_event = NULL;
158 char *statistics_cat = NULL;
160 /* create empty event packet */
161 request_event = sync_agent_create_event(event_type);
162 if (request_event == NULL) {
163 _DEBUG_ERROR("event is NULL");
168 /* add request parameter to event packet */
169 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
170 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &service_type);
172 /* send event request to ds agent daemon, waiting for response */
173 response_event = sync_agent_send_event(request_event, &error);
174 if (error != SYNC_AGENT_EVENT_SUCCESS) {
175 _DEBUG_ERROR("error = %d", error);
176 sync_agent_free_event(request_event);
180 if (response_event == NULL) {
181 _DEBUG_ERROR("response_event is null!!");
182 sync_agent_free_event(request_event);
187 *statistics = (sync_agent_ds_statistics_info *) calloc(1, sizeof(sync_agent_ds_statistics_info));
188 if (*statistics == NULL) {
189 _DEBUG_ERROR("calloc failed");
190 sync_agent_free_event(request_event);
191 sync_agent_free_event_data(response_event);
195 /* get response parameter from event packet */
197 sync_agent_get_event_data_param(response_event, &api_result);
198 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
199 _DEBUG_ERROR("api_result = failed");
200 sync_agent_free_event(request_event);
201 sync_agent_free_event_data(response_event);
203 return SYNC_AGENT_DS_FAIL;
206 if (service_type == SYNC_AGENT_DS_SYNC_CONTACTS)
207 statistics_cat = "contacts";
208 else if (service_type == SYNC_AGENT_DS_SYNC_SCHEDULE)
209 statistics_cat = "schedule";
210 else if (service_type == SYNC_AGENT_DS_SYNC_MEMO)
211 statistics_cat = "memo";
213 sync_agent_get_event_data_param(response_event, &((*statistics)->dbsynced));
214 sync_agent_get_event_data_param(response_event, &((*statistics)->last_session_time));
215 sync_agent_get_event_data_param(response_event, &((*statistics)->server2client_total));
216 sync_agent_get_event_data_param(response_event, &((*statistics)->server2client_nrofadd));
217 sync_agent_get_event_data_param(response_event, &((*statistics)->server2client_nrofdelete));
218 sync_agent_get_event_data_param(response_event, &((*statistics)->server2client_nrofreplace));
219 sync_agent_get_event_data_param(response_event, &((*statistics)->client2server_total));
220 sync_agent_get_event_data_param(response_event, &((*statistics)->client2server_nrofadd));
221 sync_agent_get_event_data_param(response_event, &((*statistics)->client2server_nrofdelete));
222 sync_agent_get_event_data_param(response_event, &((*statistics)->client2server_nrofreplace));
224 _DEBUG_TRACE("%s dbSynced = %s", statistics_cat, (*statistics)->dbsynced);
225 _DEBUG_TRACE("%s lastSessionTime = %d", statistics_cat, (*statistics)->last_session_time);
226 _DEBUG_TRACE("%s server2Client_Total = %d", statistics_cat, (*statistics)->server2client_total);
227 _DEBUG_TRACE("%s server2Client_NrOrAdd = %d", statistics_cat, (*statistics)->server2client_nrofadd);
228 _DEBUG_TRACE("%s server2Client_NrOfDelete = %d", statistics_cat, (*statistics)->server2client_nrofdelete);
229 _DEBUG_TRACE("%s server2Client_NrOfReplace = %d", statistics_cat, (*statistics)->server2client_nrofreplace);
230 _DEBUG_TRACE("%s client2Server_Total = %d", statistics_cat, (*statistics)->client2server_total);
231 _DEBUG_TRACE("%s client2Server_NrOfAdd = %d", statistics_cat, (*statistics)->client2server_nrofadd);
232 _DEBUG_TRACE("%s client2Server_NrOfDelete = %d", statistics_cat, (*statistics)->client2server_nrofdelete);
233 _DEBUG_TRACE("%s client2Server_NrOfReplace = %d", statistics_cat, (*statistics)->client2server_nrofreplace);
235 /* free request & response event */
236 sync_agent_free_event(request_event);
237 sync_agent_free_event_data(response_event);
244 static void _free_sync_category_info(sync_agent_ds_service_info * data)
246 g_free(data->src_uri);
247 g_free(data->tgt_uri);
249 g_free(data->password);
252 EXPORT_API sync_agent_ds_error_e sync_agent_ds_init()
256 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
258 sync_agent_init_error_e init_error = sync_agent_init(OMA_DS_CONFIG_FILE);
260 if (init_error != SYNC_AGENT_INIT_SUCCESS) {
261 _DEBUG_ERROR("ds init failed");
262 result = SYNC_AGENT_DS_FAIL;
265 sync_agent_event_error_e err = sync_agent_run_noti_listener("omads");
266 if (err != SYNC_AGENT_EVENT_SUCCESS) {
267 _DEBUG_ERROR("RUN NOTILISTNER is failed");
268 result = SYNC_AGENT_DS_FAIL;
276 EXPORT_API sync_agent_ds_error_e sync_agent_ds_create_profile_info(ds_profile_h * profile_h)
280 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
281 sync_agent_ds_profile_info *profile_info = NULL;
283 // allocate memory for ds profile info
284 profile_info = (sync_agent_ds_profile_info *) calloc(1, sizeof(sync_agent_ds_profile_info));
285 if (profile_info == NULL) {
286 _DEBUG_ERROR("calloc failed !!");
287 return SYNC_AGENT_DS_FAIL;
289 // pass memory pointer to ds profile handle
290 *profile_h = profile_info;
297 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_profile_name(ds_profile_h profile_h, char *profile_dir_name, char *profile_name)
301 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
302 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
304 // check mandatory parameter
305 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
306 retvm_if(profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
309 profile_info->profile_dir_name = g_strdup(profile_dir_name);
310 profile_info->profile_name = g_strdup(profile_name);
312 if (profile_info->profile_dir_name == NULL) {
313 _DEBUG_ERROR("g_strdup failed !!");
314 return SYNC_AGENT_DS_FAIL;
322 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_server_info(ds_profile_h profile_h, char *addr, char *id, char *password)
326 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
327 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
328 sync_agent_ds_server_info *server_info = &profile_info->server_info;
330 // check mandatory parameter
331 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
332 retvm_if(addr == NULL, SYNC_AGENT_DS_FAIL, "addr is null!!");
333 retvm_if(id == NULL, SYNC_AGENT_DS_FAIL, "id is null!!");
334 retvm_if(password == NULL, SYNC_AGENT_DS_FAIL, "password is null!!");
337 server_info->addr = g_strdup(addr);
338 server_info->id = g_strdup(id);
339 server_info->password = g_strdup(password);
341 if ((server_info->addr == NULL)
342 || (server_info->id == NULL)
343 || (server_info->password == NULL)) {
344 _DEBUG_ERROR("g_strdup failed !!");
345 return SYNC_AGENT_DS_FAIL;
353 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_sync_info(ds_profile_h profile_h, char *sync_mode, char *sync_type, char *interval)
357 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
358 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
359 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
361 // check mandatory parameter
362 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
363 retvm_if(sync_mode == NULL, SYNC_AGENT_DS_FAIL, "sync_mode is null!!");
364 retvm_if(sync_type == NULL, SYNC_AGENT_DS_FAIL, "sync_type is null!!");
365 retvm_if(interval == NULL, SYNC_AGENT_DS_FAIL, "interval is null!!");
368 sync_info->sync_mode = g_strdup(sync_mode);
369 sync_info->sync_type = g_strdup(sync_type);
370 sync_info->interval = g_strdup(interval);
372 if ((sync_info->sync_mode == NULL)
373 || (sync_info->sync_type == NULL)
374 || (sync_info->interval == NULL)) {
375 _DEBUG_ERROR("g_strdup failed !!");
376 return SYNC_AGENT_DS_FAIL;
384 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_sync_service_info(ds_profile_h profile_h, sync_agent_ds_service_type_e service_type, int enabled, char *src_uri, char *tgt_uri, char *id, char *password)
388 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
389 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
390 sync_agent_ds_service_info *category_info = NULL;
392 // check mandatory parameter
393 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
394 retvm_if(src_uri == NULL, SYNC_AGENT_DS_FAIL, "src_uri is null!!");
396 // allocate memory for sync_category
397 category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
398 retvm_if(category_info == NULL, SYNC_AGENT_DS_FAIL, "calloc failed");
399 category_info->service_type = service_type;
400 category_info->enabled = enabled;
401 category_info->src_uri = g_strdup(src_uri);
402 category_info->tgt_uri = g_strdup(tgt_uri);
404 profile_info->service_list = g_list_append(profile_info->service_list, category_info);
406 if (category_info->src_uri == NULL) {
407 _DEBUG_ERROR("g_strdup failed !!");
408 return SYNC_AGENT_DS_FAIL;
416 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_name(ds_profile_h profile_h, char **profile_dir_name, char **profile_name)
420 // check mandatory parameter
421 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
423 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
425 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
427 *profile_dir_name = g_strdup(profile_info->profile_dir_name);
428 *profile_name = g_strdup(profile_info->profile_name);
430 if ((*profile_dir_name == NULL)
431 || (*profile_name == NULL)) {
432 _DEBUG_ERROR("g_strdup failed !!");
433 return SYNC_AGENT_DS_FAIL;
436 _DEBUG_INFO("profileDirame = %s", *profile_dir_name);
437 _DEBUG_INFO("get_profile_name = %s", *profile_name);
444 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_server_info(ds_profile_h profile_h, sync_agent_ds_server_info * server_info)
448 // check mandatory parameter
449 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
450 retvm_if(server_info == NULL, SYNC_AGENT_DS_FAIL, "server_info is null!!");
452 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
453 sync_agent_ds_server_info *ds_server_info = &profile_info->server_info;
455 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
457 server_info->addr = g_strdup(ds_server_info->addr);
458 server_info->id = g_strdup(ds_server_info->id);
459 server_info->password = g_strdup(ds_server_info->password);
461 if ((server_info->addr == NULL)
462 || (server_info->id == NULL)
463 || (server_info->password == NULL)) {
464 _DEBUG_ERROR("g_strdup failed !!");
465 return SYNC_AGENT_DS_FAIL;
468 _DEBUG_INFO("get_addr = %s", server_info->addr);
469 _DEBUG_INFO("get_id = %s", server_info->id);
470 _DEBUG_INFO("get_password = %s", server_info->password);
477 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_info(ds_profile_h profile_h, sync_agent_ds_sync_info * sync_info)
481 // check mandatory parameter
482 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
483 retvm_if(sync_info == NULL, SYNC_AGENT_DS_FAIL, "sync_info is null!!");
485 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
486 sync_agent_ds_sync_info *ds_sync_info = &profile_info->sync_info;
488 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
490 sync_info->sync_mode = g_strdup(ds_sync_info->sync_mode);
491 sync_info->sync_type = g_strdup(ds_sync_info->sync_type);
492 sync_info->interval = g_strdup(ds_sync_info->interval);
494 if ((sync_info->sync_mode == NULL)
495 || (sync_info->sync_type == NULL)
496 || (sync_info->interval == NULL)) {
497 _DEBUG_ERROR("g_strdup failed !!");
498 return SYNC_AGENT_DS_FAIL;
501 _DEBUG_INFO("get_sync_mode = %s", sync_info->sync_mode);
502 _DEBUG_INFO("get_sync_type = %s", sync_info->sync_type);
503 _DEBUG_INFO("get_interval = %s", sync_info->interval);
510 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_service_info(ds_profile_h profile_h, GList ** category_list)
514 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
516 int category_count = 0;
518 sync_agent_ds_service_info *category_info = NULL;
520 *category_list = g_list_copy(profile_info->service_list);
522 if (*category_list == NULL) {
523 _DEBUG_ERROR("g_list_copy failed !!");
524 return SYNC_AGENT_DS_FAIL;
527 category_count = g_list_length(*category_list);
528 for (; i < category_count; i++) {
529 category_info = (sync_agent_ds_service_info *) g_list_nth_data(*category_list, i);
531 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
532 _DEBUG_INFO("category[%d]->src_uri = %s", i, category_info->src_uri);
533 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
534 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
535 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
540 return SYNC_AGENT_DS_SUCCESS;
543 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_statistics(ds_profile_h profile_h, GList ** statistics_list)
547 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
548 sync_agent_ds_statistics_info *statistics = NULL;
550 gboolean result_sync_category = FALSE;
552 /* get last contacts sync result */
553 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_CONTACTS, &statistics);
554 if (result_sync_category)
555 *statistics_list = g_list_append(*statistics_list, statistics);
557 /* get last schedule sync result */
559 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_SCHEDULE, &statistics);
560 if (result_sync_category)
561 *statistics_list = g_list_append(*statistics_list, statistics);
563 /* get last memo sync result */
565 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_MEMO, &statistics);
566 if (result_sync_category)
567 *statistics_list = g_list_append(*statistics_list, statistics);
571 return SYNC_AGENT_DS_SUCCESS;
574 EXPORT_API sync_agent_ds_error_e sync_agent_ds_add_profile(ds_profile_h profile_h, int *profile_id)
578 // check mandatory parameter
579 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
581 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
582 sync_agent_ds_server_info *server_info = &profile_info->server_info;
583 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
584 GList *list = profile_info->service_list;
586 int event_type = SYNC_AGENT_DS_ADD_PROFILE;
587 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
588 sync_agent_event_data_s *request_event = NULL;
589 sync_agent_event_data_s *response_event = NULL;
592 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
593 sync_agent_ds_service_info *category_info = NULL;
594 int category_count = 0;
597 /* create empty event packet */
598 request_event = sync_agent_create_event(event_type);
599 if (request_event == NULL) {
600 _DEBUG_ERROR("event is NULL");
602 return SYNC_AGENT_DS_FAIL;
605 /* add request parameter to event packet */
606 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
607 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
608 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
609 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name);
610 _DEBUG_INFO("addr = %s", server_info->addr);
611 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr);
612 _DEBUG_INFO("id = %s", server_info->id);
613 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id);
614 _DEBUG_INFO("password = %s", server_info->password);
615 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password);
616 _DEBUG_INFO("sync_mode = %s", sync_info->sync_mode);
617 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->sync_mode);
618 _DEBUG_INFO("sync_type = %s", sync_info->sync_type);
619 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->sync_type);
620 _DEBUG_INFO("interval = %s", sync_info->interval);
621 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->interval);
623 category_count = g_list_length(list);
624 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count);
626 for (; i < category_count; i++) {
627 category_info = (sync_agent_ds_service_info *) g_list_nth_data(list, i);
629 _DEBUG_INFO("category[%d]->service_type = %d", i, category_info->service_type);
630 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->service_type));
631 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
632 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->enabled));
633 _DEBUG_INFO("category[%d]->src_uri = %s", i, category_info->src_uri);
634 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->src_uri);
635 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
636 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri);
637 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
638 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id);
639 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
640 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password);
643 /* send event request to ds agent daemon, waiting for response */
644 response_event = sync_agent_send_event(request_event, &error);
645 if (error != SYNC_AGENT_EVENT_SUCCESS) {
646 _DEBUG_ERROR("error = %d", error);
647 sync_agent_free_event(request_event);
649 return SYNC_AGENT_DS_FAIL;
651 if (response_event == NULL) {
652 _DEBUG_ERROR("response_event is null!!");
653 sync_agent_free_event(request_event);
655 return SYNC_AGENT_DS_FAIL;
658 /* get response parameter from event packet */
659 sync_agent_get_event_data_param(response_event, &api_result);
661 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
662 _DEBUG_ERROR("api_result = failed");
663 sync_agent_free_event(request_event);
664 sync_agent_free_event_data(response_event);
666 return SYNC_AGENT_DS_FAIL;
669 sync_agent_get_event_data_param(response_event, &prof_id);
671 _DEBUG_VERBOSE("profile_id = %d", prof_id);
672 *profile_id = prof_id;
674 /* free request & response event */
675 sync_agent_free_event(request_event);
676 sync_agent_free_event_data(response_event);
680 return SYNC_AGENT_DS_SUCCESS;
683 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile(char *profile_dir_name, ds_profile_h * profile_h)
687 int event_type = SYNC_AGENT_DS_GET_PROFILE;
688 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
689 sync_agent_event_data_s *request_event = NULL;
690 sync_agent_event_data_s *response_event = NULL;
692 gboolean result_sync_category = FALSE;
693 sync_agent_ds_error_e result = SYNC_AGENT_DS_FAIL;
694 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
695 sync_agent_ds_service_info *category = NULL;
697 // check mandatory parameter
698 retvm_if(profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
700 //////////////////////////////////
702 // Phase 1. get profile detail info
704 /* create empty event packet */
705 request_event = sync_agent_create_event(event_type);
706 if (request_event == NULL) {
707 _DEBUG_ERROR("event is NULL");
709 return SYNC_AGENT_DS_FAIL;
712 /* add request parameter to event packet */
713 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
715 /* send event request to ds agent daemon, waiting for response */
716 response_event = sync_agent_send_event(request_event, &error);
717 if (error != SYNC_AGENT_EVENT_SUCCESS) {
718 _DEBUG_ERROR("error = %d", error);
719 sync_agent_free_event(request_event);
721 return SYNC_AGENT_DS_FAIL;
723 if (response_event == NULL) {
724 _DEBUG_ERROR("response_event is null!!");
725 sync_agent_free_event(request_event);
727 return SYNC_AGENT_DS_FAIL;
730 /* get response parameter from event packet */
732 result = sync_agent_ds_create_profile_info(profile_h);
733 if (result == SYNC_AGENT_DS_FAIL) {
734 _DEBUG_ERROR("failed to create profile info!");
735 sync_agent_free_event(request_event);
736 sync_agent_free_event_data(response_event);
740 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) (*profile_h);
741 sync_agent_ds_server_info *server_info = &profile_info->server_info;
742 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
743 // GList * list = profile_info->category_list;
745 sync_agent_get_event_data_param(response_event, &api_result);
746 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
747 _DEBUG_ERROR("api_result = failed");
748 sync_agent_free_event(request_event);
749 sync_agent_free_event_data(response_event);
751 return SYNC_AGENT_DS_FAIL;
754 profile_info->profile_dir_name = g_strdup(profile_dir_name);
756 sync_agent_get_event_data_param(response_event, &profile_info->profile_name);
757 sync_agent_get_event_data_param(response_event, &server_info->addr);
758 sync_agent_get_event_data_param(response_event, &server_info->id);
759 sync_agent_get_event_data_param(response_event, &server_info->password);
760 sync_agent_get_event_data_param(response_event, &sync_info->sync_mode);
761 sync_agent_get_event_data_param(response_event, &sync_info->sync_type);
762 sync_agent_get_event_data_param(response_event, &sync_info->interval);
763 sync_agent_get_event_data_param(response_event, &profile_info->last_sync_status);
764 sync_agent_get_event_data_param(response_event, &profile_info->last_sync_time);
766 _DEBUG_INFO("profileDirame = %s", profile_info->profile_name);
767 _DEBUG_INFO("addr = %s", server_info->addr);
768 _DEBUG_INFO("id = %s", server_info->id);
769 _DEBUG_INFO("password = %s", server_info->password);
770 _DEBUG_INFO("sync_mode = %s", sync_info->sync_mode);
771 _DEBUG_INFO("sync_type = %s", sync_info->sync_type);
772 _DEBUG_INFO("interval = %s", sync_info->interval);
773 _DEBUG_VERBOSE("lastSyncStatus = %d\n", profile_info->last_sync_status);
774 _DEBUG_VERBOSE("lastSyncTime = %d\n", profile_info->last_sync_time);
776 /* free request & response event */
777 sync_agent_free_event(request_event);
778 sync_agent_free_event_data(response_event);
780 //////////////////////////////////
782 // Phase 2. get sync category info
784 /* get contacts sync_category */
785 result_sync_category = _get_sync_category(profile_dir_name, SYNC_AGENT_DS_SYNC_CONTACTS, &category);
786 if (result_sync_category)
787 profile_info->service_list = g_list_append(profile_info->service_list, category);
789 /* get schedule sync_category */
791 result_sync_category = _get_sync_category(profile_dir_name, SYNC_AGENT_DS_SYNC_SCHEDULE, &category);
792 if (result_sync_category)
793 profile_info->service_list = g_list_append(profile_info->service_list, category);
795 /* get memo sync_category */
797 result_sync_category = _get_sync_category(profile_dir_name, SYNC_AGENT_DS_SYNC_MEMO, &category);
798 if (result_sync_category)
799 profile_info->service_list = g_list_append(profile_info->service_list, category);
803 return SYNC_AGENT_DS_SUCCESS;
806 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_all_profile(GList ** profile_list)
810 int event_type = SYNC_AGENT_DS_GET_ALL_PROFILES;
811 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
812 sync_agent_event_data_s *request_event = NULL;
813 sync_agent_event_data_s *response_event = NULL;
815 ds_profile_h profile_h = NULL;
816 sync_agent_ds_service_info *category_info = NULL;
818 int profile_count = 0;
819 int category_count = 0;
821 sync_agent_ds_error_e result = SYNC_AGENT_DS_FAIL;
822 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
824 /* create empty event packet */
825 request_event = sync_agent_create_event(event_type);
826 if (request_event == NULL) {
827 _DEBUG_ERROR("event is NULL");
829 return SYNC_AGENT_DS_FAIL;
832 /* send event request to ds agent daemon, waiting for response */
833 response_event = sync_agent_send_event(request_event, &error);
834 if (error != SYNC_AGENT_EVENT_SUCCESS) {
835 _DEBUG_ERROR("error = %d", error);
836 sync_agent_free_event(request_event);
838 return SYNC_AGENT_DS_FAIL;
840 if (response_event == NULL) {
841 _DEBUG_ERROR("response_event is null!!");
842 sync_agent_free_event(request_event);
844 return SYNC_AGENT_DS_FAIL;
847 sync_agent_get_event_data_param(response_event, &api_result);
848 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
849 _DEBUG_ERROR("api_result = failed");
850 sync_agent_free_event(request_event);
851 sync_agent_free_event_data(response_event);
853 return SYNC_AGENT_DS_FAIL;
856 sync_agent_get_event_data_param(response_event, &profile_count);
857 _DEBUG_INFO("profile_count = %d", profile_count);
860 for (i = 0; i < profile_count; i++) {
862 result = sync_agent_ds_create_profile_info(&profile_h);
863 if (result == SYNC_AGENT_DS_FAIL) {
864 _DEBUG_ERROR("failed to create profile info!");
865 sync_agent_free_event(request_event);
866 sync_agent_free_event_data(response_event);
870 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
871 sync_agent_ds_server_info *server_info = &profile_info->server_info;
872 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
874 sync_agent_get_event_data_param(response_event, &profile_info->profile_dir_name);
875 sync_agent_get_event_data_param(response_event, &profile_info->profile_name);
876 sync_agent_get_event_data_param(response_event, &server_info->addr);
877 sync_agent_get_event_data_param(response_event, &server_info->id);
878 sync_agent_get_event_data_param(response_event, &server_info->password);
879 sync_agent_get_event_data_param(response_event, &sync_info->sync_mode);
880 sync_agent_get_event_data_param(response_event, &sync_info->sync_type);
881 sync_agent_get_event_data_param(response_event, &sync_info->interval);
882 sync_agent_get_event_data_param(response_event, &profile_info->last_sync_status);
883 sync_agent_get_event_data_param(response_event, &profile_info->last_sync_time);
885 _DEBUG_INFO("profile_info->profile_dir_name = %s", profile_info->profile_dir_name);
886 _DEBUG_INFO("profile_info->profile_name = %s", profile_info->profile_name);
887 _DEBUG_INFO("profile_info->addr = %s", server_info->addr);
888 _DEBUG_INFO("profile_info->id = %s", server_info->id);
889 _DEBUG_INFO("profile_info->password = %s", server_info->password);
890 _DEBUG_INFO("profile_info->sync_mode = %s", sync_info->sync_mode);
891 _DEBUG_INFO("profile_info->sync_type = %s", sync_info->sync_type);
892 _DEBUG_INFO("profile_info->interval = %s", sync_info->interval);
893 _DEBUG_INFO("profile_info->lastSyncStatus = %d", profile_info->last_sync_status);
894 _DEBUG_INFO("profile_info->lastSyncStatus = %d", profile_info->last_sync_status);
896 sync_agent_get_event_data_param(response_event, &category_count);
899 for (j = 0; j < category_count; j++) {
901 category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
902 if (category_info == NULL) {
903 _DEBUG_ERROR("calloc failed");
904 sync_agent_ds_free_profile_info(profile_h);
905 sync_agent_free_event(request_event);
906 sync_agent_free_event_data(response_event);
910 sync_agent_get_event_data_param(response_event, &category_info->service_type);
911 sync_agent_get_event_data_param(response_event, &category_info->enabled);
912 sync_agent_get_event_data_param(response_event, &category_info->src_uri);
913 sync_agent_get_event_data_param(response_event, &category_info->tgt_uri);
914 sync_agent_get_event_data_param(response_event, &category_info->id);
915 sync_agent_get_event_data_param(response_event, &category_info->password);
917 _DEBUG_INFO("category_info->service_type = %d", category_info->service_type);
918 _DEBUG_INFO("category_info->enabled = %d", category_info->enabled);
919 _DEBUG_INFO("category_info->src_uri = %s", category_info->src_uri);
920 _DEBUG_INFO("category_info->tgt_uri = %s", category_info->tgt_uri);
921 _DEBUG_INFO("category_info->id = %s", category_info->id);
922 _DEBUG_INFO("category_info->password = %s", category_info->password);
924 profile_info->service_list = g_list_append(profile_info->service_list, category_info);
925 category_info = NULL;
928 *profile_list = g_list_append(*profile_list, profile_h);
932 /* free request & response event */
933 sync_agent_free_event(request_event);
934 sync_agent_free_event_data(response_event);
938 return SYNC_AGENT_DS_SUCCESS;
941 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_last_sync_info(ds_profile_h profile_h, int *lastSyncStatus, int *lastSyncTime)
945 // check mandatory parameter
946 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
947 retvm_if(lastSyncStatus == NULL, SYNC_AGENT_DS_FAIL, "last session status is null!!");
948 retvm_if(lastSyncTime == NULL, SYNC_AGENT_DS_FAIL, "last session time is null!!");
950 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
952 *lastSyncStatus = profile_info->last_sync_status;
953 *lastSyncTime = profile_info->last_sync_time;
957 return SYNC_AGENT_DS_SUCCESS;
960 EXPORT_API sync_agent_ds_error_e sync_agent_ds_update_profile(ds_profile_h profile_h)
964 // check mandatory parameter
965 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
967 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
968 sync_agent_ds_server_info *server_info = &profile_info->server_info;
969 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
970 GList *list = profile_info->service_list;
972 int event_type = SYNC_AGENT_DS_UPDATE_PROFILE;
973 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
974 sync_agent_event_data_s *request_event = NULL;
975 sync_agent_event_data_s *response_event = NULL;
977 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
978 sync_agent_ds_service_info *category_info = NULL;
979 int category_count = 0;
982 /* create empty event packet */
983 request_event = sync_agent_create_event(event_type);
984 if (request_event == NULL) {
985 _DEBUG_ERROR("event is NULL");
987 return SYNC_AGENT_DS_FAIL;
990 /* add request parameter to event packet */
991 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
992 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
993 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
994 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name);
995 _DEBUG_INFO("addr = %s", server_info->addr);
996 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr);
997 _DEBUG_INFO("id = %s", server_info->id);
998 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id);
999 _DEBUG_INFO("password = %s", server_info->password);
1000 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password);
1001 _DEBUG_INFO("sync_mode = %s", sync_info->sync_mode);
1002 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->sync_mode);
1003 _DEBUG_INFO("sync_type = %s", sync_info->sync_type);
1004 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->sync_type);
1005 _DEBUG_INFO("interval = %s", sync_info->interval);
1006 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->interval);
1008 category_count = g_list_length(list);
1009 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count);
1011 for (; i < category_count; i++) {
1012 category_info = (sync_agent_ds_service_info *) g_list_nth_data(list, i);
1014 _DEBUG_INFO("category[%d]->service_type = %d", i, category_info->service_type);
1015 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->service_type));
1016 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
1017 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->enabled));
1018 _DEBUG_INFO("category[%d]->src_uri = %s", i, category_info->src_uri);
1019 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->src_uri);
1020 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
1021 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri);
1022 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
1023 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id);
1024 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
1025 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password);
1028 /* send event request to ds agent daemon, waiting for response */
1029 response_event = sync_agent_send_event(request_event, &error);
1030 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1031 _DEBUG_ERROR("error = %d", error);
1032 sync_agent_free_event(request_event);
1034 return SYNC_AGENT_DS_FAIL;
1036 if (response_event == NULL) {
1037 _DEBUG_ERROR("response_event is null!!");
1038 sync_agent_free_event(request_event);
1040 return SYNC_AGENT_DS_FAIL;
1043 /* get response parameter from event packet */
1044 sync_agent_get_event_data_param(response_event, &api_result);
1046 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1047 _DEBUG_ERROR("api_result = failed");
1048 sync_agent_free_event(request_event);
1049 sync_agent_free_event_data(response_event);
1051 return SYNC_AGENT_DS_FAIL;
1054 /* free request & response event */
1055 sync_agent_free_event(request_event);
1056 sync_agent_free_event_data(response_event);
1060 return SYNC_AGENT_DS_SUCCESS;
1063 EXPORT_API sync_agent_ds_error_e sync_agent_ds_delete_profile(ds_profile_h profile_h)
1067 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1069 int event_type = SYNC_AGENT_DS_DELETE_PROFILE;
1070 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1071 sync_agent_event_data_s *request_event = NULL;
1072 sync_agent_event_data_s *response_event = NULL;
1075 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1077 // check mandatory parameter
1078 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1079 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1081 /* create empty event packet */
1082 request_event = sync_agent_create_event(event_type);
1083 if (request_event == NULL) {
1084 _DEBUG_ERROR("event is NULL");
1085 return SYNC_AGENT_DS_FAIL;
1088 /* add request parameter to event packet */
1089 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &count);
1091 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1092 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1094 /* send event request to ds agent daemon, waiting for response */
1095 response_event = sync_agent_send_event(request_event, &error);
1096 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1097 _DEBUG_ERROR("error = %d", error);
1098 sync_agent_free_event(request_event);
1100 return SYNC_AGENT_DS_FAIL;
1102 if (response_event == NULL) {
1103 _DEBUG_ERROR("response_event is null!!");
1104 sync_agent_free_event(request_event);
1106 return SYNC_AGENT_DS_FAIL;
1109 /* get response parameter from event packet */
1110 sync_agent_get_event_data_param(response_event, &api_result);
1112 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1113 _DEBUG_ERROR("api_result = failed");
1114 sync_agent_free_event(request_event);
1115 sync_agent_free_event_data(response_event);
1117 return SYNC_AGENT_DS_FAIL;
1120 /* free request & response event */
1121 sync_agent_free_event(request_event);
1122 sync_agent_free_event_data(response_event);
1126 return SYNC_AGENT_DS_SUCCESS;
1129 EXPORT_API sync_agent_ds_error_e sync_agent_ds_start_sync(ds_profile_h profile_h)
1133 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1135 int event_type = SYNC_AGENT_DS_START_SYNC;
1136 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1137 sync_agent_event_data_s *request_event = NULL;
1138 sync_agent_event_data_s *response_event = NULL;
1140 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1142 // check mandatory parameter
1143 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1144 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1146 /* create empty event packet */
1147 request_event = sync_agent_create_event(event_type);
1148 if (request_event == NULL) {
1149 _DEBUG_ERROR("event is NULL");
1150 return SYNC_AGENT_DS_FAIL;
1153 /* add request parameter to event packet */
1154 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1156 /* send event request to ds agent daemon, waiting for response */
1157 response_event = sync_agent_send_event(request_event, &error);
1158 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1159 _DEBUG_ERROR("error = %d", error);
1160 sync_agent_free_event(request_event);
1162 return SYNC_AGENT_DS_FAIL;
1164 if (response_event == NULL) {
1165 _DEBUG_ERROR("response_event is null!!");
1166 sync_agent_free_event(request_event);
1168 return SYNC_AGENT_DS_FAIL;
1171 /* get response parameter from event packet */
1172 sync_agent_get_event_data_param(response_event, &api_result);
1174 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1175 _DEBUG_ERROR("api_result = failed");
1176 sync_agent_free_event(request_event);
1177 sync_agent_free_event_data(response_event);
1179 return SYNC_AGENT_DS_FAIL;
1182 /* free request & response event */
1183 sync_agent_free_event(request_event);
1184 sync_agent_free_event_data(response_event);
1188 return SYNC_AGENT_DS_SUCCESS;
1191 EXPORT_API sync_agent_ds_error_e sync_agent_ds_stop_sync(ds_profile_h profile_h)
1195 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1197 int event_type = SYNC_AGENT_DS_STOP_SYNC;
1198 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1199 sync_agent_event_data_s *request_event = NULL;
1200 sync_agent_event_data_s *response_event = NULL;
1202 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1204 // check mandatory parameter
1205 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1206 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1208 /* create empty event packet */
1209 request_event = sync_agent_create_event(event_type);
1210 if (request_event == NULL) {
1211 _DEBUG_ERROR("event is NULL");
1212 return SYNC_AGENT_DS_FAIL;
1215 /* add request parameter to event packet */
1216 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1218 /* send event request to ds agent daemon, waiting for response */
1219 response_event = sync_agent_send_event(request_event, &error);
1220 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1221 _DEBUG_ERROR("error = %d", error);
1222 sync_agent_free_event(request_event);
1224 return SYNC_AGENT_DS_FAIL;
1226 if (response_event == NULL) {
1227 _DEBUG_ERROR("response_event is null!!");
1228 sync_agent_free_event(request_event);
1230 return SYNC_AGENT_DS_FAIL;
1233 /* get response parameter from event packet */
1234 sync_agent_get_event_data_param(response_event, &api_result);
1236 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1237 _DEBUG_ERROR("api_result = failed");
1238 sync_agent_free_event(request_event);
1239 sync_agent_free_event_data(response_event);
1241 return SYNC_AGENT_DS_FAIL;
1244 /* free request & response event */
1245 sync_agent_free_event(request_event);
1246 sync_agent_free_event_data(response_event);
1250 return SYNC_AGENT_DS_SUCCESS;
1253 EXPORT_API void sync_agent_ds_free_profile_info(ds_profile_h profile_h)
1257 // check mandatory parameter
1258 retm_if(profile_h == NULL, "profile handle is null!!");
1260 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1262 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1263 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1264 GList *category_list = profile_info->service_list;
1266 // free profile name
1267 g_free(profile_info->profile_dir_name);
1268 g_free(profile_info->profile_name);
1270 // free server information
1271 g_free(server_info->addr);
1272 g_free(server_info->id);
1273 g_free(server_info->password);
1275 // free sync mode information
1276 g_free(sync_info->sync_mode);
1277 g_free(sync_info->sync_type);
1278 g_free(sync_info->interval);
1280 // free sync category information
1281 g_list_free_full(category_list, (GDestroyNotify) _free_sync_category_info);
1283 // free profile information
1284 g_free(profile_info);
1289 EXPORT_API sync_agent_ds_error_e sync_agent_ds_deinit()
1293 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
1295 sync_agent_deinit_error_e deinit = SYNC_AGENT_DEINIT_SUCCESS;
1297 deinit = sync_agent_deinit();
1298 if (deinit != SYNC_AGENT_DEINIT_SUCCESS) {
1299 _DEBUG_ERROR("sync_agent_clean_event_handler() failed !!");
1300 result = SYNC_AGENT_DS_FAIL;
1302 // if (err != SYNC_AGENT_EVENT_SUCCESS) {
1303 // sync_agent_event_error_e err = sync_agent_stop_noti_listener();
1304 // _DEBUG_INFO("STOP NOTILISTNER is failed");
1305 // result = SYNC_AGENT_DS_FAIL;
1308 // err = sync_agent_clean_event_handler();
1309 // if (err != SYNC_AGENT_EVENT_SUCCESS) {
1310 // _DEBUG_ERROR("sync_agent_clean_event_handler() failed !!");
1311 // result = SYNC_AGENT_DS_FAIL;