• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "calendar_manager_ffi.h"
16 #include "cj_calendar_manager.h"
17 #include "cj_common_ffi.h"
18 #include "ffi_remote_data.h"
19 #include "cj_calendar.h"
20 #include "calendar_log.h"
21 #include "cj_event_filter.h"
22 
23 extern "C" {
FfiOHOSGetCalendarManager(int64_t contextId,int32_t * errcode)24     void FfiOHOSGetCalendarManager(int64_t contextId, int32_t* errcode)
25     {
26         return OHOS::CalendarApi::CJCalendarManager::GetCalendarManager(contextId, errcode);
27     }
28 
FfiOHOSCalendarManagerCreateCalendar(CCalendarAccount calendarAccount,int64_t * calendarId,int32_t * errcode)29     int64_t FfiOHOSCalendarManagerCreateCalendar(
30         CCalendarAccount calendarAccount, int64_t* calendarId, int32_t* errcode)
31     {
32         return OHOS::CalendarApi::CJCalendarManager::CreateCalendar(calendarAccount, calendarId, errcode);
33     }
34 
FfiOHOSCalendarManagerdeleteCalendar(int64_t calendarId,int32_t * errcode)35     void FfiOHOSCalendarManagerdeleteCalendar(int64_t calendarId, int32_t* errcode)
36     {
37         return OHOS::CalendarApi::CJCalendarManager::DeleteCalendar(calendarId, errcode);
38     }
39 
FfiOHOSCalendarManagerGetCalendar(CCalendarAccount calendarAccount,int64_t * calendarId,int32_t * errcode)40     int64_t FfiOHOSCalendarManagerGetCalendar(CCalendarAccount calendarAccount, int64_t* calendarId, int32_t* errcode)
41     {
42         return OHOS::CalendarApi::CJCalendarManager::GetCalendar(calendarAccount, calendarId, errcode);
43     }
44 
FfiOHOSCalendarManagerGetAllCalendars(int32_t * errcode)45     CArrI64 FfiOHOSCalendarManagerGetAllCalendars(int32_t* errcode)
46     {
47         return OHOS::CalendarApi::CJCalendarManager::GetAllCalendars(errcode);
48     }
49 
FfiOHOSCalendarManagerEditerEvent(char * eventstr,int32_t * errcode)50     int64_t FfiOHOSCalendarManagerEditerEvent(char* eventstr, int32_t* errcode)
51     {
52         return OHOS::CalendarApi::CJCalendarManager::EditerEvent(eventstr, errcode);
53     }
54 
FfiOHOSCalendarAddEvent(int64_t id,CEvent event,int32_t * errcode)55     int64_t FfiOHOSCalendarAddEvent(int64_t id, CEvent event, int32_t* errcode)
56     {
57         auto instance = OHOS::FFI::FFIData::GetData<OHOS::CalendarApi::CJCalendar>(id);
58         if (instance == nullptr) {
59             LOG_ERROR("CJCalendar instance is nullptr");
60             *errcode = CJ_ERR_ILLEGAL_INSTANCE;
61             return -1;
62         }
63         return instance->AddEvent(event, errcode);
64     }
65 
FfiOHOSCalendarAddEvents(int64_t id,CArrEvents event,int32_t * errcode)66     void FfiOHOSCalendarAddEvents(int64_t id, CArrEvents event, int32_t* errcode)
67     {
68         auto instance = OHOS::FFI::FFIData::GetData<OHOS::CalendarApi::CJCalendar>(id);
69         if (instance == nullptr) {
70             LOG_ERROR("CJCalendar instance is nullptr");
71             *errcode = CJ_ERR_ILLEGAL_INSTANCE;
72             return;
73         }
74         instance->AddEvents(event, errcode);
75     }
76 
FfiOHOSCalendarDeleteEvent(int64_t id,int64_t eventId,int32_t * errcode)77     void FfiOHOSCalendarDeleteEvent(int64_t id, int64_t eventId, int32_t* errcode)
78     {
79         auto instance = OHOS::FFI::FFIData::GetData<OHOS::CalendarApi::CJCalendar>(id);
80         if (instance == nullptr) {
81             LOG_ERROR("CJCalendar instance is nullptr");
82             *errcode = CJ_ERR_ILLEGAL_INSTANCE;
83             return;
84         }
85         instance->DeleteEvent(eventId, errcode);
86     }
87 
FfiOHOSCalendarDeleteEvents(int64_t id,CArrI64 eventIds,int32_t * errcode)88     void FfiOHOSCalendarDeleteEvents(int64_t id, CArrI64 eventIds, int32_t* errcode)
89     {
90         auto instance = OHOS::FFI::FFIData::GetData<OHOS::CalendarApi::CJCalendar>(id);
91         if (instance == nullptr) {
92             LOG_ERROR("CJCalendar instance is nullptr");
93             *errcode = CJ_ERR_ILLEGAL_INSTANCE;
94             return;
95         }
96         instance->DeleteEvents(eventIds, errcode);
97     }
98 
FfiOHOSCalendarUpdateEvent(int64_t id,CEvent event,int32_t * errcode)99     void FfiOHOSCalendarUpdateEvent(int64_t id, CEvent event, int32_t* errcode)
100     {
101         auto instance = OHOS::FFI::FFIData::GetData<OHOS::CalendarApi::CJCalendar>(id);
102         if (instance == nullptr) {
103             LOG_ERROR("CJCalendar instance is nullptr");
104             *errcode = CJ_ERR_ILLEGAL_INSTANCE;
105             return;
106         }
107         instance->UpdateEvent(event, errcode);
108     }
109 
FfiOHOSCalendarGetEvents(int64_t id,int64_t eventFilterId,CArrString eventKey,int32_t * errcode)110     CArrEvents FfiOHOSCalendarGetEvents(int64_t id, int64_t eventFilterId, CArrString eventKey, int32_t* errcode)
111     {
112         CArrEvents arr;
113         auto instance = OHOS::FFI::FFIData::GetData<OHOS::CalendarApi::CJCalendar>(id);
114         if (instance == nullptr) {
115             LOG_ERROR("CJCalendar instance is nullptr");
116             *errcode = CJ_ERR_ILLEGAL_INSTANCE;
117             return arr;
118         }
119         return instance->GetEvents(eventFilterId, eventKey, errcode);
120     }
121 
FfiOHOSCalendarGetConfig(int64_t id,int32_t * errcode)122     CCalendarConfig FfiOHOSCalendarGetConfig(int64_t id, int32_t* errcode)
123     {
124         CCalendarConfig config;
125         auto instance = OHOS::FFI::FFIData::GetData<OHOS::CalendarApi::CJCalendar>(id);
126         if (instance == nullptr) {
127             LOG_ERROR("CJCalendar instance is nullptr");
128             *errcode = CJ_ERR_ILLEGAL_INSTANCE;
129             return config;
130         }
131         return instance->GetConfig(errcode);
132     }
133 
FfiOHOSCalendarSetConfig(int64_t id,CCalendarConfig cCalendarConfig,int32_t * errcode)134     void FfiOHOSCalendarSetConfig(int64_t id, CCalendarConfig cCalendarConfig, int32_t* errcode)
135     {
136         auto instance = OHOS::FFI::FFIData::GetData<OHOS::CalendarApi::CJCalendar>(id);
137         if (instance == nullptr) {
138             LOG_ERROR("CJCalendar instance is nullptr");
139             *errcode = CJ_ERR_ILLEGAL_INSTANCE;
140             return;
141         }
142         instance->SetConfig(cCalendarConfig, errcode);
143     }
144 
FfiOHOSCalendarGetAccount(int64_t id,int32_t * errcode)145     CCalendarAccount FfiOHOSCalendarGetAccount(int64_t id, int32_t* errcode)
146     {
147         CCalendarAccount account;
148         auto instance = OHOS::FFI::FFIData::GetData<OHOS::CalendarApi::CJCalendar>(id);
149         if (instance == nullptr) {
150             LOG_ERROR("CJCalendar instance is nullptr");
151             *errcode = CJ_ERR_ILLEGAL_INSTANCE;
152             return account;
153         }
154         return instance->GetAccount(errcode);
155     }
156 
FfiOHOSEventFilterFilterById(CArrI64 idsCArr,int32_t * errcode)157     int64_t FfiOHOSEventFilterFilterById(CArrI64 idsCArr, int32_t* errcode)
158     {
159         return OHOS::CalendarApi::CJEventFilter::FilterById(idsCArr, errcode);
160     }
161 
FfiOHOSEventFilterFilterByTime(int64_t startTime,int64_t end,int32_t * errcode)162     int64_t FfiOHOSEventFilterFilterByTime(int64_t startTime, int64_t end, int32_t* errcode)
163     {
164         return OHOS::CalendarApi::CJEventFilter::FilterByTime(startTime, end, errcode);
165     }
166 
FfiOHOSEventFilterFilterByTitle(char * title,int32_t * errcode)167     int64_t FfiOHOSEventFilterFilterByTitle(char* title, int32_t* errcode)
168     {
169         return OHOS::CalendarApi::CJEventFilter::FilterByTitle(title, errcode);
170     }
171 }
172