Modify the spec file for secure log
[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.normalized_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                 break;
231         };
232
233         return match;
234 }
235
236 contacts_match_str_flag_e
237 _AddressbookFilterImpl::GetMatchStrFlag(FilterStringOperator stringOperstor)
238 {
239         contacts_match_str_flag_e match = CONTACTS_MATCH_EXISTS;
240         switch(stringOperstor)
241         {
242         case FI_STR_OP_EQUAL:
243                 match = CONTACTS_MATCH_EXACTLY;
244                 break;
245         case FI_STR_OP_FULL_STRING:
246                 match = CONTACTS_MATCH_FULLSTRING;
247                 break;
248         case FI_STR_OP_START_WITH:
249                 match = CONTACTS_MATCH_STARTSWITH;
250                 break;
251         case FI_STR_OP_END_WITH:
252                 match = CONTACTS_MATCH_ENDSWITH;
253                 break;
254         case FI_STR_OP_CONTAIN:
255                 match = CONTACTS_MATCH_CONTAINS;
256                 break;
257         case FI_STR_OP_IS_NOT_NULL:
258                 match = CONTACTS_MATCH_EXISTS;
259                 break;
260         default:
261                 match = CONTACTS_MATCH_EXISTS;
262                 break;
263         };
264
265         return match;
266 }
267
268
269 result
270 _AddressbookFilterImpl::AppendInt(FilterConjunctiveOperator conjunctiveOperator, unsigned long filterProperty, FilterComparisonOperator comparisonOperator, int value)
271 {
272         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));
273         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);
274         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND || conjunctiveOperator == FI_CONJ_OP_OR)),\
275                         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",\
276                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
277         SysTryReturn(NID_SCL, !(!__isEmpty && (conjunctiveOperator == FI_CONJ_OP_NONE)),\
278                         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.",\
279                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
280
281
282         unsigned int id = _AddressbookFilterImpl::GetViewPropertyId(__filterType, filterProperty);
283         contacts_match_int_flag_e match = GetMatchIntFlag(comparisonOperator);
284
285         if (!__isEmpty)
286         {
287                 contacts_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CONTACTS_FILTER_OPERATOR_AND : CONTACTS_FILTER_OPERATOR_OR;
288
289                 contacts_filter_add_operator(__filterHandle, filterOperator);
290         }
291
292         int ret = contacts_filter_add_int(__filterHandle, id, match, value);
293         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
294
295         __isEmpty = false;
296
297         return E_SUCCESS;
298 }
299
300 result
301 _AddressbookFilterImpl::AppendBool(FilterConjunctiveOperator conjunctiveOperator, unsigned long filterProperty, FilterComparisonOperator comparisonOperator, bool value)
302 {
303         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));
304         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);
305         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND || conjunctiveOperator == FI_CONJ_OP_OR)),\
306                         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",\
307                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
308         SysTryReturn(NID_SCL, !(!__isEmpty && conjunctiveOperator == FI_CONJ_OP_NONE),\
309                         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.",\
310                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
311         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);
312
313         unsigned int viewPropertyId = _AddressbookFilterImpl::GetViewPropertyId(__filterType, filterProperty);
314
315         if (!__isEmpty)
316         {
317                 contacts_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CONTACTS_FILTER_OPERATOR_AND : CONTACTS_FILTER_OPERATOR_OR;
318
319                 contacts_filter_add_operator(__filterHandle, filterOperator);
320         }
321
322
323         int ret = contacts_filter_add_bool(__filterHandle, viewPropertyId, value);
324         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
325
326         __isEmpty = false;
327
328         return E_SUCCESS;
329 }
330
331 result
332 _AddressbookFilterImpl::AppendString(FilterConjunctiveOperator conjunctiveOperator, unsigned long filterProperty, FilterStringOperator comparisonOperator, const Tizen::Base::String& value)
333 {
334         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));
335         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);
336         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND  || conjunctiveOperator == FI_CONJ_OP_OR)),\
337                         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",\
338                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
339         SysTryReturn(NID_SCL, !(!__isEmpty && conjunctiveOperator == FI_CONJ_OP_NONE),\
340                         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.",\
341                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
342
343
344         unsigned int viewPropertyId = _AddressbookFilterImpl::GetViewPropertyId(__filterType, filterProperty);
345         contacts_match_str_flag_e match = GetMatchStrFlag(comparisonOperator);
346         std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(value));
347         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
348
349         if (!__isEmpty)
350         {
351                 contacts_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CONTACTS_FILTER_OPERATOR_AND : CONTACTS_FILTER_OPERATOR_OR;
352
353                 contacts_filter_add_operator(__filterHandle, filterOperator);
354         }
355
356         int ret = CONTACTS_ERROR_NONE;
357
358         if (filterProperty == PHONE_CONTACT_FI_PR_PHONE)
359         {
360                 contacts_filter_h numberHandle = null;
361                 ret = contacts_filter_create(_contacts_contact_number._uri, &numberHandle);
362                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s ] Memory allocation failed.", GetErrorMessage(GetLastResult()));
363
364                 contacts_filter_add_str(numberHandle, viewPropertyId, match, pCharArray.get());
365                 contacts_filter_add_operator(numberHandle, CONTACTS_FILTER_OPERATOR_OR);
366                 contacts_filter_add_str(numberHandle, _contacts_contact_number.number, match, pCharArray.get());
367
368                 ret = contacts_filter_add_filter(__filterHandle, numberHandle);
369                 contacts_filter_destroy(numberHandle);
370                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
371         }
372         else
373         {
374                 ret = contacts_filter_add_str(__filterHandle, viewPropertyId, match, pCharArray.get());
375                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
376         }
377
378         __isEmpty = false;
379
380         return E_SUCCESS;
381 }
382
383 result
384 _AddressbookFilterImpl::AppendFilter(FilterConjunctiveOperator conjunctiveOperator, const _AddressbookFilterImpl& filter)
385 {
386         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));
387         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));
388         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND || conjunctiveOperator == FI_CONJ_OP_OR)),\
389                         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",\
390                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
391         SysTryReturn(NID_SCL, !(!__isEmpty && conjunctiveOperator == FI_CONJ_OP_NONE),\
392                         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.",\
393                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
394
395         if (!__isEmpty)
396         {
397                 contacts_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CONTACTS_FILTER_OPERATOR_AND : CONTACTS_FILTER_OPERATOR_OR;
398                 contacts_filter_add_operator(__filterHandle, filterOperator);
399         }
400
401         int ret = contacts_filter_add_filter(__filterHandle, filter.__filterHandle);
402         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
403
404         __isEmpty = false;
405
406         return E_SUCCESS;
407 }
408
409 contacts_filter_h
410 _AddressbookFilterImpl::GetFilterHandle(void) const
411 {
412         if (!__isEmpty)
413         {
414                 return __filterHandle;
415         }
416
417         return null;
418 }
419
420 AddressbookFilterType
421 _AddressbookFilterImpl::GetType(void) const
422 {
423         return __filterType;
424 }
425
426 bool
427 _AddressbookFilterImpl::IsEmpty(void) const
428 {
429         return __isEmpty;
430 }
431
432 const _AddressbookFilterImpl*
433 _AddressbookFilterImpl::GetInstance(const AddressbookFilter& filter)
434 {
435         return filter.__pAddressbookFilterImpl;
436 }
437
438 _AddressbookFilterImpl*
439 _AddressbookFilterImpl::GetInstance(AddressbookFilter& filter)
440 {
441         return filter.__pAddressbookFilterImpl;
442 }
443
444 }} // Tizen::Social