Merge "Export internal APIs needed by samsung-socil" into tizen_2.1
[framework/osp/social.git] / src / FScl_AddressbookFilterImpl.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 /**
17 * @file         FScl_AddressbookFilterImpl.cpp
18 * @brief        This is the implementation for _AddressbookFilterImpl class.
19 *
20 * This file contains definitions of @e _AddressbookFilterImpl class.
21 */
22
23 #include <unique_ptr.h>
24 #include <FBaseSysLog.h>
25 #include <FSclAddressbookFilter.h>
26 #include <FBase_StringConverter.h>
27 #include "FScl_ContactDbConnector.h"
28 #include "FScl_AddressbookFilterImpl.h"
29
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32
33 namespace Tizen { namespace Social
34 {
35
36 // AB_FI_TYPE_ADDRESSBOOK
37 // The entries must be ordered same as AddressbookFilterProperty
38 const _AddressbookFilterImpl::__FilterPropertyInfoEntry _AddressbookFilterImpl::__addressbookFilterPropertyInfos[] =
39 {
40         {AB_FI_PR_ADDRESSBOOK_ID, _contacts_address_book.id, DATA_TYPE_INT},
41         {AB_FI_PR_ACCOUNT_ID, _contacts_address_book.account_id, DATA_TYPE_INT},
42         {AB_FI_PR_NAME, _contacts_address_book.name, DATA_TYPE_STRING},
43 };
44
45 // AB_FI_TYPE_PERSON
46 // The entries must be ordered same as PersonFilterProperty
47 const _AddressbookFilterImpl::__FilterPropertyInfoEntry _AddressbookFilterImpl::__personFilterPropertyInfos[] =
48 {
49         {PERSON_FI_PR_PERSON_ID, _contacts_person_grouprel.person_id, DATA_TYPE_INT},
50         {PERSON_FI_PR_DISPLAY_NAME, _contacts_person_grouprel.display_name, DATA_TYPE_STRING},
51         {PERSON_FI_PR_HAS_PHONE, _contacts_person_grouprel.has_phonenumber, DATA_TYPE_BOOL},
52         {PERSON_FI_PR_HAS_EMAIL, _contacts_person_grouprel.has_email, DATA_TYPE_BOOL},
53         {PERSON_FI_PR_IS_FAVORITE, _contacts_person_grouprel.is_favorite, DATA_TYPE_BOOL},
54         {PERSON_FI_PR_CATEGORY_ID, _contacts_person_grouprel.group_id, DATA_TYPE_INT},
55         {PERSON_FI_PR_ADDRESSBOOK_ID, _contacts_person_grouprel.address_book_id, DATA_TYPE_INT},
56 };
57
58 // AB_FI_TYPE_CONTACT
59 // The entries must be ordered same as ContactFilterProperty
60 const _AddressbookFilterImpl::__FilterPropertyInfoEntry _AddressbookFilterImpl::__contactFilterPropertyInfos[] =
61 {
62         {CONTACT_FI_PR_CONTACT_ID, _contacts_contact.id, DATA_TYPE_INT},
63         {CONTACT_FI_PR_ADDRESSBOOK_ID, _contacts_contact.address_book_id, DATA_TYPE_INT},
64         {CONTACT_FI_PR_PERSON_ID, _contacts_contact.person_id, DATA_TYPE_INT},
65         {CONTACT_FI_PR_DISPLAY_NAME, _contacts_contact.display_name, DATA_TYPE_STRING},
66         {CONTACT_FI_PR_HAS_PHONE, _contacts_contact.has_phonenumber, DATA_TYPE_BOOL},
67         {CONTACT_FI_PR_HAS_EMAIL, _contacts_contact.has_email, DATA_TYPE_BOOL},
68 };
69
70 // AB_FI_TYPE_CATEGORY
71 // The entries must be ordered same as CategoryFilterProperty
72 const _AddressbookFilterImpl::__FilterPropertyInfoEntry _AddressbookFilterImpl::__categoryFilterPropertyInfos[] =
73 {
74         {CATEGORY_FI_PR_CATEGORY_ID, _contacts_group.id, DATA_TYPE_INT},
75         {CATEGORY_FI_PR_ADDRESSBOOK_ID, _contacts_group.address_book_id, DATA_TYPE_INT},
76         {CATEGORY_FI_PR_NAME, _contacts_group.name, DATA_TYPE_STRING},
77 };
78
79 // AB_FI_TYPE_PHONE_CONTACT
80 // The entries must be ordered same as PhoneContactFilterProperty
81 const _AddressbookFilterImpl::__FilterPropertyInfoEntry _AddressbookFilterImpl::__phoneContactFilterPropertyInfos[] =
82 {
83         {PHONE_CONTACT_FI_PR_CONTACT_ID, _contacts_contact_number.contact_id, DATA_TYPE_INT},
84         {PHONE_CONTACT_FI_PR_ADDRESSBOOK_ID, _contacts_contact_number.address_book_id, DATA_TYPE_INT},
85         {PHONE_CONTACT_FI_PR_PERSON_ID, _contacts_contact_number.person_id, DATA_TYPE_INT},
86         {PHONE_CONTACT_FI_PR_DISPLAY_NAME, _contacts_contact_number.display_name, DATA_TYPE_STRING},
87         {PHONE_CONTACT_FI_PR_PHONE, _contacts_contact_number.number, DATA_TYPE_STRING},
88 };
89
90 // AB_FI_TYPE_EMAIL_CONTACT
91 // The entries must be ordered same as EmailContactFilterProperty
92 const _AddressbookFilterImpl::__FilterPropertyInfoEntry _AddressbookFilterImpl::__emailContactFilterPropertyInfos[] =
93 {
94         {EMAIL_CONTACT_FI_PR_CONTACT_ID, _contacts_contact_email.contact_id, DATA_TYPE_INT},
95         {EMAIL_CONTACT_FI_PR_ADDRESSBOOK_ID, _contacts_contact_email.address_book_id, DATA_TYPE_INT},
96         {EMAIL_CONTACT_FI_PR_PERSON_ID, _contacts_contact_email.person_id, DATA_TYPE_INT},
97         {EMAIL_CONTACT_FI_PR_DISPLAY_NAME, _contacts_contact_email.display_name, DATA_TYPE_STRING},
98         {EMAIL_CONTACT_FI_PR_EMAIL, _contacts_contact_email.email, DATA_TYPE_STRING},
99 };
100
101 const _AddressbookFilterImpl::__FilterInfoEntry _AddressbookFilterImpl::__filterInfos[] =
102 {
103         {AB_FI_TYPE_ADDRESSBOOK, _contacts_address_book._uri, AB_FI_PR_ADDRESSBOOK_ID, sizeof(__addressbookFilterPropertyInfos)/sizeof(_AddressbookFilterImpl::__FilterPropertyInfoEntry), __addressbookFilterPropertyInfos},
104         {AB_FI_TYPE_PERSON, _contacts_person_grouprel._uri, PERSON_FI_PR_PERSON_ID, sizeof(__personFilterPropertyInfos)/sizeof(_AddressbookFilterImpl::__FilterPropertyInfoEntry), __personFilterPropertyInfos},
105         {AB_FI_TYPE_CONTACT, _contacts_contact._uri, CONTACT_FI_PR_CONTACT_ID, sizeof(__contactFilterPropertyInfos)/sizeof(_AddressbookFilterImpl::__FilterPropertyInfoEntry), __contactFilterPropertyInfos},
106         {AB_FI_TYPE_CATEGORY, _contacts_group._uri, CATEGORY_FI_PR_CATEGORY_ID, sizeof(__categoryFilterPropertyInfos)/sizeof(_AddressbookFilterImpl::__FilterPropertyInfoEntry), __categoryFilterPropertyInfos},
107         {AB_FI_TYPE_PHONE_CONTACT, _contacts_contact_number._uri, PHONE_CONTACT_FI_PR_CONTACT_ID, sizeof(__phoneContactFilterPropertyInfos)/sizeof(_AddressbookFilterImpl::__FilterPropertyInfoEntry), __phoneContactFilterPropertyInfos},
108         {AB_FI_TYPE_EMAIL_CONTACT, _contacts_contact_email._uri, EMAIL_CONTACT_FI_PR_CONTACT_ID, sizeof(__emailContactFilterPropertyInfos)/sizeof(_AddressbookFilterImpl::__FilterPropertyInfoEntry), __emailContactFilterPropertyInfos},
109 };
110
111 bool
112 _AddressbookFilterImpl::IsValidProperty(AddressbookFilterType filterType, unsigned long property)
113 {
114         int filterInfoCount = sizeof(__filterInfos)/sizeof(__FilterInfoEntry);
115
116         if (filterType < 0 || filterType > (filterInfoCount - 1))
117         {
118                 return false;
119         }
120
121         unsigned long baseIndex = __filterInfos[filterType].baseIndex;
122         int propertyInfoCount = __filterInfos[filterType].propertyInfoCount;
123
124         if (property < baseIndex || property >= (baseIndex + propertyInfoCount))
125         {
126                 return false;
127         }
128
129         return true;
130 }
131
132 // IsValidProperty must be called before calling this. If IsValidProperty returns false
133 // this should not be called.
134 const char*
135 _AddressbookFilterImpl::GetUriFromType(AddressbookFilterType filterType)
136 {
137         return __filterInfos[filterType].pViewUri;
138 }
139
140 // IsValidProperty must be called before calling this. If IsValidProperty returns false
141 // this should not be called.
142 unsigned int
143 _AddressbookFilterImpl::GetViewPropertyId(AddressbookFilterType filterType, unsigned long property)
144 {
145         const __FilterPropertyInfoEntry* propertyInfos = __filterInfos[filterType].propertyInfos;
146         unsigned long baseIndex = __filterInfos[filterType].baseIndex;
147
148         return propertyInfos[property - baseIndex].viewPropertyId;
149 }
150
151 // IsValidProperty must be called before calling this. If IsValidProperty returns false
152 // this should not be called.
153 __DataType
154 _AddressbookFilterImpl::GetPropertyType(AddressbookFilterType filterType, unsigned long property)
155 {
156         const __FilterPropertyInfoEntry* propertyInfos = __filterInfos[filterType].propertyInfos;
157         unsigned long baseIndex = __filterInfos[filterType].baseIndex;
158
159         return propertyInfos[property - baseIndex].dataType;
160 }
161
162 _AddressbookFilterImpl::_AddressbookFilterImpl(AddressbookFilterType type)
163         : __filterHandle(null)
164         , __filterType(type)
165         , __isEmpty(true)
166 {
167         contacts_filter_h filterHandle = null;
168         const char* pUri = GetUriFromType(type);
169
170         SysTryReturnVoidResult(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
171
172         int ret = contacts_filter_create(pUri, &filterHandle);
173         SysTryReturnVoidResult(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, "[%s ] Memory allocation failed.", GetErrorMessage(GetLastResult()));
174
175         __filterHandle = filterHandle;
176 }
177
178 _AddressbookFilterImpl::~_AddressbookFilterImpl(void)
179 {
180         if (__filterHandle != null)
181         {
182                 contacts_filter_destroy(__filterHandle);
183         }
184 }
185
186 bool
187 _AddressbookFilterImpl::Equals(const Tizen::Base::Object& rhs) const
188 {
189         const _AddressbookFilterImpl* pAddressbookFilter = dynamic_cast<const _AddressbookFilterImpl*>(&rhs);
190         if (this == pAddressbookFilter)
191         {
192                 return true;
193         }
194
195         return false;
196 }
197
198 int
199 _AddressbookFilterImpl::GetHashCode(void) const
200 {
201         return (int)__filterHandle;
202 }
203
204 contacts_match_int_flag_e
205 _AddressbookFilterImpl::GetMatchIntFlag(FilterComparisonOperator comparisonOperator)
206 {
207         contacts_match_int_flag_e match = CONTACTS_MATCH_NONE;
208         switch(comparisonOperator)
209         {
210         case FI_CMP_OP_EQUAL:
211                 match = CONTACTS_MATCH_EQUAL;
212                 break;
213         case FI_CMP_OP_LESS_THAN:
214                 match = CONTACTS_MATCH_GREATER_THAN;
215                 break;
216         case FI_CMP_OP_LESS_THAN_OR_EQUAL:
217                 match = CONTACTS_MATCH_GREATER_THAN_OR_EQUAL;
218                 break;
219         case FI_CMP_OP_GREATER_THAN:
220                 match = CONTACTS_MATCH_LESS_THAN;
221                 break;
222         case FI_CMP_OP_GREATER_THAN_OR_EQUAL:
223                 match = CONTACTS_MATCH_LESS_THAN_OR_EQUAL;
224                 break;
225         case FI_CMP_OP_IS_NULL:
226                 match = CONTACTS_MATCH_NONE;
227                 break;
228         default:
229                 match = CONTACTS_MATCH_NONE;
230         };
231
232         return match;
233 }
234
235 contacts_match_str_flag_e
236 _AddressbookFilterImpl::GetMatchStrFlag(FilterStringOperator stringOperstor)
237 {
238         contacts_match_str_flag_e match = CONTACTS_MATCH_EXISTS;
239         switch(stringOperstor)
240         {
241         case FI_STR_OP_EQUAL:
242                 match = CONTACTS_MATCH_EXACTLY;
243                 break;
244         case FI_STR_OP_FULL_STRING:
245                 match = CONTACTS_MATCH_FULLSTRING;
246                 break;
247         case FI_STR_OP_START_WITH:
248                 match = CONTACTS_MATCH_STARTSWITH;
249                 break;
250         case FI_STR_OP_END_WITH:
251                 match = CONTACTS_MATCH_ENDSWITH;
252                 break;
253         case FI_STR_OP_CONTAIN:
254                 match = CONTACTS_MATCH_CONTAINS;
255                 break;
256         case FI_STR_OP_IS_NOT_NULL:
257                 match = CONTACTS_MATCH_EXISTS;
258                 break;
259         default:
260                 match = CONTACTS_MATCH_EXISTS;
261         };
262
263         return match;
264 }
265
266
267 result
268 _AddressbookFilterImpl::AppendInt(FilterConjunctiveOperator conjunctiveOperator, unsigned long filterProperty, FilterComparisonOperator comparisonOperator, int value)
269 {
270         SysTryReturn(NID_SCL, IsValidProperty(__filterType, filterProperty), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified filter property is invalid.", GetErrorMessage(E_INVALID_ARG));
271         SysTryReturn(NID_SCL, GetPropertyType(__filterType, filterProperty) == DATA_TYPE_INT, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the specified filter property %d must be int.", GetErrorMessage(E_INVALID_ARG), filterProperty);
272         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND || conjunctiveOperator == FI_CONJ_OP_OR)),\
273                         E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. conjunctiveOperator %d must be FI_CONJ_OP_NONE if there is no filtering expression or filter that has been appended before",\
274                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
275         SysTryReturn(NID_SCL, !(!__isEmpty && (conjunctiveOperator == FI_CONJ_OP_NONE)),\
276                         E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. conjunctiveOperator %d must be either of FI_CONJ_OP_AND or FI_CONJ_OP_OR, if there is a filtering expression or filter that has been appended before.",\
277                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
278
279
280         unsigned int id = _AddressbookFilterImpl::GetViewPropertyId(__filterType, filterProperty);
281         contacts_match_int_flag_e match = GetMatchIntFlag(comparisonOperator);
282
283         if (!__isEmpty)
284         {
285                 contacts_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CONTACTS_FILTER_OPERATOR_AND : CONTACTS_FILTER_OPERATOR_OR;
286
287                 contacts_filter_add_operator(__filterHandle, filterOperator);
288         }
289
290         int ret = contacts_filter_add_int(__filterHandle, id, match, value);
291         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
292
293         __isEmpty = false;
294
295         return E_SUCCESS;
296 }
297
298 result
299 _AddressbookFilterImpl::AppendBool(FilterConjunctiveOperator conjunctiveOperator, unsigned long filterProperty, FilterComparisonOperator comparisonOperator, bool value)
300 {
301         SysTryReturn(NID_SCL, IsValidProperty(__filterType, filterProperty), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified filter property is invalid.", GetErrorMessage(E_INVALID_ARG));
302         SysTryReturn(NID_SCL, GetPropertyType(__filterType, filterProperty) == DATA_TYPE_BOOL, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the specified filter property %d must be bool.", GetErrorMessage(E_INVALID_ARG), filterProperty);
303         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND || conjunctiveOperator == FI_CONJ_OP_OR)),\
304                         E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. conjunctiveOperator %d must be FI_CONJ_OP_NONE if there is no filtering expression or filter that has been appended before",\
305                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
306         SysTryReturn(NID_SCL, !(!__isEmpty && conjunctiveOperator == FI_CONJ_OP_NONE),\
307                         E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. conjunctiveOperator %d must be either of FI_CONJ_OP_AND or FI_CONJ_OP_OR, if there is a filtering expression or filter that has been appended before.",\
308                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
309         SysTryReturn(NID_SCL, comparisonOperator == FI_CMP_OP_EQUAL, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. comparisonOperator %d must be FI_CMP_OP_EQUAL.", GetErrorMessage(E_INVALID_ARG), comparisonOperator);
310
311         unsigned int viewPropertyId = _AddressbookFilterImpl::GetViewPropertyId(__filterType, filterProperty);
312
313         if (!__isEmpty)
314         {
315                 contacts_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CONTACTS_FILTER_OPERATOR_AND : CONTACTS_FILTER_OPERATOR_OR;
316
317                 contacts_filter_add_operator(__filterHandle, filterOperator);
318         }
319
320
321         int ret = contacts_filter_add_bool(__filterHandle, viewPropertyId, value);
322         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
323
324         __isEmpty = false;
325
326         return E_SUCCESS;
327 }
328
329 result
330 _AddressbookFilterImpl::AppendString(FilterConjunctiveOperator conjunctiveOperator, unsigned long filterProperty, FilterStringOperator comparisonOperator, const Tizen::Base::String& value)
331 {
332         SysTryReturn(NID_SCL, IsValidProperty(__filterType, filterProperty), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified filter property is invalid.", GetErrorMessage(E_INVALID_ARG));
333         SysTryReturn(NID_SCL, GetPropertyType(__filterType, filterProperty) == DATA_TYPE_STRING, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the specified filter property %d must be String.", GetErrorMessage(E_INVALID_ARG), filterProperty);
334         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND  || conjunctiveOperator == FI_CONJ_OP_OR)),\
335                         E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. conjunctiveOperator %d must be FI_CONJ_OP_NONE if there is no filtering expression or filter that has been appended before",\
336                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
337         SysTryReturn(NID_SCL, !(!__isEmpty && conjunctiveOperator == FI_CONJ_OP_NONE),\
338                         E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. conjunctiveOperator %d must be either of FI_CONJ_OP_AND or FI_CONJ_OP_OR, if there is a filtering expression or filter that has been appended before.",\
339                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
340
341
342         unsigned int viewPropertyId = _AddressbookFilterImpl::GetViewPropertyId(__filterType, filterProperty);
343         contacts_match_str_flag_e match = GetMatchStrFlag(comparisonOperator);
344         std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(value));
345         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
346
347         if (!__isEmpty)
348         {
349                 contacts_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CONTACTS_FILTER_OPERATOR_AND : CONTACTS_FILTER_OPERATOR_OR;
350
351                 contacts_filter_add_operator(__filterHandle, filterOperator);
352         }
353
354         int ret = contacts_filter_add_str(__filterHandle, viewPropertyId, match, pCharArray.get());
355         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
356
357
358         __isEmpty = false;
359
360         return E_SUCCESS;
361 }
362
363 result
364 _AddressbookFilterImpl::AppendFilter(FilterConjunctiveOperator conjunctiveOperator, const _AddressbookFilterImpl& filter)
365 {
366         SysTryReturn(NID_SCL, !filter.IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified filter should not be empty.", GetErrorMessage(E_INVALID_ARG));
367         SysTryReturn(NID_SCL, __filterType == filter.__filterType, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the filter must be same with the type of this filter.", GetErrorMessage(E_INVALID_ARG));
368         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND || conjunctiveOperator == FI_CONJ_OP_OR)),\
369                         E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. conjunctiveOperator %d must be FI_CONJ_OP_NONE if there is no filtering expression or filter that has been appended before",\
370                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
371         SysTryReturn(NID_SCL, !(!__isEmpty && conjunctiveOperator == FI_CONJ_OP_NONE),\
372                         E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. conjunctiveOperator %d must be either of FI_CONJ_OP_AND or FI_CONJ_OP_OR, if there is a filtering expression or filter that has been appended before.",\
373                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
374
375         if (!__isEmpty)
376         {
377                 contacts_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CONTACTS_FILTER_OPERATOR_AND : CONTACTS_FILTER_OPERATOR_OR;
378                 contacts_filter_add_operator(__filterHandle, filterOperator);
379         }
380
381         int ret = contacts_filter_add_filter(__filterHandle, filter.__filterHandle);
382         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
383
384         __isEmpty = false;
385
386         return E_SUCCESS;
387 }
388
389 contacts_filter_h
390 _AddressbookFilterImpl::GetFilterHandle(void) const
391 {
392         if (!__isEmpty)
393         {
394                 return __filterHandle;
395         }
396
397         return null;
398 }
399
400 AddressbookFilterType
401 _AddressbookFilterImpl::GetType(void) const
402 {
403         return __filterType;
404 }
405
406 bool
407 _AddressbookFilterImpl::IsEmpty(void) const
408 {
409         return __isEmpty;
410 }
411
412 const _AddressbookFilterImpl*
413 _AddressbookFilterImpl::GetInstance(const AddressbookFilter& filter)
414 {
415         return filter.__pAddressbookFilterImpl;
416 }
417
418 _AddressbookFilterImpl*
419 _AddressbookFilterImpl::GetInstance(AddressbookFilter& filter)
420 {
421         return filter.__pAddressbookFilterImpl;
422 }
423
424 }} // Tizen::Social