improve line coverage
[platform/core/pim/contacts-service.git] / common / ctsvc_record.h
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #ifndef __CTSVC_RECORD_H__
21 #define __CTSVC_RECORD_H__
22
23 #define CTSVC_RECORD_INIT_BASE(base, type, cb, uri) do {\
24         (base)->r_type = (type);\
25         (base)->plugin_cbs = (cb);\
26         (base)->view_uri = (uri);\
27         (base)->property_max_count = 0;\
28 } while (0)
29
30 static inline int ctsvc_record_copy_base(ctsvc_record_s *dest, ctsvc_record_s *src)
31 {
32         dest->r_type = src->r_type;
33         dest->plugin_cbs = src->plugin_cbs;
34         dest->view_uri = src->view_uri;
35         dest->property_max_count = src->property_max_count;
36         dest->property_flag = src->property_flag;
37         if (src->properties_flags) {
38                 dest->properties_flags = calloc(dest->property_max_count, sizeof(char));
39                 if (NULL == dest->properties_flags) {
40                         /* LCOV_EXCL_START */
41                         ERR("calloc() Fail");
42                         return CONTACTS_ERROR_OUT_OF_MEMORY;
43                         /* LCOV_EXCL_STOP */
44                 }
45                 if (dest->properties_flags)
46                         memcpy(dest->properties_flags, src->properties_flags, sizeof(char)*dest->property_max_count);
47         }
48         return CONTACTS_ERROR_NONE;
49 }
50
51 #define CTSVC_RECORD_RESET_PROPERTY_FLAGS(base)do {\
52         if ((base)->properties_flags) {\
53                 free((base)->properties_flags); \
54                 (base)->property_max_count = 0;\
55                 (base)->properties_flags = NULL;\
56                 (base)->property_flag = 0;\
57         } \
58 } while (0)
59
60 int ctsvc_record_set_property_flag(ctsvc_record_s *_record, int property_id, contacts_property_flag_e flag);
61 int ctsvc_record_set_projection_flags(contacts_record_h record, const unsigned int *projection, const unsigned int projection_count, const unsigned int property_max_count);
62 int ctsvc_record_set_str(contacts_record_h record, unsigned int property_id, const char *value);
63 int ctsvc_record_set_bool(contacts_record_h record, unsigned int property_id, bool value);
64 int ctsvc_record_set_int(contacts_record_h record, unsigned int property_id, int value);
65 int ctsvc_record_set_lli(contacts_record_h record, unsigned int property_id, long long int value);
66 int ctsvc_record_set_double(contacts_record_h record, unsigned int property_id, double value);
67 bool ctsvc_record_check_property_flag(const ctsvc_record_s *s_record, unsigned int property_id, contacts_property_flag_e flag);
68
69 #endif /* __CTSVC_RECORD_H__ */