1100ae2f9Sopenharmony_ci/*
2100ae2f9Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3100ae2f9Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4100ae2f9Sopenharmony_ci * you may not use this file except in compliance with the License.
5100ae2f9Sopenharmony_ci * You may obtain a copy of the License at
6100ae2f9Sopenharmony_ci *
7100ae2f9Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8100ae2f9Sopenharmony_ci *
9100ae2f9Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10100ae2f9Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11100ae2f9Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12100ae2f9Sopenharmony_ci * See the License for the specific language governing permissions and
13100ae2f9Sopenharmony_ci * limitations under the License.
14100ae2f9Sopenharmony_ci */
15100ae2f9Sopenharmony_ci
16100ae2f9Sopenharmony_ci#include "native_interface_eventhandler.h"
17100ae2f9Sopenharmony_ci#include "native_implement_eventhandler.h"
18100ae2f9Sopenharmony_ci
19100ae2f9Sopenharmony_ci#include <cstdint>
20100ae2f9Sopenharmony_ci
21100ae2f9Sopenharmony_ci#include "hilog/log.h"
22100ae2f9Sopenharmony_ci#include "errors.h"                         // for ErrCode
23100ae2f9Sopenharmony_ci#include "event_handler_errors.h"           // for EVENT_HANDLER_ERR_INVALID...
24100ae2f9Sopenharmony_ci
25100ae2f9Sopenharmony_ciusing OHOS::ErrCode;
26100ae2f9Sopenharmony_ciusing OHOS::HiviewDFX::HiLog;
27100ae2f9Sopenharmony_ciusing OHOS::HiviewDFX::HiLogLabel;
28100ae2f9Sopenharmony_ci
29100ae2f9Sopenharmony_cinamespace {
30100ae2f9Sopenharmony_ciconstexpr HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "EventRunnerNativeInterface"};
31100ae2f9Sopenharmony_ci}
32100ae2f9Sopenharmony_ci
33100ae2f9Sopenharmony_ciconst EventRunnerNativeImplement *GetEventRunnerNativeObjForThread()
34100ae2f9Sopenharmony_ci{
35100ae2f9Sopenharmony_ci    return EventRunnerNativeImplement::GetEventRunnerNativeObj();
36100ae2f9Sopenharmony_ci}
37100ae2f9Sopenharmony_ci
38100ae2f9Sopenharmony_ciconst EventRunnerNativeImplement *CreateEventRunnerNativeObj()
39100ae2f9Sopenharmony_ci{
40100ae2f9Sopenharmony_ci    return EventRunnerNativeImplement::CreateEventRunnerNativeObj();
41100ae2f9Sopenharmony_ci}
42100ae2f9Sopenharmony_ci
43100ae2f9Sopenharmony_ciint EventRunnerRun(const EventRunnerNativeImplement *nativeObj)
44100ae2f9Sopenharmony_ci{
45100ae2f9Sopenharmony_ci    if (nativeObj == nullptr) {
46100ae2f9Sopenharmony_ci        HiLog::Error(LABEL, "Input nkd object is null");
47100ae2f9Sopenharmony_ci        return OHOS::AppExecFwk::EVENT_HANDLER_ERR_INVALID_PARAM;
48100ae2f9Sopenharmony_ci    }
49100ae2f9Sopenharmony_ci    return nativeObj->RunEventRunnerNativeObj();
50100ae2f9Sopenharmony_ci}
51100ae2f9Sopenharmony_ci
52100ae2f9Sopenharmony_ciint EventRunnerStop(const EventRunnerNativeImplement *nativeObj)
53100ae2f9Sopenharmony_ci{
54100ae2f9Sopenharmony_ci    if (nativeObj == nullptr) {
55100ae2f9Sopenharmony_ci        HiLog::Error(LABEL, "Input nkd object is null");
56100ae2f9Sopenharmony_ci        return OHOS::AppExecFwk::EVENT_HANDLER_ERR_INVALID_PARAM;
57100ae2f9Sopenharmony_ci    }
58100ae2f9Sopenharmony_ci    return nativeObj->StopEventRunnerNativeObj();
59100ae2f9Sopenharmony_ci}
60100ae2f9Sopenharmony_ci
61100ae2f9Sopenharmony_ciint EventRunnerAddFileDescriptorListener(const EventRunnerNativeImplement *nativeObj, int32_t fileDescriptor,
62100ae2f9Sopenharmony_ci    uint32_t events, const FileDescriptorCallbacks *fileDescriptorCallbacks)
63100ae2f9Sopenharmony_ci{
64100ae2f9Sopenharmony_ci    if (nativeObj == nullptr) {
65100ae2f9Sopenharmony_ci        HiLog::Error(LABEL, "Input nkd object is null");
66100ae2f9Sopenharmony_ci        return OHOS::AppExecFwk::EVENT_HANDLER_ERR_INVALID_PARAM;
67100ae2f9Sopenharmony_ci    }
68100ae2f9Sopenharmony_ci    return nativeObj->AddFileDescriptorListener(fileDescriptor, events, fileDescriptorCallbacks);
69100ae2f9Sopenharmony_ci}
70100ae2f9Sopenharmony_ci
71100ae2f9Sopenharmony_civoid EventRunnerRemoveFileDescriptorListener(const EventRunnerNativeImplement *nativeObj, int32_t fileDescriptor)
72100ae2f9Sopenharmony_ci{
73100ae2f9Sopenharmony_ci    if (nativeObj == nullptr) {
74100ae2f9Sopenharmony_ci        HiLog::Error(LABEL, "Input nkd object is null");
75100ae2f9Sopenharmony_ci        return;
76100ae2f9Sopenharmony_ci    }
77100ae2f9Sopenharmony_ci    nativeObj->RemoveFileDescriptorListener(fileDescriptor);
78100ae2f9Sopenharmony_ci}
79