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"
37 #define EXPORT_API __attribute__ ((visibility("default")))
40 #define OMA_DS_CONFIG_FILE "/usr/share/oma-ds-cfg/omadsUI_fw_config.xml"
42 #define SYNC_AGENT_DS_API_RESULT_FAILURE 0
43 #define SYNC_AGENT_DS_API_RESULT_SUCCESS 1
45 #define SYNC_TYPE_SLOW_SYNC_STR "Full"
46 #define SYNC_TYPE_TWO_WAY_STR "Update both"
47 #define SYNC_TYPE_ONE_WAY_FROM_CLIENT_STR "Update to server"
48 #define SYNC_TYPE_ONE_WAY_FROM_SERVER_STR "Update to phone"
49 #define SYNC_TYPE_REFRESH_FROM_SERVER_STR "Refresh from server"
50 #define SYNC_TYPE_REFRESH_FROM_CLIENT_STR "Refresh from phone"
52 #define SYNC_MODE_MANUAL_STR "Manual"
53 #define SYNC_MODE_PUSH_STR "Push"
54 #define SYNC_MODE_PERIODIC_STR "Periodic"
56 #define SYNC_INTERVAL_NONE "None"
57 #define SYNC_INTERVAL_5_MINUTES "5 minutes"
58 #define SYNC_INTERVAL_15_MINUTES "15 minutes"
59 #define SYNC_INTERVAL_1_HOUR "1 hour"
60 #define SYNC_INTERVAL_4_HOURS "4 hours"
61 #define SYNC_INTERVAL_12_HOURS "12 hours"
62 #define SYNC_INTERVAL_1_DAY "1 day"
63 #define SYNC_INTERVAL_1_WEEK "1 week"
64 #define SYNC_INTERVAL_1_MONTH "1 month"
66 #define SRC_URI_CONTACT_STR "Contacts"
67 #define SRC_URI_CALENDAR_STR "Organizer"
70 SYNC_AGENT_DS_ADD_PROFILE = 1,
71 SYNC_AGENT_DS_UPDATE_PROFILE = 2,
72 SYNC_AGENT_DS_DELETE_PROFILE = 3,
73 SYNC_AGENT_DS_START_SYNC = 4,
74 SYNC_AGENT_DS_STOP_SYNC = 5,
75 SYNC_AGENT_DS_GET_PROFILE = 6,
76 SYNC_AGENT_DS_GET_SYNC_CATEGORY = 7,
77 SYNC_AGENT_DS_GET_SYNC_STATISTICS = 8,
78 SYNC_AGENT_DS_GET_ALL_PROFILES = 9
79 } sync_agent_ds_event_e;
82 SYNC_AGENT_DS_SYNC_CONTACTS = 0,
83 SYNC_AGENT_DS_SYNC_SCHEDULE = 1,
84 SYNC_AGENT_DS_SYNC_MEMO = 2
85 } sync_agent_ds_sync_e;
87 static gboolean _get_sync_category(char *profile_dir_name, int service_type, sync_agent_ds_service_info ** service)
91 int event_type = SYNC_AGENT_DS_GET_SYNC_CATEGORY;
92 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
94 // check mandatory parameter
95 retvm_if(profile_dir_name == NULL, FALSE, "profile_dir_name is null!!");
96 retvm_if(service_type < 0, FALSE, "service_type is wrong!!");
98 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
99 sync_agent_event_data_s *request_event = NULL;
100 sync_agent_event_data_s *response_event = NULL;
102 /* create empty event packet */
103 request_event = sync_agent_create_event(event_type);
104 if (request_event == NULL) {
105 _DEBUG_ERROR("event is NULL");
110 /* add request parameter to event packet */
111 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
112 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &service_type);
114 /* send event request to ds agent daemon, waiting for response */
115 response_event = sync_agent_send_event(request_event, &error);
116 if (error != SYNC_AGENT_EVENT_SUCCESS) {
117 _DEBUG_ERROR("error = %d", error);
118 sync_agent_free_event(request_event);
122 if (response_event == NULL) {
123 _DEBUG_ERROR("response_event is null!!");
124 sync_agent_free_event(request_event);
129 *service = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
130 if (*service == NULL) {
131 _DEBUG_ERROR("calloc failed");
132 sync_agent_free_event(request_event);
133 sync_agent_free_event_data(response_event);
137 /* get response parameter from event packet */
139 sync_agent_get_event_data_param_int(response_event, &api_result);
140 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
141 _DEBUG_ERROR("api_result = failed");
142 sync_agent_free_event(request_event);
143 sync_agent_free_event_data(response_event);
145 return SYNC_AGENT_DS_FAIL;
148 sync_agent_get_event_data_param_int(response_event, &((*service)->enabled));
149 sync_agent_get_event_data_param_int(response_event, (int*) &((*service)->src_uri));
150 sync_agent_get_event_data_param_str(response_event, &((*service)->tgt_uri));
151 sync_agent_get_event_data_param_str(response_event, &((*service)->id));
152 sync_agent_get_event_data_param_str(response_event, &((*service)->password));
154 _DEBUG_TRACE("enabled = %d", (*service)->enabled);
155 _DEBUG_TRACE("src_uri = %d", (*service)->src_uri);
156 _DEBUG_TRACE("tgt_uri = %s", (*service)->tgt_uri);
157 _DEBUG_TRACE("id = %s", (*service)->id);
158 _DEBUG_TRACE("password = %s", (*service)->password);
160 /* free request & response event */
161 sync_agent_free_event(request_event);
162 sync_agent_free_event_data(response_event);
169 static gboolean _get_sync_statistics(char *profile_dir_name, int service_type, sync_agent_ds_statistics_info ** statistics)
173 int event_type = SYNC_AGENT_DS_GET_SYNC_STATISTICS;
174 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
176 // check mandatory parameter
177 retvm_if(profile_dir_name == NULL, FALSE, "profile_dir_name is null!!");
178 retvm_if(service_type < 0, FALSE, "service_type is wrong!!");
180 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
181 sync_agent_event_data_s *request_event = NULL;
182 sync_agent_event_data_s *response_event = NULL;
184 char *statistics_cat = NULL;
186 /* create empty event packet */
187 request_event = sync_agent_create_event(event_type);
188 if (request_event == NULL) {
189 _DEBUG_ERROR("event is NULL");
194 /* add request parameter to event packet */
195 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
196 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &service_type);
198 /* send event request to ds agent daemon, waiting for response */
199 response_event = sync_agent_send_event(request_event, &error);
200 if (error != SYNC_AGENT_EVENT_SUCCESS) {
201 _DEBUG_ERROR("error = %d", error);
202 sync_agent_free_event(request_event);
206 if (response_event == NULL) {
207 _DEBUG_ERROR("response_event is null!!");
208 sync_agent_free_event(request_event);
213 *statistics = (sync_agent_ds_statistics_info *) calloc(1, sizeof(sync_agent_ds_statistics_info));
214 if (*statistics == NULL) {
215 _DEBUG_ERROR("calloc failed");
216 sync_agent_free_event(request_event);
217 sync_agent_free_event_data(response_event);
221 /* get response parameter from event packet */
223 sync_agent_get_event_data_param_int(response_event, &api_result);
224 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
225 _DEBUG_ERROR("api_result = failed");
226 sync_agent_free_event(request_event);
227 sync_agent_free_event_data(response_event);
229 return SYNC_AGENT_DS_FAIL;
232 if (service_type == SYNC_AGENT_DS_SYNC_CONTACTS)
233 statistics_cat = "contacts";
234 else if (service_type == SYNC_AGENT_DS_SYNC_SCHEDULE)
235 statistics_cat = "schedule";
236 else if (service_type == SYNC_AGENT_DS_SYNC_MEMO)
237 statistics_cat = "memo";
239 sync_agent_get_event_data_param_str(response_event, &((*statistics)->dbsynced));
240 sync_agent_get_event_data_param_int(response_event, &((*statistics)->last_session_time));
241 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_total));
242 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_nrofadd));
243 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_nrofdelete));
244 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_nrofreplace));
245 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_total));
246 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_nrofadd));
247 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_nrofdelete));
248 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_nrofreplace));
250 _DEBUG_TRACE("%s dbSynced = %s", statistics_cat, (*statistics)->dbsynced);
251 _DEBUG_TRACE("%s lastSessionTime = %d", statistics_cat, (*statistics)->last_session_time);
252 _DEBUG_TRACE("%s server2Client_Total = %d", statistics_cat, (*statistics)->server2client_total);
253 _DEBUG_TRACE("%s server2Client_NrOrAdd = %d", statistics_cat, (*statistics)->server2client_nrofadd);
254 _DEBUG_TRACE("%s server2Client_NrOfDelete = %d", statistics_cat, (*statistics)->server2client_nrofdelete);
255 _DEBUG_TRACE("%s server2Client_NrOfReplace = %d", statistics_cat, (*statistics)->server2client_nrofreplace);
256 _DEBUG_TRACE("%s client2Server_Total = %d", statistics_cat, (*statistics)->client2server_total);
257 _DEBUG_TRACE("%s client2Server_NrOfAdd = %d", statistics_cat, (*statistics)->client2server_nrofadd);
258 _DEBUG_TRACE("%s client2Server_NrOfDelete = %d", statistics_cat, (*statistics)->client2server_nrofdelete);
259 _DEBUG_TRACE("%s client2Server_NrOfReplace = %d", statistics_cat, (*statistics)->client2server_nrofreplace);
261 /* free request & response event */
262 sync_agent_free_event(request_event);
263 sync_agent_free_event_data(response_event);
270 static char * _convert_sync_mode_str(sync_agent_ds_sync_mode_e sync_mode)
274 char* sync_mode_str = NULL;
276 _DEBUG_INFO("sync_mode : [%d]",sync_mode);
278 case SYNC_AGENT_SYNC_MODE_MANUAL:
279 sync_mode_str = SYNC_MODE_MANUAL_STR;
281 case SYNC_AGENT_SYNC_MODE_PERIODIC:
282 sync_mode_str = SYNC_MODE_PERIODIC_STR;
284 case SYNC_AGENT_SYNC_MODE_PUSH:
285 sync_mode_str = SYNC_MODE_PUSH_STR;
292 return sync_mode_str;
295 static char * _convert_sync_type_str(sync_agent_ds_sync_type_e sync_type)
299 char* sync_type_str = NULL;
301 _DEBUG_INFO("sync_type : [%d]",sync_type);
303 case SYNC_AGENT_SYNC_TYPE_FULL_SYNC:
304 sync_type_str = SYNC_TYPE_SLOW_SYNC_STR;
306 case SYNC_AGENT_SYNC_TYPE_UPDATE_BOTH:
307 sync_type_str = SYNC_TYPE_TWO_WAY_STR;
309 case SYNC_AGENT_SYNC_TYPE_UPDATE_TO_SERVER:
310 sync_type_str = SYNC_TYPE_ONE_WAY_FROM_CLIENT_STR;
312 case SYNC_AGENT_SYNC_TYPE_UPDATE_TO_PHONE:
313 sync_type_str = SYNC_TYPE_ONE_WAY_FROM_SERVER_STR;
315 case SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_SERVER:
316 sync_type_str = SYNC_TYPE_REFRESH_FROM_SERVER_STR;
318 case SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_PHONE:
319 sync_type_str = SYNC_TYPE_REFRESH_FROM_CLIENT_STR;
326 return sync_type_str;
329 static char * _convert_sync_interval_str(sync_agent_ds_sync_interval_e interval)
333 char* interval_str = NULL;
335 _DEBUG_INFO("interval : [%d]",interval);
337 case SYNC_AGENT_SYNC_INTERVAL_5_MINUTES:
338 interval_str = SYNC_INTERVAL_5_MINUTES;
340 case SYNC_AGENT_SYNC_INTERVAL_15_MINUTES:
341 interval_str = SYNC_INTERVAL_15_MINUTES;
343 case SYNC_AGENT_SYNC_INTERVAL_1_HOUR:
344 interval_str = SYNC_INTERVAL_1_HOUR;
346 case SYNC_AGENT_SYNC_INTERVAL_4_HOURS:
347 interval_str = SYNC_INTERVAL_4_HOURS;
349 case SYNC_AGENT_SYNC_INTERVAL_12_HOURS:
350 interval_str = SYNC_INTERVAL_12_HOURS;
352 case SYNC_AGENT_SYNC_INTERVAL_1_DAY:
353 interval_str = SYNC_INTERVAL_1_DAY;
355 case SYNC_AGENT_SYNC_INTERVAL_1_WEEK:
356 interval_str = SYNC_INTERVAL_1_WEEK;
358 case SYNC_AGENT_SYNC_INTERVAL_1_MONTH:
359 interval_str = SYNC_INTERVAL_1_MONTH;
362 interval_str = SYNC_INTERVAL_NONE;
370 static char * _convert_src_uri_str(sync_agent_ds_src_uri_e src_uri)
374 char* src_uri_str = NULL;
376 _DEBUG_INFO("src_uri : [%d]",src_uri);
378 case SYNC_AGENT_SRC_URI_CONTACT:
379 src_uri_str = SRC_URI_CONTACT_STR;
381 case SYNC_AGENT_SRC_URI_CALENDAR:
382 src_uri_str = SRC_URI_CALENDAR_STR;
392 static void _free_sync_category_info(sync_agent_ds_service_info * data)
394 g_free(data->tgt_uri);
396 g_free(data->password);
399 static gboolean _is_existing_profile(void)
403 int event_type = SYNC_AGENT_DS_GET_ALL_PROFILES;
404 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
405 sync_agent_event_data_s *request_event = NULL;
406 sync_agent_event_data_s *response_event = NULL;
408 int profile_count = 0;
410 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
412 /* create empty event packet */
413 request_event = sync_agent_create_event(event_type);
414 if (request_event == NULL) {
415 _DEBUG_ERROR("event is NULL");
417 return SYNC_AGENT_DS_FAIL;
420 /* send event request to ds agent daemon, waiting for response */
421 response_event = sync_agent_send_event(request_event, &error);
422 if (error != SYNC_AGENT_EVENT_SUCCESS) {
423 _DEBUG_ERROR("error = %d", error);
424 sync_agent_free_event(request_event);
426 return SYNC_AGENT_DS_FAIL;
428 if (response_event == NULL) {
429 _DEBUG_ERROR("response_event is null!!");
430 sync_agent_free_event(request_event);
432 return SYNC_AGENT_DS_FAIL;
435 sync_agent_get_event_data_param_int(response_event, &api_result);
436 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
437 _DEBUG_ERROR("api_result = failed");
438 sync_agent_free_event(request_event);
439 sync_agent_free_event_data(response_event);
441 return SYNC_AGENT_DS_FAIL;
444 sync_agent_get_event_data_param_int(response_event, &profile_count);
445 _DEBUG_INFO("profile_count = %d", profile_count);
447 if (profile_count > 0) {
448 sync_agent_free_event(request_event);
449 sync_agent_free_event_data(response_event);
455 /* free request & response event */
456 sync_agent_free_event(request_event);
457 sync_agent_free_event_data(response_event);
464 static int _launch_omads_agent(void)
467 GError *error = NULL;
469 DBusGConnection *connection = NULL;
470 DBusGProxy *dbus_proxy = NULL;
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 dbus_g_proxy_call(dbus_proxy, "Hello_Agent", &error, G_TYPE_INVALID, G_TYPE_INVALID);
490 g_object_unref(dbus_proxy);
491 dbus_g_connection_unref(connection);
497 static int _kill_omads_agent(void)
500 GError *error = NULL;
502 DBusGConnection *connection = NULL;
503 DBusGProxy *dbus_proxy = NULL;
504 gboolean isExisting = FALSE;
506 isExisting = _is_existing_profile();
509 _DEBUG_INFO("Existing profile !!");
515 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
517 _DEBUG_ERROR("dbus_g_bus_get failed: %s\n", error->message);
523 dbus_proxy = dbus_g_proxy_new_for_name(connection, "com.samsung.omadsagent",
524 "/com/samsung/omadsagent", "com.samsung.omadsagent");
526 _DEBUG_INFO("dbus_proxy %x", dbus_proxy);
528 dbus_g_proxy_call_no_reply(dbus_proxy, "Goodbye_Agent", G_TYPE_INVALID);
530 g_object_unref(dbus_proxy);
531 dbus_g_connection_unref(connection);
537 EXPORT_API sync_agent_ds_error_e sync_agent_ds_init()
541 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
542 sync_agent_init_error_e init_error = SYNC_AGENT_INIT_SUCCESS;
546 _DEBUG_INFO("before sysman_get_pid");
547 pid = sysman_get_pid("/usr/bin/oma-ds-agent");
548 _DEBUG_INFO("oma-ds-agent pid [%d]", pid);
551 ret = _launch_omads_agent();
553 _DEBUG_ERROR("_launch_omads_agent() failed !!");
554 result = SYNC_AGENT_DS_FAIL;
561 init_error = sync_agent_init(OMA_DS_CONFIG_FILE);
563 if (init_error != SYNC_AGENT_INIT_SUCCESS) {
564 _DEBUG_ERROR("ds init failed");
565 result = SYNC_AGENT_DS_FAIL;
568 sync_agent_event_error_e err = sync_agent_run_noti_listener("omads");
569 if (err != SYNC_AGENT_EVENT_SUCCESS) {
570 _DEBUG_ERROR("RUN NOTILISTNER is failed");
571 result = SYNC_AGENT_DS_FAIL;
579 EXPORT_API sync_agent_ds_error_e sync_agent_ds_create_profile_info(ds_profile_h * profile_h)
583 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
584 sync_agent_ds_profile_info *profile_info = NULL;
586 // allocate memory for ds profile info
587 profile_info = (sync_agent_ds_profile_info *) calloc(1, sizeof(sync_agent_ds_profile_info));
588 if (profile_info == NULL) {
589 _DEBUG_ERROR("calloc failed !!");
590 return SYNC_AGENT_DS_FAIL;
592 // pass memory pointer to ds profile handle
593 *profile_h = profile_info;
600 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_profile_dir_name(ds_profile_h profile_h, char *profile_dir_name)
604 // check mandatory parameter
605 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
606 retvm_if(profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
608 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
609 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
612 profile_info->profile_dir_name = g_strdup(profile_dir_name);
614 if (profile_info->profile_dir_name == NULL) {
615 _DEBUG_ERROR("g_strdup failed !!");
616 return SYNC_AGENT_DS_FAIL;
624 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_profile_name(ds_profile_h profile_h, char *profile_name)
628 // check mandatory parameter
629 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
630 retvm_if(profile_name == NULL, SYNC_AGENT_DS_FAIL, "profile_name is null!!");
632 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
633 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
636 profile_info->profile_name = g_strdup(profile_name);
638 if (profile_info->profile_name == NULL) {
639 _DEBUG_ERROR("g_strdup failed !!");
640 return SYNC_AGENT_DS_FAIL;
648 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_server_info(ds_profile_h profile_h, char *addr, char *id, char *password)
652 // check mandatory parameter
653 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
654 retvm_if(addr == NULL, SYNC_AGENT_DS_FAIL, "addr is null!!");
655 retvm_if(id == NULL, SYNC_AGENT_DS_FAIL, "id is null!!");
656 retvm_if(password == NULL, SYNC_AGENT_DS_FAIL, "password is null!!");
658 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
659 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
660 sync_agent_ds_server_info *server_info = &profile_info->server_info;
663 server_info->addr = g_strdup(addr);
664 server_info->id = g_strdup(id);
665 server_info->password = g_strdup(password);
667 if ((server_info->addr == NULL)
668 || (server_info->id == NULL)
669 || (server_info->password == NULL)) {
670 _DEBUG_ERROR("g_strdup failed !!");
671 return SYNC_AGENT_DS_FAIL;
679 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)
683 // check mandatory parameter
684 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
685 retvm_if(sync_mode < 0, SYNC_AGENT_DS_FAIL, "sync_mode is invalid!!");
686 retvm_if(sync_type < 0, SYNC_AGENT_DS_FAIL, "sync_type is invalid!!");
687 retvm_if(interval < 0, SYNC_AGENT_DS_FAIL, "interval is invalid!!");
689 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
690 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
691 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
693 char* sync_mode_str = NULL;
694 char* sync_type_str = NULL;
695 char* interval_str = NULL;
697 sync_mode_str = _convert_sync_mode_str(sync_mode);
698 if (sync_mode_str == NULL) {
699 _DEBUG_ERROR("_convert_sync_mode_str failed !!");
701 return SYNC_AGENT_DS_FAIL;
704 sync_type_str = _convert_sync_type_str(sync_type);
705 if (sync_type_str == NULL) {
706 _DEBUG_ERROR("_convert_sync_type_str failed !!");
708 return SYNC_AGENT_DS_FAIL;
711 interval_str = _convert_sync_interval_str(interval);
712 if (interval_str == NULL) {
713 _DEBUG_ERROR("_convert_sync_interval_str failed !!");
715 return SYNC_AGENT_DS_FAIL;
719 sync_info->sync_mode = sync_mode;
720 sync_info->sync_type = sync_type;
721 sync_info->interval = interval;
728 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)
732 // check mandatory parameter
733 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
734 retvm_if(src_uri < 0, SYNC_AGENT_DS_FAIL, "src_uri is invalid!!");
736 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
737 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
738 sync_agent_ds_service_info *category_info = NULL;
739 char* src_uri_str = NULL;
741 src_uri_str = _convert_src_uri_str(src_uri);
742 if (src_uri_str == NULL) {
743 _DEBUG_ERROR("_get_src_uri_string failed !!");
745 return SYNC_AGENT_DS_FAIL;
748 // allocate memory for sync_category
749 category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
750 retvm_if(category_info == NULL, SYNC_AGENT_DS_FAIL, "calloc failed");
751 category_info->service_type = service_type;
752 category_info->enabled = enabled;
753 category_info->src_uri = src_uri;
754 category_info->tgt_uri = g_strdup(tgt_uri);
756 profile_info->service_list = g_list_append(profile_info->service_list, category_info);
763 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_id(ds_profile_h profile_h, int *profile_id)
767 // check mandatory parameter
768 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
770 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
772 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
774 *profile_id = profile_info->profile_id;
776 if (*profile_id < 1) {
777 _DEBUG_ERROR("profile_id is invalid!!");
778 return SYNC_AGENT_DS_FAIL;
781 _DEBUG_INFO("profile_id = %d", *profile_id);
788 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_dir_name(ds_profile_h profile_h, char **profile_dir_name)
792 // check mandatory parameter
793 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
795 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
797 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
799 *profile_dir_name = g_strdup(profile_info->profile_dir_name);
801 if (*profile_dir_name == NULL) {
802 _DEBUG_ERROR("g_strdup failed !!");
803 return SYNC_AGENT_DS_FAIL;
806 _DEBUG_INFO("profile_dir_name = %s", *profile_dir_name);
813 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_name(ds_profile_h profile_h, char **profile_name)
817 // check mandatory parameter
818 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
820 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
822 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
824 *profile_name = g_strdup(profile_info->profile_name);
826 if (*profile_name == NULL) {
827 _DEBUG_ERROR("g_strdup failed !!");
828 return SYNC_AGENT_DS_FAIL;
831 _DEBUG_INFO("profile_name = %s", *profile_name);
838 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)
842 // check mandatory parameter
843 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
844 retvm_if(server_info == NULL, SYNC_AGENT_DS_FAIL, "server_info is null!!");
846 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
847 sync_agent_ds_server_info *ds_server_info = &profile_info->server_info;
849 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
851 server_info->addr = g_strdup(ds_server_info->addr);
852 server_info->id = g_strdup(ds_server_info->id);
853 server_info->password = g_strdup(ds_server_info->password);
855 if ((server_info->addr == NULL)
856 || (server_info->id == NULL)
857 || (server_info->password == NULL)) {
858 _DEBUG_ERROR("g_strdup failed !!");
859 return SYNC_AGENT_DS_FAIL;
862 _DEBUG_INFO("get_addr = %s", server_info->addr);
863 _DEBUG_INFO("get_id = %s", server_info->id);
864 _DEBUG_INFO("get_password = %s", server_info->password);
871 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)
875 // check mandatory parameter
876 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
877 retvm_if(sync_info == NULL, SYNC_AGENT_DS_FAIL, "sync_info is null!!");
879 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
880 sync_agent_ds_sync_info *ds_sync_info = &profile_info->sync_info;
882 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
884 sync_info->sync_mode = ds_sync_info->sync_mode;
885 sync_info->sync_type = ds_sync_info->sync_type;
886 sync_info->interval = ds_sync_info->interval;
888 _DEBUG_INFO("get_sync_mode = %d", sync_info->sync_mode);
889 _DEBUG_INFO("get_sync_type = %d", sync_info->sync_type);
890 _DEBUG_INFO("get_interval = %d", sync_info->interval);
892 if (sync_info->sync_mode < 0) {
893 _DEBUG_ERROR("sync_mode is invalid !!");
894 return SYNC_AGENT_DS_FAIL;
897 if (sync_info->sync_type < 0) {
898 _DEBUG_ERROR("sync_type is invalid !!");
899 return SYNC_AGENT_DS_FAIL;
902 if (sync_info->interval < 0) {
903 _DEBUG_ERROR("interval is invalid !!");
904 return SYNC_AGENT_DS_FAIL;
912 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_service_info(ds_profile_h profile_h, GList ** category_list)
916 // check mandatory parameter
917 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
919 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
921 int category_count = 0;
923 sync_agent_ds_service_info *category_info = NULL;
925 *category_list = g_list_copy(profile_info->service_list);
927 if (*category_list == NULL) {
928 _DEBUG_ERROR("g_list_copy failed !!");
929 return SYNC_AGENT_DS_FAIL;
932 category_count = g_list_length(*category_list);
933 for (; i < category_count; i++) {
934 category_info = (sync_agent_ds_service_info *) g_list_nth_data(*category_list, i);
936 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
937 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
938 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
939 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
940 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
945 return SYNC_AGENT_DS_SUCCESS;
948 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_statistics(ds_profile_h profile_h, GList ** statistics_list)
952 // check mandatory parameter
953 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
955 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
956 sync_agent_ds_statistics_info *statistics = NULL;
958 gboolean result_sync_category = FALSE;
960 /* get last contacts sync result */
961 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_CONTACTS, &statistics);
962 if (result_sync_category)
963 *statistics_list = g_list_append(*statistics_list, statistics);
965 /* get last schedule sync result */
967 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_SCHEDULE, &statistics);
968 if (result_sync_category)
969 *statistics_list = g_list_append(*statistics_list, statistics);
971 /* get last memo sync result */
973 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_MEMO, &statistics);
974 if (result_sync_category)
975 *statistics_list = g_list_append(*statistics_list, statistics);
979 return SYNC_AGENT_DS_SUCCESS;
982 EXPORT_API sync_agent_ds_error_e sync_agent_ds_add_profile(ds_profile_h profile_h, int *profile_id)
986 // check mandatory parameter
987 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
989 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
990 sync_agent_ds_server_info *server_info = &profile_info->server_info;
991 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
992 GList *list = profile_info->service_list;
994 int event_type = SYNC_AGENT_DS_ADD_PROFILE;
995 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
996 sync_agent_event_data_s *request_event = NULL;
997 sync_agent_event_data_s *response_event = NULL;
1000 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1001 sync_agent_ds_service_info *category_info = NULL;
1002 int category_count = 0;
1005 /* create empty event packet */
1006 request_event = sync_agent_create_event(event_type);
1007 if (request_event == NULL) {
1008 _DEBUG_ERROR("event is NULL");
1010 return SYNC_AGENT_DS_FAIL;
1013 /* add request parameter to event packet */
1014 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
1015 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name);
1016 _DEBUG_INFO("addr = %s", server_info->addr);
1017 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr);
1018 _DEBUG_INFO("id = %s", server_info->id);
1019 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id);
1020 _DEBUG_INFO("password = %s", server_info->password);
1021 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password);
1022 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
1023 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_mode));
1024 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
1025 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_type));
1026 _DEBUG_INFO("interval = %d", sync_info->interval);
1027 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->interval));
1029 category_count = g_list_length(list);
1030 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count);
1032 for (; i < category_count; i++) {
1033 category_info = (sync_agent_ds_service_info *) g_list_nth_data(list, i);
1035 _DEBUG_INFO("category[%d]->service_type = %d", i, category_info->service_type);
1036 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->service_type));
1037 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
1038 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->enabled));
1039 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
1040 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->src_uri));
1041 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
1042 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri);
1043 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
1044 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id);
1045 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
1046 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password);
1049 /* send event request to ds agent daemon, waiting for response */
1050 response_event = sync_agent_send_event(request_event, &error);
1051 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1052 _DEBUG_ERROR("error = %d", error);
1053 sync_agent_free_event(request_event);
1055 return SYNC_AGENT_DS_FAIL;
1057 if (response_event == NULL) {
1058 _DEBUG_ERROR("response_event is null!!");
1059 sync_agent_free_event(request_event);
1061 return SYNC_AGENT_DS_FAIL;
1064 /* get response parameter from event packet */
1065 sync_agent_get_event_data_param_int(response_event, &api_result);
1067 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1068 _DEBUG_ERROR("api_result = failed");
1069 sync_agent_free_event(request_event);
1070 sync_agent_free_event_data(response_event);
1072 return SYNC_AGENT_DS_FAIL;
1075 sync_agent_get_event_data_param_int(response_event, &prof_id);
1077 _DEBUG_VERBOSE("profile_id = %d", prof_id);
1078 *profile_id = prof_id;
1080 /* free request & response event */
1081 sync_agent_free_event(request_event);
1082 sync_agent_free_event_data(response_event);
1086 return SYNC_AGENT_DS_SUCCESS;
1089 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile(int profile_id, ds_profile_h * profile_h)
1093 // check mandatory parameter
1094 retvm_if(profile_id < 1, SYNC_AGENT_DS_FAIL, "profile_id is invalid!!");
1096 int event_type = SYNC_AGENT_DS_GET_PROFILE;
1097 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1098 sync_agent_event_data_s *request_event = NULL;
1099 sync_agent_event_data_s *response_event = NULL;
1101 gboolean result_sync_category = FALSE;
1102 sync_agent_ds_error_e result = SYNC_AGENT_DS_FAIL;
1103 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1104 sync_agent_ds_service_info *category = NULL;
1106 //////////////////////////////////
1108 // Phase 1. get profile detail info
1110 /* create empty event packet */
1111 request_event = sync_agent_create_event(event_type);
1112 if (request_event == NULL) {
1113 _DEBUG_ERROR("event is NULL");
1115 return SYNC_AGENT_DS_FAIL;
1118 /* add request parameter to event packet */
1119 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &profile_id);
1120 _DEBUG_INFO("profile_id = %d", profile_id);
1122 /* send event request to ds agent daemon, waiting for response */
1123 response_event = sync_agent_send_event(request_event, &error);
1124 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1125 _DEBUG_ERROR("error = %d", error);
1126 sync_agent_free_event(request_event);
1128 return SYNC_AGENT_DS_FAIL;
1130 if (response_event == NULL) {
1131 _DEBUG_ERROR("response_event is null!!");
1132 sync_agent_free_event(request_event);
1134 return SYNC_AGENT_DS_FAIL;
1137 /* get response parameter from event packet */
1139 result = sync_agent_ds_create_profile_info(profile_h);
1140 if (result == SYNC_AGENT_DS_FAIL) {
1141 _DEBUG_ERROR("failed to create profile info!");
1142 sync_agent_free_event(request_event);
1143 sync_agent_free_event_data(response_event);
1147 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) (*profile_h);
1148 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1149 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1150 // GList * list = profile_info->category_list;
1152 sync_agent_get_event_data_param_int(response_event, &api_result);
1153 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1154 _DEBUG_ERROR("api_result = failed");
1155 sync_agent_free_event(request_event);
1156 sync_agent_free_event_data(response_event);
1158 return SYNC_AGENT_DS_FAIL;
1161 //profile_info->profile_dir_name = g_strdup(profile_dir_name);
1163 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_dir_name);
1164 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_name);
1165 sync_agent_get_event_data_param_str(response_event, &server_info->addr);
1166 sync_agent_get_event_data_param_str(response_event, &server_info->id);
1167 sync_agent_get_event_data_param_str(response_event, &server_info->password);
1168 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_mode);
1169 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_type);
1170 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->interval);
1171 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_status);
1172 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_time);
1174 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1175 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
1176 _DEBUG_INFO("addr = %s", server_info->addr);
1177 _DEBUG_INFO("id = %s", server_info->id);
1178 _DEBUG_INFO("password = %s", server_info->password);
1179 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
1180 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
1181 _DEBUG_INFO("interval = %d", sync_info->interval);
1182 _DEBUG_VERBOSE("lastSyncStatus = %d\n", profile_info->last_sync_status);
1183 _DEBUG_VERBOSE("lastSyncTime = %d\n", profile_info->last_sync_time);
1185 /* free request & response event */
1186 sync_agent_free_event(request_event);
1187 sync_agent_free_event_data(response_event);
1189 // Phase 2. get sync category info
1191 /* get contacts sync_category */
1192 result_sync_category = _get_sync_category(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_CONTACTS, &category);
1193 if (result_sync_category)
1194 profile_info->service_list = g_list_append(profile_info->service_list, category);
1196 /* get schedule sync_category */
1198 result_sync_category = _get_sync_category(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_SCHEDULE, &category);
1199 if (result_sync_category)
1200 profile_info->service_list = g_list_append(profile_info->service_list, category);
1204 return SYNC_AGENT_DS_SUCCESS;
1207 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_all_profile(GList ** profile_list)
1211 int event_type = SYNC_AGENT_DS_GET_ALL_PROFILES;
1212 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1213 sync_agent_event_data_s *request_event = NULL;
1214 sync_agent_event_data_s *response_event = NULL;
1216 ds_profile_h profile_h = NULL;
1217 sync_agent_ds_service_info *category_info = NULL;
1219 int profile_count = 0;
1220 int category_count = 0;
1222 sync_agent_ds_error_e result = SYNC_AGENT_DS_FAIL;
1223 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1225 /* create empty event packet */
1226 request_event = sync_agent_create_event(event_type);
1227 if (request_event == NULL) {
1228 _DEBUG_ERROR("event is NULL");
1230 return SYNC_AGENT_DS_FAIL;
1233 /* send event request to ds agent daemon, waiting for response */
1234 response_event = sync_agent_send_event(request_event, &error);
1235 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1236 _DEBUG_ERROR("error = %d", error);
1237 sync_agent_free_event(request_event);
1239 return SYNC_AGENT_DS_FAIL;
1241 if (response_event == NULL) {
1242 _DEBUG_ERROR("response_event is null!!");
1243 sync_agent_free_event(request_event);
1245 return SYNC_AGENT_DS_FAIL;
1248 sync_agent_get_event_data_param_int(response_event, &api_result);
1249 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1250 _DEBUG_ERROR("api_result = failed");
1251 sync_agent_free_event(request_event);
1252 sync_agent_free_event_data(response_event);
1254 return SYNC_AGENT_DS_FAIL;
1257 sync_agent_get_event_data_param_int(response_event, &profile_count);
1258 _DEBUG_INFO("profile_count = %d", profile_count);
1261 for (i = 0; i < profile_count; i++) {
1263 result = sync_agent_ds_create_profile_info(&profile_h);
1264 if (result == SYNC_AGENT_DS_FAIL) {
1265 _DEBUG_ERROR("failed to create profile info!");
1266 sync_agent_free_event(request_event);
1267 sync_agent_free_event_data(response_event);
1271 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1272 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1273 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1275 sync_agent_get_event_data_param_int(response_event, &profile_info->profile_id);
1276 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_dir_name);
1277 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_name);
1278 sync_agent_get_event_data_param_str(response_event, &server_info->addr);
1279 sync_agent_get_event_data_param_str(response_event, &server_info->id);
1280 sync_agent_get_event_data_param_str(response_event, &server_info->password);
1281 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_mode);
1282 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_type);
1283 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->interval);
1284 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_status);
1285 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_time);
1287 _DEBUG_INFO("profile_info->profile_id = %d", profile_info->profile_id);
1288 _DEBUG_INFO("profile_info->profile_dir_name = %s", profile_info->profile_dir_name);
1289 _DEBUG_INFO("profile_info->profile_name = %s", profile_info->profile_name);
1290 _DEBUG_INFO("profile_info->addr = %s", server_info->addr);
1291 _DEBUG_INFO("profile_info->id = %s", server_info->id);
1292 _DEBUG_INFO("profile_info->password = %s", server_info->password);
1293 _DEBUG_INFO("profile_info->sync_mode = %d", sync_info->sync_mode);
1294 _DEBUG_INFO("profile_info->sync_type = %d", sync_info->sync_type);
1295 _DEBUG_INFO("profile_info->interval = %d", sync_info->interval);
1296 _DEBUG_INFO("profile_info->lastSyncStatus = %d", profile_info->last_sync_status);
1297 _DEBUG_INFO("profile_info->lastSyncStatus = %d", profile_info->last_sync_status);
1299 sync_agent_get_event_data_param_int(response_event, &category_count);
1302 for (j = 0; j < category_count; j++) {
1304 category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
1305 if (category_info == NULL) {
1306 _DEBUG_ERROR("calloc failed");
1307 sync_agent_ds_free_profile_info(profile_h);
1308 sync_agent_free_event(request_event);
1309 sync_agent_free_event_data(response_event);
1313 sync_agent_get_event_data_param_int(response_event, (int*) &category_info->service_type);
1314 sync_agent_get_event_data_param_int(response_event, &category_info->enabled);
1315 sync_agent_get_event_data_param_int(response_event, (int*) &category_info->src_uri);
1316 sync_agent_get_event_data_param_str(response_event, &category_info->tgt_uri);
1317 sync_agent_get_event_data_param_str(response_event, &category_info->id);
1318 sync_agent_get_event_data_param_str(response_event, &category_info->password);
1320 _DEBUG_INFO("category_info->service_type = %d", category_info->service_type);
1321 _DEBUG_INFO("category_info->enabled = %d", category_info->enabled);
1322 _DEBUG_INFO("category_info->src_uri = %d", category_info->src_uri);
1323 _DEBUG_INFO("category_info->tgt_uri = %s", category_info->tgt_uri);
1324 _DEBUG_INFO("category_info->id = %s", category_info->id);
1325 _DEBUG_INFO("category_info->password = %s", category_info->password);
1327 profile_info->service_list = g_list_append(profile_info->service_list, category_info);
1328 category_info = NULL;
1331 *profile_list = g_list_append(*profile_list, profile_h);
1335 /* free request & response event */
1336 sync_agent_free_event(request_event);
1337 sync_agent_free_event_data(response_event);
1341 return SYNC_AGENT_DS_SUCCESS;
1344 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_last_sync_info(ds_profile_h profile_h, int *lastSyncStatus, int *lastSyncTime)
1348 // check mandatory parameter
1349 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1350 retvm_if(lastSyncStatus == NULL, SYNC_AGENT_DS_FAIL, "last session status is null!!");
1351 retvm_if(lastSyncTime == NULL, SYNC_AGENT_DS_FAIL, "last session time is null!!");
1353 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1355 *lastSyncStatus = profile_info->last_sync_status;
1356 *lastSyncTime = profile_info->last_sync_time;
1360 return SYNC_AGENT_DS_SUCCESS;
1363 EXPORT_API sync_agent_ds_error_e sync_agent_ds_update_profile(ds_profile_h profile_h)
1367 // check mandatory parameter
1368 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1370 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1371 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1372 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1373 GList *list = profile_info->service_list;
1375 int event_type = SYNC_AGENT_DS_UPDATE_PROFILE;
1376 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1377 sync_agent_event_data_s *request_event = NULL;
1378 sync_agent_event_data_s *response_event = NULL;
1380 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1381 sync_agent_ds_service_info *category_info = NULL;
1382 int category_count = 0;
1385 /* create empty event packet */
1386 request_event = sync_agent_create_event(event_type);
1387 if (request_event == NULL) {
1388 _DEBUG_ERROR("event is NULL");
1390 return SYNC_AGENT_DS_FAIL;
1393 /* add request parameter to event packet */
1394 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1395 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1396 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
1397 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name);
1398 _DEBUG_INFO("addr = %s", server_info->addr);
1399 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr);
1400 _DEBUG_INFO("id = %s", server_info->id);
1401 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id);
1402 _DEBUG_INFO("password = %s", server_info->password);
1403 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password);
1404 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
1405 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_mode));
1406 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
1407 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_type));
1408 _DEBUG_INFO("interval = %d", sync_info->interval);
1409 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->interval));
1411 category_count = g_list_length(list);
1412 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count);
1414 for (; i < category_count; i++) {
1415 category_info = (sync_agent_ds_service_info *) g_list_nth_data(list, i);
1417 _DEBUG_INFO("category[%d]->service_type = %d", i, category_info->service_type);
1418 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->service_type));
1419 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
1420 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->enabled));
1421 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
1422 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->src_uri));
1423 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
1424 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri);
1425 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
1426 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id);
1427 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
1428 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password);
1431 /* send event request to ds agent daemon, waiting for response */
1432 response_event = sync_agent_send_event(request_event, &error);
1433 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1434 _DEBUG_ERROR("error = %d", error);
1435 sync_agent_free_event(request_event);
1437 return SYNC_AGENT_DS_FAIL;
1439 if (response_event == NULL) {
1440 _DEBUG_ERROR("response_event is null!!");
1441 sync_agent_free_event(request_event);
1443 return SYNC_AGENT_DS_FAIL;
1446 /* get response parameter from event packet */
1447 sync_agent_get_event_data_param_int(response_event, &api_result);
1449 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1450 _DEBUG_ERROR("api_result = failed");
1451 sync_agent_free_event(request_event);
1452 sync_agent_free_event_data(response_event);
1454 return SYNC_AGENT_DS_FAIL;
1457 /* free request & response event */
1458 sync_agent_free_event(request_event);
1459 sync_agent_free_event_data(response_event);
1463 return SYNC_AGENT_DS_SUCCESS;
1466 EXPORT_API sync_agent_ds_error_e sync_agent_ds_delete_profile(ds_profile_h profile_h)
1470 // check mandatory parameter
1471 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1473 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1475 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1477 int event_type = SYNC_AGENT_DS_DELETE_PROFILE;
1478 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1479 sync_agent_event_data_s *request_event = NULL;
1480 sync_agent_event_data_s *response_event = NULL;
1483 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1485 /* create empty event packet */
1486 request_event = sync_agent_create_event(event_type);
1487 if (request_event == NULL) {
1488 _DEBUG_ERROR("event is NULL");
1489 return SYNC_AGENT_DS_FAIL;
1492 /* add request parameter to event packet */
1493 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &count);
1495 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1496 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1498 /* send event request to ds agent daemon, waiting for response */
1499 response_event = sync_agent_send_event(request_event, &error);
1500 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1501 _DEBUG_ERROR("error = %d", error);
1502 sync_agent_free_event(request_event);
1504 return SYNC_AGENT_DS_FAIL;
1506 if (response_event == NULL) {
1507 _DEBUG_ERROR("response_event is null!!");
1508 sync_agent_free_event(request_event);
1510 return SYNC_AGENT_DS_FAIL;
1513 /* get response parameter from event packet */
1514 sync_agent_get_event_data_param_int(response_event, &api_result);
1516 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1517 _DEBUG_ERROR("api_result = failed");
1518 sync_agent_free_event(request_event);
1519 sync_agent_free_event_data(response_event);
1521 return SYNC_AGENT_DS_FAIL;
1524 /* free request & response event */
1525 sync_agent_free_event(request_event);
1526 sync_agent_free_event_data(response_event);
1530 return SYNC_AGENT_DS_SUCCESS;
1533 EXPORT_API sync_agent_ds_error_e sync_agent_ds_start_sync(ds_profile_h profile_h)
1537 // check mandatory parameter
1538 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1540 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1542 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1544 int event_type = SYNC_AGENT_DS_START_SYNC;
1545 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1546 sync_agent_event_data_s *request_event = NULL;
1547 sync_agent_event_data_s *response_event = NULL;
1549 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1551 /* create empty event packet */
1552 request_event = sync_agent_create_event(event_type);
1553 if (request_event == NULL) {
1554 _DEBUG_ERROR("event is NULL");
1555 return SYNC_AGENT_DS_FAIL;
1558 /* add request parameter to event packet */
1559 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1561 /* send event request to ds agent daemon, waiting for response */
1562 response_event = sync_agent_send_event(request_event, &error);
1563 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1564 _DEBUG_ERROR("error = %d", error);
1565 sync_agent_free_event(request_event);
1567 return SYNC_AGENT_DS_FAIL;
1569 if (response_event == NULL) {
1570 _DEBUG_ERROR("response_event is null!!");
1571 sync_agent_free_event(request_event);
1573 return SYNC_AGENT_DS_FAIL;
1576 /* get response parameter from event packet */
1577 sync_agent_get_event_data_param_int(response_event, &api_result);
1579 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1580 _DEBUG_ERROR("api_result = failed");
1581 sync_agent_free_event(request_event);
1582 sync_agent_free_event_data(response_event);
1584 return SYNC_AGENT_DS_FAIL;
1587 /* free request & response event */
1588 sync_agent_free_event(request_event);
1589 sync_agent_free_event_data(response_event);
1593 return SYNC_AGENT_DS_SUCCESS;
1596 EXPORT_API sync_agent_ds_error_e sync_agent_ds_stop_sync(ds_profile_h profile_h)
1600 // check mandatory parameter
1601 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1603 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1605 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1607 int event_type = SYNC_AGENT_DS_STOP_SYNC;
1608 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1609 sync_agent_event_data_s *request_event = NULL;
1610 sync_agent_event_data_s *response_event = NULL;
1612 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1614 /* create empty event packet */
1615 request_event = sync_agent_create_event(event_type);
1616 if (request_event == NULL) {
1617 _DEBUG_ERROR("event is NULL");
1618 return SYNC_AGENT_DS_FAIL;
1621 /* add request parameter to event packet */
1622 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1624 /* send event request to ds agent daemon, waiting for response */
1625 response_event = sync_agent_send_event(request_event, &error);
1626 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1627 _DEBUG_ERROR("error = %d", error);
1628 sync_agent_free_event(request_event);
1630 return SYNC_AGENT_DS_FAIL;
1632 if (response_event == NULL) {
1633 _DEBUG_ERROR("response_event is null!!");
1634 sync_agent_free_event(request_event);
1636 return SYNC_AGENT_DS_FAIL;
1639 /* get response parameter from event packet */
1640 sync_agent_get_event_data_param_int(response_event, &api_result);
1642 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1643 _DEBUG_ERROR("api_result = failed");
1644 sync_agent_free_event(request_event);
1645 sync_agent_free_event_data(response_event);
1647 return SYNC_AGENT_DS_FAIL;
1650 /* free request & response event */
1651 sync_agent_free_event(request_event);
1652 sync_agent_free_event_data(response_event);
1656 return SYNC_AGENT_DS_SUCCESS;
1659 EXPORT_API void sync_agent_ds_free_profile_info(ds_profile_h profile_h)
1663 // check mandatory parameter
1664 retm_if(profile_h == NULL, "profile handle is null!!");
1666 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1668 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1669 //sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1670 GList *category_list = profile_info->service_list;
1672 // free profile name
1673 g_free(profile_info->profile_dir_name);
1674 g_free(profile_info->profile_name);
1676 // free server information
1677 g_free(server_info->addr);
1678 g_free(server_info->id);
1679 g_free(server_info->password);
1681 // free sync category information
1682 g_list_free_full(category_list, (GDestroyNotify) _free_sync_category_info);
1684 // free profile information
1685 g_free(profile_info);
1690 EXPORT_API sync_agent_ds_error_e sync_agent_ds_deinit()
1694 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
1695 sync_agent_deinit_error_e deinit = SYNC_AGENT_DEINIT_SUCCESS;
1699 ret = _kill_omads_agent();
1702 _DEBUG_ERROR("_kill_omads_agent() failed !!");
1703 result = SYNC_AGENT_DS_FAIL;
1709 deinit = sync_agent_deinit();
1710 if (deinit != SYNC_AGENT_DEINIT_SUCCESS) {
1711 _DEBUG_ERROR("sync_agent_clean_event_handler() failed !!");
1712 result = SYNC_AGENT_DS_FAIL;
1714 // if (err != SYNC_AGENT_EVENT_SUCCESS) {
1715 // sync_agent_event_error_e err = sync_agent_stop_noti_listener();
1716 // _DEBUG_INFO("STOP NOTILISTNER is failed");
1717 // result = SYNC_AGENT_DS_FAIL;
1720 // err = sync_agent_clean_event_handler();
1721 // if (err != SYNC_AGENT_EVENT_SUCCESS) {
1722 // _DEBUG_ERROR("sync_agent_clean_event_handler() failed !!");
1723 // result = SYNC_AGENT_DS_FAIL;
1731 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)
1735 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
1737 sync_agent_event_error_e err = sync_agent_set_noti_callback(type, callback, data);
1738 if (err != SYNC_AGENT_EVENT_SUCCESS) {
1739 _DEBUG_ERROR("failed sync_agent_set_noti_callback()");
1740 result = SYNC_AGENT_DS_FAIL;