f6e272f063de2d001e45e943455cffc90b5bd0e3
[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                         ERR("calloc() Fail");
41                         return CONTACTS_ERROR_OUT_OF_MEMORY;
42                 }
43                 if (dest->properties_flags)
44                         memcpy(dest->properties_flags, src->properties_flags, sizeof(char)*dest->property_max_count);
45         }
46         return CONTACTS_ERROR_NONE;
47 }
48
49 #define CTSVC_RECORD_RESET_PROPERTY_FLAGS(base)do {\
50         if ((base)->properties_flags) {\
51                 free((base)->properties_flags); \
52                 (base)->property_max_count = 0;\
53                 (base)->properties_flags = NULL;\
54                 (base)->property_flag = 0;\
55         } \
56 } while (0)
57
58 int ctsvc_record_set_property_flag(ctsvc_record_s *_record, int property_id, contacts_property_flag_e flag);
59 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);
60 int ctsvc_record_set_str(contacts_record_h record, unsigned int property_id, const char *value);
61 int ctsvc_record_set_bool(contacts_record_h record, unsigned int property_id, bool value);
62 int ctsvc_record_set_int(contacts_record_h record, unsigned int property_id, int value);
63 int ctsvc_record_set_lli(contacts_record_h record, unsigned int property_id, long long int value);
64 int ctsvc_record_set_double(contacts_record_h record, unsigned int property_id, double value);
65 bool ctsvc_record_check_property_flag(const ctsvc_record_s *s_record, unsigned int property_id, contacts_property_flag_e flag);
66
67 #endif /* __CTSVC_RECORD_H__ */