[Internal: merge private->RSA , Patch create momanager.db]
[platform/core/system/sync-agent.git] / src / fw-plugins / common-public / contact / src / plugin_interface.c
index c9c7afc..8eaf89d 100755 (executable)
@@ -293,6 +293,80 @@ DACI_FINISH:
        return ret;
 }
 
+EXPORT_API sync_agent_da_return_e sync_agent_plugin_add_async_item(GList *data, int count)
+{
+       _EXTERN_FUNC_ENTER;
+
+       retvm_if(data == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "[da_contact_plugIn] data is NULL");
+       retvm_if(count == 0, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "[da_contact_plugIn] count is 0");
+
+       contacts_error_e contacts_err = CONTACTS_ERROR_NONE;
+       contacts_list_h converted_list = NULL;
+       contacts_list_h input_list = NULL;
+       contacts_record_h converted_record = NULL;
+       contacts_record_h input_record = NULL;
+       GList *converted_data = NULL;
+       int index = 0;
+       unsigned int id_count = 0;
+       int *ids = NULL;
+
+       //for test
+       _DEBUG_INFO("[da_contact_plugIn] count = [%d]", count);
+       for (index = 0; index < count; ++index) {
+               _DEBUG_INFO("[da_contact_plugIn] nth[%d] data = [%s]", index, (char *)g_list_nth_data(data, index));
+       }
+
+       /* Convert from vCard to ctsvc struct */
+       for (index = 0; index < count; ++index) {
+               contacts_err = contacts_vcard_parse_to_contacts((char *)g_list_nth_data(data, index), &converted_list);
+               goto_if(contacts_err != CONTACTS_ERROR_NONE, "[da_contact_plugIn] contacts_vcard_parse_to_contacts() fail, contacts_err[%d]", contacts_err);
+
+               contacts_err = contacts_list_first(converted_list);
+               goto_if(contacts_err != CONTACTS_ERROR_NONE, "[da_contact_plugIn] contacts_list_first() fail, contacts_err[%d]", contacts_err);
+
+               contacts_err = contacts_list_get_current_record_p(converted_list, &converted_record);
+               goto_if(contacts_err != CONTACTS_ERROR_NONE, "[da_contact_plugIn] contacts_list_get_current_record_p() fail, contacts_err[%d]", contacts_err);
+
+               converted_data = g_list_append(converted_data, converted_record);
+       }
+       _DEBUG_INFO("[da_contact_plugIn] count of ctsvc struct list = [%d]", g_list_length(converted_data));
+
+       /* Insert item to Contact DB using Bulk API */
+       contacts_err = contacts_list_create(&input_list);
+       goto_if(contacts_err != CONTACTS_ERROR_NONE, "[da_contact_plugIn] contacts_list_create() fail, contacts_err[%d]", contacts_err);
+
+       for (index = 0; index < count; ++index) {
+               input_record = (contacts_record_h)g_list_nth_data(converted_data, index);
+               contacts_err = contacts_list_add(input_list, input_record);
+               goto_if(contacts_err != CONTACTS_ERROR_NONE, "[da_contact_plugIn] contacts_list_add() fail, contacts_err[%d]", contacts_err);
+       }
+
+       contacts_err = contacts_db_insert_records(input_list, &ids, &id_count);
+       goto_if(contacts_err != CONTACTS_ERROR_NONE, "[da_contact_plugIn] contacts_db_insert_records() fail, contacts_err[%d]", contacts_err);
+       _DEBUG_INFO("[da_contact_plugIn] Inputed count of data = [%d], Saved count of data = [%d]", count, id_count);
+       goto_if(count != id_count, "[da_contact_plugIn] contacts_db_insert_records() API wesn't create all contact data");
+
+return_part:
+       _DEBUG_INFO("[da_contact_plugIn] return_part");
+
+       if (converted_list != NULL) {
+               contacts_err = contacts_list_destroy(converted_list, false);
+               if (contacts_err != CONTACTS_ERROR_NONE) {
+                       _DEBUG_ERROR("[da_contact_plugIn] contacts_list_destroy() fail, contacts_err[%d]", contacts_err);
+               }
+       }
+
+       if (input_list != NULL) {
+               contacts_err = contacts_list_destroy(input_list, false);
+               if (contacts_err != CONTACTS_ERROR_NONE) {
+                       _DEBUG_ERROR("[da_contact_plugIn] contacts_list_destroy() fail, contacts_err[%d]", contacts_err);
+               }
+       }
+
+       _EXTERN_FUNC_EXIT;
+       return _convert_service_error_to_common_error(contacts_err);
+}
+
 EXPORT_API sync_agent_da_return_e sync_agent_plugin_update_item(int account_id, char *folder_id, char *item_id, void *data)
 {
        _EXTERN_FUNC_ENTER;