1 /*
2 * Copyright (c) 2021 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
16 #include "native_interface_eventhandler.h"
17 #include "hilog/log.h"
18 #include "native_implement_eventhandler.h"
19
20 #include <cstdint>
21
22 using OHOS::ErrCode;
23 using OHOS::HiviewDFX::HiLog;
24 using OHOS::HiviewDFX::HiLogLabel;
25
26 namespace {
27 constexpr HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "EventRunnerNativeInterface"};
28 }
29
GetEventRunnerNativeObjForThread()30 const EventRunnerNativeImplement *GetEventRunnerNativeObjForThread()
31 {
32 return EventRunnerNativeImplement::GetEventRunnerNativeObj();
33 }
34
CreateEventRunnerNativeObj()35 const EventRunnerNativeImplement *CreateEventRunnerNativeObj()
36 {
37 return EventRunnerNativeImplement::CreateEventRunnerNativeObj();
38 }
39
EventRunnerRun(const EventRunnerNativeImplement * nativeObj)40 int EventRunnerRun(const EventRunnerNativeImplement *nativeObj)
41 {
42 if (nativeObj == nullptr) {
43 HiLog::Error(LABEL, "Input nkd object is null");
44 return OHOS::AppExecFwk::EVENT_HANDLER_ERR_INVALID_PARAM;
45 }
46 return nativeObj->RunEventRunnerNativeObj();
47 }
48
EventRunnerStop(const EventRunnerNativeImplement * nativeObj)49 int EventRunnerStop(const EventRunnerNativeImplement *nativeObj)
50 {
51 if (nativeObj == nullptr) {
52 HiLog::Error(LABEL, "Input nkd object is null");
53 return OHOS::AppExecFwk::EVENT_HANDLER_ERR_INVALID_PARAM;
54 }
55 return nativeObj->StopEventRunnerNativeObj();
56 }
57
EventRunnerAddFileDescriptorListener(const EventRunnerNativeImplement * nativeObj,int32_t fileDescriptor,uint32_t events,const FileDescriptorCallbacks * fileDescriptorCallbacks)58 int EventRunnerAddFileDescriptorListener(const EventRunnerNativeImplement *nativeObj, int32_t fileDescriptor,
59 uint32_t events, const FileDescriptorCallbacks *fileDescriptorCallbacks)
60 {
61 if (nativeObj == nullptr) {
62 HiLog::Error(LABEL, "Input nkd object is null");
63 return OHOS::AppExecFwk::EVENT_HANDLER_ERR_INVALID_PARAM;
64 }
65 return nativeObj->AddFileDescriptorListener(fileDescriptor, events, fileDescriptorCallbacks);
66 }
67
EventRunnerRemoveFileDescriptorListener(const EventRunnerNativeImplement * nativeObj,int32_t fileDescriptor)68 void EventRunnerRemoveFileDescriptorListener(const EventRunnerNativeImplement *nativeObj, int32_t fileDescriptor)
69 {
70 if (nativeObj == nullptr) {
71 HiLog::Error(LABEL, "Input nkd object is null");
72 return;
73 }
74 nativeObj->RemoveFileDescriptorListener(fileDescriptor);
75 }
76