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.
23 #include <dbus/dbus-glib.h>
25 #ifndef SYNC_AGENT_LOG
27 #define LOG_TAG "OMADS_CLIENT"
30 //#include <sync_agent.h>
31 #include "event/event.h"
32 #include "utility/sync_util.h"
33 #include "initialization/initialization.h"
36 #define EXPORT_API __attribute__ ((visibility("default")))
39 #define OMA_DS_CONFIG_FILE "/usr/share/oma-ds-cfg/omadsUI_fw_config.xml"
41 #define SYNC_AGENT_DS_API_RESULT_FAILURE 0
42 #define SYNC_AGENT_DS_API_RESULT_SUCCESS 1
44 #define SYNC_TYPE_SLOW_SYNC_STR "Full"
45 #define SYNC_TYPE_TWO_WAY_STR "Update both"
46 #define SYNC_TYPE_ONE_WAY_FROM_CLIENT_STR "Update to server"
47 #define SYNC_TYPE_ONE_WAY_FROM_SERVER_STR "Update to phone"
48 #define SYNC_TYPE_REFRESH_FROM_SERVER_STR "Refresh from server"
49 #define SYNC_TYPE_REFRESH_FROM_CLIENT_STR "Refresh from phone"
51 #define SYNC_MODE_MANUAL_STR "Manual"
52 #define SYNC_MODE_PUSH_STR "Push"
53 #define SYNC_MODE_PERIODIC_STR "Periodic"
55 #define SYNC_INTERVAL_NONE "None"
56 #define SYNC_INTERVAL_5_MINUTES "5 minutes"
57 #define SYNC_INTERVAL_15_MINUTES "15 minutes"
58 #define SYNC_INTERVAL_1_HOUR "1 hour"
59 #define SYNC_INTERVAL_4_HOURS "4 hours"
60 #define SYNC_INTERVAL_12_HOURS "12 hours"
61 #define SYNC_INTERVAL_1_DAY "1 day"
62 #define SYNC_INTERVAL_1_WEEK "1 week"
63 #define SYNC_INTERVAL_1_MONTH "1 month"
65 #define SRC_URI_CONTACT_STR "Contacts"
66 #define SRC_URI_CALENDAR_STR "Organizer"
69 SYNC_AGENT_DS_ADD_PROFILE = 1,
70 SYNC_AGENT_DS_UPDATE_PROFILE = 2,
71 SYNC_AGENT_DS_DELETE_PROFILE = 3,
72 SYNC_AGENT_DS_START_SYNC = 4,
73 SYNC_AGENT_DS_STOP_SYNC = 5,
74 SYNC_AGENT_DS_GET_PROFILE = 6,
75 SYNC_AGENT_DS_GET_SYNC_CATEGORY = 7,
76 SYNC_AGENT_DS_GET_SYNC_STATISTICS = 8,
77 SYNC_AGENT_DS_GET_ALL_PROFILES = 9
78 } sync_agent_ds_event_e;
81 SYNC_AGENT_DS_SYNC_CONTACTS = 0,
82 SYNC_AGENT_DS_SYNC_SCHEDULE = 1,
83 SYNC_AGENT_DS_SYNC_MEMO = 2
84 } sync_agent_ds_sync_e;
86 static gboolean _get_sync_category(char *profile_dir_name, int service_type, sync_agent_ds_service_info ** service)
90 int event_type = SYNC_AGENT_DS_GET_SYNC_CATEGORY;
91 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
93 // check mandatory parameter
94 retvm_if(profile_dir_name == NULL, FALSE, "profile_dir_name is null!!");
95 retvm_if(service_type < 0, FALSE, "service_type is wrong!!");
97 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
98 sync_agent_event_data_s *request_event = NULL;
99 sync_agent_event_data_s *response_event = NULL;
101 /* create empty event packet */
102 request_event = sync_agent_create_event(event_type);
103 if (request_event == NULL) {
104 _DEBUG_ERROR("event is NULL");
109 /* add request parameter to event packet */
110 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
111 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &service_type);
113 /* send event request to ds agent daemon, waiting for response */
114 response_event = sync_agent_send_event(request_event, &error);
115 if (error != SYNC_AGENT_EVENT_SUCCESS) {
116 _DEBUG_ERROR("error = %d", error);
117 sync_agent_free_event(request_event);
121 if (response_event == NULL) {
122 _DEBUG_ERROR("response_event is null!!");
123 sync_agent_free_event(request_event);
128 *service = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
129 if (*service == NULL) {
130 _DEBUG_ERROR("calloc failed");
131 sync_agent_free_event(request_event);
132 sync_agent_free_event_data(response_event);
136 /* get response parameter from event packet */
138 sync_agent_get_event_data_param_int(response_event, &api_result);
139 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
140 _DEBUG_ERROR("api_result = failed");
141 sync_agent_free_event(request_event);
142 sync_agent_free_event_data(response_event);
144 return SYNC_AGENT_DS_FAIL;
147 sync_agent_get_event_data_param_int(response_event, &((*service)->enabled));
148 sync_agent_get_event_data_param_int(response_event, (int*) &((*service)->src_uri));
149 sync_agent_get_event_data_param_str(response_event, &((*service)->tgt_uri));
150 sync_agent_get_event_data_param_str(response_event, &((*service)->id));
151 sync_agent_get_event_data_param_str(response_event, &((*service)->password));
153 _DEBUG_TRACE("enabled = %d", (*service)->enabled);
154 _DEBUG_TRACE("src_uri = %d", (*service)->src_uri);
155 _DEBUG_TRACE("tgt_uri = %s", (*service)->tgt_uri);
156 _DEBUG_TRACE("id = %s", (*service)->id);
157 _DEBUG_TRACE("password = %s", (*service)->password);
159 /* free request & response event */
160 sync_agent_free_event(request_event);
161 sync_agent_free_event_data(response_event);
168 static gboolean _get_sync_statistics(char *profile_dir_name, int service_type, sync_agent_ds_statistics_info ** statistics)
172 int event_type = SYNC_AGENT_DS_GET_SYNC_STATISTICS;
173 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
175 // check mandatory parameter
176 retvm_if(profile_dir_name == NULL, FALSE, "profile_dir_name is null!!");
177 retvm_if(service_type < 0, FALSE, "service_type is wrong!!");
179 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
180 sync_agent_event_data_s *request_event = NULL;
181 sync_agent_event_data_s *response_event = NULL;
183 char *statistics_cat = NULL;
185 /* create empty event packet */
186 request_event = sync_agent_create_event(event_type);
187 if (request_event == NULL) {
188 _DEBUG_ERROR("event is NULL");
193 /* add request parameter to event packet */
194 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
195 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &service_type);
197 /* send event request to ds agent daemon, waiting for response */
198 response_event = sync_agent_send_event(request_event, &error);
199 if (error != SYNC_AGENT_EVENT_SUCCESS) {
200 _DEBUG_ERROR("error = %d", error);
201 sync_agent_free_event(request_event);
205 if (response_event == NULL) {
206 _DEBUG_ERROR("response_event is null!!");
207 sync_agent_free_event(request_event);
212 *statistics = (sync_agent_ds_statistics_info *) calloc(1, sizeof(sync_agent_ds_statistics_info));
213 if (*statistics == NULL) {
214 _DEBUG_ERROR("calloc failed");
215 sync_agent_free_event(request_event);
216 sync_agent_free_event_data(response_event);
220 /* get response parameter from event packet */
222 sync_agent_get_event_data_param_int(response_event, &api_result);
223 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
224 _DEBUG_ERROR("api_result = failed");
225 sync_agent_free_event(request_event);
226 sync_agent_free_event_data(response_event);
228 return SYNC_AGENT_DS_FAIL;
231 if (service_type == SYNC_AGENT_DS_SYNC_CONTACTS)
232 statistics_cat = "contacts";
233 else if (service_type == SYNC_AGENT_DS_SYNC_SCHEDULE)
234 statistics_cat = "schedule";
235 else if (service_type == SYNC_AGENT_DS_SYNC_MEMO)
236 statistics_cat = "memo";
238 sync_agent_get_event_data_param_str(response_event, &((*statistics)->dbsynced));
239 sync_agent_get_event_data_param_int(response_event, &((*statistics)->last_session_time));
240 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_total));
241 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_nrofadd));
242 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_nrofdelete));
243 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_nrofreplace));
244 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_total));
245 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_nrofadd));
246 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_nrofdelete));
247 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_nrofreplace));
249 _DEBUG_TRACE("%s dbSynced = %s", statistics_cat, (*statistics)->dbsynced);
250 _DEBUG_TRACE("%s lastSessionTime = %d", statistics_cat, (*statistics)->last_session_time);
251 _DEBUG_TRACE("%s server2Client_Total = %d", statistics_cat, (*statistics)->server2client_total);
252 _DEBUG_TRACE("%s server2Client_NrOrAdd = %d", statistics_cat, (*statistics)->server2client_nrofadd);
253 _DEBUG_TRACE("%s server2Client_NrOfDelete = %d", statistics_cat, (*statistics)->server2client_nrofdelete);
254 _DEBUG_TRACE("%s server2Client_NrOfReplace = %d", statistics_cat, (*statistics)->server2client_nrofreplace);
255 _DEBUG_TRACE("%s client2Server_Total = %d", statistics_cat, (*statistics)->client2server_total);
256 _DEBUG_TRACE("%s client2Server_NrOfAdd = %d", statistics_cat, (*statistics)->client2server_nrofadd);
257 _DEBUG_TRACE("%s client2Server_NrOfDelete = %d", statistics_cat, (*statistics)->client2server_nrofdelete);
258 _DEBUG_TRACE("%s client2Server_NrOfReplace = %d", statistics_cat, (*statistics)->client2server_nrofreplace);
260 /* free request & response event */
261 sync_agent_free_event(request_event);
262 sync_agent_free_event_data(response_event);
269 static char * _convert_sync_mode_str(sync_agent_ds_sync_mode_e sync_mode)
273 char* sync_mode_str = NULL;
275 _DEBUG_INFO("sync_mode : [%d]",sync_mode);
277 case SYNC_AGENT_SYNC_MODE_MANUAL:
278 sync_mode_str = SYNC_MODE_MANUAL_STR;
280 case SYNC_AGENT_SYNC_MODE_PERIODIC:
281 sync_mode_str = SYNC_MODE_PERIODIC_STR;
283 case SYNC_AGENT_SYNC_MODE_PUSH:
284 sync_mode_str = SYNC_MODE_PUSH_STR;
291 return sync_mode_str;
294 static char * _convert_sync_type_str(sync_agent_ds_sync_type_e sync_type)
298 char* sync_type_str = NULL;
300 _DEBUG_INFO("sync_type : [%d]",sync_type);
302 case SYNC_AGENT_SYNC_TYPE_FULL_SYNC:
303 sync_type_str = SYNC_TYPE_SLOW_SYNC_STR;
305 case SYNC_AGENT_SYNC_TYPE_UPDATE_BOTH:
306 sync_type_str = SYNC_TYPE_TWO_WAY_STR;
308 case SYNC_AGENT_SYNC_TYPE_UPDATE_TO_SERVER:
309 sync_type_str = SYNC_TYPE_ONE_WAY_FROM_CLIENT_STR;
311 case SYNC_AGENT_SYNC_TYPE_UPDATE_TO_PHONE:
312 sync_type_str = SYNC_TYPE_ONE_WAY_FROM_SERVER_STR;
314 case SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_SERVER:
315 sync_type_str = SYNC_TYPE_REFRESH_FROM_SERVER_STR;
317 case SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_PHONE:
318 sync_type_str = SYNC_TYPE_REFRESH_FROM_CLIENT_STR;
325 return sync_type_str;
328 static char * _convert_sync_interval_str(sync_agent_ds_sync_interval_e interval)
332 char* interval_str = NULL;
334 _DEBUG_INFO("interval : [%d]",interval);
336 case SYNC_AGENT_SYNC_INTERVAL_5_MINUTES:
337 interval_str = SYNC_INTERVAL_5_MINUTES;
339 case SYNC_AGENT_SYNC_INTERVAL_15_MINUTES:
340 interval_str = SYNC_INTERVAL_15_MINUTES;
342 case SYNC_AGENT_SYNC_INTERVAL_1_HOUR:
343 interval_str = SYNC_INTERVAL_1_HOUR;
345 case SYNC_AGENT_SYNC_INTERVAL_4_HOURS:
346 interval_str = SYNC_INTERVAL_4_HOURS;
348 case SYNC_AGENT_SYNC_INTERVAL_12_HOURS:
349 interval_str = SYNC_INTERVAL_12_HOURS;
351 case SYNC_AGENT_SYNC_INTERVAL_1_DAY:
352 interval_str = SYNC_INTERVAL_1_DAY;
354 case SYNC_AGENT_SYNC_INTERVAL_1_WEEK:
355 interval_str = SYNC_INTERVAL_1_WEEK;
357 case SYNC_AGENT_SYNC_INTERVAL_1_MONTH:
358 interval_str = SYNC_INTERVAL_1_MONTH;
361 interval_str = SYNC_INTERVAL_NONE;
369 static char * _convert_src_uri_str(sync_agent_ds_src_uri_e src_uri)
373 char* src_uri_str = NULL;
375 _DEBUG_INFO("src_uri : [%d]",src_uri);
377 case SYNC_AGENT_SRC_URI_CONTACT:
378 src_uri_str = SRC_URI_CONTACT_STR;
380 case SYNC_AGENT_SRC_URI_CALENDAR:
381 src_uri_str = SRC_URI_CALENDAR_STR;
391 static void _free_sync_category_info(sync_agent_ds_service_info * data)
393 g_free(data->tgt_uri);
395 g_free(data->password);
398 static gboolean _is_existing_profile(void)
402 int event_type = SYNC_AGENT_DS_GET_ALL_PROFILES;
403 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
404 sync_agent_event_data_s *request_event = NULL;
405 sync_agent_event_data_s *response_event = NULL;
407 int profile_count = 0;
409 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
411 /* create empty event packet */
412 request_event = sync_agent_create_event(event_type);
413 if (request_event == NULL) {
414 _DEBUG_ERROR("event is NULL");
416 return SYNC_AGENT_DS_FAIL;
419 /* send event request to ds agent daemon, waiting for response */
420 response_event = sync_agent_send_event(request_event, &error);
421 if (error != SYNC_AGENT_EVENT_SUCCESS) {
422 _DEBUG_ERROR("error = %d", error);
423 sync_agent_free_event(request_event);
425 return SYNC_AGENT_DS_FAIL;
427 if (response_event == NULL) {
428 _DEBUG_ERROR("response_event is null!!");
429 sync_agent_free_event(request_event);
431 return SYNC_AGENT_DS_FAIL;
434 sync_agent_get_event_data_param_int(response_event, &api_result);
435 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
436 _DEBUG_ERROR("api_result = failed");
437 sync_agent_free_event(request_event);
438 sync_agent_free_event_data(response_event);
440 return SYNC_AGENT_DS_FAIL;
443 sync_agent_get_event_data_param_int(response_event, &profile_count);
444 _DEBUG_INFO("profile_count = %d", profile_count);
446 if (profile_count > 0) {
447 sync_agent_free_event(request_event);
448 sync_agent_free_event_data(response_event);
454 /* free request & response event */
455 sync_agent_free_event(request_event);
456 sync_agent_free_event_data(response_event);
463 static int _launch_omads_agent(void)
466 GError *error = NULL;
468 DBusGConnection *connection = NULL;
469 DBusGProxy *dbus_proxy = NULL;
473 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
475 _DEBUG_ERROR("Connecting to system bus failed: %s\n", error->message);
481 dbus_proxy = dbus_g_proxy_new_for_name(connection, "com.samsung.omadsagent",
482 "/com/samsung/omadsagent", "com.samsung.omadsagent");
484 _DEBUG_INFO("dbus_proxy %x", dbus_proxy);
486 //dbus_g_proxy_call_no_reply(dbus_proxy, "Hello_Agent", G_TYPE_INVALID);
487 dbus_g_proxy_call(dbus_proxy, "Hello_Agent", &error, G_TYPE_INVALID, G_TYPE_INVALID);
489 g_object_unref(dbus_proxy);
490 dbus_g_connection_unref(connection);
496 static int _kill_omads_agent(void)
499 GError *error = NULL;
501 DBusGConnection *connection = NULL;
502 DBusGProxy *dbus_proxy = NULL;
503 gboolean isExisting = FALSE;
505 isExisting = _is_existing_profile();
508 _DEBUG_INFO("Existing profile !!");
514 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
516 _DEBUG_ERROR("Connecting to system bus failed: %s\n", error->message);
522 dbus_proxy = dbus_g_proxy_new_for_name(connection, "com.samsung.omadsagent",
523 "/com/samsung/omadsagent", "com.samsung.omadsagent");
525 _DEBUG_INFO("dbus_proxy %x", dbus_proxy);
527 dbus_g_proxy_call_no_reply(dbus_proxy, "Goodbye_Agent", G_TYPE_INVALID);
529 g_object_unref(dbus_proxy);
530 dbus_g_connection_unref(connection);
536 EXPORT_API sync_agent_ds_error_e sync_agent_ds_init()
540 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
541 sync_agent_init_error_e init_error = SYNC_AGENT_INIT_SUCCESS;
544 ret = _launch_omads_agent();
547 _DEBUG_ERROR("_launch_omads_agent() failed !!");
548 result = SYNC_AGENT_DS_FAIL;
554 init_error = sync_agent_init(OMA_DS_CONFIG_FILE);
556 if (init_error != SYNC_AGENT_INIT_SUCCESS) {
557 _DEBUG_ERROR("ds init failed");
558 result = SYNC_AGENT_DS_FAIL;
561 sync_agent_event_error_e err = sync_agent_run_noti_listener("omads");
562 if (err != SYNC_AGENT_EVENT_SUCCESS) {
563 _DEBUG_ERROR("RUN NOTILISTNER is failed");
564 result = SYNC_AGENT_DS_FAIL;
572 EXPORT_API sync_agent_ds_error_e sync_agent_ds_create_profile_info(ds_profile_h * profile_h)
576 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
577 sync_agent_ds_profile_info *profile_info = NULL;
579 // allocate memory for ds profile info
580 profile_info = (sync_agent_ds_profile_info *) calloc(1, sizeof(sync_agent_ds_profile_info));
581 if (profile_info == NULL) {
582 _DEBUG_ERROR("calloc failed !!");
583 return SYNC_AGENT_DS_FAIL;
585 // pass memory pointer to ds profile handle
586 *profile_h = profile_info;
593 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_profile_dir_name(ds_profile_h profile_h, char *profile_dir_name)
597 // check mandatory parameter
598 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
599 retvm_if(profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
601 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
602 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
605 profile_info->profile_dir_name = g_strdup(profile_dir_name);
607 if (profile_info->profile_dir_name == NULL) {
608 _DEBUG_ERROR("g_strdup failed !!");
609 return SYNC_AGENT_DS_FAIL;
617 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_profile_name(ds_profile_h profile_h, char *profile_name)
621 // check mandatory parameter
622 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
623 retvm_if(profile_name == NULL, SYNC_AGENT_DS_FAIL, "profile_name is null!!");
625 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
626 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
629 profile_info->profile_name = g_strdup(profile_name);
631 if (profile_info->profile_name == NULL) {
632 _DEBUG_ERROR("g_strdup failed !!");
633 return SYNC_AGENT_DS_FAIL;
641 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_server_info(ds_profile_h profile_h, char *addr, char *id, char *password)
645 // check mandatory parameter
646 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
647 retvm_if(addr == NULL, SYNC_AGENT_DS_FAIL, "addr is null!!");
648 retvm_if(id == NULL, SYNC_AGENT_DS_FAIL, "id is null!!");
649 retvm_if(password == NULL, SYNC_AGENT_DS_FAIL, "password is null!!");
651 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
652 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
653 sync_agent_ds_server_info *server_info = &profile_info->server_info;
656 server_info->addr = g_strdup(addr);
657 server_info->id = g_strdup(id);
658 server_info->password = g_strdup(password);
660 if ((server_info->addr == NULL)
661 || (server_info->id == NULL)
662 || (server_info->password == NULL)) {
663 _DEBUG_ERROR("g_strdup failed !!");
664 return SYNC_AGENT_DS_FAIL;
672 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_sync_info(ds_profile_h profile_h, sync_agent_ds_sync_mode_e sync_mode, sync_agent_ds_sync_type_e sync_type, sync_agent_ds_sync_interval_e interval)
676 // check mandatory parameter
677 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
678 retvm_if(sync_mode < 0, SYNC_AGENT_DS_FAIL, "sync_mode is invalid!!");
679 retvm_if(sync_type < 0, SYNC_AGENT_DS_FAIL, "sync_type is invalid!!");
680 retvm_if(interval < 0, SYNC_AGENT_DS_FAIL, "interval is invalid!!");
682 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
683 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
684 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
686 char* sync_mode_str = NULL;
687 char* sync_type_str = NULL;
688 char* interval_str = NULL;
690 sync_mode_str = _convert_sync_mode_str(sync_mode);
691 if (sync_mode_str == NULL) {
692 _DEBUG_ERROR("_convert_sync_mode_str failed !!");
694 return SYNC_AGENT_DS_FAIL;
697 sync_type_str = _convert_sync_type_str(sync_type);
698 if (sync_type_str == NULL) {
699 _DEBUG_ERROR("_convert_sync_type_str failed !!");
701 return SYNC_AGENT_DS_FAIL;
704 interval_str = _convert_sync_interval_str(interval);
705 if (interval_str == NULL) {
706 _DEBUG_ERROR("_convert_sync_interval_str failed !!");
708 return SYNC_AGENT_DS_FAIL;
712 sync_info->sync_mode = sync_mode;
713 sync_info->sync_type = sync_type;
714 sync_info->interval = interval;
721 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, sync_agent_ds_src_uri_e src_uri, char *tgt_uri, char *id, char *password)
725 // check mandatory parameter
726 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
727 retvm_if(src_uri < 0, SYNC_AGENT_DS_FAIL, "src_uri is invalid!!");
729 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
730 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
731 sync_agent_ds_service_info *category_info = NULL;
732 char* src_uri_str = NULL;
734 src_uri_str = _convert_src_uri_str(src_uri);
735 if (src_uri_str == NULL) {
736 _DEBUG_ERROR("_get_src_uri_string failed !!");
738 return SYNC_AGENT_DS_FAIL;
741 // allocate memory for sync_category
742 category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
743 retvm_if(category_info == NULL, SYNC_AGENT_DS_FAIL, "calloc failed");
744 category_info->service_type = service_type;
745 category_info->enabled = enabled;
746 category_info->src_uri = src_uri;
747 category_info->tgt_uri = g_strdup(tgt_uri);
749 profile_info->service_list = g_list_append(profile_info->service_list, category_info);
756 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_id(ds_profile_h profile_h, int *profile_id)
760 // check mandatory parameter
761 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
763 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
765 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
767 *profile_id = profile_info->profile_id;
769 if (*profile_id < 1) {
770 _DEBUG_ERROR("profile_id is invalid!!");
771 return SYNC_AGENT_DS_FAIL;
774 _DEBUG_INFO("profile_id = %d", *profile_id);
781 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_dir_name(ds_profile_h profile_h, char **profile_dir_name)
785 // check mandatory parameter
786 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
788 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
790 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
792 *profile_dir_name = g_strdup(profile_info->profile_dir_name);
794 if (*profile_dir_name == NULL) {
795 _DEBUG_ERROR("g_strdup failed !!");
796 return SYNC_AGENT_DS_FAIL;
799 _DEBUG_INFO("profile_dir_name = %s", *profile_dir_name);
806 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_name(ds_profile_h profile_h, char **profile_name)
810 // check mandatory parameter
811 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
813 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
815 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
817 *profile_name = g_strdup(profile_info->profile_name);
819 if (*profile_name == NULL) {
820 _DEBUG_ERROR("g_strdup failed !!");
821 return SYNC_AGENT_DS_FAIL;
824 _DEBUG_INFO("profile_name = %s", *profile_name);
831 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)
835 // check mandatory parameter
836 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
837 retvm_if(server_info == NULL, SYNC_AGENT_DS_FAIL, "server_info is null!!");
839 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
840 sync_agent_ds_server_info *ds_server_info = &profile_info->server_info;
842 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
844 server_info->addr = g_strdup(ds_server_info->addr);
845 server_info->id = g_strdup(ds_server_info->id);
846 server_info->password = g_strdup(ds_server_info->password);
848 if ((server_info->addr == NULL)
849 || (server_info->id == NULL)
850 || (server_info->password == NULL)) {
851 _DEBUG_ERROR("g_strdup failed !!");
852 return SYNC_AGENT_DS_FAIL;
855 _DEBUG_INFO("get_addr = %s", server_info->addr);
856 _DEBUG_INFO("get_id = %s", server_info->id);
857 _DEBUG_INFO("get_password = %s", server_info->password);
864 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)
868 // check mandatory parameter
869 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
870 retvm_if(sync_info == NULL, SYNC_AGENT_DS_FAIL, "sync_info is null!!");
872 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
873 sync_agent_ds_sync_info *ds_sync_info = &profile_info->sync_info;
875 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
877 sync_info->sync_mode = ds_sync_info->sync_mode;
878 sync_info->sync_type = ds_sync_info->sync_type;
879 sync_info->interval = ds_sync_info->interval;
881 _DEBUG_INFO("get_sync_mode = %d", sync_info->sync_mode);
882 _DEBUG_INFO("get_sync_type = %d", sync_info->sync_type);
883 _DEBUG_INFO("get_interval = %d", sync_info->interval);
885 if (sync_info->sync_mode < 0) {
886 _DEBUG_ERROR("sync_mode is invalid !!");
887 return SYNC_AGENT_DS_FAIL;
890 if (sync_info->sync_type < 0) {
891 _DEBUG_ERROR("sync_type is invalid !!");
892 return SYNC_AGENT_DS_FAIL;
895 if (sync_info->interval < 0) {
896 _DEBUG_ERROR("interval is invalid !!");
897 return SYNC_AGENT_DS_FAIL;
905 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_service_info(ds_profile_h profile_h, GList ** category_list)
909 // check mandatory parameter
910 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
912 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
914 int category_count = 0;
916 sync_agent_ds_service_info *category_info = NULL;
918 *category_list = g_list_copy(profile_info->service_list);
920 if (*category_list == NULL) {
921 _DEBUG_ERROR("g_list_copy failed !!");
922 return SYNC_AGENT_DS_FAIL;
925 category_count = g_list_length(*category_list);
926 for (; i < category_count; i++) {
927 category_info = (sync_agent_ds_service_info *) g_list_nth_data(*category_list, i);
929 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
930 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
931 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
932 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
933 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
938 return SYNC_AGENT_DS_SUCCESS;
941 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_statistics(ds_profile_h profile_h, GList ** statistics_list)
945 // check mandatory parameter
946 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
948 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
949 sync_agent_ds_statistics_info *statistics = NULL;
951 gboolean result_sync_category = FALSE;
953 /* get last contacts sync result */
954 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_CONTACTS, &statistics);
955 if (result_sync_category)
956 *statistics_list = g_list_append(*statistics_list, statistics);
958 /* get last schedule sync result */
960 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_SCHEDULE, &statistics);
961 if (result_sync_category)
962 *statistics_list = g_list_append(*statistics_list, statistics);
964 /* get last memo sync result */
966 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_MEMO, &statistics);
967 if (result_sync_category)
968 *statistics_list = g_list_append(*statistics_list, statistics);
972 return SYNC_AGENT_DS_SUCCESS;
975 EXPORT_API sync_agent_ds_error_e sync_agent_ds_add_profile(ds_profile_h profile_h, int *profile_id)
979 // check mandatory parameter
980 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
982 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
983 sync_agent_ds_server_info *server_info = &profile_info->server_info;
984 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
985 GList *list = profile_info->service_list;
987 int event_type = SYNC_AGENT_DS_ADD_PROFILE;
988 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
989 sync_agent_event_data_s *request_event = NULL;
990 sync_agent_event_data_s *response_event = NULL;
993 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
994 sync_agent_ds_service_info *category_info = NULL;
995 int category_count = 0;
998 /* create empty event packet */
999 request_event = sync_agent_create_event(event_type);
1000 if (request_event == NULL) {
1001 _DEBUG_ERROR("event is NULL");
1003 return SYNC_AGENT_DS_FAIL;
1006 /* add request parameter to event packet */
1007 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
1008 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name);
1009 _DEBUG_INFO("addr = %s", server_info->addr);
1010 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr);
1011 _DEBUG_INFO("id = %s", server_info->id);
1012 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id);
1013 _DEBUG_INFO("password = %s", server_info->password);
1014 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password);
1015 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
1016 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_mode));
1017 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
1018 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_type));
1019 _DEBUG_INFO("interval = %d", sync_info->interval);
1020 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->interval));
1022 category_count = g_list_length(list);
1023 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count);
1025 for (; i < category_count; i++) {
1026 category_info = (sync_agent_ds_service_info *) g_list_nth_data(list, i);
1028 _DEBUG_INFO("category[%d]->service_type = %d", i, category_info->service_type);
1029 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->service_type));
1030 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
1031 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->enabled));
1032 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
1033 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->src_uri));
1034 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
1035 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri);
1036 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
1037 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id);
1038 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
1039 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password);
1042 /* send event request to ds agent daemon, waiting for response */
1043 response_event = sync_agent_send_event(request_event, &error);
1044 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1045 _DEBUG_ERROR("error = %d", error);
1046 sync_agent_free_event(request_event);
1048 return SYNC_AGENT_DS_FAIL;
1050 if (response_event == NULL) {
1051 _DEBUG_ERROR("response_event is null!!");
1052 sync_agent_free_event(request_event);
1054 return SYNC_AGENT_DS_FAIL;
1057 /* get response parameter from event packet */
1058 sync_agent_get_event_data_param_int(response_event, &api_result);
1060 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1061 _DEBUG_ERROR("api_result = failed");
1062 sync_agent_free_event(request_event);
1063 sync_agent_free_event_data(response_event);
1065 return SYNC_AGENT_DS_FAIL;
1068 sync_agent_get_event_data_param_int(response_event, &prof_id);
1070 _DEBUG_VERBOSE("profile_id = %d", prof_id);
1071 *profile_id = prof_id;
1073 /* free request & response event */
1074 sync_agent_free_event(request_event);
1075 sync_agent_free_event_data(response_event);
1079 return SYNC_AGENT_DS_SUCCESS;
1082 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile(int profile_id, ds_profile_h * profile_h)
1086 // check mandatory parameter
1087 retvm_if(profile_id < 1, SYNC_AGENT_DS_FAIL, "profile_id is invalid!!");
1089 int event_type = SYNC_AGENT_DS_GET_PROFILE;
1090 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1091 sync_agent_event_data_s *request_event = NULL;
1092 sync_agent_event_data_s *response_event = NULL;
1094 gboolean result_sync_category = FALSE;
1095 sync_agent_ds_error_e result = SYNC_AGENT_DS_FAIL;
1096 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1097 sync_agent_ds_service_info *category = NULL;
1099 //////////////////////////////////
1101 // Phase 1. get profile detail info
1103 /* create empty event packet */
1104 request_event = sync_agent_create_event(event_type);
1105 if (request_event == NULL) {
1106 _DEBUG_ERROR("event is NULL");
1108 return SYNC_AGENT_DS_FAIL;
1111 /* add request parameter to event packet */
1112 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &profile_id);
1113 _DEBUG_INFO("profile_id = %d", profile_id);
1115 /* send event request to ds agent daemon, waiting for response */
1116 response_event = sync_agent_send_event(request_event, &error);
1117 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1118 _DEBUG_ERROR("error = %d", error);
1119 sync_agent_free_event(request_event);
1121 return SYNC_AGENT_DS_FAIL;
1123 if (response_event == NULL) {
1124 _DEBUG_ERROR("response_event is null!!");
1125 sync_agent_free_event(request_event);
1127 return SYNC_AGENT_DS_FAIL;
1130 /* get response parameter from event packet */
1132 result = sync_agent_ds_create_profile_info(profile_h);
1133 if (result == SYNC_AGENT_DS_FAIL) {
1134 _DEBUG_ERROR("failed to create profile info!");
1135 sync_agent_free_event(request_event);
1136 sync_agent_free_event_data(response_event);
1140 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) (*profile_h);
1141 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1142 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1143 // GList * list = profile_info->category_list;
1145 sync_agent_get_event_data_param_int(response_event, &api_result);
1146 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1147 _DEBUG_ERROR("api_result = failed");
1148 sync_agent_free_event(request_event);
1149 sync_agent_free_event_data(response_event);
1151 return SYNC_AGENT_DS_FAIL;
1154 //profile_info->profile_dir_name = g_strdup(profile_dir_name);
1156 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_dir_name);
1157 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_name);
1158 sync_agent_get_event_data_param_str(response_event, &server_info->addr);
1159 sync_agent_get_event_data_param_str(response_event, &server_info->id);
1160 sync_agent_get_event_data_param_str(response_event, &server_info->password);
1161 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_mode);
1162 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_type);
1163 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->interval);
1164 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_status);
1165 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_time);
1167 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1168 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
1169 _DEBUG_INFO("addr = %s", server_info->addr);
1170 _DEBUG_INFO("id = %s", server_info->id);
1171 _DEBUG_INFO("password = %s", server_info->password);
1172 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
1173 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
1174 _DEBUG_INFO("interval = %d", sync_info->interval);
1175 _DEBUG_VERBOSE("lastSyncStatus = %d\n", profile_info->last_sync_status);
1176 _DEBUG_VERBOSE("lastSyncTime = %d\n", profile_info->last_sync_time);
1178 /* free request & response event */
1179 sync_agent_free_event(request_event);
1180 sync_agent_free_event_data(response_event);
1182 // Phase 2. get sync category info
1184 /* get contacts sync_category */
1185 result_sync_category = _get_sync_category(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_CONTACTS, &category);
1186 if (result_sync_category)
1187 profile_info->service_list = g_list_append(profile_info->service_list, category);
1189 /* get schedule sync_category */
1191 result_sync_category = _get_sync_category(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_SCHEDULE, &category);
1192 if (result_sync_category)
1193 profile_info->service_list = g_list_append(profile_info->service_list, category);
1197 return SYNC_AGENT_DS_SUCCESS;
1200 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_all_profile(GList ** profile_list)
1204 int event_type = SYNC_AGENT_DS_GET_ALL_PROFILES;
1205 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1206 sync_agent_event_data_s *request_event = NULL;
1207 sync_agent_event_data_s *response_event = NULL;
1209 ds_profile_h profile_h = NULL;
1210 sync_agent_ds_service_info *category_info = NULL;
1212 int profile_count = 0;
1213 int category_count = 0;
1215 sync_agent_ds_error_e result = SYNC_AGENT_DS_FAIL;
1216 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1218 /* create empty event packet */
1219 request_event = sync_agent_create_event(event_type);
1220 if (request_event == NULL) {
1221 _DEBUG_ERROR("event is NULL");
1223 return SYNC_AGENT_DS_FAIL;
1226 /* send event request to ds agent daemon, waiting for response */
1227 response_event = sync_agent_send_event(request_event, &error);
1228 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1229 _DEBUG_ERROR("error = %d", error);
1230 sync_agent_free_event(request_event);
1232 return SYNC_AGENT_DS_FAIL;
1234 if (response_event == NULL) {
1235 _DEBUG_ERROR("response_event is null!!");
1236 sync_agent_free_event(request_event);
1238 return SYNC_AGENT_DS_FAIL;
1241 sync_agent_get_event_data_param_int(response_event, &api_result);
1242 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1243 _DEBUG_ERROR("api_result = failed");
1244 sync_agent_free_event(request_event);
1245 sync_agent_free_event_data(response_event);
1247 return SYNC_AGENT_DS_FAIL;
1250 sync_agent_get_event_data_param_int(response_event, &profile_count);
1251 _DEBUG_INFO("profile_count = %d", profile_count);
1254 for (i = 0; i < profile_count; i++) {
1256 result = sync_agent_ds_create_profile_info(&profile_h);
1257 if (result == SYNC_AGENT_DS_FAIL) {
1258 _DEBUG_ERROR("failed to create profile info!");
1259 sync_agent_free_event(request_event);
1260 sync_agent_free_event_data(response_event);
1264 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1265 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1266 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1268 sync_agent_get_event_data_param_int(response_event, &profile_info->profile_id);
1269 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_dir_name);
1270 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_name);
1271 sync_agent_get_event_data_param_str(response_event, &server_info->addr);
1272 sync_agent_get_event_data_param_str(response_event, &server_info->id);
1273 sync_agent_get_event_data_param_str(response_event, &server_info->password);
1274 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_mode);
1275 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_type);
1276 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->interval);
1277 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_status);
1278 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_time);
1280 _DEBUG_INFO("profile_info->profile_id = %d", profile_info->profile_id);
1281 _DEBUG_INFO("profile_info->profile_dir_name = %s", profile_info->profile_dir_name);
1282 _DEBUG_INFO("profile_info->profile_name = %s", profile_info->profile_name);
1283 _DEBUG_INFO("profile_info->addr = %s", server_info->addr);
1284 _DEBUG_INFO("profile_info->id = %s", server_info->id);
1285 _DEBUG_INFO("profile_info->password = %s", server_info->password);
1286 _DEBUG_INFO("profile_info->sync_mode = %d", sync_info->sync_mode);
1287 _DEBUG_INFO("profile_info->sync_type = %d", sync_info->sync_type);
1288 _DEBUG_INFO("profile_info->interval = %d", sync_info->interval);
1289 _DEBUG_INFO("profile_info->lastSyncStatus = %d", profile_info->last_sync_status);
1290 _DEBUG_INFO("profile_info->lastSyncStatus = %d", profile_info->last_sync_status);
1292 sync_agent_get_event_data_param_int(response_event, &category_count);
1295 for (j = 0; j < category_count; j++) {
1297 category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
1298 if (category_info == NULL) {
1299 _DEBUG_ERROR("calloc failed");
1300 sync_agent_ds_free_profile_info(profile_h);
1301 sync_agent_free_event(request_event);
1302 sync_agent_free_event_data(response_event);
1306 sync_agent_get_event_data_param_int(response_event, (int*) &category_info->service_type);
1307 sync_agent_get_event_data_param_int(response_event, &category_info->enabled);
1308 sync_agent_get_event_data_param_int(response_event, (int*) &category_info->src_uri);
1309 sync_agent_get_event_data_param_str(response_event, &category_info->tgt_uri);
1310 sync_agent_get_event_data_param_str(response_event, &category_info->id);
1311 sync_agent_get_event_data_param_str(response_event, &category_info->password);
1313 _DEBUG_INFO("category_info->service_type = %d", category_info->service_type);
1314 _DEBUG_INFO("category_info->enabled = %d", category_info->enabled);
1315 _DEBUG_INFO("category_info->src_uri = %d", category_info->src_uri);
1316 _DEBUG_INFO("category_info->tgt_uri = %s", category_info->tgt_uri);
1317 _DEBUG_INFO("category_info->id = %s", category_info->id);
1318 _DEBUG_INFO("category_info->password = %s", category_info->password);
1320 profile_info->service_list = g_list_append(profile_info->service_list, category_info);
1321 category_info = NULL;
1324 *profile_list = g_list_append(*profile_list, profile_h);
1328 /* free request & response event */
1329 sync_agent_free_event(request_event);
1330 sync_agent_free_event_data(response_event);
1334 return SYNC_AGENT_DS_SUCCESS;
1337 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_last_sync_info(ds_profile_h profile_h, int *lastSyncStatus, int *lastSyncTime)
1341 // check mandatory parameter
1342 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1343 retvm_if(lastSyncStatus == NULL, SYNC_AGENT_DS_FAIL, "last session status is null!!");
1344 retvm_if(lastSyncTime == NULL, SYNC_AGENT_DS_FAIL, "last session time is null!!");
1346 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1348 *lastSyncStatus = profile_info->last_sync_status;
1349 *lastSyncTime = profile_info->last_sync_time;
1353 return SYNC_AGENT_DS_SUCCESS;
1356 EXPORT_API sync_agent_ds_error_e sync_agent_ds_update_profile(ds_profile_h profile_h)
1360 // check mandatory parameter
1361 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1363 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1364 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1365 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1366 GList *list = profile_info->service_list;
1368 int event_type = SYNC_AGENT_DS_UPDATE_PROFILE;
1369 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1370 sync_agent_event_data_s *request_event = NULL;
1371 sync_agent_event_data_s *response_event = NULL;
1373 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1374 sync_agent_ds_service_info *category_info = NULL;
1375 int category_count = 0;
1378 /* create empty event packet */
1379 request_event = sync_agent_create_event(event_type);
1380 if (request_event == NULL) {
1381 _DEBUG_ERROR("event is NULL");
1383 return SYNC_AGENT_DS_FAIL;
1386 /* add request parameter to event packet */
1387 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1388 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1389 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
1390 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name);
1391 _DEBUG_INFO("addr = %s", server_info->addr);
1392 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr);
1393 _DEBUG_INFO("id = %s", server_info->id);
1394 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id);
1395 _DEBUG_INFO("password = %s", server_info->password);
1396 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password);
1397 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
1398 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_mode));
1399 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
1400 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_type));
1401 _DEBUG_INFO("interval = %d", sync_info->interval);
1402 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->interval));
1404 category_count = g_list_length(list);
1405 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count);
1407 for (; i < category_count; i++) {
1408 category_info = (sync_agent_ds_service_info *) g_list_nth_data(list, i);
1410 _DEBUG_INFO("category[%d]->service_type = %d", i, category_info->service_type);
1411 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->service_type));
1412 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
1413 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->enabled));
1414 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
1415 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->src_uri));
1416 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
1417 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri);
1418 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
1419 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id);
1420 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
1421 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password);
1424 /* send event request to ds agent daemon, waiting for response */
1425 response_event = sync_agent_send_event(request_event, &error);
1426 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1427 _DEBUG_ERROR("error = %d", error);
1428 sync_agent_free_event(request_event);
1430 return SYNC_AGENT_DS_FAIL;
1432 if (response_event == NULL) {
1433 _DEBUG_ERROR("response_event is null!!");
1434 sync_agent_free_event(request_event);
1436 return SYNC_AGENT_DS_FAIL;
1439 /* get response parameter from event packet */
1440 sync_agent_get_event_data_param_int(response_event, &api_result);
1442 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1443 _DEBUG_ERROR("api_result = failed");
1444 sync_agent_free_event(request_event);
1445 sync_agent_free_event_data(response_event);
1447 return SYNC_AGENT_DS_FAIL;
1450 /* free request & response event */
1451 sync_agent_free_event(request_event);
1452 sync_agent_free_event_data(response_event);
1456 return SYNC_AGENT_DS_SUCCESS;
1459 EXPORT_API sync_agent_ds_error_e sync_agent_ds_delete_profile(ds_profile_h profile_h)
1463 // check mandatory parameter
1464 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1466 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1468 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1470 int event_type = SYNC_AGENT_DS_DELETE_PROFILE;
1471 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1472 sync_agent_event_data_s *request_event = NULL;
1473 sync_agent_event_data_s *response_event = NULL;
1476 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1478 /* create empty event packet */
1479 request_event = sync_agent_create_event(event_type);
1480 if (request_event == NULL) {
1481 _DEBUG_ERROR("event is NULL");
1482 return SYNC_AGENT_DS_FAIL;
1485 /* add request parameter to event packet */
1486 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &count);
1488 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1489 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1491 /* send event request to ds agent daemon, waiting for response */
1492 response_event = sync_agent_send_event(request_event, &error);
1493 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1494 _DEBUG_ERROR("error = %d", error);
1495 sync_agent_free_event(request_event);
1497 return SYNC_AGENT_DS_FAIL;
1499 if (response_event == NULL) {
1500 _DEBUG_ERROR("response_event is null!!");
1501 sync_agent_free_event(request_event);
1503 return SYNC_AGENT_DS_FAIL;
1506 /* get response parameter from event packet */
1507 sync_agent_get_event_data_param_int(response_event, &api_result);
1509 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1510 _DEBUG_ERROR("api_result = failed");
1511 sync_agent_free_event(request_event);
1512 sync_agent_free_event_data(response_event);
1514 return SYNC_AGENT_DS_FAIL;
1517 /* free request & response event */
1518 sync_agent_free_event(request_event);
1519 sync_agent_free_event_data(response_event);
1523 return SYNC_AGENT_DS_SUCCESS;
1526 EXPORT_API sync_agent_ds_error_e sync_agent_ds_start_sync(ds_profile_h profile_h)
1530 // check mandatory parameter
1531 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1533 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1535 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1537 int event_type = SYNC_AGENT_DS_START_SYNC;
1538 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1539 sync_agent_event_data_s *request_event = NULL;
1540 sync_agent_event_data_s *response_event = NULL;
1542 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1544 /* create empty event packet */
1545 request_event = sync_agent_create_event(event_type);
1546 if (request_event == NULL) {
1547 _DEBUG_ERROR("event is NULL");
1548 return SYNC_AGENT_DS_FAIL;
1551 /* add request parameter to event packet */
1552 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1554 /* send event request to ds agent daemon, waiting for response */
1555 response_event = sync_agent_send_event(request_event, &error);
1556 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1557 _DEBUG_ERROR("error = %d", error);
1558 sync_agent_free_event(request_event);
1560 return SYNC_AGENT_DS_FAIL;
1562 if (response_event == NULL) {
1563 _DEBUG_ERROR("response_event is null!!");
1564 sync_agent_free_event(request_event);
1566 return SYNC_AGENT_DS_FAIL;
1569 /* get response parameter from event packet */
1570 sync_agent_get_event_data_param_int(response_event, &api_result);
1572 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1573 _DEBUG_ERROR("api_result = failed");
1574 sync_agent_free_event(request_event);
1575 sync_agent_free_event_data(response_event);
1577 return SYNC_AGENT_DS_FAIL;
1580 /* free request & response event */
1581 sync_agent_free_event(request_event);
1582 sync_agent_free_event_data(response_event);
1586 return SYNC_AGENT_DS_SUCCESS;
1589 EXPORT_API sync_agent_ds_error_e sync_agent_ds_stop_sync(ds_profile_h profile_h)
1593 // check mandatory parameter
1594 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1596 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1598 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1600 int event_type = SYNC_AGENT_DS_STOP_SYNC;
1601 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1602 sync_agent_event_data_s *request_event = NULL;
1603 sync_agent_event_data_s *response_event = NULL;
1605 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1607 /* create empty event packet */
1608 request_event = sync_agent_create_event(event_type);
1609 if (request_event == NULL) {
1610 _DEBUG_ERROR("event is NULL");
1611 return SYNC_AGENT_DS_FAIL;
1614 /* add request parameter to event packet */
1615 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1617 /* send event request to ds agent daemon, waiting for response */
1618 response_event = sync_agent_send_event(request_event, &error);
1619 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1620 _DEBUG_ERROR("error = %d", error);
1621 sync_agent_free_event(request_event);
1623 return SYNC_AGENT_DS_FAIL;
1625 if (response_event == NULL) {
1626 _DEBUG_ERROR("response_event is null!!");
1627 sync_agent_free_event(request_event);
1629 return SYNC_AGENT_DS_FAIL;
1632 /* get response parameter from event packet */
1633 sync_agent_get_event_data_param_int(response_event, &api_result);
1635 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1636 _DEBUG_ERROR("api_result = failed");
1637 sync_agent_free_event(request_event);
1638 sync_agent_free_event_data(response_event);
1640 return SYNC_AGENT_DS_FAIL;
1643 /* free request & response event */
1644 sync_agent_free_event(request_event);
1645 sync_agent_free_event_data(response_event);
1649 return SYNC_AGENT_DS_SUCCESS;
1652 EXPORT_API void sync_agent_ds_free_profile_info(ds_profile_h profile_h)
1656 // check mandatory parameter
1657 retm_if(profile_h == NULL, "profile handle is null!!");
1659 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1661 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1662 //sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1663 GList *category_list = profile_info->service_list;
1665 // free profile name
1666 g_free(profile_info->profile_dir_name);
1667 g_free(profile_info->profile_name);
1669 // free server information
1670 g_free(server_info->addr);
1671 g_free(server_info->id);
1672 g_free(server_info->password);
1674 // free sync category information
1675 g_list_free_full(category_list, (GDestroyNotify) _free_sync_category_info);
1677 // free profile information
1678 g_free(profile_info);
1683 EXPORT_API sync_agent_ds_error_e sync_agent_ds_deinit()
1687 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
1688 sync_agent_deinit_error_e deinit = SYNC_AGENT_DEINIT_SUCCESS;
1691 ret = _kill_omads_agent();
1694 _DEBUG_ERROR("_kill_omads_agent() failed !!");
1695 result = SYNC_AGENT_DS_FAIL;
1701 deinit = sync_agent_deinit();
1702 if (deinit != SYNC_AGENT_DEINIT_SUCCESS) {
1703 _DEBUG_ERROR("sync_agent_clean_event_handler() failed !!");
1704 result = SYNC_AGENT_DS_FAIL;
1706 // if (err != SYNC_AGENT_EVENT_SUCCESS) {
1707 // sync_agent_event_error_e err = sync_agent_stop_noti_listener();
1708 // _DEBUG_INFO("STOP NOTILISTNER is failed");
1709 // result = SYNC_AGENT_DS_FAIL;
1712 // err = sync_agent_clean_event_handler();
1713 // if (err != SYNC_AGENT_EVENT_SUCCESS) {
1714 // _DEBUG_ERROR("sync_agent_clean_event_handler() failed !!");
1715 // result = SYNC_AGENT_DS_FAIL;
1723 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_noti_callback(sync_agent_ds_sync_callback_e type, sync_agent_noti_cb callback, void *data)
1727 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
1729 sync_agent_event_error_e err = sync_agent_set_noti_callback(type, callback, data);
1730 if (err != SYNC_AGENT_EVENT_SUCCESS) {
1731 _DEBUG_ERROR("failed sync_agent_set_noti_callback()");
1732 result = SYNC_AGENT_DS_FAIL;