diff options
author | vivek <vivek.ellur@samsung.com> | 2013-08-21 17:06:50 +0530 |
---|---|---|
committer | hs321.lee <hs321.lee@samsung.com> | 2013-11-21 13:02:31 +0900 |
commit | 75c4e38509a0e37238953b6980da9262be1c1487 (patch) | |
tree | b957c70274722085fc015e3bd4fdb222f1c37e85 | |
parent | 695c1244399b6c8b1983b411ab29ff9122dab56e (diff) | |
download | social-75c4e38509a0e37238953b6980da9262be1c1487.tar.gz social-75c4e38509a0e37238953b6980da9262be1c1487.tar.bz2 social-75c4e38509a0e37238953b6980da9262be1c1487.zip |
Replaced all the references for contacts_db_get_record with AddressbookUtil::GetContactRecord method and replaced all the references of contacts_db_insert_record with AddressbookUtil::InsertContactRecord
Change-Id: I203a70936ff42f2d30f28061ceb12aa5f6cca315
Signed-off-by: vivek <vivek.ellur@samsung.com>
Signed-off-by: hs321.lee <hs321.lee@samsung.com>
-rw-r--r-- | src/FScl_AddressbookImpl.cpp | 206 | ||||
-rw-r--r-- | src/FScl_AddressbookUtil.cpp | 67 | ||||
-rw-r--r-- | src/FScl_PersonImpl.cpp | 18 |
3 files changed, 106 insertions, 185 deletions
diff --git a/src/FScl_AddressbookImpl.cpp b/src/FScl_AddressbookImpl.cpp index a74129b..8076da7 100644 --- a/src/FScl_AddressbookImpl.cpp +++ b/src/FScl_AddressbookImpl.cpp @@ -95,19 +95,13 @@ _AddressbookImpl::Construct(void) if (name.IsEmpty()) { SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); + char *pName = null; - char* pName = null; - contacts_record_h recordHandle = null; - int ret = contacts_db_get_record(_contacts_address_book._uri, DEFAULT_ADDRESSBOOK_ID, &recordHandle); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred. Addressbook Id(%d), error code(%d)", GetErrorMessage(E_SYSTEM), DEFAULT_ADDRESSBOOK_ID, ret); - - contacts_record_get_str_p(recordHandle, _contacts_address_book.name, &pName); - contacts_record_get_int(recordHandle, _contacts_address_book.account_id, &accountId); - + unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, DEFAULT_ADDRESSBOOK_ID)); + SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); + contacts_record_get_str_p(pAbRecord.get(), _contacts_address_book.name, &pName); + contacts_record_get_int(pAbRecord.get(), _contacts_address_book.account_id, &accountId); name = pName; - - contacts_record_destroy(recordHandle, true); } __addressbookId = DEFAULT_ADDRESSBOOK_ID; @@ -303,24 +297,17 @@ _AddressbookImpl::AddContact(Contact& contact) SysTryReturn(NID_SCL, !_ContactImpl::GetInstance(contact)->IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contact does not have any property.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - int recordId = 0; - contacts_record_h recordHandle = null; - - recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle(); - - contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, __addressbookId); + contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle(); + contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, __addressbookId); - int ret = contacts_db_insert_record(recordHandle, &recordId); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); + int recordId = 0; + result r = _AddressbookUtil::InsertContactRecordN(recordHandle, recordId); + SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); - ret = contacts_db_get_record(_contacts_contact._uri, recordId, &recordHandle); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The contact is not found."); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OBJ_NOT_FOUND, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); + unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, recordId)); + SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - _ContactImpl::GetInstance(contact)->SetContactRecordHandle(recordHandle); + _ContactImpl::GetInstance(contact)->SetContactRecordHandle(pContactRecord.release()); _RecordImpl::GetInstance(contact)->SetRecordId(recordId); return E_SUCCESS; @@ -332,11 +319,11 @@ _AddressbookImpl::AddCategory(Category& category) SysTryReturn(NID_SCL, category.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified categoryId is not INVALID_RECORD_ID.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - int recordId = 0; contacts_record_h recordHandle = null; unique_ptr<IListT<int> > pList(null); recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle(); + contacts_record_set_int(recordHandle, _contacts_group.address_book_id, __addressbookId); if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()) { @@ -360,21 +347,14 @@ _AddressbookImpl::AddCategory(Category& category) SysTryReturn(NID_SCL, count == 0, E_OBJ_ALREADY_EXIST, E_OBJ_ALREADY_EXIST, "[%s] The category name is already being used by other category.", GetErrorMessage(E_OBJ_ALREADY_EXIST)); } - recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle(); - - contacts_record_set_int(recordHandle, _contacts_group.address_book_id, __addressbookId); - - int ret = contacts_db_insert_record(recordHandle, &recordId); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); + int recordId = 0; + result r = _AddressbookUtil::InsertContactRecordN(recordHandle, recordId); + SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); - ret = contacts_db_get_record(_contacts_group._uri, recordId, &recordHandle); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%d] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); + unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, recordId)); + SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - _CategoryImpl::GetInstance(category)->SetRecordHandle(recordHandle); + _CategoryImpl::GetInstance(category)->SetRecordHandle(pCategoryRecord.release()); _RecordImpl::GetInstance(category)->SetRecordId(recordId); pList.reset(_CategoryImpl::GetInstance(category)->GetAddedMembersN()); @@ -448,20 +428,14 @@ _AddressbookImpl::UpdateContact(const Contact& contact) SysTryReturn(NID_SCL, !_ContactImpl::GetInstance(contact)->IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contact does not have any property.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - contacts_record_h recordHandle = null; - - int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); + unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_simple_contact._uri, contactId)); + SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); int intValue = 0; - contacts_record_get_int(recordHandle, _contacts_simple_contact.id, &intValue); - - contacts_record_destroy(recordHandle, true); + contacts_record_get_int(pContactRecord.get(), _contacts_simple_contact.id, &intValue); SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); - recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle(); + contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle(); SysTryReturn(NID_SCL, recordHandle != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); result r = _AddressbookUtil::UpdateContactRecord(recordHandle); @@ -471,7 +445,7 @@ _AddressbookImpl::UpdateContact(const Contact& contact) unsigned int count2 = 0; contacts_record_h newRecordHandle = null; - ret = contacts_db_get_record(_contacts_contact._uri, contactId, &newRecordHandle); + int ret = contacts_db_get_record(_contacts_contact._uri, contactId, &newRecordHandle); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); @@ -565,12 +539,10 @@ _AddressbookImpl::UpdateContact(const Contact& contact) { SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); } - ret = contacts_db_get_record(_contacts_contact._uri, contactId, &recordHandle); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); + pContactRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, contact.GetRecordId())); + SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - _ContactImpl::GetInstance(*const_cast<Contact*>(&contact))->SetContactRecordHandle(recordHandle); + _ContactImpl::GetInstance(*const_cast<Contact*>(&contact))->SetContactRecordHandle(pContactRecord.release()); return E_SUCCESS; } @@ -583,22 +555,14 @@ _AddressbookImpl::UpdateCategory(const Category& category) SysTryReturn(NID_SCL, !category.GetName().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified category does not have name.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - contacts_record_h recordHandle = null; - int intValue = 0; - int ret = CONTACTS_ERROR_NONE; - - ret = contacts_db_get_record(_contacts_group._uri, category.GetRecordId(), &recordHandle); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); - - contacts_record_get_int(recordHandle, _contacts_group.id, &intValue); - - contacts_record_destroy(recordHandle, true); + unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, category.GetRecordId())); + SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); + int intValue = 0; + contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue); + SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); - recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle(); + contacts_record_h recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle(); if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()) { @@ -635,12 +599,10 @@ _AddressbookImpl::UpdateCategory(const Category& category) result r = _AddressbookUtil::UpdateContactRecord(recordHandle); SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); - ret = contacts_db_get_record(_contacts_group._uri, category.GetRecordId(), &recordHandle); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); + pCategoryRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, category.GetRecordId())); + SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - _CategoryImpl::GetInstance(*const_cast<Category*>(&category))->SetRecordHandle(recordHandle); + _CategoryImpl::GetInstance(*const_cast<Category*>(&category))->SetRecordHandle(pCategoryRecord.release()); std::unique_ptr<IListT<int> > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN()); if (pList != null && pList->GetCount() > 0) @@ -682,18 +644,14 @@ _AddressbookImpl::AddMemberToCategory(RecordId categoryId, RecordId contactId) SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - contacts_record_h recordHandle = null; int addressbookId = 0; - int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The contact does not exist.", GetErrorMessage(E_INVALID_ARG)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); - contacts_record_get_int(recordHandle, _contacts_simple_contact.address_book_id, &addressbookId); - contacts_record_destroy(recordHandle, true); + unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_simple_contact._uri, contactId)); + SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); + contacts_record_get_int(pContactRecord.get(), _contacts_simple_contact.address_book_id, &addressbookId); SysTryReturn(NID_SCL, addressbookId == __addressbookId, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The contact does not exist in this addresbook.", GetErrorMessage(E_INVALID_ARG)); - ret = contacts_group_add_contact(categoryId, contactId); + int ret = contacts_group_add_contact(categoryId, contactId); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); @@ -708,28 +666,20 @@ _AddressbookImpl::RemoveMemberFromCategory(RecordId categoryId, RecordId contact SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - contacts_record_h recordHandle = null; int addressbookId = 0; - int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The contact does not exist.", GetErrorMessage(E_INVALID_ARG)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); - contacts_record_get_int(recordHandle, _contacts_simple_contact.address_book_id, &addressbookId); - contacts_record_destroy(recordHandle, true); + unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_simple_contact._uri, contactId)); + SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); + contacts_record_get_int(pContactRecord.get(), _contacts_simple_contact.address_book_id, &addressbookId); SysTryReturn(NID_SCL, addressbookId == __addressbookId, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The contact does not exist in this addresbook.", GetErrorMessage(E_INVALID_ARG)); - ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The category does not exist.", GetErrorMessage(E_INVALID_ARG)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); - - contacts_record_get_int(recordHandle, _contacts_group.address_book_id, &addressbookId); - contacts_record_destroy(recordHandle, true); + unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId)); + SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); + contacts_record_get_int(pCategoryRecord.get(), _contacts_group.address_book_id, &addressbookId); SysTryReturn(NID_SCL, addressbookId == __addressbookId, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The category does not exist in this addresbook.", GetErrorMessage(E_INVALID_ARG)); - ret = contacts_group_remove_contact(categoryId, contactId); + int ret = contacts_group_remove_contact(categoryId, contactId); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); @@ -747,7 +697,7 @@ _AddressbookImpl::GetAllCategoriesN(void) const __Filter<__ContactsGroup> filter; filter.Construct(); filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId); - + __Query<__ContactsGroup> query; query.Construct(); query.SetFilter(filter); @@ -1059,24 +1009,19 @@ _AddressbookImpl::GetContactN(RecordId contactId) const SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - int intValue = 0; - contacts_record_h contactHandle = null; - ClearLastResult(); - std::unique_ptr<Contact> pContact(new (std::nothrow) Contact()); - SysTryReturn(NID_SCL, pContact, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); + unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, contactId)); + SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - int ret = contacts_db_get_record(_contacts_contact._uri, contactId, &contactHandle); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); - - _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(contactHandle); - - contacts_record_get_int(contactHandle, _contacts_contact.id, &intValue); + int intValue = 0; + contacts_record_get_int(pContactRecord.get(), _contacts_contact.id, &intValue); SysTryReturn(NID_SCL, intValue == contactId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); + unique_ptr<Contact> pContact(new (std::nothrow) Contact()); + SysTryReturn(NID_SCL, pContact, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); + + _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release()); _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue); return pContact.release(); @@ -1088,21 +1033,18 @@ _AddressbookImpl::GetCategoryN(RecordId categoryId) const SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - contacts_record_h recordHandle = null; - ClearLastResult(); - int intValue = 0; - int ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); + unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId)); + SysTryReturn(NID_SCL, pCategoryRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - std::unique_ptr<Category> pCategory(new (std::nothrow) Category()); - SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); + int intValue = 0; + + contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue); + SysTryReturn(NID_SCL, categoryId == intValue, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); - contacts_record_get_int(recordHandle, _contacts_group.id, &intValue); - SysTryReturn(NID_SCL, intValue == categoryId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); + unique_ptr<Category> pCategory(new (std::nothrow) Category()); + SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); __Filter<__ContactsGroupRelation> filter; filter.Construct(); @@ -1115,7 +1057,7 @@ _AddressbookImpl::GetCategoryN(RecordId categoryId) const int count = _AddressbookUtil::GetCountWithQuery(query); SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(recordHandle); + _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(pCategoryRecord.release()); _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count); _RecordImpl::GetInstance(*pCategory)->SetRecordId(categoryId); @@ -1182,7 +1124,7 @@ _AddressbookImpl::GetChangedCategoriesAfterN(int version, int& latestVersion) co pChangedRelations->RemoveAll(false); latestVersion = latestVersion2 > latestVersion1 ? latestVersion2 : latestVersion1; - + return pChangeList.release(); } @@ -1422,10 +1364,9 @@ _AddressbookImpl::SetUserProfile(const UserProfile* pUserProfile) return E_SYSTEM; } - ret = contacts_db_insert_record(newRecordHandle, &recordId); - contacts_record_destroy(newRecordHandle, true); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); + int recordId = 0; + result r = _AddressbookUtil::InsertContactRecordN(newRecordHandle, recordId); + SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); } else if (recordId > 0) { @@ -1468,10 +1409,9 @@ _AddressbookImpl::SetUserProfile(const UserProfile* pUserProfile) return E_SYSTEM; } - ret = contacts_db_insert_record(newRecordHandle, &recordId); - contacts_record_destroy(newRecordHandle, true); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); + int recordId = 0; + result r = _AddressbookUtil::InsertContactRecordN(newRecordHandle, recordId); + SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); } } } diff --git a/src/FScl_AddressbookUtil.cpp b/src/FScl_AddressbookUtil.cpp index aba153d..521acbd 100644 --- a/src/FScl_AddressbookUtil.cpp +++ b/src/FScl_AddressbookUtil.cpp @@ -21,6 +21,7 @@ */ #include <stdlib.h> +#include <unique_ptr.h> #include <FBaseDateTime.h> #include <FBaseColArrayList.h> #include <FBaseColArrayListT.h> @@ -54,6 +55,7 @@ #include "FScl_AddressbookImpl.h" #include "FScl_UserProfileImpl.h" +using namespace std; using namespace Tizen::Base; using namespace Tizen::Base::Collection; @@ -136,7 +138,6 @@ __ContactsGroupRelation::ConvertResultTo<Category>(__SearchResult<__ContactsGrou SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); int intValue = 0; - contacts_record_h newRecord = null; contacts_record_h currentRecord = searchResult.GetCurrentRecord(); SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); @@ -147,12 +148,10 @@ __ContactsGroupRelation::ConvertResultTo<Category>(__SearchResult<__ContactsGrou std::unique_ptr<Category> pCategory(new (std::nothrow) Category()); SysTryReturn(NID_SCL, pCategory != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - int ret = contacts_db_get_record(_contacts_group._uri, intValue, &newRecord); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); + unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, intValue)); + SysTryReturn(NID_SCL, pCategoryRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(newRecord); + _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(pCategoryRecord.release()); _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue); __Filter<__ContactsGroupRelation> filter; @@ -184,7 +183,6 @@ __ContactsContactGroupRel::ConvertResultTo<Category>(__SearchResult<__ContactsCo SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); int intValue = 0; - contacts_record_h newRecord = null; contacts_record_h currentRecord = searchResult.GetCurrentRecord(); SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); @@ -195,12 +193,10 @@ __ContactsContactGroupRel::ConvertResultTo<Category>(__SearchResult<__ContactsCo std::unique_ptr<Category> pCategory(new (std::nothrow) Category()); SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - int ret = contacts_db_get_record(_contacts_group._uri, intValue, &newRecord); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); + unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, intValue)); + SysTryReturn(NID_SCL, pCategoryRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(newRecord); + _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(pCategoryRecord.release()); _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue); __Filter<__ContactsGroupRelation> filter; @@ -233,7 +229,6 @@ __ContactsContactGroupRel::ConvertResultTo<Contact>(__SearchResult<__ContactsCon SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); int intValue = 0; - contacts_record_h newRecord = null; contacts_record_h currentRecord = searchResult.GetCurrentRecord(); SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); @@ -244,12 +239,10 @@ __ContactsContactGroupRel::ConvertResultTo<Contact>(__SearchResult<__ContactsCon std::unique_ptr<Contact> pContact(new (std::nothrow) Contact()); SysTryReturn(NID_SCL, pContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - int ret = contacts_db_get_record(_contacts_contact._uri, intValue, &newRecord); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); + unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, intValue)); + SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecord); + _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release()); _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue); return pContact.release(); @@ -263,7 +256,6 @@ __ContactsContactEmail::ConvertResultTo<Contact>(__SearchResult<__ContactsContac SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); int intValue = 0; - contacts_record_h newRecord = null; contacts_record_h currentRecord = searchResult.GetCurrentRecord(); SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); @@ -274,12 +266,10 @@ __ContactsContactEmail::ConvertResultTo<Contact>(__SearchResult<__ContactsContac std::unique_ptr<Contact> pContact(new (std::nothrow) Contact()); SysTryReturn(NID_SCL, pContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - int ret = contacts_db_get_record(_contacts_contact._uri, intValue, &newRecord); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); + unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, intValue)); + SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecord); + _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release()); _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue); return pContact.release(); @@ -365,7 +355,6 @@ __ContactsContactNumber::ConvertResultTo<Contact>(__SearchResult<__ContactsConta SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); int intValue = 0; - contacts_record_h newRecord = null; contacts_record_h currentRecord = searchResult.GetCurrentRecord(); SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); @@ -376,12 +365,10 @@ __ContactsContactNumber::ConvertResultTo<Contact>(__SearchResult<__ContactsConta std::unique_ptr<Contact> pContact(new (std::nothrow) Contact()); SysTryReturn(NID_SCL, pContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - int ret = contacts_db_get_record(_contacts_contact._uri, intValue, &newRecord); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); + unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, intValue)); + SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecord); + _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release()); _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue); return pContact.release(); @@ -539,7 +526,7 @@ __ContactsPerson::ConvertResultTo<Person>(__SearchResult<__ContactsPerson>& quer contacts_record_get_str_p(currentRecord, _contacts_person.display_name, &pCharValue); _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue); - + return pPerson.release(); } @@ -548,7 +535,7 @@ Person* _AddressbookUtil::CreatePersonN(void) { Person* pPerson = new (std::nothrow) Person(); - return pPerson; + return pPerson; } template<> @@ -588,7 +575,7 @@ __ContactsPersonGroupRel::ConvertResultTo<Person>(__SearchResult<__ContactsPerso contacts_record_get_str_p(currentRecord, _contacts_person_grouprel.display_name, &pCharValue); _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue); - + return pPerson.release(); } @@ -599,7 +586,6 @@ __ContactsPersonGroupRel::ConvertResultTo<Category>(__SearchResult<__ContactsPer SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); int intValue = 0; - contacts_record_h newRecord = null; contacts_record_h currentRecord = searchResult.GetCurrentRecord(); SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); @@ -610,12 +596,11 @@ __ContactsPersonGroupRel::ConvertResultTo<Category>(__SearchResult<__ContactsPer contacts_record_get_int(currentRecord, _contacts_person_grouprel.group_id, &intValue); SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); - int ret = contacts_db_get_record(_contacts_group._uri, intValue, &newRecord); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); - _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(newRecord); + unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, intValue)); + SysTryReturn(NID_SCL, pCategoryRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); + + _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(pCategoryRecord.release()); _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue); __Filter<__ContactsGroupRelation> filter; @@ -674,7 +659,7 @@ __ContactsPerson::ConvertHandleTo<Person>(contacts_record_h recordHandle) contacts_record_get_str_p(recordHandle, _contacts_person.display_name, &pCharValue); _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue); - + return pPerson.release(); } @@ -712,7 +697,7 @@ __ContactsPersonGroupRel::ConvertHandleTo<Person>(contacts_record_h recordHandle contacts_record_get_str_p(recordHandle, _contacts_person_grouprel.display_name, &pCharValue); _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue); - + return pPerson.release(); } diff --git a/src/FScl_PersonImpl.cpp b/src/FScl_PersonImpl.cpp index f8df1f8..2eea727 100644 --- a/src/FScl_PersonImpl.cpp +++ b/src/FScl_PersonImpl.cpp @@ -38,6 +38,7 @@ #include "FScl_ContactDbConnector.h" #include "FScl_ContactDbMonitor.h" +using namespace std; using namespace Tizen::App; using namespace Tizen::Base; using namespace Tizen::Base::Collection; @@ -238,22 +239,17 @@ _PersonImpl::SetAsFavorite(bool isFavorite) { SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - bool boolValue = false; - contacts_record_h personHandle = null; - - int ret = contacts_db_get_record(_contacts_person._uri, __personId, &personHandle); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The person is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); + unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, __personId)); + SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); - __ContactsRecordHandle recordHandle(personHandle); - - contacts_record_get_bool(personHandle, _contacts_person.is_favorite, &boolValue); + bool boolValue = false; + contacts_record_get_bool(pPersonRecord.get(), _contacts_person.is_favorite, &boolValue); if (boolValue != isFavorite) { - contacts_record_set_bool(personHandle, _contacts_person.is_favorite, isFavorite); + contacts_record_set_bool(pPersonRecord.get(), _contacts_person.is_favorite, isFavorite); - result r = _AddressbookUtil::UpdateContactRecord(personHandle); + result r = _AddressbookUtil::UpdateContactRecord(pPersonRecord.get()); SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); __isFavorite = isFavorite; |