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