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;
470 gboolean bResult = FALSE;
474 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
476 _DEBUG_ERROR("dbus_g_bus_get failed: %s\n", error->message);
482 dbus_proxy = dbus_g_proxy_new_for_name(connection, "com.samsung.omadsagent",
483 "/com/samsung/omadsagent", "com.samsung.omadsagent");
485 _DEBUG_INFO("dbus_proxy %x", dbus_proxy);
487 //dbus_g_proxy_call_no_reply(dbus_proxy, "Hello_Agent", G_TYPE_INVALID);
488 bResult = dbus_g_proxy_call(dbus_proxy, "Hello_Agent", &error, G_TYPE_INVALID, G_TYPE_INVALID);
490 if (bResult == FALSE) {
491 _DEBUG_ERROR("dbus_g_proxy_call failed: %s\n", error->message);
493 g_object_unref(dbus_proxy);
494 dbus_g_connection_unref(connection);
500 g_object_unref(dbus_proxy);
501 dbus_g_connection_unref(connection);
507 static int _kill_omads_agent(void)
510 GError *error = NULL;
512 DBusGConnection *connection = NULL;
513 DBusGProxy *dbus_proxy = NULL;
514 gboolean isExisting = FALSE;
516 isExisting = _is_existing_profile();
519 _DEBUG_INFO("Existing profile !!");
525 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
527 _DEBUG_ERROR("dbus_g_bus_get failed: %s\n", error->message);
533 dbus_proxy = dbus_g_proxy_new_for_name(connection, "com.samsung.omadsagent",
534 "/com/samsung/omadsagent", "com.samsung.omadsagent");
536 _DEBUG_INFO("dbus_proxy %x", dbus_proxy);
538 dbus_g_proxy_call_no_reply(dbus_proxy, "Goodbye_Agent", G_TYPE_INVALID);
540 g_object_unref(dbus_proxy);
541 dbus_g_connection_unref(connection);
547 EXPORT_API sync_agent_ds_error_e sync_agent_ds_init()
551 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
552 sync_agent_init_error_e init_error = SYNC_AGENT_INIT_SUCCESS;
555 ret = _launch_omads_agent();
558 _DEBUG_ERROR("_launch_omads_agent() failed !!");
559 result = SYNC_AGENT_DS_FAIL;
565 init_error = sync_agent_init(OMA_DS_CONFIG_FILE);
567 if (init_error != SYNC_AGENT_INIT_SUCCESS) {
568 _DEBUG_ERROR("ds init failed");
569 result = SYNC_AGENT_DS_FAIL;
572 sync_agent_event_error_e err = sync_agent_run_noti_listener("omads");
573 if (err != SYNC_AGENT_EVENT_SUCCESS) {
574 _DEBUG_ERROR("RUN NOTILISTNER is failed");
575 result = SYNC_AGENT_DS_FAIL;
583 EXPORT_API sync_agent_ds_error_e sync_agent_ds_create_profile_info(ds_profile_h * profile_h)
587 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
588 sync_agent_ds_profile_info *profile_info = NULL;
590 // allocate memory for ds profile info
591 profile_info = (sync_agent_ds_profile_info *) calloc(1, sizeof(sync_agent_ds_profile_info));
592 if (profile_info == NULL) {
593 _DEBUG_ERROR("calloc failed !!");
594 return SYNC_AGENT_DS_FAIL;
596 // pass memory pointer to ds profile handle
597 *profile_h = profile_info;
604 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_profile_dir_name(ds_profile_h profile_h, char *profile_dir_name)
608 // check mandatory parameter
609 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
610 retvm_if(profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
612 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
613 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
616 profile_info->profile_dir_name = g_strdup(profile_dir_name);
618 if (profile_info->profile_dir_name == NULL) {
619 _DEBUG_ERROR("g_strdup failed !!");
620 return SYNC_AGENT_DS_FAIL;
628 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_profile_name(ds_profile_h profile_h, char *profile_name)
632 // check mandatory parameter
633 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
634 retvm_if(profile_name == NULL, SYNC_AGENT_DS_FAIL, "profile_name is null!!");
636 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
637 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
640 profile_info->profile_name = g_strdup(profile_name);
642 if (profile_info->profile_name == NULL) {
643 _DEBUG_ERROR("g_strdup failed !!");
644 return SYNC_AGENT_DS_FAIL;
652 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_server_info(ds_profile_h profile_h, char *addr, char *id, char *password)
656 // check mandatory parameter
657 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
658 retvm_if(addr == NULL, SYNC_AGENT_DS_FAIL, "addr is null!!");
659 retvm_if(id == NULL, SYNC_AGENT_DS_FAIL, "id is null!!");
660 retvm_if(password == NULL, SYNC_AGENT_DS_FAIL, "password is null!!");
662 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
663 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
664 sync_agent_ds_server_info *server_info = &profile_info->server_info;
667 server_info->addr = g_strdup(addr);
668 server_info->id = g_strdup(id);
669 server_info->password = g_strdup(password);
671 if ((server_info->addr == NULL)
672 || (server_info->id == NULL)
673 || (server_info->password == NULL)) {
674 _DEBUG_ERROR("g_strdup failed !!");
675 return SYNC_AGENT_DS_FAIL;
683 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)
687 // check mandatory parameter
688 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
689 retvm_if(sync_mode < 0, SYNC_AGENT_DS_FAIL, "sync_mode is invalid!!");
690 retvm_if(sync_type < 0, SYNC_AGENT_DS_FAIL, "sync_type is invalid!!");
691 retvm_if(interval < 0, SYNC_AGENT_DS_FAIL, "interval is invalid!!");
693 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
694 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
695 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
697 char* sync_mode_str = NULL;
698 char* sync_type_str = NULL;
699 char* interval_str = NULL;
701 sync_mode_str = _convert_sync_mode_str(sync_mode);
702 if (sync_mode_str == NULL) {
703 _DEBUG_ERROR("_convert_sync_mode_str failed !!");
705 return SYNC_AGENT_DS_FAIL;
708 sync_type_str = _convert_sync_type_str(sync_type);
709 if (sync_type_str == NULL) {
710 _DEBUG_ERROR("_convert_sync_type_str failed !!");
712 return SYNC_AGENT_DS_FAIL;
715 interval_str = _convert_sync_interval_str(interval);
716 if (interval_str == NULL) {
717 _DEBUG_ERROR("_convert_sync_interval_str failed !!");
719 return SYNC_AGENT_DS_FAIL;
723 sync_info->sync_mode = sync_mode;
724 sync_info->sync_type = sync_type;
725 sync_info->interval = interval;
732 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)
736 // check mandatory parameter
737 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
738 retvm_if(src_uri < 0, SYNC_AGENT_DS_FAIL, "src_uri is invalid!!");
740 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
741 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
742 sync_agent_ds_service_info *category_info = NULL;
743 char* src_uri_str = NULL;
745 src_uri_str = _convert_src_uri_str(src_uri);
746 if (src_uri_str == NULL) {
747 _DEBUG_ERROR("_get_src_uri_string failed !!");
749 return SYNC_AGENT_DS_FAIL;
752 // allocate memory for sync_category
753 category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
754 retvm_if(category_info == NULL, SYNC_AGENT_DS_FAIL, "calloc failed");
755 category_info->service_type = service_type;
756 category_info->enabled = enabled;
757 category_info->src_uri = src_uri;
758 category_info->tgt_uri = g_strdup(tgt_uri);
760 profile_info->service_list = g_list_append(profile_info->service_list, category_info);
767 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_id(ds_profile_h profile_h, int *profile_id)
771 // check mandatory parameter
772 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
774 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
776 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
778 *profile_id = profile_info->profile_id;
780 if (*profile_id < 1) {
781 _DEBUG_ERROR("profile_id is invalid!!");
782 return SYNC_AGENT_DS_FAIL;
785 _DEBUG_INFO("profile_id = %d", *profile_id);
792 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_dir_name(ds_profile_h profile_h, char **profile_dir_name)
796 // check mandatory parameter
797 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
799 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
801 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
803 *profile_dir_name = g_strdup(profile_info->profile_dir_name);
805 if (*profile_dir_name == NULL) {
806 _DEBUG_ERROR("g_strdup failed !!");
807 return SYNC_AGENT_DS_FAIL;
810 _DEBUG_INFO("profile_dir_name = %s", *profile_dir_name);
817 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_name(ds_profile_h profile_h, char **profile_name)
821 // check mandatory parameter
822 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
824 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
826 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
828 *profile_name = g_strdup(profile_info->profile_name);
830 if (*profile_name == NULL) {
831 _DEBUG_ERROR("g_strdup failed !!");
832 return SYNC_AGENT_DS_FAIL;
835 _DEBUG_INFO("profile_name = %s", *profile_name);
842 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)
846 // check mandatory parameter
847 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
848 retvm_if(server_info == NULL, SYNC_AGENT_DS_FAIL, "server_info is null!!");
850 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
851 sync_agent_ds_server_info *ds_server_info = &profile_info->server_info;
853 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
855 server_info->addr = g_strdup(ds_server_info->addr);
856 server_info->id = g_strdup(ds_server_info->id);
857 server_info->password = g_strdup(ds_server_info->password);
859 if ((server_info->addr == NULL)
860 || (server_info->id == NULL)
861 || (server_info->password == NULL)) {
862 _DEBUG_ERROR("g_strdup failed !!");
863 return SYNC_AGENT_DS_FAIL;
866 _DEBUG_INFO("get_addr = %s", server_info->addr);
867 _DEBUG_INFO("get_id = %s", server_info->id);
868 _DEBUG_INFO("get_password = %s", server_info->password);
875 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)
879 // check mandatory parameter
880 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
881 retvm_if(sync_info == NULL, SYNC_AGENT_DS_FAIL, "sync_info is null!!");
883 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
884 sync_agent_ds_sync_info *ds_sync_info = &profile_info->sync_info;
886 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
888 sync_info->sync_mode = ds_sync_info->sync_mode;
889 sync_info->sync_type = ds_sync_info->sync_type;
890 sync_info->interval = ds_sync_info->interval;
892 _DEBUG_INFO("get_sync_mode = %d", sync_info->sync_mode);
893 _DEBUG_INFO("get_sync_type = %d", sync_info->sync_type);
894 _DEBUG_INFO("get_interval = %d", sync_info->interval);
896 if (sync_info->sync_mode < 0) {
897 _DEBUG_ERROR("sync_mode is invalid !!");
898 return SYNC_AGENT_DS_FAIL;
901 if (sync_info->sync_type < 0) {
902 _DEBUG_ERROR("sync_type is invalid !!");
903 return SYNC_AGENT_DS_FAIL;
906 if (sync_info->interval < 0) {
907 _DEBUG_ERROR("interval is invalid !!");
908 return SYNC_AGENT_DS_FAIL;
916 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_service_info(ds_profile_h profile_h, GList ** category_list)
920 // check mandatory parameter
921 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
923 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
925 int category_count = 0;
927 sync_agent_ds_service_info *category_info = NULL;
929 *category_list = g_list_copy(profile_info->service_list);
931 if (*category_list == NULL) {
932 _DEBUG_ERROR("g_list_copy failed !!");
933 return SYNC_AGENT_DS_FAIL;
936 category_count = g_list_length(*category_list);
937 for (; i < category_count; i++) {
938 category_info = (sync_agent_ds_service_info *) g_list_nth_data(*category_list, i);
940 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
941 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
942 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
943 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
944 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
949 return SYNC_AGENT_DS_SUCCESS;
952 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_statistics(ds_profile_h profile_h, GList ** statistics_list)
956 // check mandatory parameter
957 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
959 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
960 sync_agent_ds_statistics_info *statistics = NULL;
962 gboolean result_sync_category = FALSE;
964 /* get last contacts sync result */
965 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_CONTACTS, &statistics);
966 if (result_sync_category)
967 *statistics_list = g_list_append(*statistics_list, statistics);
969 /* get last schedule sync result */
971 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_SCHEDULE, &statistics);
972 if (result_sync_category)
973 *statistics_list = g_list_append(*statistics_list, statistics);
975 /* get last memo sync result */
977 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_MEMO, &statistics);
978 if (result_sync_category)
979 *statistics_list = g_list_append(*statistics_list, statistics);
983 return SYNC_AGENT_DS_SUCCESS;
986 EXPORT_API sync_agent_ds_error_e sync_agent_ds_add_profile(ds_profile_h profile_h, int *profile_id)
990 // check mandatory parameter
991 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
993 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
994 sync_agent_ds_server_info *server_info = &profile_info->server_info;
995 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
996 GList *list = profile_info->service_list;
998 int event_type = SYNC_AGENT_DS_ADD_PROFILE;
999 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1000 sync_agent_event_data_s *request_event = NULL;
1001 sync_agent_event_data_s *response_event = NULL;
1004 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1005 sync_agent_ds_service_info *category_info = NULL;
1006 int category_count = 0;
1009 /* create empty event packet */
1010 request_event = sync_agent_create_event(event_type);
1011 if (request_event == NULL) {
1012 _DEBUG_ERROR("event is NULL");
1014 return SYNC_AGENT_DS_FAIL;
1017 /* add request parameter to event packet */
1018 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
1019 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name);
1020 _DEBUG_INFO("addr = %s", server_info->addr);
1021 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr);
1022 _DEBUG_INFO("id = %s", server_info->id);
1023 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id);
1024 _DEBUG_INFO("password = %s", server_info->password);
1025 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password);
1026 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
1027 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_mode));
1028 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
1029 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_type));
1030 _DEBUG_INFO("interval = %d", sync_info->interval);
1031 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->interval));
1033 category_count = g_list_length(list);
1034 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count);
1036 for (; i < category_count; i++) {
1037 category_info = (sync_agent_ds_service_info *) g_list_nth_data(list, i);
1039 _DEBUG_INFO("category[%d]->service_type = %d", i, category_info->service_type);
1040 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->service_type));
1041 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
1042 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->enabled));
1043 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
1044 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->src_uri));
1045 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
1046 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri);
1047 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
1048 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id);
1049 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
1050 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password);
1053 /* send event request to ds agent daemon, waiting for response */
1054 response_event = sync_agent_send_event(request_event, &error);
1055 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1056 _DEBUG_ERROR("error = %d", error);
1057 sync_agent_free_event(request_event);
1059 return SYNC_AGENT_DS_FAIL;
1061 if (response_event == NULL) {
1062 _DEBUG_ERROR("response_event is null!!");
1063 sync_agent_free_event(request_event);
1065 return SYNC_AGENT_DS_FAIL;
1068 /* get response parameter from event packet */
1069 sync_agent_get_event_data_param_int(response_event, &api_result);
1071 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1072 _DEBUG_ERROR("api_result = failed");
1073 sync_agent_free_event(request_event);
1074 sync_agent_free_event_data(response_event);
1076 return SYNC_AGENT_DS_FAIL;
1079 sync_agent_get_event_data_param_int(response_event, &prof_id);
1081 _DEBUG_VERBOSE("profile_id = %d", prof_id);
1082 *profile_id = prof_id;
1084 /* free request & response event */
1085 sync_agent_free_event(request_event);
1086 sync_agent_free_event_data(response_event);
1090 return SYNC_AGENT_DS_SUCCESS;
1093 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile(int profile_id, ds_profile_h * profile_h)
1097 // check mandatory parameter
1098 retvm_if(profile_id < 1, SYNC_AGENT_DS_FAIL, "profile_id is invalid!!");
1100 int event_type = SYNC_AGENT_DS_GET_PROFILE;
1101 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1102 sync_agent_event_data_s *request_event = NULL;
1103 sync_agent_event_data_s *response_event = NULL;
1105 gboolean result_sync_category = FALSE;
1106 sync_agent_ds_error_e result = SYNC_AGENT_DS_FAIL;
1107 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1108 sync_agent_ds_service_info *category = NULL;
1110 //////////////////////////////////
1112 // Phase 1. get profile detail info
1114 /* create empty event packet */
1115 request_event = sync_agent_create_event(event_type);
1116 if (request_event == NULL) {
1117 _DEBUG_ERROR("event is NULL");
1119 return SYNC_AGENT_DS_FAIL;
1122 /* add request parameter to event packet */
1123 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &profile_id);
1124 _DEBUG_INFO("profile_id = %d", profile_id);
1126 /* send event request to ds agent daemon, waiting for response */
1127 response_event = sync_agent_send_event(request_event, &error);
1128 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1129 _DEBUG_ERROR("error = %d", error);
1130 sync_agent_free_event(request_event);
1132 return SYNC_AGENT_DS_FAIL;
1134 if (response_event == NULL) {
1135 _DEBUG_ERROR("response_event is null!!");
1136 sync_agent_free_event(request_event);
1138 return SYNC_AGENT_DS_FAIL;
1141 /* get response parameter from event packet */
1143 result = sync_agent_ds_create_profile_info(profile_h);
1144 if (result == SYNC_AGENT_DS_FAIL) {
1145 _DEBUG_ERROR("failed to create profile info!");
1146 sync_agent_free_event(request_event);
1147 sync_agent_free_event_data(response_event);
1151 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) (*profile_h);
1152 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1153 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1154 // GList * list = profile_info->category_list;
1156 sync_agent_get_event_data_param_int(response_event, &api_result);
1157 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1158 _DEBUG_ERROR("api_result = failed");
1159 sync_agent_free_event(request_event);
1160 sync_agent_free_event_data(response_event);
1162 return SYNC_AGENT_DS_FAIL;
1165 //profile_info->profile_dir_name = g_strdup(profile_dir_name);
1167 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_dir_name);
1168 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_name);
1169 sync_agent_get_event_data_param_str(response_event, &server_info->addr);
1170 sync_agent_get_event_data_param_str(response_event, &server_info->id);
1171 sync_agent_get_event_data_param_str(response_event, &server_info->password);
1172 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_mode);
1173 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_type);
1174 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->interval);
1175 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_status);
1176 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_time);
1178 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1179 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
1180 _DEBUG_INFO("addr = %s", server_info->addr);
1181 _DEBUG_INFO("id = %s", server_info->id);
1182 _DEBUG_INFO("password = %s", server_info->password);
1183 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
1184 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
1185 _DEBUG_INFO("interval = %d", sync_info->interval);
1186 _DEBUG_VERBOSE("lastSyncStatus = %d\n", profile_info->last_sync_status);
1187 _DEBUG_VERBOSE("lastSyncTime = %d\n", profile_info->last_sync_time);
1189 /* free request & response event */
1190 sync_agent_free_event(request_event);
1191 sync_agent_free_event_data(response_event);
1193 // Phase 2. get sync category info
1195 /* get contacts sync_category */
1196 result_sync_category = _get_sync_category(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_CONTACTS, &category);
1197 if (result_sync_category)
1198 profile_info->service_list = g_list_append(profile_info->service_list, category);
1200 /* get schedule sync_category */
1202 result_sync_category = _get_sync_category(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_SCHEDULE, &category);
1203 if (result_sync_category)
1204 profile_info->service_list = g_list_append(profile_info->service_list, category);
1208 return SYNC_AGENT_DS_SUCCESS;
1211 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_all_profile(GList ** profile_list)
1215 int event_type = SYNC_AGENT_DS_GET_ALL_PROFILES;
1216 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1217 sync_agent_event_data_s *request_event = NULL;
1218 sync_agent_event_data_s *response_event = NULL;
1220 ds_profile_h profile_h = NULL;
1221 sync_agent_ds_service_info *category_info = NULL;
1223 int profile_count = 0;
1224 int category_count = 0;
1226 sync_agent_ds_error_e result = SYNC_AGENT_DS_FAIL;
1227 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1229 /* create empty event packet */
1230 request_event = sync_agent_create_event(event_type);
1231 if (request_event == NULL) {
1232 _DEBUG_ERROR("event is NULL");
1234 return SYNC_AGENT_DS_FAIL;
1237 /* send event request to ds agent daemon, waiting for response */
1238 response_event = sync_agent_send_event(request_event, &error);
1239 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1240 _DEBUG_ERROR("error = %d", error);
1241 sync_agent_free_event(request_event);
1243 return SYNC_AGENT_DS_FAIL;
1245 if (response_event == NULL) {
1246 _DEBUG_ERROR("response_event is null!!");
1247 sync_agent_free_event(request_event);
1249 return SYNC_AGENT_DS_FAIL;
1252 sync_agent_get_event_data_param_int(response_event, &api_result);
1253 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1254 _DEBUG_ERROR("api_result = failed");
1255 sync_agent_free_event(request_event);
1256 sync_agent_free_event_data(response_event);
1258 return SYNC_AGENT_DS_FAIL;
1261 sync_agent_get_event_data_param_int(response_event, &profile_count);
1262 _DEBUG_INFO("profile_count = %d", profile_count);
1265 for (i = 0; i < profile_count; i++) {
1267 result = sync_agent_ds_create_profile_info(&profile_h);
1268 if (result == SYNC_AGENT_DS_FAIL) {
1269 _DEBUG_ERROR("failed to create profile info!");
1270 sync_agent_free_event(request_event);
1271 sync_agent_free_event_data(response_event);
1275 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1276 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1277 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1279 sync_agent_get_event_data_param_int(response_event, &profile_info->profile_id);
1280 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_dir_name);
1281 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_name);
1282 sync_agent_get_event_data_param_str(response_event, &server_info->addr);
1283 sync_agent_get_event_data_param_str(response_event, &server_info->id);
1284 sync_agent_get_event_data_param_str(response_event, &server_info->password);
1285 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_mode);
1286 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_type);
1287 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->interval);
1288 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_status);
1289 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_time);
1291 _DEBUG_INFO("profile_info->profile_id = %d", profile_info->profile_id);
1292 _DEBUG_INFO("profile_info->profile_dir_name = %s", profile_info->profile_dir_name);
1293 _DEBUG_INFO("profile_info->profile_name = %s", profile_info->profile_name);
1294 _DEBUG_INFO("profile_info->addr = %s", server_info->addr);
1295 _DEBUG_INFO("profile_info->id = %s", server_info->id);
1296 _DEBUG_INFO("profile_info->password = %s", server_info->password);
1297 _DEBUG_INFO("profile_info->sync_mode = %d", sync_info->sync_mode);
1298 _DEBUG_INFO("profile_info->sync_type = %d", sync_info->sync_type);
1299 _DEBUG_INFO("profile_info->interval = %d", sync_info->interval);
1300 _DEBUG_INFO("profile_info->lastSyncStatus = %d", profile_info->last_sync_status);
1301 _DEBUG_INFO("profile_info->lastSyncStatus = %d", profile_info->last_sync_status);
1303 sync_agent_get_event_data_param_int(response_event, &category_count);
1306 for (j = 0; j < category_count; j++) {
1308 category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
1309 if (category_info == NULL) {
1310 _DEBUG_ERROR("calloc failed");
1311 sync_agent_ds_free_profile_info(profile_h);
1312 sync_agent_free_event(request_event);
1313 sync_agent_free_event_data(response_event);
1317 sync_agent_get_event_data_param_int(response_event, (int*) &category_info->service_type);
1318 sync_agent_get_event_data_param_int(response_event, &category_info->enabled);
1319 sync_agent_get_event_data_param_int(response_event, (int*) &category_info->src_uri);
1320 sync_agent_get_event_data_param_str(response_event, &category_info->tgt_uri);
1321 sync_agent_get_event_data_param_str(response_event, &category_info->id);
1322 sync_agent_get_event_data_param_str(response_event, &category_info->password);
1324 _DEBUG_INFO("category_info->service_type = %d", category_info->service_type);
1325 _DEBUG_INFO("category_info->enabled = %d", category_info->enabled);
1326 _DEBUG_INFO("category_info->src_uri = %d", category_info->src_uri);
1327 _DEBUG_INFO("category_info->tgt_uri = %s", category_info->tgt_uri);
1328 _DEBUG_INFO("category_info->id = %s", category_info->id);
1329 _DEBUG_INFO("category_info->password = %s", category_info->password);
1331 profile_info->service_list = g_list_append(profile_info->service_list, category_info);
1332 category_info = NULL;
1335 *profile_list = g_list_append(*profile_list, profile_h);
1339 /* free request & response event */
1340 sync_agent_free_event(request_event);
1341 sync_agent_free_event_data(response_event);
1345 return SYNC_AGENT_DS_SUCCESS;
1348 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_last_sync_info(ds_profile_h profile_h, int *lastSyncStatus, int *lastSyncTime)
1352 // check mandatory parameter
1353 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1354 retvm_if(lastSyncStatus == NULL, SYNC_AGENT_DS_FAIL, "last session status is null!!");
1355 retvm_if(lastSyncTime == NULL, SYNC_AGENT_DS_FAIL, "last session time is null!!");
1357 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1359 *lastSyncStatus = profile_info->last_sync_status;
1360 *lastSyncTime = profile_info->last_sync_time;
1364 return SYNC_AGENT_DS_SUCCESS;
1367 EXPORT_API sync_agent_ds_error_e sync_agent_ds_update_profile(ds_profile_h profile_h)
1371 // check mandatory parameter
1372 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1374 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1375 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1376 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1377 GList *list = profile_info->service_list;
1379 int event_type = SYNC_AGENT_DS_UPDATE_PROFILE;
1380 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1381 sync_agent_event_data_s *request_event = NULL;
1382 sync_agent_event_data_s *response_event = NULL;
1384 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1385 sync_agent_ds_service_info *category_info = NULL;
1386 int category_count = 0;
1389 /* create empty event packet */
1390 request_event = sync_agent_create_event(event_type);
1391 if (request_event == NULL) {
1392 _DEBUG_ERROR("event is NULL");
1394 return SYNC_AGENT_DS_FAIL;
1397 /* add request parameter to event packet */
1398 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1399 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1400 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
1401 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name);
1402 _DEBUG_INFO("addr = %s", server_info->addr);
1403 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr);
1404 _DEBUG_INFO("id = %s", server_info->id);
1405 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id);
1406 _DEBUG_INFO("password = %s", server_info->password);
1407 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password);
1408 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
1409 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_mode));
1410 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
1411 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_type));
1412 _DEBUG_INFO("interval = %d", sync_info->interval);
1413 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->interval));
1415 category_count = g_list_length(list);
1416 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count);
1418 for (; i < category_count; i++) {
1419 category_info = (sync_agent_ds_service_info *) g_list_nth_data(list, i);
1421 _DEBUG_INFO("category[%d]->service_type = %d", i, category_info->service_type);
1422 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->service_type));
1423 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
1424 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->enabled));
1425 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
1426 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->src_uri));
1427 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
1428 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri);
1429 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
1430 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id);
1431 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
1432 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password);
1435 /* send event request to ds agent daemon, waiting for response */
1436 response_event = sync_agent_send_event(request_event, &error);
1437 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1438 _DEBUG_ERROR("error = %d", error);
1439 sync_agent_free_event(request_event);
1441 return SYNC_AGENT_DS_FAIL;
1443 if (response_event == NULL) {
1444 _DEBUG_ERROR("response_event is null!!");
1445 sync_agent_free_event(request_event);
1447 return SYNC_AGENT_DS_FAIL;
1450 /* get response parameter from event packet */
1451 sync_agent_get_event_data_param_int(response_event, &api_result);
1453 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1454 _DEBUG_ERROR("api_result = failed");
1455 sync_agent_free_event(request_event);
1456 sync_agent_free_event_data(response_event);
1458 return SYNC_AGENT_DS_FAIL;
1461 /* free request & response event */
1462 sync_agent_free_event(request_event);
1463 sync_agent_free_event_data(response_event);
1467 return SYNC_AGENT_DS_SUCCESS;
1470 EXPORT_API sync_agent_ds_error_e sync_agent_ds_delete_profile(ds_profile_h profile_h)
1474 // check mandatory parameter
1475 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1477 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1479 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1481 int event_type = SYNC_AGENT_DS_DELETE_PROFILE;
1482 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1483 sync_agent_event_data_s *request_event = NULL;
1484 sync_agent_event_data_s *response_event = NULL;
1487 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1489 /* create empty event packet */
1490 request_event = sync_agent_create_event(event_type);
1491 if (request_event == NULL) {
1492 _DEBUG_ERROR("event is NULL");
1493 return SYNC_AGENT_DS_FAIL;
1496 /* add request parameter to event packet */
1497 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &count);
1499 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1500 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1502 /* send event request to ds agent daemon, waiting for response */
1503 response_event = sync_agent_send_event(request_event, &error);
1504 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1505 _DEBUG_ERROR("error = %d", error);
1506 sync_agent_free_event(request_event);
1508 return SYNC_AGENT_DS_FAIL;
1510 if (response_event == NULL) {
1511 _DEBUG_ERROR("response_event is null!!");
1512 sync_agent_free_event(request_event);
1514 return SYNC_AGENT_DS_FAIL;
1517 /* get response parameter from event packet */
1518 sync_agent_get_event_data_param_int(response_event, &api_result);
1520 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1521 _DEBUG_ERROR("api_result = failed");
1522 sync_agent_free_event(request_event);
1523 sync_agent_free_event_data(response_event);
1525 return SYNC_AGENT_DS_FAIL;
1528 /* free request & response event */
1529 sync_agent_free_event(request_event);
1530 sync_agent_free_event_data(response_event);
1534 return SYNC_AGENT_DS_SUCCESS;
1537 EXPORT_API sync_agent_ds_error_e sync_agent_ds_start_sync(ds_profile_h profile_h)
1541 // check mandatory parameter
1542 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1544 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1546 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1548 int event_type = SYNC_AGENT_DS_START_SYNC;
1549 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1550 sync_agent_event_data_s *request_event = NULL;
1551 sync_agent_event_data_s *response_event = NULL;
1553 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1555 /* create empty event packet */
1556 request_event = sync_agent_create_event(event_type);
1557 if (request_event == NULL) {
1558 _DEBUG_ERROR("event is NULL");
1559 return SYNC_AGENT_DS_FAIL;
1562 /* add request parameter to event packet */
1563 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1565 /* send event request to ds agent daemon, waiting for response */
1566 response_event = sync_agent_send_event(request_event, &error);
1567 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1568 _DEBUG_ERROR("error = %d", error);
1569 sync_agent_free_event(request_event);
1571 return SYNC_AGENT_DS_FAIL;
1573 if (response_event == NULL) {
1574 _DEBUG_ERROR("response_event is null!!");
1575 sync_agent_free_event(request_event);
1577 return SYNC_AGENT_DS_FAIL;
1580 /* get response parameter from event packet */
1581 sync_agent_get_event_data_param_int(response_event, &api_result);
1583 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1584 _DEBUG_ERROR("api_result = failed");
1585 sync_agent_free_event(request_event);
1586 sync_agent_free_event_data(response_event);
1588 return SYNC_AGENT_DS_FAIL;
1591 /* free request & response event */
1592 sync_agent_free_event(request_event);
1593 sync_agent_free_event_data(response_event);
1597 return SYNC_AGENT_DS_SUCCESS;
1600 EXPORT_API sync_agent_ds_error_e sync_agent_ds_stop_sync(ds_profile_h profile_h)
1604 // check mandatory parameter
1605 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1607 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1609 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1611 int event_type = SYNC_AGENT_DS_STOP_SYNC;
1612 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1613 sync_agent_event_data_s *request_event = NULL;
1614 sync_agent_event_data_s *response_event = NULL;
1616 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1618 /* create empty event packet */
1619 request_event = sync_agent_create_event(event_type);
1620 if (request_event == NULL) {
1621 _DEBUG_ERROR("event is NULL");
1622 return SYNC_AGENT_DS_FAIL;
1625 /* add request parameter to event packet */
1626 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1628 /* send event request to ds agent daemon, waiting for response */
1629 response_event = sync_agent_send_event(request_event, &error);
1630 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1631 _DEBUG_ERROR("error = %d", error);
1632 sync_agent_free_event(request_event);
1634 return SYNC_AGENT_DS_FAIL;
1636 if (response_event == NULL) {
1637 _DEBUG_ERROR("response_event is null!!");
1638 sync_agent_free_event(request_event);
1640 return SYNC_AGENT_DS_FAIL;
1643 /* get response parameter from event packet */
1644 sync_agent_get_event_data_param_int(response_event, &api_result);
1646 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1647 _DEBUG_ERROR("api_result = failed");
1648 sync_agent_free_event(request_event);
1649 sync_agent_free_event_data(response_event);
1651 return SYNC_AGENT_DS_FAIL;
1654 /* free request & response event */
1655 sync_agent_free_event(request_event);
1656 sync_agent_free_event_data(response_event);
1660 return SYNC_AGENT_DS_SUCCESS;
1663 EXPORT_API void sync_agent_ds_free_profile_info(ds_profile_h profile_h)
1667 // check mandatory parameter
1668 retm_if(profile_h == NULL, "profile handle is null!!");
1670 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1672 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1673 //sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1674 GList *category_list = profile_info->service_list;
1676 // free profile name
1677 g_free(profile_info->profile_dir_name);
1678 g_free(profile_info->profile_name);
1680 // free server information
1681 g_free(server_info->addr);
1682 g_free(server_info->id);
1683 g_free(server_info->password);
1685 // free sync category information
1686 g_list_free_full(category_list, (GDestroyNotify) _free_sync_category_info);
1688 // free profile information
1689 g_free(profile_info);
1694 EXPORT_API sync_agent_ds_error_e sync_agent_ds_deinit()
1698 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
1699 sync_agent_deinit_error_e deinit = SYNC_AGENT_DEINIT_SUCCESS;
1702 ret = _kill_omads_agent();
1705 _DEBUG_ERROR("_kill_omads_agent() failed !!");
1706 result = SYNC_AGENT_DS_FAIL;
1712 deinit = sync_agent_deinit();
1713 if (deinit != SYNC_AGENT_DEINIT_SUCCESS) {
1714 _DEBUG_ERROR("sync_agent_clean_event_handler() failed !!");
1715 result = SYNC_AGENT_DS_FAIL;
1717 // if (err != SYNC_AGENT_EVENT_SUCCESS) {
1718 // sync_agent_event_error_e err = sync_agent_stop_noti_listener();
1719 // _DEBUG_INFO("STOP NOTILISTNER is failed");
1720 // result = SYNC_AGENT_DS_FAIL;
1723 // err = sync_agent_clean_event_handler();
1724 // if (err != SYNC_AGENT_EVENT_SUCCESS) {
1725 // _DEBUG_ERROR("sync_agent_clean_event_handler() failed !!");
1726 // result = SYNC_AGENT_DS_FAIL;
1734 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)
1738 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
1740 sync_agent_event_error_e err = sync_agent_set_noti_callback(type, callback, data);
1741 if (err != SYNC_AGENT_EVENT_SUCCESS) {
1742 _DEBUG_ERROR("failed sync_agent_set_noti_callback()");
1743 result = SYNC_AGENT_DS_FAIL;