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