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_5_MINUTES "5 minutes"
56 #define SYNC_INTERVAL_15_MINUTES "15 minutes"
57 #define SYNC_INTERVAL_1_HOUR "1 hour"
58 #define SYNC_INTERVAL_4_HOURS "4 hours"
59 #define SYNC_INTERVAL_12_HOURS "12 hours"
60 #define SYNC_INTERVAL_1_DAY "1 day"
61 #define SYNC_INTERVAL_1_WEEK "1 week"
62 #define SYNC_INTERVAL_1_MONTH "1 month"
64 #define SRC_URI_CONTACT_STR "Contacts"
65 #define SRC_URI_CALENDAR_STR "Organizer"
68 SYNC_AGENT_DS_ADD_PROFILE = 1,
69 SYNC_AGENT_DS_UPDATE_PROFILE = 2,
70 SYNC_AGENT_DS_DELETE_PROFILE = 3,
71 SYNC_AGENT_DS_START_SYNC = 4,
72 SYNC_AGENT_DS_STOP_SYNC = 5,
73 SYNC_AGENT_DS_GET_PROFILE = 6,
74 SYNC_AGENT_DS_GET_SYNC_CATEGORY = 7,
75 SYNC_AGENT_DS_GET_SYNC_STATISTICS = 8,
76 SYNC_AGENT_DS_GET_ALL_PROFILES = 9
77 } sync_agent_ds_event_e;
80 SYNC_AGENT_DS_SYNC_CONTACTS = 0,
81 SYNC_AGENT_DS_SYNC_SCHEDULE = 1,
82 SYNC_AGENT_DS_SYNC_MEMO = 2
83 } sync_agent_ds_sync_e;
85 static gboolean _get_sync_category(char *profile_dir_name, int service_type, sync_agent_ds_service_info ** service)
89 int event_type = SYNC_AGENT_DS_GET_SYNC_CATEGORY;
90 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
92 // check mandatory parameter
93 retvm_if(profile_dir_name == NULL, FALSE, "profile_dir_name is null!!");
94 retvm_if(service_type < 0, FALSE, "service_type is wrong!!");
96 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
97 sync_agent_event_data_s *request_event = NULL;
98 sync_agent_event_data_s *response_event = NULL;
100 /* create empty event packet */
101 request_event = sync_agent_create_event(event_type);
102 if (request_event == NULL) {
103 _DEBUG_ERROR("event is NULL");
108 /* add request parameter to event packet */
109 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
110 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &service_type);
112 /* send event request to ds agent daemon, waiting for response */
113 response_event = sync_agent_send_event(request_event, &error);
114 if (error != SYNC_AGENT_EVENT_SUCCESS) {
115 _DEBUG_ERROR("error = %d", error);
116 sync_agent_free_event(request_event);
120 if (response_event == NULL) {
121 _DEBUG_ERROR("response_event is null!!");
122 sync_agent_free_event(request_event);
127 *service = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
128 if (*service == NULL) {
129 _DEBUG_ERROR("calloc failed");
130 sync_agent_free_event(request_event);
131 sync_agent_free_event_data(response_event);
135 /* get response parameter from event packet */
137 sync_agent_get_event_data_param_int(response_event, &api_result);
138 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
139 _DEBUG_ERROR("api_result = failed");
140 sync_agent_free_event(request_event);
141 sync_agent_free_event_data(response_event);
143 return SYNC_AGENT_DS_FAIL;
146 sync_agent_get_event_data_param_int(response_event, &((*service)->enabled));
147 sync_agent_get_event_data_param_int(response_event, (int*) &((*service)->src_uri));
148 sync_agent_get_event_data_param_str(response_event, &((*service)->tgt_uri));
149 sync_agent_get_event_data_param_str(response_event, &((*service)->id));
150 sync_agent_get_event_data_param_str(response_event, &((*service)->password));
152 _DEBUG_TRACE("enabled = %d", (*service)->enabled);
153 _DEBUG_TRACE("src_uri = %d", (*service)->src_uri);
154 _DEBUG_TRACE("tgt_uri = %s", (*service)->tgt_uri);
155 _DEBUG_TRACE("id = %s", (*service)->id);
156 _DEBUG_TRACE("password = %s", (*service)->password);
158 /* free request & response event */
159 sync_agent_free_event(request_event);
160 sync_agent_free_event_data(response_event);
167 static gboolean _get_sync_statistics(char *profile_dir_name, int service_type, sync_agent_ds_statistics_info ** statistics)
171 int event_type = SYNC_AGENT_DS_GET_SYNC_STATISTICS;
172 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
174 // check mandatory parameter
175 retvm_if(profile_dir_name == NULL, FALSE, "profile_dir_name is null!!");
176 retvm_if(service_type < 0, FALSE, "service_type is wrong!!");
178 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
179 sync_agent_event_data_s *request_event = NULL;
180 sync_agent_event_data_s *response_event = NULL;
182 char *statistics_cat = NULL;
184 /* create empty event packet */
185 request_event = sync_agent_create_event(event_type);
186 if (request_event == NULL) {
187 _DEBUG_ERROR("event is NULL");
192 /* add request parameter to event packet */
193 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
194 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &service_type);
196 /* send event request to ds agent daemon, waiting for response */
197 response_event = sync_agent_send_event(request_event, &error);
198 if (error != SYNC_AGENT_EVENT_SUCCESS) {
199 _DEBUG_ERROR("error = %d", error);
200 sync_agent_free_event(request_event);
204 if (response_event == NULL) {
205 _DEBUG_ERROR("response_event is null!!");
206 sync_agent_free_event(request_event);
211 *statistics = (sync_agent_ds_statistics_info *) calloc(1, sizeof(sync_agent_ds_statistics_info));
212 if (*statistics == NULL) {
213 _DEBUG_ERROR("calloc failed");
214 sync_agent_free_event(request_event);
215 sync_agent_free_event_data(response_event);
219 /* get response parameter from event packet */
221 sync_agent_get_event_data_param_int(response_event, &api_result);
222 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
223 _DEBUG_ERROR("api_result = failed");
224 sync_agent_free_event(request_event);
225 sync_agent_free_event_data(response_event);
227 return SYNC_AGENT_DS_FAIL;
230 if (service_type == SYNC_AGENT_DS_SYNC_CONTACTS)
231 statistics_cat = "contacts";
232 else if (service_type == SYNC_AGENT_DS_SYNC_SCHEDULE)
233 statistics_cat = "schedule";
234 else if (service_type == SYNC_AGENT_DS_SYNC_MEMO)
235 statistics_cat = "memo";
237 sync_agent_get_event_data_param_str(response_event, &((*statistics)->dbsynced));
238 sync_agent_get_event_data_param_int(response_event, &((*statistics)->last_session_time));
239 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_total));
240 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_nrofadd));
241 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_nrofdelete));
242 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_nrofreplace));
243 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_total));
244 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_nrofadd));
245 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_nrofdelete));
246 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_nrofreplace));
248 _DEBUG_TRACE("%s dbSynced = %s", statistics_cat, (*statistics)->dbsynced);
249 _DEBUG_TRACE("%s lastSessionTime = %d", statistics_cat, (*statistics)->last_session_time);
250 _DEBUG_TRACE("%s server2Client_Total = %d", statistics_cat, (*statistics)->server2client_total);
251 _DEBUG_TRACE("%s server2Client_NrOrAdd = %d", statistics_cat, (*statistics)->server2client_nrofadd);
252 _DEBUG_TRACE("%s server2Client_NrOfDelete = %d", statistics_cat, (*statistics)->server2client_nrofdelete);
253 _DEBUG_TRACE("%s server2Client_NrOfReplace = %d", statistics_cat, (*statistics)->server2client_nrofreplace);
254 _DEBUG_TRACE("%s client2Server_Total = %d", statistics_cat, (*statistics)->client2server_total);
255 _DEBUG_TRACE("%s client2Server_NrOfAdd = %d", statistics_cat, (*statistics)->client2server_nrofadd);
256 _DEBUG_TRACE("%s client2Server_NrOfDelete = %d", statistics_cat, (*statistics)->client2server_nrofdelete);
257 _DEBUG_TRACE("%s client2Server_NrOfReplace = %d", statistics_cat, (*statistics)->client2server_nrofreplace);
259 /* free request & response event */
260 sync_agent_free_event(request_event);
261 sync_agent_free_event_data(response_event);
268 static char * _convert_sync_mode_str(sync_agent_ds_sync_mode_e sync_mode)
272 char* sync_mode_str = NULL;
274 _DEBUG_INFO("sync_mode : [%d]",sync_mode);
276 case SYNC_AGENT_SYNC_MODE_MANUAL:
277 sync_mode_str = SYNC_MODE_MANUAL_STR;
279 case SYNC_AGENT_SYNC_MODE_PERIODIC:
280 sync_mode_str = SYNC_MODE_PERIODIC_STR;
282 case SYNC_AGENT_SYNC_MODE_PUSH:
283 sync_mode_str = SYNC_MODE_PUSH_STR;
290 return sync_mode_str;
293 static char * _convert_sync_type_str(sync_agent_ds_sync_type_e sync_type)
297 char* sync_type_str = NULL;
299 _DEBUG_INFO("sync_type : [%d]",sync_type);
301 case SYNC_AGENT_SYNC_TYPE_FULL_SYNC:
302 sync_type_str = SYNC_TYPE_SLOW_SYNC_STR;
304 case SYNC_AGENT_SYNC_TYPE_UPDATE_BOTH:
305 sync_type_str = SYNC_TYPE_TWO_WAY_STR;
307 case SYNC_AGENT_SYNC_TYPE_UPDATE_TO_SERVER:
308 sync_type_str = SYNC_TYPE_ONE_WAY_FROM_CLIENT_STR;
310 case SYNC_AGENT_SYNC_TYPE_UPDATE_TO_PHONE:
311 sync_type_str = SYNC_TYPE_ONE_WAY_FROM_SERVER_STR;
313 case SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_SERVER:
314 sync_type_str = SYNC_TYPE_REFRESH_FROM_SERVER_STR;
316 case SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_PHONE:
317 sync_type_str = SYNC_TYPE_REFRESH_FROM_CLIENT_STR;
324 return sync_type_str;
327 static char * _convert_sync_interval_str(sync_agent_ds_sync_interval_e interval)
331 char* interval_str = NULL;
333 _DEBUG_INFO("interval : [%d]",interval);
335 case SYNC_AGENT_SYNC_INTERVAL_5_MINUTES:
336 interval_str = SYNC_INTERVAL_5_MINUTES;
338 case SYNC_AGENT_SYNC_INTERVAL_15_MINUTES:
339 interval_str = SYNC_INTERVAL_15_MINUTES;
341 case SYNC_AGENT_SYNC_INTERVAL_1_HOUR:
342 interval_str = SYNC_INTERVAL_1_HOUR;
344 case SYNC_AGENT_SYNC_INTERVAL_4_HOURS:
345 interval_str = SYNC_INTERVAL_4_HOURS;
347 case SYNC_AGENT_SYNC_INTERVAL_12_HOURS:
348 interval_str = SYNC_INTERVAL_12_HOURS;
350 case SYNC_AGENT_SYNC_INTERVAL_1_DAY:
351 interval_str = SYNC_INTERVAL_1_DAY;
353 case SYNC_AGENT_SYNC_INTERVAL_1_WEEK:
354 interval_str = SYNC_INTERVAL_1_WEEK;
356 case SYNC_AGENT_SYNC_INTERVAL_1_MONTH:
357 interval_str = SYNC_INTERVAL_1_MONTH;
367 static char * _convert_src_uri_str(sync_agent_ds_src_uri_e src_uri)
371 char* src_uri_str = NULL;
373 _DEBUG_INFO("src_uri : [%d]",src_uri);
375 case SYNC_AGENT_SRC_URI_CONTACT:
376 src_uri_str = SRC_URI_CONTACT_STR;
378 case SYNC_AGENT_SRC_URI_CALENDAR:
379 src_uri_str = SRC_URI_CALENDAR_STR;
389 static void _free_sync_category_info(sync_agent_ds_service_info * data)
391 g_free(data->tgt_uri);
393 g_free(data->password);
396 static gboolean _is_existing_profile(void)
400 int event_type = SYNC_AGENT_DS_GET_ALL_PROFILES;
401 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
402 sync_agent_event_data_s *request_event = NULL;
403 sync_agent_event_data_s *response_event = NULL;
405 int profile_count = 0;
407 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
409 /* create empty event packet */
410 request_event = sync_agent_create_event(event_type);
411 if (request_event == NULL) {
412 _DEBUG_ERROR("event is NULL");
414 return SYNC_AGENT_DS_FAIL;
417 /* send event request to ds agent daemon, waiting for response */
418 response_event = sync_agent_send_event(request_event, &error);
419 if (error != SYNC_AGENT_EVENT_SUCCESS) {
420 _DEBUG_ERROR("error = %d", error);
421 sync_agent_free_event(request_event);
423 return SYNC_AGENT_DS_FAIL;
425 if (response_event == NULL) {
426 _DEBUG_ERROR("response_event is null!!");
427 sync_agent_free_event(request_event);
429 return SYNC_AGENT_DS_FAIL;
432 sync_agent_get_event_data_param_int(response_event, &api_result);
433 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
434 _DEBUG_ERROR("api_result = failed");
435 sync_agent_free_event(request_event);
436 sync_agent_free_event_data(response_event);
438 return SYNC_AGENT_DS_FAIL;
441 sync_agent_get_event_data_param_int(response_event, &profile_count);
442 _DEBUG_INFO("profile_count = %d", profile_count);
444 if (profile_count > 0) {
445 sync_agent_free_event(request_event);
446 sync_agent_free_event_data(response_event);
452 /* free request & response event */
453 sync_agent_free_event(request_event);
454 sync_agent_free_event_data(response_event);
461 static int _launch_omads_agent(void)
464 GError *error = NULL;
466 DBusGConnection *connection = NULL;
467 DBusGProxy *dbus_proxy = NULL;
471 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
473 _DEBUG_ERROR("Connecting to system bus failed: %s\n", error->message);
479 dbus_proxy = dbus_g_proxy_new_for_name(connection, "com.samsung.omadsagent",
480 "/com/samsung/omadsagent", "com.samsung.omadsagent");
482 _DEBUG_INFO("dbus_proxy %x", dbus_proxy);
484 //dbus_g_proxy_call_no_reply(dbus_proxy, "Hello_Agent", G_TYPE_INVALID);
485 dbus_g_proxy_call(dbus_proxy, "Hello_Agent", &error, G_TYPE_INVALID, G_TYPE_INVALID);
487 g_object_unref(dbus_proxy);
488 dbus_g_connection_unref(connection);
494 static int _kill_omads_agent(void)
497 GError *error = NULL;
499 DBusGConnection *connection = NULL;
500 DBusGProxy *dbus_proxy = NULL;
501 gboolean isExisting = FALSE;
503 isExisting = _is_existing_profile();
506 _DEBUG_INFO("Existing profile !!");
512 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
514 _DEBUG_ERROR("Connecting to system bus failed: %s\n", error->message);
520 dbus_proxy = dbus_g_proxy_new_for_name(connection, "com.samsung.omadsagent",
521 "/com/samsung/omadsagent", "com.samsung.omadsagent");
523 _DEBUG_INFO("dbus_proxy %x", dbus_proxy);
525 dbus_g_proxy_call_no_reply(dbus_proxy, "Goodbye_Agent", G_TYPE_INVALID);
527 g_object_unref(dbus_proxy);
528 dbus_g_connection_unref(connection);
534 EXPORT_API sync_agent_ds_error_e sync_agent_ds_init()
538 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
539 sync_agent_init_error_e init_error = SYNC_AGENT_INIT_SUCCESS;
542 ret = _launch_omads_agent();
545 _DEBUG_ERROR("_launch_omads_agent() failed !!");
546 result = SYNC_AGENT_DS_FAIL;
552 init_error = sync_agent_init(OMA_DS_CONFIG_FILE);
554 if (init_error != SYNC_AGENT_INIT_SUCCESS) {
555 _DEBUG_ERROR("ds init failed");
556 result = SYNC_AGENT_DS_FAIL;
559 sync_agent_event_error_e err = sync_agent_run_noti_listener("omads");
560 if (err != SYNC_AGENT_EVENT_SUCCESS) {
561 _DEBUG_ERROR("RUN NOTILISTNER is failed");
562 result = SYNC_AGENT_DS_FAIL;
570 EXPORT_API sync_agent_ds_error_e sync_agent_ds_create_profile_info(ds_profile_h * profile_h)
574 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
575 sync_agent_ds_profile_info *profile_info = NULL;
577 // allocate memory for ds profile info
578 profile_info = (sync_agent_ds_profile_info *) calloc(1, sizeof(sync_agent_ds_profile_info));
579 if (profile_info == NULL) {
580 _DEBUG_ERROR("calloc failed !!");
581 return SYNC_AGENT_DS_FAIL;
583 // pass memory pointer to ds profile handle
584 *profile_h = profile_info;
591 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_profile_dir_name(ds_profile_h profile_h, char *profile_dir_name)
595 // check mandatory parameter
596 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
597 retvm_if(profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
599 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
600 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
603 profile_info->profile_dir_name = g_strdup(profile_dir_name);
605 if (profile_info->profile_dir_name == NULL) {
606 _DEBUG_ERROR("g_strdup failed !!");
607 return SYNC_AGENT_DS_FAIL;
615 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_profile_name(ds_profile_h profile_h, char *profile_name)
619 // check mandatory parameter
620 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
621 retvm_if(profile_name == NULL, SYNC_AGENT_DS_FAIL, "profile_name is null!!");
623 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
624 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
627 profile_info->profile_name = g_strdup(profile_name);
629 if (profile_info->profile_name == NULL) {
630 _DEBUG_ERROR("g_strdup failed !!");
631 return SYNC_AGENT_DS_FAIL;
639 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_server_info(ds_profile_h profile_h, char *addr, char *id, char *password)
643 // check mandatory parameter
644 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
645 retvm_if(addr == NULL, SYNC_AGENT_DS_FAIL, "addr is null!!");
646 retvm_if(id == NULL, SYNC_AGENT_DS_FAIL, "id is null!!");
647 retvm_if(password == NULL, SYNC_AGENT_DS_FAIL, "password is null!!");
649 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
650 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
651 sync_agent_ds_server_info *server_info = &profile_info->server_info;
654 server_info->addr = g_strdup(addr);
655 server_info->id = g_strdup(id);
656 server_info->password = g_strdup(password);
658 if ((server_info->addr == NULL)
659 || (server_info->id == NULL)
660 || (server_info->password == NULL)) {
661 _DEBUG_ERROR("g_strdup failed !!");
662 return SYNC_AGENT_DS_FAIL;
670 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)
674 // check mandatory parameter
675 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
676 retvm_if(sync_mode < 0, SYNC_AGENT_DS_FAIL, "sync_mode is invalid!!");
677 retvm_if(sync_type < 0, SYNC_AGENT_DS_FAIL, "sync_type is invalid!!");
678 retvm_if(interval < 0, SYNC_AGENT_DS_FAIL, "interval is invalid!!");
680 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
681 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
682 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
684 char* sync_mode_str = NULL;
685 char* sync_type_str = NULL;
686 char* interval_str = NULL;
688 sync_mode_str = _convert_sync_mode_str(sync_mode);
689 if (sync_mode_str == NULL) {
690 _DEBUG_ERROR("_convert_sync_mode_str failed !!");
692 return SYNC_AGENT_DS_FAIL;
695 sync_type_str = _convert_sync_type_str(sync_type);
696 if (sync_type_str == NULL) {
697 _DEBUG_ERROR("_convert_sync_type_str failed !!");
699 return SYNC_AGENT_DS_FAIL;
702 interval_str = _convert_sync_interval_str(interval);
703 if (interval_str == NULL) {
704 _DEBUG_ERROR("_convert_sync_interval_str failed !!");
706 return SYNC_AGENT_DS_FAIL;
710 sync_info->sync_mode = sync_mode;
711 sync_info->sync_type = sync_type;
712 sync_info->interval = interval;
719 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)
723 // check mandatory parameter
724 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
725 retvm_if(src_uri < 0, SYNC_AGENT_DS_FAIL, "src_uri is invalid!!");
727 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
728 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
729 sync_agent_ds_service_info *category_info = NULL;
730 char* src_uri_str = NULL;
732 src_uri_str = _convert_src_uri_str(src_uri);
733 if (src_uri_str == NULL) {
734 _DEBUG_ERROR("_get_src_uri_string failed !!");
736 return SYNC_AGENT_DS_FAIL;
739 // allocate memory for sync_category
740 category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
741 retvm_if(category_info == NULL, SYNC_AGENT_DS_FAIL, "calloc failed");
742 category_info->service_type = service_type;
743 category_info->enabled = enabled;
744 category_info->src_uri = src_uri;
745 category_info->tgt_uri = g_strdup(tgt_uri);
747 profile_info->service_list = g_list_append(profile_info->service_list, category_info);
754 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_dir_name(ds_profile_h profile_h, char **profile_dir_name)
758 // check mandatory parameter
759 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
761 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
763 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
765 *profile_dir_name = g_strdup(profile_info->profile_dir_name);
767 if (*profile_dir_name == NULL) {
768 _DEBUG_ERROR("g_strdup failed !!");
769 return SYNC_AGENT_DS_FAIL;
772 _DEBUG_INFO("profile_dir_name = %s", *profile_dir_name);
779 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_name(ds_profile_h profile_h, char **profile_name)
783 // check mandatory parameter
784 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
786 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
788 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
790 *profile_name = g_strdup(profile_info->profile_name);
792 if (*profile_name == NULL) {
793 _DEBUG_ERROR("g_strdup failed !!");
794 return SYNC_AGENT_DS_FAIL;
797 _DEBUG_INFO("profile_name = %s", *profile_name);
804 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)
808 // check mandatory parameter
809 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
810 retvm_if(server_info == NULL, SYNC_AGENT_DS_FAIL, "server_info is null!!");
812 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
813 sync_agent_ds_server_info *ds_server_info = &profile_info->server_info;
815 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
817 server_info->addr = g_strdup(ds_server_info->addr);
818 server_info->id = g_strdup(ds_server_info->id);
819 server_info->password = g_strdup(ds_server_info->password);
821 if ((server_info->addr == NULL)
822 || (server_info->id == NULL)
823 || (server_info->password == NULL)) {
824 _DEBUG_ERROR("g_strdup failed !!");
825 return SYNC_AGENT_DS_FAIL;
828 _DEBUG_INFO("get_addr = %s", server_info->addr);
829 _DEBUG_INFO("get_id = %s", server_info->id);
830 _DEBUG_INFO("get_password = %s", server_info->password);
837 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)
841 // check mandatory parameter
842 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
843 retvm_if(sync_info == NULL, SYNC_AGENT_DS_FAIL, "sync_info is null!!");
845 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
846 sync_agent_ds_sync_info *ds_sync_info = &profile_info->sync_info;
848 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
850 sync_info->sync_mode = ds_sync_info->sync_mode;
851 sync_info->sync_type = ds_sync_info->sync_type;
852 sync_info->interval = ds_sync_info->interval;
854 _DEBUG_INFO("get_sync_mode = %d", sync_info->sync_mode);
855 _DEBUG_INFO("get_sync_type = %d", sync_info->sync_type);
856 _DEBUG_INFO("get_interval = %d", sync_info->interval);
858 if (sync_info->sync_mode < 0) {
859 _DEBUG_ERROR("sync_mode is invalid !!");
860 return SYNC_AGENT_DS_FAIL;
863 if (sync_info->sync_type < 0) {
864 _DEBUG_ERROR("sync_type is invalid !!");
865 return SYNC_AGENT_DS_FAIL;
868 if (sync_info->interval < 0) {
869 _DEBUG_ERROR("interval is invalid !!");
870 return SYNC_AGENT_DS_FAIL;
878 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_service_info(ds_profile_h profile_h, GList ** category_list)
882 // check mandatory parameter
883 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
885 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
887 int category_count = 0;
889 sync_agent_ds_service_info *category_info = NULL;
891 *category_list = g_list_copy(profile_info->service_list);
893 if (*category_list == NULL) {
894 _DEBUG_ERROR("g_list_copy failed !!");
895 return SYNC_AGENT_DS_FAIL;
898 category_count = g_list_length(*category_list);
899 for (; i < category_count; i++) {
900 category_info = (sync_agent_ds_service_info *) g_list_nth_data(*category_list, i);
902 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
903 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
904 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
905 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
906 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
911 return SYNC_AGENT_DS_SUCCESS;
914 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_statistics(ds_profile_h profile_h, GList ** statistics_list)
918 // check mandatory parameter
919 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
921 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
922 sync_agent_ds_statistics_info *statistics = NULL;
924 gboolean result_sync_category = FALSE;
926 /* get last contacts sync result */
927 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_CONTACTS, &statistics);
928 if (result_sync_category)
929 *statistics_list = g_list_append(*statistics_list, statistics);
931 /* get last schedule sync result */
933 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_SCHEDULE, &statistics);
934 if (result_sync_category)
935 *statistics_list = g_list_append(*statistics_list, statistics);
937 /* get last memo sync result */
939 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_MEMO, &statistics);
940 if (result_sync_category)
941 *statistics_list = g_list_append(*statistics_list, statistics);
945 return SYNC_AGENT_DS_SUCCESS;
948 EXPORT_API sync_agent_ds_error_e sync_agent_ds_add_profile(ds_profile_h profile_h, int *profile_id)
952 // check mandatory parameter
953 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
955 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
956 sync_agent_ds_server_info *server_info = &profile_info->server_info;
957 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
958 GList *list = profile_info->service_list;
960 int event_type = SYNC_AGENT_DS_ADD_PROFILE;
961 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
962 sync_agent_event_data_s *request_event = NULL;
963 sync_agent_event_data_s *response_event = NULL;
966 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
967 sync_agent_ds_service_info *category_info = NULL;
968 int category_count = 0;
971 /* create empty event packet */
972 request_event = sync_agent_create_event(event_type);
973 if (request_event == NULL) {
974 _DEBUG_ERROR("event is NULL");
976 return SYNC_AGENT_DS_FAIL;
979 /* add request parameter to event packet */
980 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
981 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name);
982 _DEBUG_INFO("addr = %s", server_info->addr);
983 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr);
984 _DEBUG_INFO("id = %s", server_info->id);
985 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id);
986 _DEBUG_INFO("password = %s", server_info->password);
987 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password);
988 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
989 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_mode));
990 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
991 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_type));
992 _DEBUG_INFO("interval = %d", sync_info->interval);
993 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->interval));
995 category_count = g_list_length(list);
996 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count);
998 for (; i < category_count; i++) {
999 category_info = (sync_agent_ds_service_info *) g_list_nth_data(list, i);
1001 _DEBUG_INFO("category[%d]->service_type = %d", i, category_info->service_type);
1002 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->service_type));
1003 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
1004 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->enabled));
1005 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
1006 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->src_uri));
1007 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
1008 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri);
1009 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
1010 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id);
1011 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
1012 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password);
1015 /* send event request to ds agent daemon, waiting for response */
1016 response_event = sync_agent_send_event(request_event, &error);
1017 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1018 _DEBUG_ERROR("error = %d", error);
1019 sync_agent_free_event(request_event);
1021 return SYNC_AGENT_DS_FAIL;
1023 if (response_event == NULL) {
1024 _DEBUG_ERROR("response_event is null!!");
1025 sync_agent_free_event(request_event);
1027 return SYNC_AGENT_DS_FAIL;
1030 /* get response parameter from event packet */
1031 sync_agent_get_event_data_param_int(response_event, &api_result);
1033 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1034 _DEBUG_ERROR("api_result = failed");
1035 sync_agent_free_event(request_event);
1036 sync_agent_free_event_data(response_event);
1038 return SYNC_AGENT_DS_FAIL;
1041 sync_agent_get_event_data_param_int(response_event, &prof_id);
1043 _DEBUG_VERBOSE("profile_id = %d", prof_id);
1044 *profile_id = prof_id;
1046 /* free request & response event */
1047 sync_agent_free_event(request_event);
1048 sync_agent_free_event_data(response_event);
1052 return SYNC_AGENT_DS_SUCCESS;
1055 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile(char *profile_dir_name, ds_profile_h * profile_h)
1059 // check mandatory parameter
1060 retvm_if(profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1062 int event_type = SYNC_AGENT_DS_GET_PROFILE;
1063 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1064 sync_agent_event_data_s *request_event = NULL;
1065 sync_agent_event_data_s *response_event = NULL;
1067 gboolean result_sync_category = FALSE;
1068 sync_agent_ds_error_e result = SYNC_AGENT_DS_FAIL;
1069 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1070 sync_agent_ds_service_info *category = NULL;
1072 //////////////////////////////////
1074 // Phase 1. get profile detail info
1076 /* create empty event packet */
1077 request_event = sync_agent_create_event(event_type);
1078 if (request_event == NULL) {
1079 _DEBUG_ERROR("event is NULL");
1081 return SYNC_AGENT_DS_FAIL;
1084 /* add request parameter to event packet */
1085 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
1087 /* send event request to ds agent daemon, waiting for response */
1088 response_event = sync_agent_send_event(request_event, &error);
1089 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1090 _DEBUG_ERROR("error = %d", error);
1091 sync_agent_free_event(request_event);
1093 return SYNC_AGENT_DS_FAIL;
1095 if (response_event == NULL) {
1096 _DEBUG_ERROR("response_event is null!!");
1097 sync_agent_free_event(request_event);
1099 return SYNC_AGENT_DS_FAIL;
1102 /* get response parameter from event packet */
1104 result = sync_agent_ds_create_profile_info(profile_h);
1105 if (result == SYNC_AGENT_DS_FAIL) {
1106 _DEBUG_ERROR("failed to create profile info!");
1107 sync_agent_free_event(request_event);
1108 sync_agent_free_event_data(response_event);
1112 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) (*profile_h);
1113 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1114 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1115 // GList * list = profile_info->category_list;
1117 sync_agent_get_event_data_param_int(response_event, &api_result);
1118 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1119 _DEBUG_ERROR("api_result = failed");
1120 sync_agent_free_event(request_event);
1121 sync_agent_free_event_data(response_event);
1123 return SYNC_AGENT_DS_FAIL;
1126 profile_info->profile_dir_name = g_strdup(profile_dir_name);
1128 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_name);
1129 sync_agent_get_event_data_param_str(response_event, &server_info->addr);
1130 sync_agent_get_event_data_param_str(response_event, &server_info->id);
1131 sync_agent_get_event_data_param_str(response_event, &server_info->password);
1132 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_mode);
1133 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_type);
1134 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->interval);
1135 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_status);
1136 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_time);
1138 _DEBUG_INFO("profileDirame = %s", profile_info->profile_name);
1139 _DEBUG_INFO("addr = %s", server_info->addr);
1140 _DEBUG_INFO("id = %s", server_info->id);
1141 _DEBUG_INFO("password = %s", server_info->password);
1142 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
1143 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
1144 _DEBUG_INFO("interval = %d", sync_info->interval);
1145 _DEBUG_VERBOSE("lastSyncStatus = %d\n", profile_info->last_sync_status);
1146 _DEBUG_VERBOSE("lastSyncTime = %d\n", profile_info->last_sync_time);
1148 /* free request & response event */
1149 sync_agent_free_event(request_event);
1150 sync_agent_free_event_data(response_event);
1152 //////////////////////////////////
1154 // Phase 2. get sync category info
1156 /* get contacts sync_category */
1157 result_sync_category = _get_sync_category(profile_dir_name, SYNC_AGENT_DS_SYNC_CONTACTS, &category);
1158 if (result_sync_category)
1159 profile_info->service_list = g_list_append(profile_info->service_list, category);
1161 /* get schedule sync_category */
1163 result_sync_category = _get_sync_category(profile_dir_name, SYNC_AGENT_DS_SYNC_SCHEDULE, &category);
1164 if (result_sync_category)
1165 profile_info->service_list = g_list_append(profile_info->service_list, category);
1167 /* get memo sync_category */
1169 result_sync_category = _get_sync_category(profile_dir_name, SYNC_AGENT_DS_SYNC_MEMO, &category);
1170 if (result_sync_category)
1171 profile_info->service_list = g_list_append(profile_info->service_list, category);
1175 return SYNC_AGENT_DS_SUCCESS;
1178 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_all_profile(GList ** profile_list)
1182 int event_type = SYNC_AGENT_DS_GET_ALL_PROFILES;
1183 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1184 sync_agent_event_data_s *request_event = NULL;
1185 sync_agent_event_data_s *response_event = NULL;
1187 ds_profile_h profile_h = NULL;
1188 sync_agent_ds_service_info *category_info = NULL;
1190 int profile_count = 0;
1191 int category_count = 0;
1193 sync_agent_ds_error_e result = SYNC_AGENT_DS_FAIL;
1194 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1196 /* create empty event packet */
1197 request_event = sync_agent_create_event(event_type);
1198 if (request_event == NULL) {
1199 _DEBUG_ERROR("event is NULL");
1201 return SYNC_AGENT_DS_FAIL;
1204 /* send event request to ds agent daemon, waiting for response */
1205 response_event = sync_agent_send_event(request_event, &error);
1206 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1207 _DEBUG_ERROR("error = %d", error);
1208 sync_agent_free_event(request_event);
1210 return SYNC_AGENT_DS_FAIL;
1212 if (response_event == NULL) {
1213 _DEBUG_ERROR("response_event is null!!");
1214 sync_agent_free_event(request_event);
1216 return SYNC_AGENT_DS_FAIL;
1219 sync_agent_get_event_data_param_int(response_event, &api_result);
1220 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1221 _DEBUG_ERROR("api_result = failed");
1222 sync_agent_free_event(request_event);
1223 sync_agent_free_event_data(response_event);
1225 return SYNC_AGENT_DS_FAIL;
1228 sync_agent_get_event_data_param_int(response_event, &profile_count);
1229 _DEBUG_INFO("profile_count = %d", profile_count);
1232 for (i = 0; i < profile_count; i++) {
1234 result = sync_agent_ds_create_profile_info(&profile_h);
1235 if (result == SYNC_AGENT_DS_FAIL) {
1236 _DEBUG_ERROR("failed to create profile info!");
1237 sync_agent_free_event(request_event);
1238 sync_agent_free_event_data(response_event);
1242 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1243 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1244 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1246 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_dir_name);
1247 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_name);
1248 sync_agent_get_event_data_param_str(response_event, &server_info->addr);
1249 sync_agent_get_event_data_param_str(response_event, &server_info->id);
1250 sync_agent_get_event_data_param_str(response_event, &server_info->password);
1251 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_mode);
1252 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_type);
1253 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->interval);
1254 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_status);
1255 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_time);
1257 _DEBUG_INFO("profile_info->profile_dir_name = %s", profile_info->profile_dir_name);
1258 _DEBUG_INFO("profile_info->profile_name = %s", profile_info->profile_name);
1259 _DEBUG_INFO("profile_info->addr = %s", server_info->addr);
1260 _DEBUG_INFO("profile_info->id = %s", server_info->id);
1261 _DEBUG_INFO("profile_info->password = %s", server_info->password);
1262 _DEBUG_INFO("profile_info->sync_mode = %d", sync_info->sync_mode);
1263 _DEBUG_INFO("profile_info->sync_type = %d", sync_info->sync_type);
1264 _DEBUG_INFO("profile_info->interval = %d", sync_info->interval);
1265 _DEBUG_INFO("profile_info->lastSyncStatus = %d", profile_info->last_sync_status);
1266 _DEBUG_INFO("profile_info->lastSyncStatus = %d", profile_info->last_sync_status);
1268 sync_agent_get_event_data_param_int(response_event, &category_count);
1271 for (j = 0; j < category_count; j++) {
1273 category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
1274 if (category_info == NULL) {
1275 _DEBUG_ERROR("calloc failed");
1276 sync_agent_ds_free_profile_info(profile_h);
1277 sync_agent_free_event(request_event);
1278 sync_agent_free_event_data(response_event);
1282 sync_agent_get_event_data_param_int(response_event, (int*) &category_info->service_type);
1283 sync_agent_get_event_data_param_int(response_event, &category_info->enabled);
1284 sync_agent_get_event_data_param_int(response_event, (int*) &category_info->src_uri);
1285 sync_agent_get_event_data_param_str(response_event, &category_info->tgt_uri);
1286 sync_agent_get_event_data_param_str(response_event, &category_info->id);
1287 sync_agent_get_event_data_param_str(response_event, &category_info->password);
1289 _DEBUG_INFO("category_info->service_type = %d", category_info->service_type);
1290 _DEBUG_INFO("category_info->enabled = %d", category_info->enabled);
1291 _DEBUG_INFO("category_info->src_uri = %d", category_info->src_uri);
1292 _DEBUG_INFO("category_info->tgt_uri = %s", category_info->tgt_uri);
1293 _DEBUG_INFO("category_info->id = %s", category_info->id);
1294 _DEBUG_INFO("category_info->password = %s", category_info->password);
1296 profile_info->service_list = g_list_append(profile_info->service_list, category_info);
1297 category_info = NULL;
1300 *profile_list = g_list_append(*profile_list, profile_h);
1304 /* free request & response event */
1305 sync_agent_free_event(request_event);
1306 sync_agent_free_event_data(response_event);
1310 return SYNC_AGENT_DS_SUCCESS;
1313 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_last_sync_info(ds_profile_h profile_h, int *lastSyncStatus, int *lastSyncTime)
1317 // check mandatory parameter
1318 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1319 retvm_if(lastSyncStatus == NULL, SYNC_AGENT_DS_FAIL, "last session status is null!!");
1320 retvm_if(lastSyncTime == NULL, SYNC_AGENT_DS_FAIL, "last session time is null!!");
1322 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1324 *lastSyncStatus = profile_info->last_sync_status;
1325 *lastSyncTime = profile_info->last_sync_time;
1329 return SYNC_AGENT_DS_SUCCESS;
1332 EXPORT_API sync_agent_ds_error_e sync_agent_ds_update_profile(ds_profile_h profile_h)
1336 // check mandatory parameter
1337 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1339 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1340 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1341 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1342 GList *list = profile_info->service_list;
1344 int event_type = SYNC_AGENT_DS_UPDATE_PROFILE;
1345 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1346 sync_agent_event_data_s *request_event = NULL;
1347 sync_agent_event_data_s *response_event = NULL;
1349 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1350 sync_agent_ds_service_info *category_info = NULL;
1351 int category_count = 0;
1354 /* create empty event packet */
1355 request_event = sync_agent_create_event(event_type);
1356 if (request_event == NULL) {
1357 _DEBUG_ERROR("event is NULL");
1359 return SYNC_AGENT_DS_FAIL;
1362 /* add request parameter to event packet */
1363 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1364 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1365 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
1366 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name);
1367 _DEBUG_INFO("addr = %s", server_info->addr);
1368 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr);
1369 _DEBUG_INFO("id = %s", server_info->id);
1370 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id);
1371 _DEBUG_INFO("password = %s", server_info->password);
1372 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password);
1373 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
1374 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_mode));
1375 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
1376 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_type));
1377 _DEBUG_INFO("interval = %d", sync_info->interval);
1378 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->interval));
1380 category_count = g_list_length(list);
1381 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count);
1383 for (; i < category_count; i++) {
1384 category_info = (sync_agent_ds_service_info *) g_list_nth_data(list, i);
1386 _DEBUG_INFO("category[%d]->service_type = %d", i, category_info->service_type);
1387 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->service_type));
1388 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
1389 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->enabled));
1390 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
1391 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->src_uri));
1392 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
1393 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri);
1394 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
1395 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id);
1396 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
1397 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password);
1400 /* send event request to ds agent daemon, waiting for response */
1401 response_event = sync_agent_send_event(request_event, &error);
1402 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1403 _DEBUG_ERROR("error = %d", error);
1404 sync_agent_free_event(request_event);
1406 return SYNC_AGENT_DS_FAIL;
1408 if (response_event == NULL) {
1409 _DEBUG_ERROR("response_event is null!!");
1410 sync_agent_free_event(request_event);
1412 return SYNC_AGENT_DS_FAIL;
1415 /* get response parameter from event packet */
1416 sync_agent_get_event_data_param_int(response_event, &api_result);
1418 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1419 _DEBUG_ERROR("api_result = failed");
1420 sync_agent_free_event(request_event);
1421 sync_agent_free_event_data(response_event);
1423 return SYNC_AGENT_DS_FAIL;
1426 /* free request & response event */
1427 sync_agent_free_event(request_event);
1428 sync_agent_free_event_data(response_event);
1432 return SYNC_AGENT_DS_SUCCESS;
1435 EXPORT_API sync_agent_ds_error_e sync_agent_ds_delete_profile(ds_profile_h profile_h)
1439 // check mandatory parameter
1440 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1442 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1444 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1446 int event_type = SYNC_AGENT_DS_DELETE_PROFILE;
1447 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1448 sync_agent_event_data_s *request_event = NULL;
1449 sync_agent_event_data_s *response_event = NULL;
1452 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1454 /* create empty event packet */
1455 request_event = sync_agent_create_event(event_type);
1456 if (request_event == NULL) {
1457 _DEBUG_ERROR("event is NULL");
1458 return SYNC_AGENT_DS_FAIL;
1461 /* add request parameter to event packet */
1462 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &count);
1464 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1465 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1467 /* send event request to ds agent daemon, waiting for response */
1468 response_event = sync_agent_send_event(request_event, &error);
1469 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1470 _DEBUG_ERROR("error = %d", error);
1471 sync_agent_free_event(request_event);
1473 return SYNC_AGENT_DS_FAIL;
1475 if (response_event == NULL) {
1476 _DEBUG_ERROR("response_event is null!!");
1477 sync_agent_free_event(request_event);
1479 return SYNC_AGENT_DS_FAIL;
1482 /* get response parameter from event packet */
1483 sync_agent_get_event_data_param_int(response_event, &api_result);
1485 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1486 _DEBUG_ERROR("api_result = failed");
1487 sync_agent_free_event(request_event);
1488 sync_agent_free_event_data(response_event);
1490 return SYNC_AGENT_DS_FAIL;
1493 /* free request & response event */
1494 sync_agent_free_event(request_event);
1495 sync_agent_free_event_data(response_event);
1499 return SYNC_AGENT_DS_SUCCESS;
1502 EXPORT_API sync_agent_ds_error_e sync_agent_ds_start_sync(ds_profile_h profile_h)
1506 // check mandatory parameter
1507 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1509 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1511 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1513 int event_type = SYNC_AGENT_DS_START_SYNC;
1514 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1515 sync_agent_event_data_s *request_event = NULL;
1516 sync_agent_event_data_s *response_event = NULL;
1518 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1520 /* create empty event packet */
1521 request_event = sync_agent_create_event(event_type);
1522 if (request_event == NULL) {
1523 _DEBUG_ERROR("event is NULL");
1524 return SYNC_AGENT_DS_FAIL;
1527 /* add request parameter to event packet */
1528 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1530 /* send event request to ds agent daemon, waiting for response */
1531 response_event = sync_agent_send_event(request_event, &error);
1532 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1533 _DEBUG_ERROR("error = %d", error);
1534 sync_agent_free_event(request_event);
1536 return SYNC_AGENT_DS_FAIL;
1538 if (response_event == NULL) {
1539 _DEBUG_ERROR("response_event is null!!");
1540 sync_agent_free_event(request_event);
1542 return SYNC_AGENT_DS_FAIL;
1545 /* get response parameter from event packet */
1546 sync_agent_get_event_data_param_int(response_event, &api_result);
1548 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1549 _DEBUG_ERROR("api_result = failed");
1550 sync_agent_free_event(request_event);
1551 sync_agent_free_event_data(response_event);
1553 return SYNC_AGENT_DS_FAIL;
1556 /* free request & response event */
1557 sync_agent_free_event(request_event);
1558 sync_agent_free_event_data(response_event);
1562 return SYNC_AGENT_DS_SUCCESS;
1565 EXPORT_API sync_agent_ds_error_e sync_agent_ds_stop_sync(ds_profile_h profile_h)
1569 // check mandatory parameter
1570 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1572 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1574 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1576 int event_type = SYNC_AGENT_DS_STOP_SYNC;
1577 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1578 sync_agent_event_data_s *request_event = NULL;
1579 sync_agent_event_data_s *response_event = NULL;
1581 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1583 /* create empty event packet */
1584 request_event = sync_agent_create_event(event_type);
1585 if (request_event == NULL) {
1586 _DEBUG_ERROR("event is NULL");
1587 return SYNC_AGENT_DS_FAIL;
1590 /* add request parameter to event packet */
1591 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1593 /* send event request to ds agent daemon, waiting for response */
1594 response_event = sync_agent_send_event(request_event, &error);
1595 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1596 _DEBUG_ERROR("error = %d", error);
1597 sync_agent_free_event(request_event);
1599 return SYNC_AGENT_DS_FAIL;
1601 if (response_event == NULL) {
1602 _DEBUG_ERROR("response_event is null!!");
1603 sync_agent_free_event(request_event);
1605 return SYNC_AGENT_DS_FAIL;
1608 /* get response parameter from event packet */
1609 sync_agent_get_event_data_param_int(response_event, &api_result);
1611 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1612 _DEBUG_ERROR("api_result = failed");
1613 sync_agent_free_event(request_event);
1614 sync_agent_free_event_data(response_event);
1616 return SYNC_AGENT_DS_FAIL;
1619 /* free request & response event */
1620 sync_agent_free_event(request_event);
1621 sync_agent_free_event_data(response_event);
1625 return SYNC_AGENT_DS_SUCCESS;
1628 EXPORT_API void sync_agent_ds_free_profile_info(ds_profile_h profile_h)
1632 // check mandatory parameter
1633 retm_if(profile_h == NULL, "profile handle is null!!");
1635 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1637 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1638 //sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1639 GList *category_list = profile_info->service_list;
1641 // free profile name
1642 g_free(profile_info->profile_dir_name);
1643 g_free(profile_info->profile_name);
1645 // free server information
1646 g_free(server_info->addr);
1647 g_free(server_info->id);
1648 g_free(server_info->password);
1650 // free sync category information
1651 g_list_free_full(category_list, (GDestroyNotify) _free_sync_category_info);
1653 // free profile information
1654 g_free(profile_info);
1659 EXPORT_API sync_agent_ds_error_e sync_agent_ds_deinit()
1663 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
1664 sync_agent_deinit_error_e deinit = SYNC_AGENT_DEINIT_SUCCESS;
1667 ret = _kill_omads_agent();
1670 _DEBUG_ERROR("_kill_omads_agent() failed !!");
1671 result = SYNC_AGENT_DS_FAIL;
1677 deinit = sync_agent_deinit();
1678 if (deinit != SYNC_AGENT_DEINIT_SUCCESS) {
1679 _DEBUG_ERROR("sync_agent_clean_event_handler() failed !!");
1680 result = SYNC_AGENT_DS_FAIL;
1682 // if (err != SYNC_AGENT_EVENT_SUCCESS) {
1683 // sync_agent_event_error_e err = sync_agent_stop_noti_listener();
1684 // _DEBUG_INFO("STOP NOTILISTNER is failed");
1685 // result = SYNC_AGENT_DS_FAIL;
1688 // err = sync_agent_clean_event_handler();
1689 // if (err != SYNC_AGENT_EVENT_SUCCESS) {
1690 // _DEBUG_ERROR("sync_agent_clean_event_handler() failed !!");
1691 // result = SYNC_AGENT_DS_FAIL;
1699 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)
1703 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
1705 sync_agent_event_error_e err = sync_agent_set_noti_callback(type, callback, data);
1706 if (err != SYNC_AGENT_EVENT_SUCCESS) {
1707 _DEBUG_ERROR("failed sync_agent_set_noti_callback()");
1708 result = SYNC_AGENT_DS_FAIL;