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>
24 #include <sysman_managed.h>
26 #ifndef SYNC_AGENT_LOG
28 #define LOG_TAG "OMADS_CLIENT"
31 //#include <sync_agent.h>
32 #include "event/event.h"
33 #include "utility/sync_util.h"
34 #include "initialization/initialization.h"
36 #include <tzplatform_config.h>
39 #define EXPORT_API __attribute__ ((visibility("default")))
42 #define OMA_DS_CONFIG_FILE "/usr/share/oma-ds-cfg/omadsUI_fw_config.xml"
44 #define SYNC_AGENT_DS_API_RESULT_FAILURE 0
45 #define SYNC_AGENT_DS_API_RESULT_SUCCESS 1
46 #define SYNC_AGENT_DS_API_RESULT_SYNCHRONISING 2
48 #define SYNC_TYPE_SLOW_SYNC_STR "Full"
49 #define SYNC_TYPE_TWO_WAY_STR "Update both"
50 #define SYNC_TYPE_ONE_WAY_FROM_CLIENT_STR "Update to server"
51 #define SYNC_TYPE_ONE_WAY_FROM_SERVER_STR "Update to phone"
52 #define SYNC_TYPE_REFRESH_FROM_SERVER_STR "Refresh from server"
53 #define SYNC_TYPE_REFRESH_FROM_CLIENT_STR "Refresh from phone"
55 #define SYNC_MODE_MANUAL_STR "Manual"
56 #define SYNC_MODE_PUSH_STR "Push"
57 #define SYNC_MODE_PERIODIC_STR "Periodic"
59 #define SYNC_INTERVAL_NONE "None"
60 #define SYNC_INTERVAL_5_MINUTES "5 minutes"
61 #define SYNC_INTERVAL_15_MINUTES "15 minutes"
62 #define SYNC_INTERVAL_1_HOUR "1 hour"
63 #define SYNC_INTERVAL_4_HOURS "4 hours"
64 #define SYNC_INTERVAL_12_HOURS "12 hours"
65 #define SYNC_INTERVAL_1_DAY "1 day"
66 #define SYNC_INTERVAL_1_WEEK "1 week"
67 #define SYNC_INTERVAL_1_MONTH "1 month"
69 #define SRC_URI_CONTACT_STR "Contacts"
70 #define SRC_URI_CALENDAR_STR "Organizer"
73 SYNC_AGENT_DS_ADD_PROFILE = 1,
74 SYNC_AGENT_DS_UPDATE_PROFILE = 2,
75 SYNC_AGENT_DS_DELETE_PROFILE = 3,
76 SYNC_AGENT_DS_START_SYNC = 4,
77 SYNC_AGENT_DS_STOP_SYNC = 5,
78 SYNC_AGENT_DS_GET_PROFILE = 6,
79 SYNC_AGENT_DS_GET_SYNC_CATEGORY = 7,
80 SYNC_AGENT_DS_GET_SYNC_STATISTICS = 8,
81 SYNC_AGENT_DS_GET_ALL_PROFILES = 9
82 } sync_agent_ds_event_e;
85 SYNC_AGENT_DS_SYNC_CONTACTS = 0,
86 SYNC_AGENT_DS_SYNC_SCHEDULE = 1,
87 SYNC_AGENT_DS_SYNC_MEMO = 2
88 } sync_agent_ds_sync_e;
90 static gboolean _get_sync_category(char *profile_dir_name, int service_type, sync_agent_ds_service_info ** service)
94 int event_type = SYNC_AGENT_DS_GET_SYNC_CATEGORY;
95 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
97 // check mandatory parameter
98 retvm_if(profile_dir_name == NULL, FALSE, "profile_dir_name is null!!");
99 retvm_if(service_type < 0, FALSE, "service_type is wrong!!");
101 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
102 sync_agent_event_data_s *request_event = NULL;
103 sync_agent_event_data_s *response_event = NULL;
105 /* create empty event packet */
106 request_event = sync_agent_create_event(event_type);
107 if (request_event == NULL) {
108 _DEBUG_ERROR("event is NULL");
113 /* add request parameter to event packet */
114 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
115 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &service_type);
117 /* send event request to ds agent daemon, waiting for response */
118 response_event = sync_agent_send_event(request_event, &error);
119 if (error != SYNC_AGENT_EVENT_SUCCESS) {
120 _DEBUG_ERROR("error = %d", error);
121 sync_agent_free_event(request_event);
125 if (response_event == NULL) {
126 _DEBUG_ERROR("response_event is null!!");
127 sync_agent_free_event(request_event);
132 *service = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
133 if (*service == NULL) {
134 _DEBUG_ERROR("calloc failed");
135 sync_agent_free_event(request_event);
136 sync_agent_free_event_data(response_event);
140 /* get response parameter from event packet */
142 sync_agent_get_event_data_param_int(response_event, &api_result);
143 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
144 _DEBUG_ERROR("api_result = failed");
145 sync_agent_free_event(request_event);
146 sync_agent_free_event_data(response_event);
148 return SYNC_AGENT_DS_FAIL;
151 sync_agent_get_event_data_param_int(response_event, &((*service)->enabled));
152 sync_agent_get_event_data_param_int(response_event, (int*) &((*service)->src_uri));
153 sync_agent_get_event_data_param_str(response_event, &((*service)->tgt_uri));
154 sync_agent_get_event_data_param_str(response_event, &((*service)->id));
155 sync_agent_get_event_data_param_str(response_event, &((*service)->password));
157 _DEBUG_TRACE("enabled = %d", (*service)->enabled);
158 _DEBUG_TRACE("src_uri = %d", (*service)->src_uri);
159 _DEBUG_TRACE("tgt_uri = %s", (*service)->tgt_uri);
160 _DEBUG_TRACE("id = %s", (*service)->id);
161 _DEBUG_TRACE("password = %s", (*service)->password);
163 /* free request & response event */
164 sync_agent_free_event(request_event);
165 sync_agent_free_event_data(response_event);
172 static gboolean _get_sync_statistics(char *profile_dir_name, int service_type, sync_agent_ds_statistics_info ** statistics)
176 int event_type = SYNC_AGENT_DS_GET_SYNC_STATISTICS;
177 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
179 // check mandatory parameter
180 retvm_if(profile_dir_name == NULL, FALSE, "profile_dir_name is null!!");
181 retvm_if(service_type < 0, FALSE, "service_type is wrong!!");
183 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
184 sync_agent_event_data_s *request_event = NULL;
185 sync_agent_event_data_s *response_event = NULL;
187 char *statistics_cat = NULL;
189 /* create empty event packet */
190 request_event = sync_agent_create_event(event_type);
191 if (request_event == NULL) {
192 _DEBUG_ERROR("event is NULL");
197 /* add request parameter to event packet */
198 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
199 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &service_type);
201 /* send event request to ds agent daemon, waiting for response */
202 response_event = sync_agent_send_event(request_event, &error);
203 if (error != SYNC_AGENT_EVENT_SUCCESS) {
204 _DEBUG_ERROR("error = %d", error);
205 sync_agent_free_event(request_event);
209 if (response_event == NULL) {
210 _DEBUG_ERROR("response_event is null!!");
211 sync_agent_free_event(request_event);
216 *statistics = (sync_agent_ds_statistics_info *) calloc(1, sizeof(sync_agent_ds_statistics_info));
217 if (*statistics == NULL) {
218 _DEBUG_ERROR("calloc failed");
219 sync_agent_free_event(request_event);
220 sync_agent_free_event_data(response_event);
224 /* get response parameter from event packet */
226 sync_agent_get_event_data_param_int(response_event, &api_result);
227 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
228 _DEBUG_ERROR("api_result = failed");
229 sync_agent_free_event(request_event);
230 sync_agent_free_event_data(response_event);
232 return SYNC_AGENT_DS_FAIL;
235 if (service_type == SYNC_AGENT_DS_SYNC_CONTACTS)
236 statistics_cat = "contacts";
237 else if (service_type == SYNC_AGENT_DS_SYNC_SCHEDULE)
238 statistics_cat = "schedule";
239 else if (service_type == SYNC_AGENT_DS_SYNC_MEMO)
240 statistics_cat = "memo";
242 sync_agent_get_event_data_param_str(response_event, &((*statistics)->dbsynced));
243 sync_agent_get_event_data_param_int(response_event, &((*statistics)->last_session_time));
244 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_total));
245 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_nrofadd));
246 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_nrofdelete));
247 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_nrofreplace));
248 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_total));
249 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_nrofadd));
250 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_nrofdelete));
251 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_nrofreplace));
253 _DEBUG_TRACE("%s dbSynced = %s", statistics_cat, (*statistics)->dbsynced);
254 _DEBUG_TRACE("%s lastSessionTime = %d", statistics_cat, (*statistics)->last_session_time);
255 _DEBUG_TRACE("%s server2Client_Total = %d", statistics_cat, (*statistics)->server2client_total);
256 _DEBUG_TRACE("%s server2Client_NrOrAdd = %d", statistics_cat, (*statistics)->server2client_nrofadd);
257 _DEBUG_TRACE("%s server2Client_NrOfDelete = %d", statistics_cat, (*statistics)->server2client_nrofdelete);
258 _DEBUG_TRACE("%s server2Client_NrOfReplace = %d", statistics_cat, (*statistics)->server2client_nrofreplace);
259 _DEBUG_TRACE("%s client2Server_Total = %d", statistics_cat, (*statistics)->client2server_total);
260 _DEBUG_TRACE("%s client2Server_NrOfAdd = %d", statistics_cat, (*statistics)->client2server_nrofadd);
261 _DEBUG_TRACE("%s client2Server_NrOfDelete = %d", statistics_cat, (*statistics)->client2server_nrofdelete);
262 _DEBUG_TRACE("%s client2Server_NrOfReplace = %d", statistics_cat, (*statistics)->client2server_nrofreplace);
264 /* free request & response event */
265 sync_agent_free_event(request_event);
266 sync_agent_free_event_data(response_event);
273 static char * _convert_sync_mode_str(sync_agent_ds_sync_mode_e sync_mode)
277 char* sync_mode_str = NULL;
279 _DEBUG_INFO("sync_mode : [%d]",sync_mode);
281 case SYNC_AGENT_SYNC_MODE_MANUAL:
282 sync_mode_str = SYNC_MODE_MANUAL_STR;
284 case SYNC_AGENT_SYNC_MODE_PERIODIC:
285 sync_mode_str = SYNC_MODE_PERIODIC_STR;
287 case SYNC_AGENT_SYNC_MODE_PUSH:
288 sync_mode_str = SYNC_MODE_PUSH_STR;
295 return sync_mode_str;
298 static char * _convert_sync_type_str(sync_agent_ds_sync_type_e sync_type)
302 char* sync_type_str = NULL;
304 _DEBUG_INFO("sync_type : [%d]",sync_type);
306 case SYNC_AGENT_SYNC_TYPE_FULL_SYNC:
307 sync_type_str = SYNC_TYPE_SLOW_SYNC_STR;
309 case SYNC_AGENT_SYNC_TYPE_UPDATE_BOTH:
310 sync_type_str = SYNC_TYPE_TWO_WAY_STR;
312 case SYNC_AGENT_SYNC_TYPE_UPDATE_TO_SERVER:
313 sync_type_str = SYNC_TYPE_ONE_WAY_FROM_CLIENT_STR;
315 case SYNC_AGENT_SYNC_TYPE_UPDATE_TO_PHONE:
316 sync_type_str = SYNC_TYPE_ONE_WAY_FROM_SERVER_STR;
318 case SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_SERVER:
319 sync_type_str = SYNC_TYPE_REFRESH_FROM_SERVER_STR;
321 case SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_PHONE:
322 sync_type_str = SYNC_TYPE_REFRESH_FROM_CLIENT_STR;
329 return sync_type_str;
332 static char * _convert_sync_interval_str(sync_agent_ds_sync_interval_e interval)
336 char* interval_str = NULL;
338 _DEBUG_INFO("interval : [%d]",interval);
340 case SYNC_AGENT_SYNC_INTERVAL_5_MINUTES:
341 interval_str = SYNC_INTERVAL_5_MINUTES;
343 case SYNC_AGENT_SYNC_INTERVAL_15_MINUTES:
344 interval_str = SYNC_INTERVAL_15_MINUTES;
346 case SYNC_AGENT_SYNC_INTERVAL_1_HOUR:
347 interval_str = SYNC_INTERVAL_1_HOUR;
349 case SYNC_AGENT_SYNC_INTERVAL_4_HOURS:
350 interval_str = SYNC_INTERVAL_4_HOURS;
352 case SYNC_AGENT_SYNC_INTERVAL_12_HOURS:
353 interval_str = SYNC_INTERVAL_12_HOURS;
355 case SYNC_AGENT_SYNC_INTERVAL_1_DAY:
356 interval_str = SYNC_INTERVAL_1_DAY;
358 case SYNC_AGENT_SYNC_INTERVAL_1_WEEK:
359 interval_str = SYNC_INTERVAL_1_WEEK;
361 case SYNC_AGENT_SYNC_INTERVAL_1_MONTH:
362 interval_str = SYNC_INTERVAL_1_MONTH;
365 interval_str = SYNC_INTERVAL_NONE;
373 static char * _convert_src_uri_str(sync_agent_ds_src_uri_e src_uri)
377 char* src_uri_str = NULL;
379 _DEBUG_INFO("src_uri : [%d]",src_uri);
381 case SYNC_AGENT_SRC_URI_CONTACT:
382 src_uri_str = SRC_URI_CONTACT_STR;
384 case SYNC_AGENT_SRC_URI_CALENDAR:
385 src_uri_str = SRC_URI_CALENDAR_STR;
395 static void _free_sync_category_info(sync_agent_ds_service_info * data)
397 g_free(data->tgt_uri);
399 g_free(data->password);
402 static gboolean _is_existing_profile(void)
406 int event_type = SYNC_AGENT_DS_GET_ALL_PROFILES;
407 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
408 sync_agent_event_data_s *request_event = NULL;
409 sync_agent_event_data_s *response_event = NULL;
411 int profile_count = 0;
413 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
415 /* create empty event packet */
416 request_event = sync_agent_create_event(event_type);
417 if (request_event == NULL) {
418 _DEBUG_ERROR("event is NULL");
420 return SYNC_AGENT_DS_FAIL;
423 /* send event request to ds agent daemon, waiting for response */
424 response_event = sync_agent_send_event(request_event, &error);
425 if (error != SYNC_AGENT_EVENT_SUCCESS) {
426 _DEBUG_ERROR("error = %d", error);
427 sync_agent_free_event(request_event);
429 return SYNC_AGENT_DS_FAIL;
431 if (response_event == NULL) {
432 _DEBUG_ERROR("response_event is null!!");
433 sync_agent_free_event(request_event);
435 return SYNC_AGENT_DS_FAIL;
438 sync_agent_get_event_data_param_int(response_event, &api_result);
439 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
440 _DEBUG_ERROR("api_result = failed");
441 sync_agent_free_event(request_event);
442 sync_agent_free_event_data(response_event);
444 return SYNC_AGENT_DS_FAIL;
447 sync_agent_get_event_data_param_int(response_event, &profile_count);
448 _DEBUG_INFO("profile_count = %d", profile_count);
450 if (profile_count > 0) {
451 sync_agent_free_event(request_event);
452 sync_agent_free_event_data(response_event);
458 /* free request & response event */
459 sync_agent_free_event(request_event);
460 sync_agent_free_event_data(response_event);
467 static int _launch_omads_agent(void)
470 GError *error = NULL;
472 DBusGConnection *connection = NULL;
473 DBusGProxy *dbus_proxy = NULL;
477 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
479 _DEBUG_ERROR("dbus_g_bus_get failed: %s\n", error->message);
485 dbus_proxy = dbus_g_proxy_new_for_name(connection, "com.samsung.omadsagent",
486 "/com/samsung/omadsagent", "com.samsung.omadsagent");
488 _DEBUG_INFO("dbus_proxy %x", dbus_proxy);
490 //dbus_g_proxy_call_no_reply(dbus_proxy, "Hello_Agent", G_TYPE_INVALID);
491 dbus_g_proxy_call(dbus_proxy, "Hello_Agent", &error, G_TYPE_INVALID, G_TYPE_INVALID);
493 g_object_unref(dbus_proxy);
494 dbus_g_connection_unref(connection);
500 static int _kill_omads_agent(void)
503 GError *error = NULL;
505 DBusGConnection *connection = NULL;
506 DBusGProxy *dbus_proxy = NULL;
507 gboolean isExisting = FALSE;
509 isExisting = _is_existing_profile();
512 _DEBUG_INFO("Existing profile !!");
518 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
520 _DEBUG_ERROR("dbus_g_bus_get failed: %s\n", error->message);
526 dbus_proxy = dbus_g_proxy_new_for_name(connection, "com.samsung.omadsagent",
527 "/com/samsung/omadsagent", "com.samsung.omadsagent");
529 _DEBUG_INFO("dbus_proxy %x", dbus_proxy);
531 dbus_g_proxy_call_no_reply(dbus_proxy, "Goodbye_Agent", G_TYPE_INVALID);
533 g_object_unref(dbus_proxy);
534 dbus_g_connection_unref(connection);
540 EXPORT_API sync_agent_ds_error_e sync_agent_ds_init()
544 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
545 sync_agent_init_error_e init_error = SYNC_AGENT_INIT_SUCCESS;
549 _DEBUG_INFO("before sysman_get_pid");
550 pid = sysman_get_pid(tzplatform_mkpath(TZ_SYS_BIN,"oma-ds-agent"));
551 _DEBUG_INFO("oma-ds-agent pid [%d]", pid);
554 ret = _launch_omads_agent();
556 _DEBUG_ERROR("_launch_omads_agent() failed !!");
557 result = SYNC_AGENT_DS_FAIL;
564 init_error = sync_agent_init(OMA_DS_CONFIG_FILE);
566 if (init_error != SYNC_AGENT_INIT_SUCCESS) {
567 _DEBUG_ERROR("ds init failed");
568 result = SYNC_AGENT_DS_FAIL;
571 sync_agent_event_error_e err = sync_agent_run_noti_listener("omads");
572 if (err != SYNC_AGENT_EVENT_SUCCESS) {
573 _DEBUG_ERROR("RUN NOTILISTNER is failed");
574 result = SYNC_AGENT_DS_FAIL;
582 EXPORT_API sync_agent_ds_error_e sync_agent_ds_create_profile_info(ds_profile_h * profile_h)
586 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
587 sync_agent_ds_profile_info *profile_info = NULL;
589 // allocate memory for ds profile info
590 profile_info = (sync_agent_ds_profile_info *) calloc(1, sizeof(sync_agent_ds_profile_info));
591 if (profile_info == NULL) {
592 _DEBUG_ERROR("calloc failed !!");
593 return SYNC_AGENT_DS_FAIL;
595 // pass memory pointer to ds profile handle
596 *profile_h = profile_info;
603 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_profile_dir_name(ds_profile_h profile_h, char *profile_dir_name)
607 // check mandatory parameter
608 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
609 retvm_if(profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
611 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
612 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
615 profile_info->profile_dir_name = g_strdup(profile_dir_name);
617 if (profile_info->profile_dir_name == NULL) {
618 _DEBUG_ERROR("g_strdup failed !!");
619 return SYNC_AGENT_DS_FAIL;
627 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_profile_name(ds_profile_h profile_h, char *profile_name)
631 // check mandatory parameter
632 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
633 retvm_if(profile_name == NULL, SYNC_AGENT_DS_FAIL, "profile_name is null!!");
635 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
636 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
639 profile_info->profile_name = g_strdup(profile_name);
641 _DEBUG_INFO("profile_name: [%s]",profile_name);
643 if (profile_info->profile_name == NULL) {
644 _DEBUG_ERROR("g_strdup failed !!");
645 return SYNC_AGENT_DS_FAIL;
653 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_server_info(ds_profile_h profile_h, char *addr, char *id, char *password)
657 // check mandatory parameter
658 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
659 retvm_if(addr == NULL, SYNC_AGENT_DS_FAIL, "addr is null!!");
660 retvm_if(id == NULL, SYNC_AGENT_DS_FAIL, "id is null!!");
661 retvm_if(password == NULL, SYNC_AGENT_DS_FAIL, "password is null!!");
663 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
664 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
665 sync_agent_ds_server_info *server_info = &profile_info->server_info;
668 server_info->addr = g_strdup(addr);
669 server_info->id = g_strdup(id);
670 server_info->password = g_strdup(password);
672 _DEBUG_INFO("addr: [%s]",addr);
673 _DEBUG_INFO("id: [%s]",id);
674 _DEBUG_INFO("password: [%s]",password);
676 if ((server_info->addr == NULL)
677 || (server_info->id == NULL)
678 || (server_info->password == NULL)) {
679 _DEBUG_ERROR("g_strdup failed !!");
680 return SYNC_AGENT_DS_FAIL;
688 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)
692 // check mandatory parameter
693 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
694 retvm_if(sync_mode < 0, SYNC_AGENT_DS_FAIL, "sync_mode is invalid!!");
695 retvm_if(sync_type < 0, SYNC_AGENT_DS_FAIL, "sync_type is invalid!!");
696 retvm_if(interval < 0, SYNC_AGENT_DS_FAIL, "interval is invalid!!");
698 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
699 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
700 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
702 char* sync_mode_str = NULL;
703 char* sync_type_str = NULL;
704 char* interval_str = NULL;
706 sync_mode_str = _convert_sync_mode_str(sync_mode);
707 if (sync_mode_str == NULL) {
708 _DEBUG_ERROR("_convert_sync_mode_str failed !!");
710 return SYNC_AGENT_DS_FAIL;
713 sync_type_str = _convert_sync_type_str(sync_type);
714 if (sync_type_str == NULL) {
715 _DEBUG_ERROR("_convert_sync_type_str failed !!");
717 return SYNC_AGENT_DS_FAIL;
720 interval_str = _convert_sync_interval_str(interval);
721 if (interval_str == NULL) {
722 _DEBUG_ERROR("_convert_sync_interval_str failed !!");
724 return SYNC_AGENT_DS_FAIL;
728 sync_info->sync_mode = sync_mode;
729 sync_info->sync_type = sync_type;
730 sync_info->interval = interval;
732 _DEBUG_INFO("sync_mode: [%d]",sync_mode);
733 _DEBUG_INFO("sync_type: [%d]",sync_type);
734 _DEBUG_INFO("interval: [%d]",interval);
741 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)
745 // check mandatory parameter
746 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
747 retvm_if(src_uri < 0, SYNC_AGENT_DS_FAIL, "src_uri is invalid!!");
749 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
750 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
751 sync_agent_ds_service_info *category_info = NULL;
752 char* src_uri_str = NULL;
754 src_uri_str = _convert_src_uri_str(src_uri);
755 if (src_uri_str == NULL) {
756 _DEBUG_ERROR("_get_src_uri_string failed !!");
758 return SYNC_AGENT_DS_FAIL;
761 // allocate memory for sync_category
762 category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
763 retvm_if(category_info == NULL, SYNC_AGENT_DS_FAIL, "calloc failed");
764 category_info->service_type = service_type;
765 category_info->enabled = enabled;
766 category_info->src_uri = src_uri;
767 category_info->tgt_uri = g_strdup(tgt_uri);
769 _DEBUG_INFO("service_type: [%d]",service_type);
770 _DEBUG_INFO("enabled: [%d]",enabled);
771 _DEBUG_INFO("src_uri: [%d]",src_uri);
772 _DEBUG_INFO("tgt_uri: [%s]",tgt_uri);
774 profile_info->service_list = g_list_append(profile_info->service_list, category_info);
781 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_id(ds_profile_h profile_h, int *profile_id)
785 // check mandatory parameter
786 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
788 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
790 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
792 *profile_id = profile_info->profile_id;
794 if (*profile_id < 1) {
795 _DEBUG_ERROR("profile_id is invalid!!");
796 return SYNC_AGENT_DS_FAIL;
799 _DEBUG_INFO("profile_id = %d", *profile_id);
806 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_dir_name(ds_profile_h profile_h, char **profile_dir_name)
810 // check mandatory parameter
811 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
813 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
815 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
817 *profile_dir_name = g_strdup(profile_info->profile_dir_name);
819 if (*profile_dir_name == NULL) {
820 _DEBUG_ERROR("g_strdup failed !!");
821 return SYNC_AGENT_DS_FAIL;
824 _DEBUG_INFO("profile_dir_name = %s", *profile_dir_name);
831 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_name(ds_profile_h profile_h, char **profile_name)
835 // check mandatory parameter
836 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
838 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
840 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
842 *profile_name = g_strdup(profile_info->profile_name);
844 if (*profile_name == NULL) {
845 _DEBUG_ERROR("g_strdup failed !!");
846 return SYNC_AGENT_DS_FAIL;
849 _DEBUG_INFO("profile_name = %s", *profile_name);
856 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)
860 // check mandatory parameter
861 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
862 retvm_if(server_info == NULL, SYNC_AGENT_DS_FAIL, "server_info is null!!");
864 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
865 sync_agent_ds_server_info *ds_server_info = &profile_info->server_info;
867 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
869 server_info->addr = g_strdup(ds_server_info->addr);
870 server_info->id = g_strdup(ds_server_info->id);
871 server_info->password = g_strdup(ds_server_info->password);
873 if ((server_info->addr == NULL)
874 || (server_info->id == NULL)
875 || (server_info->password == NULL)) {
876 _DEBUG_ERROR("g_strdup failed !!");
877 return SYNC_AGENT_DS_FAIL;
880 _DEBUG_INFO("get_addr = %s", server_info->addr);
881 _DEBUG_INFO("get_id = %s", server_info->id);
882 _DEBUG_INFO("get_password = %s", server_info->password);
889 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)
893 // check mandatory parameter
894 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
895 retvm_if(sync_info == NULL, SYNC_AGENT_DS_FAIL, "sync_info is null!!");
897 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
898 sync_agent_ds_sync_info *ds_sync_info = &profile_info->sync_info;
900 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
902 sync_info->sync_mode = ds_sync_info->sync_mode;
903 sync_info->sync_type = ds_sync_info->sync_type;
904 sync_info->interval = ds_sync_info->interval;
906 _DEBUG_INFO("get_sync_mode = %d", sync_info->sync_mode);
907 _DEBUG_INFO("get_sync_type = %d", sync_info->sync_type);
908 _DEBUG_INFO("get_interval = %d", sync_info->interval);
910 if (sync_info->sync_mode < 0) {
911 _DEBUG_ERROR("sync_mode is invalid !!");
914 if (sync_info->sync_type < 0) {
915 _DEBUG_ERROR("sync_type is invalid !!");
918 if (sync_info->interval < 0) {
919 _DEBUG_ERROR("interval is invalid !!");
927 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_service_info(ds_profile_h profile_h, GList ** category_list)
931 // check mandatory parameter
932 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
934 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
936 int category_count = 0;
938 sync_agent_ds_service_info *category_info = NULL;
940 *category_list = g_list_copy(profile_info->service_list);
942 if (*category_list == NULL) {
943 _DEBUG_ERROR("category_list is NULL!!");
946 category_count = g_list_length(*category_list);
947 _DEBUG_INFO("category_count: [%d]", category_count);
949 for (; i < category_count; i++) {
950 category_info = (sync_agent_ds_service_info *) g_list_nth_data(*category_list, i);
952 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
953 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
954 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
955 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
956 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
961 return SYNC_AGENT_DS_SUCCESS;
964 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_statistics(ds_profile_h profile_h, GList ** statistics_list)
968 // check mandatory parameter
969 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
971 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
972 sync_agent_ds_statistics_info *statistics = NULL;
974 gboolean result_sync_category = FALSE;
976 /* get last contacts sync result */
977 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_CONTACTS, &statistics);
978 if (result_sync_category)
979 *statistics_list = g_list_append(*statistics_list, statistics);
981 /* get last schedule sync result */
983 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_SCHEDULE, &statistics);
984 if (result_sync_category)
985 *statistics_list = g_list_append(*statistics_list, statistics);
987 /* get last memo sync result */
989 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_MEMO, &statistics);
990 if (result_sync_category)
991 *statistics_list = g_list_append(*statistics_list, statistics);
995 return SYNC_AGENT_DS_SUCCESS;
998 EXPORT_API sync_agent_ds_error_e sync_agent_ds_add_profile(ds_profile_h profile_h, int *profile_id)
1002 // check mandatory parameter
1003 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1005 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1006 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1007 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1008 GList *list = profile_info->service_list;
1010 int event_type = SYNC_AGENT_DS_ADD_PROFILE;
1011 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1012 sync_agent_event_data_s *request_event = NULL;
1013 sync_agent_event_data_s *response_event = NULL;
1016 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1017 sync_agent_ds_service_info *category_info = NULL;
1018 int category_count = 0;
1020 int profile_name_len = 0;
1021 int server_addr_len = 0;
1022 int server_id_len = 0;
1023 int server_password_len = 0;
1025 /* create empty event packet */
1026 request_event = sync_agent_create_event(event_type);
1027 if (request_event == NULL) {
1028 _DEBUG_ERROR("event is NULL");
1030 return SYNC_AGENT_DS_FAIL;
1033 profile_name_len = strlen(profile_info->profile_name);
1034 server_addr_len = strlen(server_info->addr);
1035 server_id_len = strlen(server_info->id);
1036 server_password_len = strlen(server_info->password);
1038 if ((profile_name_len == 0) || (server_addr_len == 0) || (server_id_len == 0) || (server_password_len == 0)) {
1039 _DEBUG_ERROR("input value is invalid!!");
1040 _DEBUG_INFO("profile_info->profile_name: [%s]", profile_info->profile_name);
1041 _DEBUG_INFO("server_info->addr: [%s]", server_info->addr);
1042 _DEBUG_INFO("server_info->id: [%s]", server_info->id);
1043 _DEBUG_INFO("server_info->password: [%s]", server_info->password);
1044 sync_agent_free_event(request_event);
1047 return SYNC_AGENT_DS_FAIL;
1050 /* add request parameter to event packet */
1051 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
1052 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name);
1053 _DEBUG_INFO("addr = %s", server_info->addr);
1054 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr);
1055 _DEBUG_INFO("id = %s", server_info->id);
1056 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id);
1057 _DEBUG_INFO("password = %s", server_info->password);
1058 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password);
1059 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
1060 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_mode));
1061 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
1062 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_type));
1063 _DEBUG_INFO("interval = %d", sync_info->interval);
1064 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->interval));
1066 category_count = g_list_length(list);
1067 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count);
1069 for (; i < category_count; i++) {
1070 category_info = (sync_agent_ds_service_info *) g_list_nth_data(list, i);
1072 _DEBUG_INFO("category[%d]->service_type = %d", i, category_info->service_type);
1073 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->service_type));
1074 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
1075 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->enabled));
1076 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
1077 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->src_uri));
1078 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
1079 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri);
1080 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
1081 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id);
1082 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
1083 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password);
1086 /* send event request to ds agent daemon, waiting for response */
1087 response_event = sync_agent_send_event(request_event, &error);
1088 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1089 _DEBUG_ERROR("error = %d", error);
1090 sync_agent_free_event(request_event);
1092 return SYNC_AGENT_DS_FAIL;
1094 if (response_event == NULL) {
1095 _DEBUG_ERROR("response_event is null!!");
1096 sync_agent_free_event(request_event);
1098 return SYNC_AGENT_DS_FAIL;
1101 /* get response parameter from event packet */
1102 sync_agent_get_event_data_param_int(response_event, &api_result);
1104 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1105 _DEBUG_ERROR("api_result = failed");
1106 sync_agent_free_event(request_event);
1107 sync_agent_free_event_data(response_event);
1109 return SYNC_AGENT_DS_FAIL;
1112 sync_agent_get_event_data_param_int(response_event, &prof_id);
1114 _DEBUG_VERBOSE("profile_id = %d", prof_id);
1115 *profile_id = prof_id;
1117 /* free request & response event */
1118 sync_agent_free_event(request_event);
1119 sync_agent_free_event_data(response_event);
1123 return SYNC_AGENT_DS_SUCCESS;
1126 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile(int profile_id, ds_profile_h * profile_h)
1130 // check mandatory parameter
1131 retvm_if(profile_id < 1, SYNC_AGENT_DS_FAIL, "profile_id is invalid!!");
1133 int event_type = SYNC_AGENT_DS_GET_PROFILE;
1134 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1135 sync_agent_event_data_s *request_event = NULL;
1136 sync_agent_event_data_s *response_event = NULL;
1138 gboolean result_sync_category = FALSE;
1139 sync_agent_ds_error_e result = SYNC_AGENT_DS_FAIL;
1140 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1141 sync_agent_ds_service_info *category = NULL;
1143 //////////////////////////////////
1145 // Phase 1. get profile detail info
1147 /* create empty event packet */
1148 request_event = sync_agent_create_event(event_type);
1149 if (request_event == NULL) {
1150 _DEBUG_ERROR("event is NULL");
1152 return SYNC_AGENT_DS_FAIL;
1155 /* add request parameter to event packet */
1156 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &profile_id);
1157 _DEBUG_INFO("profile_id = %d", profile_id);
1159 /* send event request to ds agent daemon, waiting for response */
1160 response_event = sync_agent_send_event(request_event, &error);
1161 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1162 _DEBUG_ERROR("error = %d", error);
1163 sync_agent_free_event(request_event);
1165 return SYNC_AGENT_DS_FAIL;
1167 if (response_event == NULL) {
1168 _DEBUG_ERROR("response_event is null!!");
1169 sync_agent_free_event(request_event);
1171 return SYNC_AGENT_DS_FAIL;
1174 /* get response parameter from event packet */
1176 result = sync_agent_ds_create_profile_info(profile_h);
1177 if (result == SYNC_AGENT_DS_FAIL) {
1178 _DEBUG_ERROR("failed to create profile info!");
1179 sync_agent_free_event(request_event);
1180 sync_agent_free_event_data(response_event);
1184 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) (*profile_h);
1185 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1186 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1187 // GList * list = profile_info->category_list;
1189 sync_agent_get_event_data_param_int(response_event, &api_result);
1190 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1191 _DEBUG_ERROR("api_result = failed");
1192 sync_agent_free_event(request_event);
1193 sync_agent_free_event_data(response_event);
1195 return SYNC_AGENT_DS_FAIL;
1198 //profile_info->profile_dir_name = g_strdup(profile_dir_name);
1200 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_dir_name);
1201 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_name);
1202 sync_agent_get_event_data_param_str(response_event, &server_info->addr);
1203 sync_agent_get_event_data_param_str(response_event, &server_info->id);
1204 sync_agent_get_event_data_param_str(response_event, &server_info->password);
1205 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_mode);
1206 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_type);
1207 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->interval);
1208 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_status);
1209 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_time);
1211 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1212 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
1213 _DEBUG_INFO("addr = %s", server_info->addr);
1214 _DEBUG_INFO("id = %s", server_info->id);
1215 _DEBUG_INFO("password = %s", server_info->password);
1216 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
1217 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
1218 _DEBUG_INFO("interval = %d", sync_info->interval);
1219 _DEBUG_INFO("lastSyncStatus = %d\n", profile_info->last_sync_status);
1220 _DEBUG_INFO("lastSyncTime = %d\n", profile_info->last_sync_time);
1222 /* free request & response event */
1223 sync_agent_free_event(request_event);
1224 sync_agent_free_event_data(response_event);
1226 // Phase 2. get sync category info
1228 /* get contacts sync_category */
1229 result_sync_category = _get_sync_category(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_CONTACTS, &category);
1230 if (result_sync_category)
1231 profile_info->service_list = g_list_append(profile_info->service_list, category);
1233 /* get schedule sync_category */
1235 result_sync_category = _get_sync_category(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_SCHEDULE, &category);
1236 if (result_sync_category)
1237 profile_info->service_list = g_list_append(profile_info->service_list, category);
1241 return SYNC_AGENT_DS_SUCCESS;
1244 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_all_profile(GList ** profile_list)
1248 int event_type = SYNC_AGENT_DS_GET_ALL_PROFILES;
1249 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1250 sync_agent_event_data_s *request_event = NULL;
1251 sync_agent_event_data_s *response_event = NULL;
1253 ds_profile_h profile_h = NULL;
1254 sync_agent_ds_service_info *category_info = NULL;
1256 int profile_count = 0;
1257 int category_count = 0;
1259 sync_agent_ds_error_e result = SYNC_AGENT_DS_FAIL;
1260 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1262 /* create empty event packet */
1263 request_event = sync_agent_create_event(event_type);
1264 if (request_event == NULL) {
1265 _DEBUG_ERROR("event is NULL");
1267 return SYNC_AGENT_DS_FAIL;
1270 /* send event request to ds agent daemon, waiting for response */
1271 response_event = sync_agent_send_event(request_event, &error);
1272 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1273 _DEBUG_ERROR("error = %d", error);
1274 sync_agent_free_event(request_event);
1276 return SYNC_AGENT_DS_FAIL;
1278 if (response_event == NULL) {
1279 _DEBUG_ERROR("response_event is null!!");
1280 sync_agent_free_event(request_event);
1282 return SYNC_AGENT_DS_FAIL;
1285 sync_agent_get_event_data_param_int(response_event, &api_result);
1286 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1287 _DEBUG_ERROR("api_result = failed");
1288 sync_agent_free_event(request_event);
1289 sync_agent_free_event_data(response_event);
1291 return SYNC_AGENT_DS_FAIL;
1294 sync_agent_get_event_data_param_int(response_event, &profile_count);
1295 _DEBUG_INFO("profile_count = %d", profile_count);
1298 for (i = 0; i < profile_count; i++) {
1300 result = sync_agent_ds_create_profile_info(&profile_h);
1301 if (result == SYNC_AGENT_DS_FAIL) {
1302 _DEBUG_ERROR("failed to create profile info!");
1303 sync_agent_free_event(request_event);
1304 sync_agent_free_event_data(response_event);
1308 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1309 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1310 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1312 sync_agent_get_event_data_param_int(response_event, &profile_info->profile_id);
1313 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_dir_name);
1314 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_name);
1315 sync_agent_get_event_data_param_str(response_event, &server_info->addr);
1316 sync_agent_get_event_data_param_str(response_event, &server_info->id);
1317 sync_agent_get_event_data_param_str(response_event, &server_info->password);
1318 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_mode);
1319 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_type);
1320 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->interval);
1321 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_status);
1322 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_time);
1324 _DEBUG_INFO("profile_info->profile_id = %d", profile_info->profile_id);
1325 _DEBUG_INFO("profile_info->profile_dir_name = %s", profile_info->profile_dir_name);
1326 _DEBUG_INFO("profile_info->profile_name = %s", profile_info->profile_name);
1327 _DEBUG_INFO("profile_info->addr = %s", server_info->addr);
1328 _DEBUG_INFO("profile_info->id = %s", server_info->id);
1329 _DEBUG_INFO("profile_info->password = %s", server_info->password);
1330 _DEBUG_INFO("profile_info->sync_mode = %d", sync_info->sync_mode);
1331 _DEBUG_INFO("profile_info->sync_type = %d", sync_info->sync_type);
1332 _DEBUG_INFO("profile_info->interval = %d", sync_info->interval);
1333 _DEBUG_INFO("profile_info->lastSyncStatus = %d", profile_info->last_sync_status);
1334 _DEBUG_INFO("profile_info->lastSyncStatus = %d", profile_info->last_sync_status);
1336 sync_agent_get_event_data_param_int(response_event, &category_count);
1339 for (j = 0; j < category_count; j++) {
1341 category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
1342 if (category_info == NULL) {
1343 _DEBUG_ERROR("calloc failed");
1344 sync_agent_ds_free_profile_info(profile_h);
1345 sync_agent_free_event(request_event);
1346 sync_agent_free_event_data(response_event);
1350 sync_agent_get_event_data_param_int(response_event, (int*) &category_info->service_type);
1351 sync_agent_get_event_data_param_int(response_event, &category_info->enabled);
1352 sync_agent_get_event_data_param_int(response_event, (int*) &category_info->src_uri);
1353 sync_agent_get_event_data_param_str(response_event, &category_info->tgt_uri);
1354 sync_agent_get_event_data_param_str(response_event, &category_info->id);
1355 sync_agent_get_event_data_param_str(response_event, &category_info->password);
1357 _DEBUG_INFO("category_info->service_type = %d", category_info->service_type);
1358 _DEBUG_INFO("category_info->enabled = %d", category_info->enabled);
1359 _DEBUG_INFO("category_info->src_uri = %d", category_info->src_uri);
1360 _DEBUG_INFO("category_info->tgt_uri = %s", category_info->tgt_uri);
1361 _DEBUG_INFO("category_info->id = %s", category_info->id);
1362 _DEBUG_INFO("category_info->password = %s", category_info->password);
1364 profile_info->service_list = g_list_append(profile_info->service_list, category_info);
1365 category_info = NULL;
1368 *profile_list = g_list_append(*profile_list, profile_h);
1372 /* free request & response event */
1373 sync_agent_free_event(request_event);
1374 sync_agent_free_event_data(response_event);
1378 return SYNC_AGENT_DS_SUCCESS;
1381 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_last_sync_info(ds_profile_h profile_h, int *lastSyncStatus, int *lastSyncTime)
1385 // check mandatory parameter
1386 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1387 retvm_if(lastSyncStatus == NULL, SYNC_AGENT_DS_FAIL, "last session status is null!!");
1388 retvm_if(lastSyncTime == NULL, SYNC_AGENT_DS_FAIL, "last session time is null!!");
1390 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1392 *lastSyncStatus = profile_info->last_sync_status;
1393 *lastSyncTime = profile_info->last_sync_time;
1397 return SYNC_AGENT_DS_SUCCESS;
1400 EXPORT_API sync_agent_ds_error_e sync_agent_ds_update_profile(ds_profile_h profile_h)
1404 // check mandatory parameter
1405 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1407 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1408 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1409 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1410 GList *list = profile_info->service_list;
1412 int event_type = SYNC_AGENT_DS_UPDATE_PROFILE;
1413 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1414 sync_agent_event_data_s *request_event = NULL;
1415 sync_agent_event_data_s *response_event = NULL;
1417 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1418 sync_agent_ds_service_info *category_info = NULL;
1419 int category_count = 0;
1422 /* create empty event packet */
1423 request_event = sync_agent_create_event(event_type);
1424 if (request_event == NULL) {
1425 _DEBUG_ERROR("event is NULL");
1427 return SYNC_AGENT_DS_FAIL;
1430 /* add request parameter to event packet */
1431 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1432 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1433 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
1434 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name);
1435 _DEBUG_INFO("addr = %s", server_info->addr);
1436 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr);
1437 _DEBUG_INFO("id = %s", server_info->id);
1438 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id);
1439 _DEBUG_INFO("password = %s", server_info->password);
1440 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password);
1441 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
1442 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_mode));
1443 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
1444 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_type));
1445 _DEBUG_INFO("interval = %d", sync_info->interval);
1446 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->interval));
1448 category_count = g_list_length(list);
1449 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count);
1451 for (; i < category_count; i++) {
1452 category_info = (sync_agent_ds_service_info *) g_list_nth_data(list, i);
1454 _DEBUG_INFO("category[%d]->service_type = %d", i, category_info->service_type);
1455 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->service_type));
1456 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
1457 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->enabled));
1458 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
1459 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->src_uri));
1460 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
1461 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri);
1462 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
1463 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id);
1464 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
1465 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password);
1468 /* send event request to ds agent daemon, waiting for response */
1469 response_event = sync_agent_send_event(request_event, &error);
1470 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1471 _DEBUG_ERROR("error = %d", error);
1472 sync_agent_free_event(request_event);
1474 return SYNC_AGENT_DS_FAIL;
1476 if (response_event == NULL) {
1477 _DEBUG_ERROR("response_event is null!!");
1478 sync_agent_free_event(request_event);
1480 return SYNC_AGENT_DS_FAIL;
1483 /* get response parameter from event packet */
1484 sync_agent_get_event_data_param_int(response_event, &api_result);
1486 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1487 _DEBUG_ERROR("api_result = failed");
1488 sync_agent_free_event(request_event);
1489 sync_agent_free_event_data(response_event);
1491 return SYNC_AGENT_DS_FAIL;
1494 if (api_result ==SYNC_AGENT_DS_API_RESULT_SYNCHRONISING) {
1495 _DEBUG_ERROR("api_result = synchronising");
1496 sync_agent_free_event(request_event);
1497 sync_agent_free_event_data(response_event);
1499 return SYNC_AGENT_DS_SYNCHRONISING;
1502 /* free request & response event */
1503 sync_agent_free_event(request_event);
1504 sync_agent_free_event_data(response_event);
1508 return SYNC_AGENT_DS_SUCCESS;
1511 EXPORT_API sync_agent_ds_error_e sync_agent_ds_delete_profile(ds_profile_h profile_h)
1515 // check mandatory parameter
1516 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1518 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1520 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1522 int event_type = SYNC_AGENT_DS_DELETE_PROFILE;
1523 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1524 sync_agent_event_data_s *request_event = NULL;
1525 sync_agent_event_data_s *response_event = NULL;
1528 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1530 /* create empty event packet */
1531 request_event = sync_agent_create_event(event_type);
1532 if (request_event == NULL) {
1533 _DEBUG_ERROR("event is NULL");
1534 return SYNC_AGENT_DS_FAIL;
1537 /* add request parameter to event packet */
1538 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &count);
1540 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1541 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1543 /* send event request to ds agent daemon, waiting for response */
1544 response_event = sync_agent_send_event(request_event, &error);
1545 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1546 _DEBUG_ERROR("error = %d", error);
1547 sync_agent_free_event(request_event);
1549 return SYNC_AGENT_DS_FAIL;
1551 if (response_event == NULL) {
1552 _DEBUG_ERROR("response_event is null!!");
1553 sync_agent_free_event(request_event);
1555 return SYNC_AGENT_DS_FAIL;
1558 /* get response parameter from event packet */
1559 sync_agent_get_event_data_param_int(response_event, &api_result);
1561 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1562 _DEBUG_ERROR("api_result = failed");
1563 sync_agent_free_event(request_event);
1564 sync_agent_free_event_data(response_event);
1566 return SYNC_AGENT_DS_FAIL;
1569 if (api_result ==SYNC_AGENT_DS_API_RESULT_SYNCHRONISING) {
1570 _DEBUG_ERROR("api_result = synchronising");
1571 sync_agent_free_event(request_event);
1572 sync_agent_free_event_data(response_event);
1574 return SYNC_AGENT_DS_SYNCHRONISING;
1577 /* free request & response event */
1578 sync_agent_free_event(request_event);
1579 sync_agent_free_event_data(response_event);
1583 return SYNC_AGENT_DS_SUCCESS;
1586 EXPORT_API sync_agent_ds_error_e sync_agent_ds_start_sync(ds_profile_h profile_h)
1590 // check mandatory parameter
1591 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1593 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1595 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1597 int event_type = SYNC_AGENT_DS_START_SYNC;
1598 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1599 sync_agent_event_data_s *request_event = NULL;
1600 sync_agent_event_data_s *response_event = NULL;
1602 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1604 /* create empty event packet */
1605 request_event = sync_agent_create_event(event_type);
1606 if (request_event == NULL) {
1607 _DEBUG_ERROR("event is NULL");
1608 return SYNC_AGENT_DS_FAIL;
1611 /* add request parameter to event packet */
1612 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1614 /* send event request to ds agent daemon, waiting for response */
1615 response_event = sync_agent_send_event(request_event, &error);
1616 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1617 _DEBUG_ERROR("error = %d", error);
1618 sync_agent_free_event(request_event);
1620 return SYNC_AGENT_DS_FAIL;
1622 if (response_event == NULL) {
1623 _DEBUG_ERROR("response_event is null!!");
1624 sync_agent_free_event(request_event);
1626 return SYNC_AGENT_DS_FAIL;
1629 /* get response parameter from event packet */
1630 sync_agent_get_event_data_param_int(response_event, &api_result);
1632 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1633 _DEBUG_ERROR("api_result = failed");
1634 sync_agent_free_event(request_event);
1635 sync_agent_free_event_data(response_event);
1637 return SYNC_AGENT_DS_FAIL;
1640 /* free request & response event */
1641 sync_agent_free_event(request_event);
1642 sync_agent_free_event_data(response_event);
1646 return SYNC_AGENT_DS_SUCCESS;
1649 EXPORT_API sync_agent_ds_error_e sync_agent_ds_stop_sync(ds_profile_h profile_h)
1653 // check mandatory parameter
1654 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1656 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1658 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1660 int event_type = SYNC_AGENT_DS_STOP_SYNC;
1661 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1662 sync_agent_event_data_s *request_event = NULL;
1663 sync_agent_event_data_s *response_event = NULL;
1665 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1667 /* create empty event packet */
1668 request_event = sync_agent_create_event(event_type);
1669 if (request_event == NULL) {
1670 _DEBUG_ERROR("event is NULL");
1671 return SYNC_AGENT_DS_FAIL;
1674 /* add request parameter to event packet */
1675 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1677 /* send event request to ds agent daemon, waiting for response */
1678 response_event = sync_agent_send_event(request_event, &error);
1679 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1680 _DEBUG_ERROR("error = %d", error);
1681 sync_agent_free_event(request_event);
1683 return SYNC_AGENT_DS_FAIL;
1685 if (response_event == NULL) {
1686 _DEBUG_ERROR("response_event is null!!");
1687 sync_agent_free_event(request_event);
1689 return SYNC_AGENT_DS_FAIL;
1692 /* get response parameter from event packet */
1693 sync_agent_get_event_data_param_int(response_event, &api_result);
1695 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1696 _DEBUG_ERROR("api_result = failed");
1697 sync_agent_free_event(request_event);
1698 sync_agent_free_event_data(response_event);
1700 return SYNC_AGENT_DS_FAIL;
1703 /* free request & response event */
1704 sync_agent_free_event(request_event);
1705 sync_agent_free_event_data(response_event);
1709 return SYNC_AGENT_DS_SUCCESS;
1712 EXPORT_API void sync_agent_ds_free_profile_info(ds_profile_h profile_h)
1716 // check mandatory parameter
1717 retm_if(profile_h == NULL, "profile handle is null!!");
1719 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1721 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1722 //sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1723 GList *category_list = profile_info->service_list;
1725 // free profile name
1726 g_free(profile_info->profile_dir_name);
1727 g_free(profile_info->profile_name);
1729 // free server information
1730 g_free(server_info->addr);
1731 g_free(server_info->id);
1732 g_free(server_info->password);
1734 // free sync category information
1735 g_list_free_full(category_list, (GDestroyNotify) _free_sync_category_info);
1737 // free profile information
1738 g_free(profile_info);
1743 EXPORT_API sync_agent_ds_error_e sync_agent_ds_deinit()
1747 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
1748 sync_agent_deinit_error_e deinit = SYNC_AGENT_DEINIT_SUCCESS;
1751 ret = _kill_omads_agent();
1754 _DEBUG_ERROR("_kill_omads_agent() failed !!");
1755 result = SYNC_AGENT_DS_FAIL;
1761 deinit = sync_agent_deinit();
1762 if (deinit != SYNC_AGENT_DEINIT_SUCCESS) {
1763 _DEBUG_ERROR("sync_agent_clean_event_handler() failed !!");
1764 result = SYNC_AGENT_DS_FAIL;
1766 // if (err != SYNC_AGENT_EVENT_SUCCESS) {
1767 // sync_agent_event_error_e err = sync_agent_stop_noti_listener();
1768 // _DEBUG_INFO("STOP NOTILISTNER is failed");
1769 // result = SYNC_AGENT_DS_FAIL;
1772 // err = sync_agent_clean_event_handler();
1773 // if (err != SYNC_AGENT_EVENT_SUCCESS) {
1774 // _DEBUG_ERROR("sync_agent_clean_event_handler() failed !!");
1775 // result = SYNC_AGENT_DS_FAIL;
1783 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)
1787 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
1789 sync_agent_event_error_e err = sync_agent_set_noti_callback(type, callback, data);
1790 if (err != SYNC_AGENT_EVENT_SUCCESS) {
1791 _DEBUG_ERROR("failed sync_agent_set_noti_callback()");
1792 result = SYNC_AGENT_DS_FAIL;