modify terminology:calendar->book,allday->localtime,normal->utime,svc->service
[platform/core/pim/calendar-service.git] / client / cal_client_db_helper.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>
21 #include <unistd.h>
22
23 #include "calendar.h"
24 #include "cal_internal.h"
25 #include "cal_typedef.h"
26 #include "cal_inotify.h"
27 #include "cal_view.h"
28 #include "cal_record.h"
29 #include "cal_handle.h"
30
31 int cal_client_db_add_changed_cb(calendar_h handle, const char* view_uri, void *callback, void* user_data)
32 {
33         CAL_FN_CALL();
34         int ret;
35         cal_record_type_e type = CAL_RECORD_TYPE_INVALID;
36
37         RETV_IF(NULL == handle, CALENDAR_ERROR_INVALID_PARAMETER);
38         RETV_IF(NULL == view_uri, CALENDAR_ERROR_INVALID_PARAMETER);
39         RETV_IF(NULL == callback, CALENDAR_ERROR_INVALID_PARAMETER);
40
41         type = cal_view_get_type(view_uri);
42         switch (type) {
43         case CAL_RECORD_TYPE_BOOK:
44                 ret = cal_inotify_subscribe(CAL_NOTI_TYPE_BOOK, CAL_NOTI_FILE_BOOK,
45                                 callback, user_data);
46                 break;
47         case CAL_RECORD_TYPE_EVENT:
48                 ret = cal_inotify_subscribe(CAL_NOTI_TYPE_EVENT, CAL_NOTI_FILE_EVENT,
49                                 callback, user_data);
50                 break;
51         case CAL_RECORD_TYPE_TODO:
52                 ret = cal_inotify_subscribe(CAL_NOTI_TYPE_TODO, CAL_NOTI_FILE_TODO,
53                                 callback, user_data);
54                 break;
55         default:
56                 /* LCOV_EXCL_START */
57                 ERR("Invalid view_uri(%s)", view_uri);
58                 return CALENDAR_ERROR_INVALID_PARAMETER;
59                 /* LCOV_EXCL_STOP */
60         }
61         if (CALENDAR_ERROR_NONE != ret) {
62                 /* LCOV_EXCL_START */
63                 ERR("cal_inotify_subscribe() Fail(%d)", ret);
64                 return ret;
65                 /* LCOV_EXCL_STOP */
66         }
67
68         return CALENDAR_ERROR_NONE;
69 }
70
71 int cal_client_db_remove_changed_cb(calendar_h handle, const char* view_uri, calendar_db_changed_cb callback, void* user_data)
72 {
73         CAL_FN_CALL();
74         int ret;
75         cal_record_type_e type = CAL_RECORD_TYPE_INVALID;
76
77         RETV_IF(NULL == view_uri, CALENDAR_ERROR_INVALID_PARAMETER);
78         RETV_IF(NULL == callback, CALENDAR_ERROR_INVALID_PARAMETER);
79
80         type = cal_view_get_type(view_uri);
81         switch (type) {
82         case CAL_RECORD_TYPE_BOOK:
83                 ret = cal_inotify_unsubscribe(CAL_NOTI_FILE_BOOK, callback, user_data);
84                 break;
85         case CAL_RECORD_TYPE_EVENT:
86                 ret = cal_inotify_unsubscribe(CAL_NOTI_FILE_EVENT, callback, user_data);
87                 break;
88         case CAL_RECORD_TYPE_TODO:
89                 ret = cal_inotify_unsubscribe(CAL_NOTI_FILE_TODO, callback, user_data);
90                 break;
91         default:
92                 /* LCOV_EXCL_START */
93                 ERR("Invalid view_uri(%s)", view_uri);
94                 return CALENDAR_ERROR_INVALID_PARAMETER;
95                 /* LCOV_EXCL_STOP */
96         }
97         if (CALENDAR_ERROR_NONE != ret) {
98                 /* LCOV_EXCL_START */
99                 ERR("cal_inotify_unsubscribe() Fail(%d)", ret);
100                 return ret;
101                 /* LCOV_EXCL_STOP */
102         }
103
104         return CALENDAR_ERROR_NONE;
105 }