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