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
44 #define SYNC_AGENT_DS_API_RESULT_SYNCHRONISING 2
46 #define SYNC_TYPE_SLOW_SYNC_STR "Full"
47 #define SYNC_TYPE_TWO_WAY_STR "Update both"
48 #define SYNC_TYPE_ONE_WAY_FROM_CLIENT_STR "Update to server"
49 #define SYNC_TYPE_ONE_WAY_FROM_SERVER_STR "Update to phone"
50 #define SYNC_TYPE_REFRESH_FROM_SERVER_STR "Refresh from server"
51 #define SYNC_TYPE_REFRESH_FROM_CLIENT_STR "Refresh from phone"
53 #define SYNC_MODE_MANUAL_STR "Manual"
54 #define SYNC_MODE_PUSH_STR "Push"
55 #define SYNC_MODE_PERIODIC_STR "Periodic"
57 #define SYNC_INTERVAL_NONE "None"
58 #define SYNC_INTERVAL_5_MINUTES "5 minutes"
59 #define SYNC_INTERVAL_15_MINUTES "15 minutes"
60 #define SYNC_INTERVAL_1_HOUR "1 hour"
61 #define SYNC_INTERVAL_4_HOURS "4 hours"
62 #define SYNC_INTERVAL_12_HOURS "12 hours"
63 #define SYNC_INTERVAL_1_DAY "1 day"
64 #define SYNC_INTERVAL_1_WEEK "1 week"
65 #define SYNC_INTERVAL_1_MONTH "1 month"
67 #define SRC_URI_CONTACT_STR "Contacts"
68 #define SRC_URI_CALENDAR_STR "Organizer"
71 SYNC_AGENT_DS_ADD_PROFILE = 1,
72 SYNC_AGENT_DS_UPDATE_PROFILE = 2,
73 SYNC_AGENT_DS_DELETE_PROFILE = 3,
74 SYNC_AGENT_DS_START_SYNC = 4,
75 SYNC_AGENT_DS_STOP_SYNC = 5,
76 SYNC_AGENT_DS_GET_PROFILE = 6,
77 SYNC_AGENT_DS_GET_SYNC_CATEGORY = 7,
78 SYNC_AGENT_DS_GET_SYNC_STATISTICS = 8,
79 SYNC_AGENT_DS_GET_ALL_PROFILES = 9
80 } sync_agent_ds_event_e;
83 SYNC_AGENT_DS_SYNC_CONTACTS = 0,
84 SYNC_AGENT_DS_SYNC_SCHEDULE = 1,
85 SYNC_AGENT_DS_SYNC_MEMO = 2
86 } sync_agent_ds_sync_e;
88 static gboolean _get_sync_category(char *profile_dir_name, int service_type, sync_agent_ds_service_info ** service)
92 int event_type = SYNC_AGENT_DS_GET_SYNC_CATEGORY;
93 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
95 // check mandatory parameter
96 retvm_if(profile_dir_name == NULL, FALSE, "profile_dir_name is null!!");
97 retvm_if(service_type < 0, FALSE, "service_type is wrong!!");
99 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
100 sync_agent_event_data_s *request_event = NULL;
101 sync_agent_event_data_s *response_event = NULL;
103 /* create empty event packet */
104 request_event = sync_agent_create_event(event_type);
105 if (request_event == NULL) {
106 _DEBUG_ERROR("event is NULL");
111 /* add request parameter to event packet */
112 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
113 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &service_type);
115 /* send event request to ds agent daemon, waiting for response */
116 response_event = sync_agent_send_event(request_event, &error);
117 if (error != SYNC_AGENT_EVENT_SUCCESS) {
118 _DEBUG_ERROR("error = %d", error);
119 sync_agent_free_event(request_event);
123 if (response_event == NULL) {
124 _DEBUG_ERROR("response_event is null!!");
125 sync_agent_free_event(request_event);
130 *service = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
131 if (*service == NULL) {
132 _DEBUG_ERROR("calloc failed");
133 sync_agent_free_event(request_event);
134 sync_agent_free_event_data(response_event);
138 /* get response parameter from event packet */
140 sync_agent_get_event_data_param_int(response_event, &api_result);
141 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
142 _DEBUG_ERROR("api_result = failed");
143 sync_agent_free_event(request_event);
144 sync_agent_free_event_data(response_event);
146 return SYNC_AGENT_DS_FAIL;
149 sync_agent_get_event_data_param_int(response_event, &((*service)->enabled));
150 sync_agent_get_event_data_param_int(response_event, (int*) &((*service)->src_uri));
151 sync_agent_get_event_data_param_str(response_event, &((*service)->tgt_uri));
152 sync_agent_get_event_data_param_str(response_event, &((*service)->id));
153 sync_agent_get_event_data_param_str(response_event, &((*service)->password));
155 _DEBUG_TRACE("enabled = %d", (*service)->enabled);
156 _DEBUG_TRACE("src_uri = %d", (*service)->src_uri);
157 _DEBUG_TRACE("tgt_uri = %s", (*service)->tgt_uri);
158 _DEBUG_TRACE("id = %s", (*service)->id);
159 _DEBUG_TRACE("password = %s", (*service)->password);
161 /* free request & response event */
162 sync_agent_free_event(request_event);
163 sync_agent_free_event_data(response_event);
170 static gboolean _get_sync_statistics(char *profile_dir_name, int service_type, sync_agent_ds_statistics_info ** statistics)
174 int event_type = SYNC_AGENT_DS_GET_SYNC_STATISTICS;
175 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
177 // check mandatory parameter
178 retvm_if(profile_dir_name == NULL, FALSE, "profile_dir_name is null!!");
179 retvm_if(service_type < 0, FALSE, "service_type is wrong!!");
181 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
182 sync_agent_event_data_s *request_event = NULL;
183 sync_agent_event_data_s *response_event = NULL;
185 char *statistics_cat = NULL;
187 /* create empty event packet */
188 request_event = sync_agent_create_event(event_type);
189 if (request_event == NULL) {
190 _DEBUG_ERROR("event is NULL");
195 /* add request parameter to event packet */
196 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
197 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &service_type);
199 /* send event request to ds agent daemon, waiting for response */
200 response_event = sync_agent_send_event(request_event, &error);
201 if (error != SYNC_AGENT_EVENT_SUCCESS) {
202 _DEBUG_ERROR("error = %d", error);
203 sync_agent_free_event(request_event);
207 if (response_event == NULL) {
208 _DEBUG_ERROR("response_event is null!!");
209 sync_agent_free_event(request_event);
214 *statistics = (sync_agent_ds_statistics_info *) calloc(1, sizeof(sync_agent_ds_statistics_info));
215 if (*statistics == NULL) {
216 _DEBUG_ERROR("calloc failed");
217 sync_agent_free_event(request_event);
218 sync_agent_free_event_data(response_event);
222 /* get response parameter from event packet */
224 sync_agent_get_event_data_param_int(response_event, &api_result);
225 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
226 _DEBUG_ERROR("api_result = failed");
227 sync_agent_free_event(request_event);
228 sync_agent_free_event_data(response_event);
230 return SYNC_AGENT_DS_FAIL;
233 if (service_type == SYNC_AGENT_DS_SYNC_CONTACTS)
234 statistics_cat = "contacts";
235 else if (service_type == SYNC_AGENT_DS_SYNC_SCHEDULE)
236 statistics_cat = "schedule";
237 else if (service_type == SYNC_AGENT_DS_SYNC_MEMO)
238 statistics_cat = "memo";
240 sync_agent_get_event_data_param_str(response_event, &((*statistics)->dbsynced));
241 sync_agent_get_event_data_param_int(response_event, &((*statistics)->last_session_time));
242 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_total));
243 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_nrofadd));
244 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_nrofdelete));
245 sync_agent_get_event_data_param_int(response_event, &((*statistics)->server2client_nrofreplace));
246 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_total));
247 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_nrofadd));
248 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_nrofdelete));
249 sync_agent_get_event_data_param_int(response_event, &((*statistics)->client2server_nrofreplace));
251 _DEBUG_TRACE("%s dbSynced = %s", statistics_cat, (*statistics)->dbsynced);
252 _DEBUG_TRACE("%s lastSessionTime = %d", statistics_cat, (*statistics)->last_session_time);
253 _DEBUG_TRACE("%s server2Client_Total = %d", statistics_cat, (*statistics)->server2client_total);
254 _DEBUG_TRACE("%s server2Client_NrOrAdd = %d", statistics_cat, (*statistics)->server2client_nrofadd);
255 _DEBUG_TRACE("%s server2Client_NrOfDelete = %d", statistics_cat, (*statistics)->server2client_nrofdelete);
256 _DEBUG_TRACE("%s server2Client_NrOfReplace = %d", statistics_cat, (*statistics)->server2client_nrofreplace);
257 _DEBUG_TRACE("%s client2Server_Total = %d", statistics_cat, (*statistics)->client2server_total);
258 _DEBUG_TRACE("%s client2Server_NrOfAdd = %d", statistics_cat, (*statistics)->client2server_nrofadd);
259 _DEBUG_TRACE("%s client2Server_NrOfDelete = %d", statistics_cat, (*statistics)->client2server_nrofdelete);
260 _DEBUG_TRACE("%s client2Server_NrOfReplace = %d", statistics_cat, (*statistics)->client2server_nrofreplace);
262 /* free request & response event */
263 sync_agent_free_event(request_event);
264 sync_agent_free_event_data(response_event);
271 static char * _convert_sync_mode_str(sync_agent_ds_sync_mode_e sync_mode)
275 char* sync_mode_str = NULL;
277 _DEBUG_INFO("sync_mode : [%d]",sync_mode);
279 case SYNC_AGENT_SYNC_MODE_MANUAL:
280 sync_mode_str = SYNC_MODE_MANUAL_STR;
282 case SYNC_AGENT_SYNC_MODE_PERIODIC:
283 sync_mode_str = SYNC_MODE_PERIODIC_STR;
285 case SYNC_AGENT_SYNC_MODE_PUSH:
286 sync_mode_str = SYNC_MODE_PUSH_STR;
293 return sync_mode_str;
296 static char * _convert_sync_type_str(sync_agent_ds_sync_type_e sync_type)
300 char* sync_type_str = NULL;
302 _DEBUG_INFO("sync_type : [%d]",sync_type);
304 case SYNC_AGENT_SYNC_TYPE_FULL_SYNC:
305 sync_type_str = SYNC_TYPE_SLOW_SYNC_STR;
307 case SYNC_AGENT_SYNC_TYPE_UPDATE_BOTH:
308 sync_type_str = SYNC_TYPE_TWO_WAY_STR;
310 case SYNC_AGENT_SYNC_TYPE_UPDATE_TO_SERVER:
311 sync_type_str = SYNC_TYPE_ONE_WAY_FROM_CLIENT_STR;
313 case SYNC_AGENT_SYNC_TYPE_UPDATE_TO_PHONE:
314 sync_type_str = SYNC_TYPE_ONE_WAY_FROM_SERVER_STR;
316 case SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_SERVER:
317 sync_type_str = SYNC_TYPE_REFRESH_FROM_SERVER_STR;
319 case SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_PHONE:
320 sync_type_str = SYNC_TYPE_REFRESH_FROM_CLIENT_STR;
327 return sync_type_str;
330 static char * _convert_sync_interval_str(sync_agent_ds_sync_interval_e interval)
334 char* interval_str = NULL;
336 _DEBUG_INFO("interval : [%d]",interval);
338 case SYNC_AGENT_SYNC_INTERVAL_5_MINUTES:
339 interval_str = SYNC_INTERVAL_5_MINUTES;
341 case SYNC_AGENT_SYNC_INTERVAL_15_MINUTES:
342 interval_str = SYNC_INTERVAL_15_MINUTES;
344 case SYNC_AGENT_SYNC_INTERVAL_1_HOUR:
345 interval_str = SYNC_INTERVAL_1_HOUR;
347 case SYNC_AGENT_SYNC_INTERVAL_4_HOURS:
348 interval_str = SYNC_INTERVAL_4_HOURS;
350 case SYNC_AGENT_SYNC_INTERVAL_12_HOURS:
351 interval_str = SYNC_INTERVAL_12_HOURS;
353 case SYNC_AGENT_SYNC_INTERVAL_1_DAY:
354 interval_str = SYNC_INTERVAL_1_DAY;
356 case SYNC_AGENT_SYNC_INTERVAL_1_WEEK:
357 interval_str = SYNC_INTERVAL_1_WEEK;
359 case SYNC_AGENT_SYNC_INTERVAL_1_MONTH:
360 interval_str = SYNC_INTERVAL_1_MONTH;
363 interval_str = SYNC_INTERVAL_NONE;
371 static char * _convert_src_uri_str(sync_agent_ds_src_uri_e src_uri)
375 char* src_uri_str = NULL;
377 _DEBUG_INFO("src_uri : [%d]",src_uri);
379 case SYNC_AGENT_SRC_URI_CONTACT:
380 src_uri_str = SRC_URI_CONTACT_STR;
382 case SYNC_AGENT_SRC_URI_CALENDAR:
383 src_uri_str = SRC_URI_CALENDAR_STR;
393 static void _free_sync_category_info(sync_agent_ds_service_info * data)
395 g_free(data->tgt_uri);
397 g_free(data->password);
400 static gboolean _is_existing_profile(void)
404 int event_type = SYNC_AGENT_DS_GET_ALL_PROFILES;
405 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
406 sync_agent_event_data_s *request_event = NULL;
407 sync_agent_event_data_s *response_event = NULL;
409 int profile_count = 0;
411 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
413 /* create empty event packet */
414 request_event = sync_agent_create_event(event_type);
415 if (request_event == NULL) {
416 _DEBUG_ERROR("event is NULL");
418 return SYNC_AGENT_DS_FAIL;
421 /* send event request to ds agent daemon, waiting for response */
422 response_event = sync_agent_send_event(request_event, &error);
423 if (error != SYNC_AGENT_EVENT_SUCCESS) {
424 _DEBUG_ERROR("error = %d", error);
425 sync_agent_free_event(request_event);
427 return SYNC_AGENT_DS_FAIL;
429 if (response_event == NULL) {
430 _DEBUG_ERROR("response_event is null!!");
431 sync_agent_free_event(request_event);
433 return SYNC_AGENT_DS_FAIL;
436 sync_agent_get_event_data_param_int(response_event, &api_result);
437 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
438 _DEBUG_ERROR("api_result = failed");
439 sync_agent_free_event(request_event);
440 sync_agent_free_event_data(response_event);
442 return SYNC_AGENT_DS_FAIL;
445 sync_agent_get_event_data_param_int(response_event, &profile_count);
446 _DEBUG_INFO("profile_count = %d", profile_count);
448 if (profile_count > 0) {
449 sync_agent_free_event(request_event);
450 sync_agent_free_event_data(response_event);
456 /* free request & response event */
457 sync_agent_free_event(request_event);
458 sync_agent_free_event_data(response_event);
465 static int _launch_omads_agent(void)
468 GError *error = NULL;
470 DBusGConnection *connection = NULL;
471 DBusGProxy *dbus_proxy = NULL;
475 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
477 _DEBUG_ERROR("dbus_g_bus_get failed: %s\n", error->message);
483 dbus_proxy = dbus_g_proxy_new_for_name(connection, "com.samsung.omadsagent",
484 "/com/samsung/omadsagent", "com.samsung.omadsagent");
486 _DEBUG_INFO("dbus_proxy %x", dbus_proxy);
488 //dbus_g_proxy_call_no_reply(dbus_proxy, "Hello_Agent", G_TYPE_INVALID);
489 dbus_g_proxy_call(dbus_proxy, "Hello_Agent", &error, G_TYPE_INVALID, G_TYPE_INVALID);
491 g_object_unref(dbus_proxy);
492 dbus_g_connection_unref(connection);
498 static int _kill_omads_agent(void)
501 GError *error = NULL;
503 DBusGConnection *connection = NULL;
504 DBusGProxy *dbus_proxy = NULL;
505 gboolean isExisting = FALSE;
507 isExisting = _is_existing_profile();
510 _DEBUG_INFO("Existing profile !!");
516 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
518 _DEBUG_ERROR("dbus_g_bus_get failed: %s\n", error->message);
524 dbus_proxy = dbus_g_proxy_new_for_name(connection, "com.samsung.omadsagent",
525 "/com/samsung/omadsagent", "com.samsung.omadsagent");
527 _DEBUG_INFO("dbus_proxy %x", dbus_proxy);
529 dbus_g_proxy_call_no_reply(dbus_proxy, "Goodbye_Agent", G_TYPE_INVALID);
531 g_object_unref(dbus_proxy);
532 dbus_g_connection_unref(connection);
538 EXPORT_API sync_agent_ds_error_e sync_agent_ds_init()
542 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
543 sync_agent_init_error_e init_error = SYNC_AGENT_INIT_SUCCESS;
547 _DEBUG_INFO("before sysman_get_pid");
548 pid = sysman_get_pid("/usr/bin/oma-ds-agent");
549 _DEBUG_INFO("oma-ds-agent pid [%d]", pid);
552 ret = _launch_omads_agent();
554 _DEBUG_ERROR("_launch_omads_agent() failed !!");
555 result = SYNC_AGENT_DS_FAIL;
562 init_error = sync_agent_init(OMA_DS_CONFIG_FILE);
564 if (init_error != SYNC_AGENT_INIT_SUCCESS) {
565 _DEBUG_ERROR("ds init failed");
566 result = SYNC_AGENT_DS_FAIL;
569 sync_agent_event_error_e err = sync_agent_run_noti_listener("omads");
570 if (err != SYNC_AGENT_EVENT_SUCCESS) {
571 _DEBUG_ERROR("RUN NOTILISTNER is failed");
572 result = SYNC_AGENT_DS_FAIL;
580 EXPORT_API sync_agent_ds_error_e sync_agent_ds_create_profile_info(ds_profile_h * profile_h)
584 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
585 sync_agent_ds_profile_info *profile_info = NULL;
587 // allocate memory for ds profile info
588 profile_info = (sync_agent_ds_profile_info *) calloc(1, sizeof(sync_agent_ds_profile_info));
589 if (profile_info == NULL) {
590 _DEBUG_ERROR("calloc failed !!");
591 return SYNC_AGENT_DS_FAIL;
593 // pass memory pointer to ds profile handle
594 *profile_h = profile_info;
601 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_profile_dir_name(ds_profile_h profile_h, char *profile_dir_name)
605 // check mandatory parameter
606 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
607 retvm_if(profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
609 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
610 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
613 profile_info->profile_dir_name = g_strdup(profile_dir_name);
615 if (profile_info->profile_dir_name == NULL) {
616 _DEBUG_ERROR("g_strdup failed !!");
617 return SYNC_AGENT_DS_FAIL;
625 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_profile_name(ds_profile_h profile_h, char *profile_name)
629 // check mandatory parameter
630 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
631 retvm_if(profile_name == NULL, SYNC_AGENT_DS_FAIL, "profile_name is null!!");
633 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
634 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
637 profile_info->profile_name = g_strdup(profile_name);
639 _DEBUG_INFO("profile_name: [%s]",profile_name);
641 if (profile_info->profile_name == NULL) {
642 _DEBUG_ERROR("g_strdup failed !!");
643 return SYNC_AGENT_DS_FAIL;
651 EXPORT_API sync_agent_ds_error_e sync_agent_ds_set_server_info(ds_profile_h profile_h, char *addr, char *id, char *password)
655 // check mandatory parameter
656 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
657 retvm_if(addr == NULL, SYNC_AGENT_DS_FAIL, "addr is null!!");
658 retvm_if(id == NULL, SYNC_AGENT_DS_FAIL, "id is null!!");
659 retvm_if(password == NULL, SYNC_AGENT_DS_FAIL, "password is null!!");
661 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
662 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
663 sync_agent_ds_server_info *server_info = &profile_info->server_info;
666 server_info->addr = g_strdup(addr);
667 server_info->id = g_strdup(id);
668 server_info->password = g_strdup(password);
670 _DEBUG_INFO("addr: [%s]",addr);
671 _DEBUG_INFO("id: [%s]",id);
672 _DEBUG_INFO("password: [%s]",password);
674 if ((server_info->addr == NULL)
675 || (server_info->id == NULL)
676 || (server_info->password == NULL)) {
677 _DEBUG_ERROR("g_strdup failed !!");
678 return SYNC_AGENT_DS_FAIL;
686 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)
690 // check mandatory parameter
691 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
692 retvm_if(sync_mode < 0, SYNC_AGENT_DS_FAIL, "sync_mode is invalid!!");
693 retvm_if(sync_type < 0, SYNC_AGENT_DS_FAIL, "sync_type is invalid!!");
694 retvm_if(interval < 0, SYNC_AGENT_DS_FAIL, "interval is invalid!!");
696 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
697 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
698 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
700 char* sync_mode_str = NULL;
701 char* sync_type_str = NULL;
702 char* interval_str = NULL;
704 sync_mode_str = _convert_sync_mode_str(sync_mode);
705 if (sync_mode_str == NULL) {
706 _DEBUG_ERROR("_convert_sync_mode_str failed !!");
708 return SYNC_AGENT_DS_FAIL;
711 sync_type_str = _convert_sync_type_str(sync_type);
712 if (sync_type_str == NULL) {
713 _DEBUG_ERROR("_convert_sync_type_str failed !!");
715 return SYNC_AGENT_DS_FAIL;
718 interval_str = _convert_sync_interval_str(interval);
719 if (interval_str == NULL) {
720 _DEBUG_ERROR("_convert_sync_interval_str failed !!");
722 return SYNC_AGENT_DS_FAIL;
726 sync_info->sync_mode = sync_mode;
727 sync_info->sync_type = sync_type;
728 sync_info->interval = interval;
730 _DEBUG_INFO("sync_mode: [%d]",sync_mode);
731 _DEBUG_INFO("sync_type: [%d]",sync_type);
732 _DEBUG_INFO("interval: [%d]",interval);
739 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)
743 // check mandatory parameter
744 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
745 retvm_if(src_uri < 0, SYNC_AGENT_DS_FAIL, "src_uri is invalid!!");
747 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
748 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
749 sync_agent_ds_service_info *category_info = NULL;
750 char* src_uri_str = NULL;
752 src_uri_str = _convert_src_uri_str(src_uri);
753 if (src_uri_str == NULL) {
754 _DEBUG_ERROR("_get_src_uri_string failed !!");
756 return SYNC_AGENT_DS_FAIL;
759 // allocate memory for sync_category
760 category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
761 retvm_if(category_info == NULL, SYNC_AGENT_DS_FAIL, "calloc failed");
762 category_info->service_type = service_type;
763 category_info->enabled = enabled;
764 category_info->src_uri = src_uri;
765 category_info->tgt_uri = g_strdup(tgt_uri);
767 _DEBUG_INFO("service_type: [%d]",service_type);
768 _DEBUG_INFO("enabled: [%d]",enabled);
769 _DEBUG_INFO("src_uri: [%d]",src_uri);
770 _DEBUG_INFO("tgt_uri: [%s]",tgt_uri);
772 profile_info->service_list = g_list_append(profile_info->service_list, category_info);
779 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_id(ds_profile_h profile_h, int *profile_id)
783 // check mandatory parameter
784 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
786 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
788 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
790 *profile_id = profile_info->profile_id;
792 if (*profile_id < 1) {
793 _DEBUG_ERROR("profile_id is invalid!!");
794 return SYNC_AGENT_DS_FAIL;
797 _DEBUG_INFO("profile_id = %d", *profile_id);
804 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_dir_name(ds_profile_h profile_h, char **profile_dir_name)
808 // check mandatory parameter
809 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
811 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
813 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
815 *profile_dir_name = g_strdup(profile_info->profile_dir_name);
817 if (*profile_dir_name == NULL) {
818 _DEBUG_ERROR("g_strdup failed !!");
819 return SYNC_AGENT_DS_FAIL;
822 _DEBUG_INFO("profile_dir_name = %s", *profile_dir_name);
829 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile_name(ds_profile_h profile_h, char **profile_name)
833 // check mandatory parameter
834 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
836 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
838 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
840 *profile_name = g_strdup(profile_info->profile_name);
842 if (*profile_name == NULL) {
843 _DEBUG_ERROR("g_strdup failed !!");
844 return SYNC_AGENT_DS_FAIL;
847 _DEBUG_INFO("profile_name = %s", *profile_name);
854 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)
858 // check mandatory parameter
859 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
860 retvm_if(server_info == NULL, SYNC_AGENT_DS_FAIL, "server_info is null!!");
862 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
863 sync_agent_ds_server_info *ds_server_info = &profile_info->server_info;
865 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
867 server_info->addr = g_strdup(ds_server_info->addr);
868 server_info->id = g_strdup(ds_server_info->id);
869 server_info->password = g_strdup(ds_server_info->password);
871 if ((server_info->addr == NULL)
872 || (server_info->id == NULL)
873 || (server_info->password == NULL)) {
874 _DEBUG_ERROR("g_strdup failed !!");
875 return SYNC_AGENT_DS_FAIL;
878 _DEBUG_INFO("get_addr = %s", server_info->addr);
879 _DEBUG_INFO("get_id = %s", server_info->id);
880 _DEBUG_INFO("get_password = %s", server_info->password);
887 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)
891 // check mandatory parameter
892 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
893 retvm_if(sync_info == NULL, SYNC_AGENT_DS_FAIL, "sync_info is null!!");
895 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
896 sync_agent_ds_sync_info *ds_sync_info = &profile_info->sync_info;
898 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
900 sync_info->sync_mode = ds_sync_info->sync_mode;
901 sync_info->sync_type = ds_sync_info->sync_type;
902 sync_info->interval = ds_sync_info->interval;
904 _DEBUG_INFO("get_sync_mode = %d", sync_info->sync_mode);
905 _DEBUG_INFO("get_sync_type = %d", sync_info->sync_type);
906 _DEBUG_INFO("get_interval = %d", sync_info->interval);
908 if (sync_info->sync_mode < 0) {
909 _DEBUG_ERROR("sync_mode is invalid !!");
912 if (sync_info->sync_type < 0) {
913 _DEBUG_ERROR("sync_type is invalid !!");
916 if (sync_info->interval < 0) {
917 _DEBUG_ERROR("interval is invalid !!");
925 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_service_info(ds_profile_h profile_h, GList ** category_list)
929 // check mandatory parameter
930 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
932 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
934 int category_count = 0;
936 sync_agent_ds_service_info *category_info = NULL;
938 *category_list = g_list_copy(profile_info->service_list);
940 if (*category_list == NULL) {
941 _DEBUG_ERROR("category_list is NULL!!");
944 category_count = g_list_length(*category_list);
945 _DEBUG_INFO("category_count: [%d]", category_count);
947 for (; i < category_count; i++) {
948 category_info = (sync_agent_ds_service_info *) g_list_nth_data(*category_list, i);
950 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
951 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
952 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
953 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
954 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
959 return SYNC_AGENT_DS_SUCCESS;
962 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_sync_statistics(ds_profile_h profile_h, GList ** statistics_list)
966 // check mandatory parameter
967 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
969 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
970 sync_agent_ds_statistics_info *statistics = NULL;
972 gboolean result_sync_category = FALSE;
974 /* get last contacts sync result */
975 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_CONTACTS, &statistics);
976 if (result_sync_category)
977 *statistics_list = g_list_append(*statistics_list, statistics);
979 /* get last schedule sync result */
981 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_SCHEDULE, &statistics);
982 if (result_sync_category)
983 *statistics_list = g_list_append(*statistics_list, statistics);
985 /* get last memo sync result */
987 result_sync_category = _get_sync_statistics(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_MEMO, &statistics);
988 if (result_sync_category)
989 *statistics_list = g_list_append(*statistics_list, statistics);
993 return SYNC_AGENT_DS_SUCCESS;
996 EXPORT_API sync_agent_ds_error_e sync_agent_ds_add_profile(ds_profile_h profile_h, int *profile_id)
1000 // check mandatory parameter
1001 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1003 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1004 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1005 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1006 GList *list = profile_info->service_list;
1008 int event_type = SYNC_AGENT_DS_ADD_PROFILE;
1009 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1010 sync_agent_event_data_s *request_event = NULL;
1011 sync_agent_event_data_s *response_event = NULL;
1014 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1015 sync_agent_ds_service_info *category_info = NULL;
1016 int category_count = 0;
1018 int profile_name_len = 0;
1019 int server_addr_len = 0;
1020 int server_id_len = 0;
1021 int server_password_len = 0;
1023 /* create empty event packet */
1024 request_event = sync_agent_create_event(event_type);
1025 if (request_event == NULL) {
1026 _DEBUG_ERROR("event is NULL");
1028 return SYNC_AGENT_DS_FAIL;
1031 profile_name_len = strlen(profile_info->profile_name);
1032 server_addr_len = strlen(server_info->addr);
1033 server_id_len = strlen(server_info->id);
1034 server_password_len = strlen(server_info->password);
1036 if ((profile_name_len == 0) || (server_addr_len == 0) || (server_id_len == 0) || (server_password_len == 0)) {
1037 _DEBUG_ERROR("input value is invalid!!");
1038 _DEBUG_INFO("profile_info->profile_name: [%s]", profile_info->profile_name);
1039 _DEBUG_INFO("server_info->addr: [%s]", server_info->addr);
1040 _DEBUG_INFO("server_info->id: [%s]", server_info->id);
1041 _DEBUG_INFO("server_info->password: [%s]", server_info->password);
1042 sync_agent_free_event(request_event);
1045 return SYNC_AGENT_DS_FAIL;
1048 /* add request parameter to event packet */
1049 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
1050 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name);
1051 _DEBUG_INFO("addr = %s", server_info->addr);
1052 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr);
1053 _DEBUG_INFO("id = %s", server_info->id);
1054 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id);
1055 _DEBUG_INFO("password = %s", server_info->password);
1056 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password);
1057 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
1058 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_mode));
1059 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
1060 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_type));
1061 _DEBUG_INFO("interval = %d", sync_info->interval);
1062 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->interval));
1064 category_count = g_list_length(list);
1065 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count);
1067 for (; i < category_count; i++) {
1068 category_info = (sync_agent_ds_service_info *) g_list_nth_data(list, i);
1070 _DEBUG_INFO("category[%d]->service_type = %d", i, category_info->service_type);
1071 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->service_type));
1072 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
1073 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->enabled));
1074 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
1075 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->src_uri));
1076 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
1077 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri);
1078 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
1079 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id);
1080 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
1081 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password);
1084 /* send event request to ds agent daemon, waiting for response */
1085 response_event = sync_agent_send_event(request_event, &error);
1086 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1087 _DEBUG_ERROR("error = %d", error);
1088 sync_agent_free_event(request_event);
1090 return SYNC_AGENT_DS_FAIL;
1092 if (response_event == NULL) {
1093 _DEBUG_ERROR("response_event is null!!");
1094 sync_agent_free_event(request_event);
1096 return SYNC_AGENT_DS_FAIL;
1099 /* get response parameter from event packet */
1100 sync_agent_get_event_data_param_int(response_event, &api_result);
1102 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1103 _DEBUG_ERROR("api_result = failed");
1104 sync_agent_free_event(request_event);
1105 sync_agent_free_event_data(response_event);
1107 return SYNC_AGENT_DS_FAIL;
1110 sync_agent_get_event_data_param_int(response_event, &prof_id);
1112 _DEBUG_VERBOSE("profile_id = %d", prof_id);
1113 *profile_id = prof_id;
1115 /* free request & response event */
1116 sync_agent_free_event(request_event);
1117 sync_agent_free_event_data(response_event);
1121 return SYNC_AGENT_DS_SUCCESS;
1124 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_profile(int profile_id, ds_profile_h * profile_h)
1128 // check mandatory parameter
1129 retvm_if(profile_id < 1, SYNC_AGENT_DS_FAIL, "profile_id is invalid!!");
1131 int event_type = SYNC_AGENT_DS_GET_PROFILE;
1132 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1133 sync_agent_event_data_s *request_event = NULL;
1134 sync_agent_event_data_s *response_event = NULL;
1136 gboolean result_sync_category = FALSE;
1137 sync_agent_ds_error_e result = SYNC_AGENT_DS_FAIL;
1138 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1139 sync_agent_ds_service_info *category = NULL;
1141 //////////////////////////////////
1143 // Phase 1. get profile detail info
1145 /* create empty event packet */
1146 request_event = sync_agent_create_event(event_type);
1147 if (request_event == NULL) {
1148 _DEBUG_ERROR("event is NULL");
1150 return SYNC_AGENT_DS_FAIL;
1153 /* add request parameter to event packet */
1154 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &profile_id);
1155 _DEBUG_INFO("profile_id = %d", profile_id);
1157 /* send event request to ds agent daemon, waiting for response */
1158 response_event = sync_agent_send_event(request_event, &error);
1159 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1160 _DEBUG_ERROR("error = %d", error);
1161 sync_agent_free_event(request_event);
1163 return SYNC_AGENT_DS_FAIL;
1165 if (response_event == NULL) {
1166 _DEBUG_ERROR("response_event is null!!");
1167 sync_agent_free_event(request_event);
1169 return SYNC_AGENT_DS_FAIL;
1172 /* get response parameter from event packet */
1174 result = sync_agent_ds_create_profile_info(profile_h);
1175 if (result == SYNC_AGENT_DS_FAIL) {
1176 _DEBUG_ERROR("failed to create profile info!");
1177 sync_agent_free_event(request_event);
1178 sync_agent_free_event_data(response_event);
1182 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) (*profile_h);
1183 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1184 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1185 // GList * list = profile_info->category_list;
1187 sync_agent_get_event_data_param_int(response_event, &api_result);
1188 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1189 _DEBUG_ERROR("api_result = failed");
1190 sync_agent_free_event(request_event);
1191 sync_agent_free_event_data(response_event);
1193 return SYNC_AGENT_DS_FAIL;
1196 //profile_info->profile_dir_name = g_strdup(profile_dir_name);
1198 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_dir_name);
1199 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_name);
1200 sync_agent_get_event_data_param_str(response_event, &server_info->addr);
1201 sync_agent_get_event_data_param_str(response_event, &server_info->id);
1202 sync_agent_get_event_data_param_str(response_event, &server_info->password);
1203 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_mode);
1204 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_type);
1205 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->interval);
1206 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_status);
1207 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_time);
1209 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1210 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
1211 _DEBUG_INFO("addr = %s", server_info->addr);
1212 _DEBUG_INFO("id = %s", server_info->id);
1213 _DEBUG_INFO("password = %s", server_info->password);
1214 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
1215 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
1216 _DEBUG_INFO("interval = %d", sync_info->interval);
1217 _DEBUG_INFO("lastSyncStatus = %d\n", profile_info->last_sync_status);
1218 _DEBUG_INFO("lastSyncTime = %d\n", profile_info->last_sync_time);
1220 /* free request & response event */
1221 sync_agent_free_event(request_event);
1222 sync_agent_free_event_data(response_event);
1224 // Phase 2. get sync category info
1226 /* get contacts sync_category */
1227 result_sync_category = _get_sync_category(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_CONTACTS, &category);
1228 if (result_sync_category)
1229 profile_info->service_list = g_list_append(profile_info->service_list, category);
1231 /* get schedule sync_category */
1233 result_sync_category = _get_sync_category(profile_info->profile_dir_name, SYNC_AGENT_DS_SYNC_SCHEDULE, &category);
1234 if (result_sync_category)
1235 profile_info->service_list = g_list_append(profile_info->service_list, category);
1239 return SYNC_AGENT_DS_SUCCESS;
1242 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_all_profile(GList ** profile_list)
1246 int event_type = SYNC_AGENT_DS_GET_ALL_PROFILES;
1247 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1248 sync_agent_event_data_s *request_event = NULL;
1249 sync_agent_event_data_s *response_event = NULL;
1251 ds_profile_h profile_h = NULL;
1252 sync_agent_ds_service_info *category_info = NULL;
1254 int profile_count = 0;
1255 int category_count = 0;
1257 sync_agent_ds_error_e result = SYNC_AGENT_DS_FAIL;
1258 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1260 /* create empty event packet */
1261 request_event = sync_agent_create_event(event_type);
1262 if (request_event == NULL) {
1263 _DEBUG_ERROR("event is NULL");
1265 return SYNC_AGENT_DS_FAIL;
1268 /* send event request to ds agent daemon, waiting for response */
1269 response_event = sync_agent_send_event(request_event, &error);
1270 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1271 _DEBUG_ERROR("error = %d", error);
1272 sync_agent_free_event(request_event);
1274 return SYNC_AGENT_DS_FAIL;
1276 if (response_event == NULL) {
1277 _DEBUG_ERROR("response_event is null!!");
1278 sync_agent_free_event(request_event);
1280 return SYNC_AGENT_DS_FAIL;
1283 sync_agent_get_event_data_param_int(response_event, &api_result);
1284 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1285 _DEBUG_ERROR("api_result = failed");
1286 sync_agent_free_event(request_event);
1287 sync_agent_free_event_data(response_event);
1289 return SYNC_AGENT_DS_FAIL;
1292 sync_agent_get_event_data_param_int(response_event, &profile_count);
1293 _DEBUG_INFO("profile_count = %d", profile_count);
1296 for (i = 0; i < profile_count; i++) {
1298 result = sync_agent_ds_create_profile_info(&profile_h);
1299 if (result == SYNC_AGENT_DS_FAIL) {
1300 _DEBUG_ERROR("failed to create profile info!");
1301 sync_agent_free_event(request_event);
1302 sync_agent_free_event_data(response_event);
1306 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1307 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1308 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1310 sync_agent_get_event_data_param_int(response_event, &profile_info->profile_id);
1311 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_dir_name);
1312 sync_agent_get_event_data_param_str(response_event, &profile_info->profile_name);
1313 sync_agent_get_event_data_param_str(response_event, &server_info->addr);
1314 sync_agent_get_event_data_param_str(response_event, &server_info->id);
1315 sync_agent_get_event_data_param_str(response_event, &server_info->password);
1316 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_mode);
1317 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->sync_type);
1318 sync_agent_get_event_data_param_int(response_event, (int*) &sync_info->interval);
1319 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_status);
1320 sync_agent_get_event_data_param_int(response_event, &profile_info->last_sync_time);
1322 _DEBUG_INFO("profile_info->profile_id = %d", profile_info->profile_id);
1323 _DEBUG_INFO("profile_info->profile_dir_name = %s", profile_info->profile_dir_name);
1324 _DEBUG_INFO("profile_info->profile_name = %s", profile_info->profile_name);
1325 _DEBUG_INFO("profile_info->addr = %s", server_info->addr);
1326 _DEBUG_INFO("profile_info->id = %s", server_info->id);
1327 _DEBUG_INFO("profile_info->password = %s", server_info->password);
1328 _DEBUG_INFO("profile_info->sync_mode = %d", sync_info->sync_mode);
1329 _DEBUG_INFO("profile_info->sync_type = %d", sync_info->sync_type);
1330 _DEBUG_INFO("profile_info->interval = %d", sync_info->interval);
1331 _DEBUG_INFO("profile_info->lastSyncStatus = %d", profile_info->last_sync_status);
1332 _DEBUG_INFO("profile_info->lastSyncStatus = %d", profile_info->last_sync_status);
1334 sync_agent_get_event_data_param_int(response_event, &category_count);
1337 for (j = 0; j < category_count; j++) {
1339 category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info));
1340 if (category_info == NULL) {
1341 _DEBUG_ERROR("calloc failed");
1342 sync_agent_ds_free_profile_info(profile_h);
1343 sync_agent_free_event(request_event);
1344 sync_agent_free_event_data(response_event);
1348 sync_agent_get_event_data_param_int(response_event, (int*) &category_info->service_type);
1349 sync_agent_get_event_data_param_int(response_event, &category_info->enabled);
1350 sync_agent_get_event_data_param_int(response_event, (int*) &category_info->src_uri);
1351 sync_agent_get_event_data_param_str(response_event, &category_info->tgt_uri);
1352 sync_agent_get_event_data_param_str(response_event, &category_info->id);
1353 sync_agent_get_event_data_param_str(response_event, &category_info->password);
1355 _DEBUG_INFO("category_info->service_type = %d", category_info->service_type);
1356 _DEBUG_INFO("category_info->enabled = %d", category_info->enabled);
1357 _DEBUG_INFO("category_info->src_uri = %d", category_info->src_uri);
1358 _DEBUG_INFO("category_info->tgt_uri = %s", category_info->tgt_uri);
1359 _DEBUG_INFO("category_info->id = %s", category_info->id);
1360 _DEBUG_INFO("category_info->password = %s", category_info->password);
1362 profile_info->service_list = g_list_append(profile_info->service_list, category_info);
1363 category_info = NULL;
1366 *profile_list = g_list_append(*profile_list, profile_h);
1370 /* free request & response event */
1371 sync_agent_free_event(request_event);
1372 sync_agent_free_event_data(response_event);
1376 return SYNC_AGENT_DS_SUCCESS;
1379 EXPORT_API sync_agent_ds_error_e sync_agent_ds_get_last_sync_info(ds_profile_h profile_h, int *lastSyncStatus, int *lastSyncTime)
1383 // check mandatory parameter
1384 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1385 retvm_if(lastSyncStatus == NULL, SYNC_AGENT_DS_FAIL, "last session status is null!!");
1386 retvm_if(lastSyncTime == NULL, SYNC_AGENT_DS_FAIL, "last session time is null!!");
1388 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1390 *lastSyncStatus = profile_info->last_sync_status;
1391 *lastSyncTime = profile_info->last_sync_time;
1395 return SYNC_AGENT_DS_SUCCESS;
1398 EXPORT_API sync_agent_ds_error_e sync_agent_ds_update_profile(ds_profile_h profile_h)
1402 // check mandatory parameter
1403 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1405 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1406 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1407 sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1408 GList *list = profile_info->service_list;
1410 int event_type = SYNC_AGENT_DS_UPDATE_PROFILE;
1411 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1412 sync_agent_event_data_s *request_event = NULL;
1413 sync_agent_event_data_s *response_event = NULL;
1415 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1416 sync_agent_ds_service_info *category_info = NULL;
1417 int category_count = 0;
1420 /* create empty event packet */
1421 request_event = sync_agent_create_event(event_type);
1422 if (request_event == NULL) {
1423 _DEBUG_ERROR("event is NULL");
1425 return SYNC_AGENT_DS_FAIL;
1428 /* add request parameter to event packet */
1429 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1430 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1431 _DEBUG_INFO("profile_name = %s", profile_info->profile_name);
1432 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name);
1433 _DEBUG_INFO("addr = %s", server_info->addr);
1434 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr);
1435 _DEBUG_INFO("id = %s", server_info->id);
1436 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id);
1437 _DEBUG_INFO("password = %s", server_info->password);
1438 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password);
1439 _DEBUG_INFO("sync_mode = %d", sync_info->sync_mode);
1440 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_mode));
1441 _DEBUG_INFO("sync_type = %d", sync_info->sync_type);
1442 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->sync_type));
1443 _DEBUG_INFO("interval = %d", sync_info->interval);
1444 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(sync_info->interval));
1446 category_count = g_list_length(list);
1447 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count);
1449 for (; i < category_count; i++) {
1450 category_info = (sync_agent_ds_service_info *) g_list_nth_data(list, i);
1452 _DEBUG_INFO("category[%d]->service_type = %d", i, category_info->service_type);
1453 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->service_type));
1454 _DEBUG_INFO("category[%d]->enabled = %d", i, category_info->enabled);
1455 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->enabled));
1456 _DEBUG_INFO("category[%d]->src_uri = %d", i, category_info->src_uri);
1457 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &(category_info->src_uri));
1458 _DEBUG_INFO("category[%d]->tgt_uri = %s", i, category_info->tgt_uri);
1459 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri);
1460 _DEBUG_INFO("category[%d]->id = %s", i, category_info->id);
1461 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id);
1462 _DEBUG_INFO("category[%d]->password = %s", i, category_info->password);
1463 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password);
1466 /* send event request to ds agent daemon, waiting for response */
1467 response_event = sync_agent_send_event(request_event, &error);
1468 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1469 _DEBUG_ERROR("error = %d", error);
1470 sync_agent_free_event(request_event);
1472 return SYNC_AGENT_DS_FAIL;
1474 if (response_event == NULL) {
1475 _DEBUG_ERROR("response_event is null!!");
1476 sync_agent_free_event(request_event);
1478 return SYNC_AGENT_DS_FAIL;
1481 /* get response parameter from event packet */
1482 sync_agent_get_event_data_param_int(response_event, &api_result);
1484 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1485 _DEBUG_ERROR("api_result = failed");
1486 sync_agent_free_event(request_event);
1487 sync_agent_free_event_data(response_event);
1489 return SYNC_AGENT_DS_FAIL;
1492 if (api_result ==SYNC_AGENT_DS_API_RESULT_SYNCHRONISING) {
1493 _DEBUG_ERROR("api_result = synchronising");
1494 sync_agent_free_event(request_event);
1495 sync_agent_free_event_data(response_event);
1497 return SYNC_AGENT_DS_SYNCHRONISING;
1500 /* free request & response event */
1501 sync_agent_free_event(request_event);
1502 sync_agent_free_event_data(response_event);
1506 return SYNC_AGENT_DS_SUCCESS;
1509 EXPORT_API sync_agent_ds_error_e sync_agent_ds_delete_profile(ds_profile_h profile_h)
1513 // check mandatory parameter
1514 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1516 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1518 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1520 int event_type = SYNC_AGENT_DS_DELETE_PROFILE;
1521 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1522 sync_agent_event_data_s *request_event = NULL;
1523 sync_agent_event_data_s *response_event = NULL;
1526 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1528 /* create empty event packet */
1529 request_event = sync_agent_create_event(event_type);
1530 if (request_event == NULL) {
1531 _DEBUG_ERROR("event is NULL");
1532 return SYNC_AGENT_DS_FAIL;
1535 /* add request parameter to event packet */
1536 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &count);
1538 _DEBUG_INFO("profile_dir_name = %s", profile_info->profile_dir_name);
1539 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1541 /* send event request to ds agent daemon, waiting for response */
1542 response_event = sync_agent_send_event(request_event, &error);
1543 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1544 _DEBUG_ERROR("error = %d", error);
1545 sync_agent_free_event(request_event);
1547 return SYNC_AGENT_DS_FAIL;
1549 if (response_event == NULL) {
1550 _DEBUG_ERROR("response_event is null!!");
1551 sync_agent_free_event(request_event);
1553 return SYNC_AGENT_DS_FAIL;
1556 /* get response parameter from event packet */
1557 sync_agent_get_event_data_param_int(response_event, &api_result);
1559 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1560 _DEBUG_ERROR("api_result = failed");
1561 sync_agent_free_event(request_event);
1562 sync_agent_free_event_data(response_event);
1564 return SYNC_AGENT_DS_FAIL;
1567 if (api_result ==SYNC_AGENT_DS_API_RESULT_SYNCHRONISING) {
1568 _DEBUG_ERROR("api_result = synchronising");
1569 sync_agent_free_event(request_event);
1570 sync_agent_free_event_data(response_event);
1572 return SYNC_AGENT_DS_SYNCHRONISING;
1575 /* free request & response event */
1576 sync_agent_free_event(request_event);
1577 sync_agent_free_event_data(response_event);
1581 return SYNC_AGENT_DS_SUCCESS;
1584 EXPORT_API sync_agent_ds_error_e sync_agent_ds_start_sync(ds_profile_h profile_h)
1588 // check mandatory parameter
1589 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1591 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1593 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1595 int event_type = SYNC_AGENT_DS_START_SYNC;
1596 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1597 sync_agent_event_data_s *request_event = NULL;
1598 sync_agent_event_data_s *response_event = NULL;
1600 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1602 /* create empty event packet */
1603 request_event = sync_agent_create_event(event_type);
1604 if (request_event == NULL) {
1605 _DEBUG_ERROR("event is NULL");
1606 return SYNC_AGENT_DS_FAIL;
1609 /* add request parameter to event packet */
1610 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1612 /* send event request to ds agent daemon, waiting for response */
1613 response_event = sync_agent_send_event(request_event, &error);
1614 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1615 _DEBUG_ERROR("error = %d", error);
1616 sync_agent_free_event(request_event);
1618 return SYNC_AGENT_DS_FAIL;
1620 if (response_event == NULL) {
1621 _DEBUG_ERROR("response_event is null!!");
1622 sync_agent_free_event(request_event);
1624 return SYNC_AGENT_DS_FAIL;
1627 /* get response parameter from event packet */
1628 sync_agent_get_event_data_param_int(response_event, &api_result);
1630 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1631 _DEBUG_ERROR("api_result = failed");
1632 sync_agent_free_event(request_event);
1633 sync_agent_free_event_data(response_event);
1635 return SYNC_AGENT_DS_FAIL;
1638 /* free request & response event */
1639 sync_agent_free_event(request_event);
1640 sync_agent_free_event_data(response_event);
1644 return SYNC_AGENT_DS_SUCCESS;
1647 EXPORT_API sync_agent_ds_error_e sync_agent_ds_stop_sync(ds_profile_h profile_h)
1651 // check mandatory parameter
1652 retvm_if(profile_h == NULL, SYNC_AGENT_DS_FAIL, "profile handle is null!!");
1654 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1656 retvm_if(profile_info->profile_dir_name == NULL, SYNC_AGENT_DS_FAIL, "profile_dir_name is null!!");
1658 int event_type = SYNC_AGENT_DS_STOP_SYNC;
1659 sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS;
1660 sync_agent_event_data_s *request_event = NULL;
1661 sync_agent_event_data_s *response_event = NULL;
1663 int api_result = SYNC_AGENT_DS_API_RESULT_SUCCESS;
1665 /* create empty event packet */
1666 request_event = sync_agent_create_event(event_type);
1667 if (request_event == NULL) {
1668 _DEBUG_ERROR("event is NULL");
1669 return SYNC_AGENT_DS_FAIL;
1672 /* add request parameter to event packet */
1673 sync_agent_append_event_data_param(request_event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name);
1675 /* send event request to ds agent daemon, waiting for response */
1676 response_event = sync_agent_send_event(request_event, &error);
1677 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1678 _DEBUG_ERROR("error = %d", error);
1679 sync_agent_free_event(request_event);
1681 return SYNC_AGENT_DS_FAIL;
1683 if (response_event == NULL) {
1684 _DEBUG_ERROR("response_event is null!!");
1685 sync_agent_free_event(request_event);
1687 return SYNC_AGENT_DS_FAIL;
1690 /* get response parameter from event packet */
1691 sync_agent_get_event_data_param_int(response_event, &api_result);
1693 if (api_result == SYNC_AGENT_DS_API_RESULT_FAILURE) {
1694 _DEBUG_ERROR("api_result = failed");
1695 sync_agent_free_event(request_event);
1696 sync_agent_free_event_data(response_event);
1698 return SYNC_AGENT_DS_FAIL;
1701 /* free request & response event */
1702 sync_agent_free_event(request_event);
1703 sync_agent_free_event_data(response_event);
1707 return SYNC_AGENT_DS_SUCCESS;
1710 EXPORT_API void sync_agent_ds_free_profile_info(ds_profile_h profile_h)
1714 // check mandatory parameter
1715 retm_if(profile_h == NULL, "profile handle is null!!");
1717 sync_agent_ds_profile_info *profile_info = (sync_agent_ds_profile_info *) profile_h;
1719 sync_agent_ds_server_info *server_info = &profile_info->server_info;
1720 //sync_agent_ds_sync_info *sync_info = &profile_info->sync_info;
1721 GList *category_list = profile_info->service_list;
1723 // free profile name
1724 g_free(profile_info->profile_dir_name);
1725 g_free(profile_info->profile_name);
1727 // free server information
1728 g_free(server_info->addr);
1729 g_free(server_info->id);
1730 g_free(server_info->password);
1732 // free sync category information
1733 g_list_free_full(category_list, (GDestroyNotify) _free_sync_category_info);
1735 // free profile information
1736 g_free(profile_info);
1741 EXPORT_API sync_agent_ds_error_e sync_agent_ds_deinit()
1745 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
1746 sync_agent_deinit_error_e deinit = SYNC_AGENT_DEINIT_SUCCESS;
1749 ret = _kill_omads_agent();
1752 _DEBUG_ERROR("_kill_omads_agent() failed !!");
1753 result = SYNC_AGENT_DS_FAIL;
1759 deinit = sync_agent_deinit();
1760 if (deinit != SYNC_AGENT_DEINIT_SUCCESS) {
1761 _DEBUG_ERROR("sync_agent_clean_event_handler() failed !!");
1762 result = SYNC_AGENT_DS_FAIL;
1764 // if (err != SYNC_AGENT_EVENT_SUCCESS) {
1765 // sync_agent_event_error_e err = sync_agent_stop_noti_listener();
1766 // _DEBUG_INFO("STOP NOTILISTNER is failed");
1767 // result = SYNC_AGENT_DS_FAIL;
1770 // err = sync_agent_clean_event_handler();
1771 // if (err != SYNC_AGENT_EVENT_SUCCESS) {
1772 // _DEBUG_ERROR("sync_agent_clean_event_handler() failed !!");
1773 // result = SYNC_AGENT_DS_FAIL;
1781 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)
1785 sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS;
1787 sync_agent_event_error_e err = sync_agent_set_noti_callback(type, callback, data);
1788 if (err != SYNC_AGENT_EVENT_SUCCESS) {
1789 _DEBUG_ERROR("failed sync_agent_set_noti_callback()");
1790 result = SYNC_AGENT_DS_FAIL;