add comment LCOV_EXCL
[platform/core/pim/calendar-service.git] / common / cal_record_updated_info.c
1 /*
2  * Calendar Service
3  *
4  * Copyright (c) 2012 - 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 #include <stdlib.h>
21 #include <stdbool.h>
22 #include <string.h>
23
24 #include "cal_internal.h"
25 #include "cal_typedef.h"
26 #include "cal_view.h"
27 #include "cal_record.h"
28
29 static int _cal_record_updated_info_create(calendar_record_h* out_record);
30 static int _cal_record_updated_info_destroy(calendar_record_h record, bool delete_child);
31 static int _cal_record_updated_info_clone(calendar_record_h record, calendar_record_h* out_record);
32 static int _cal_record_updated_info_get_int(calendar_record_h record, unsigned int property_id, int* out_value);
33 static int _cal_record_updated_info_set_int(calendar_record_h record, unsigned int property_id, int value);
34
35 cal_record_plugin_cb_s cal_record_updated_info_plugin_cb = {
36         .create = _cal_record_updated_info_create,
37         .destroy = _cal_record_updated_info_destroy,
38         .clone = _cal_record_updated_info_clone,
39         .get_str = NULL,
40         .get_str_p = NULL,
41         .get_int = _cal_record_updated_info_get_int,
42         .get_double = NULL,
43         .get_lli = NULL,
44         .get_caltime = NULL,
45         .set_str = NULL,
46         .set_int = _cal_record_updated_info_set_int,
47         .set_double = NULL,
48         .set_lli = NULL,
49         .set_caltime = NULL,
50         .add_child_record = NULL,
51         .remove_child_record = NULL,
52         .get_child_record_count = NULL,
53         .get_child_record_at_p = NULL,
54         .clone_child_record_list = NULL
55 };
56
57 static int _cal_record_updated_info_create(calendar_record_h* out_record)
58 {
59         cal_updated_info_s *temp = NULL;
60         int ret = CALENDAR_ERROR_NONE;
61
62         temp = calloc(1, sizeof(cal_updated_info_s));
63         RETVM_IF(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
64
65         *out_record = (calendar_record_h)temp;
66
67         return ret;
68 }
69
70 static int _cal_record_updated_info_destroy(calendar_record_h record, bool delete_child)
71 {
72         int ret = CALENDAR_ERROR_NONE;
73
74         cal_updated_info_s *temp = (cal_updated_info_s*)(record);
75
76         CAL_FREE(temp);
77
78         return ret;
79 }
80
81 static int _cal_record_updated_info_clone(calendar_record_h record, calendar_record_h* out_record)
82 {
83         cal_updated_info_s *out_data = NULL;
84         cal_updated_info_s *src_data = NULL;
85
86         src_data = (cal_updated_info_s*)(record);
87
88         out_data = calloc(1, sizeof(cal_updated_info_s));
89         RETVM_IF(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
90
91         CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
92
93         out_data->type = src_data->type;
94         out_data->id = src_data->id;
95         out_data->calendar_id = src_data->calendar_id;
96         out_data->version = src_data->version;
97
98         *out_record = (calendar_record_h)out_data;
99
100         return CALENDAR_ERROR_NONE;
101 }
102
103 static int _cal_record_updated_info_get_int(calendar_record_h record, unsigned int property_id, int* out_value)
104 {
105         cal_updated_info_s *rec = (cal_updated_info_s*)(record);
106
107         switch (property_id) {
108         case CAL_PROPERTY_UPDATED_INFO_ID:
109                 *out_value = (rec->id);
110                 break;
111         case CAL_PROPERTY_UPDATED_INFO_CALENDAR_ID:
112                 *out_value = (rec->calendar_id);
113                 break;
114         case CAL_PROPERTY_UPDATED_INFO_TYPE:
115                 *out_value = (rec->type);
116                 break;
117         case CAL_PROPERTY_UPDATED_INFO_VERSION:
118                 *out_value = (rec->version);
119                 break;
120         default:
121                 /* LCOV_EXCL_START */
122                 ERR("invalid parameter (property:0x%x)", property_id);
123                 return CALENDAR_ERROR_INVALID_PARAMETER;
124                 /* LCOV_EXCL_STOP */
125         }
126
127         return CALENDAR_ERROR_NONE;
128 }
129
130 static int _cal_record_updated_info_set_int(calendar_record_h record, unsigned int property_id, int value)
131 {
132         cal_updated_info_s *rec = (cal_updated_info_s*)(record);
133         switch (property_id) {
134         case CAL_PROPERTY_UPDATED_INFO_ID:
135                 (rec->id) = value;
136                 break;
137         case CAL_PROPERTY_UPDATED_INFO_CALENDAR_ID:
138                 (rec->calendar_id) = value;
139                 break;
140         case CAL_PROPERTY_UPDATED_INFO_TYPE:
141                 (rec->type) = value;
142                 break;
143         case CAL_PROPERTY_UPDATED_INFO_VERSION:
144                 (rec->version) = value;
145                 break;
146         default:
147                 /* LCOV_EXCL_START */
148                 ERR("invalid parameter (property:0x%x)", property_id);
149                 return CALENDAR_ERROR_INVALID_PARAMETER;
150                 /* LCOV_EXCL_STOP */
151         }
152
153         return CALENDAR_ERROR_NONE;
154 }