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#ifndef AAFWK_APPEXECFWK_NATIVE_IMPLEMENT_EVENTHANDLER_H 17100ae2f9Sopenharmony_ci#define AAFWK_APPEXECFWK_NATIVE_IMPLEMENT_EVENTHANDLER_H 18100ae2f9Sopenharmony_ci 19100ae2f9Sopenharmony_ci#include "event_runner.h" 20100ae2f9Sopenharmony_ci 21100ae2f9Sopenharmony_ciusing OHOS::ErrCode; 22100ae2f9Sopenharmony_ciusing OHOS::AppExecFwk::EventHandler; 23100ae2f9Sopenharmony_ciusing OHOS::AppExecFwk::EventRunner; 24100ae2f9Sopenharmony_ci 25100ae2f9Sopenharmony_citypedef void (*FileFDCallback)(int32_t filedescriptor); 26100ae2f9Sopenharmony_ci 27100ae2f9Sopenharmony_cistruct FileDescriptorCallbacks; 28100ae2f9Sopenharmony_cistruct EventRunnerNativeImplement { 29100ae2f9Sopenharmony_cipublic: 30100ae2f9Sopenharmony_ci explicit EventRunnerNativeImplement(bool current); 31100ae2f9Sopenharmony_ci ~EventRunnerNativeImplement(); 32100ae2f9Sopenharmony_ci 33100ae2f9Sopenharmony_ci /** 34100ae2f9Sopenharmony_ci * Get current thread 'EventRunnerNativeImplement'. 35100ae2f9Sopenharmony_ci * 36100ae2f9Sopenharmony_ci * @return Returns pointer of the new 'EventRunnerNativeImplement'. 37100ae2f9Sopenharmony_ci */ 38100ae2f9Sopenharmony_ci static const EventRunnerNativeImplement *GetEventRunnerNativeObj(); 39100ae2f9Sopenharmony_ci 40100ae2f9Sopenharmony_ci /** 41100ae2f9Sopenharmony_ci * Create new 'EventRunnerNativeImplement'. 42100ae2f9Sopenharmony_ci * 43100ae2f9Sopenharmony_ci * @return Returns pointer of the new 'EventRunnerNativeImplement'. 44100ae2f9Sopenharmony_ci */ 45100ae2f9Sopenharmony_ci static const EventRunnerNativeImplement *CreateEventRunnerNativeObj(); 46100ae2f9Sopenharmony_ci 47100ae2f9Sopenharmony_ci /** 48100ae2f9Sopenharmony_ci * Start to run the 'EventRunnerNativeImplement'. Only running on single thread. 49100ae2f9Sopenharmony_ci * 50100ae2f9Sopenharmony_ci * @return Returns 'ERR_OK' on success. 51100ae2f9Sopenharmony_ci */ 52100ae2f9Sopenharmony_ci ErrCode RunEventRunnerNativeObj() const; 53100ae2f9Sopenharmony_ci 54100ae2f9Sopenharmony_ci /** 55100ae2f9Sopenharmony_ci * Stop to run the 'EventRunnerNativeImplement'. 56100ae2f9Sopenharmony_ci * 57100ae2f9Sopenharmony_ci * @return Returns 'ERR_OK' on success. 58100ae2f9Sopenharmony_ci */ 59100ae2f9Sopenharmony_ci ErrCode StopEventRunnerNativeObj() const; 60100ae2f9Sopenharmony_ci 61100ae2f9Sopenharmony_ci /** 62100ae2f9Sopenharmony_ci * Add file descriptor listener for a file descriptor. 63100ae2f9Sopenharmony_ci * 64100ae2f9Sopenharmony_ci * @param fileDescriptor File descriptor. 65100ae2f9Sopenharmony_ci * @param events Events from file descriptor, such as input, output, error 66100ae2f9Sopenharmony_ci * @param onReadableCallback Called while file descriptor is readable. 67100ae2f9Sopenharmony_ci * @param onWritableCallback Called while file descriptor is writable. 68100ae2f9Sopenharmony_ci * @param onShutdownCallback Called while shutting down this file descriptor. 69100ae2f9Sopenharmony_ci * @param onExceptionCallback Called while error happened on this file descriptor. 70100ae2f9Sopenharmony_ci * @return Return 'ERR_OK' on success. 71100ae2f9Sopenharmony_ci */ 72100ae2f9Sopenharmony_ci ErrCode AddFileDescriptorListener( 73100ae2f9Sopenharmony_ci int32_t fileDescriptor, uint32_t events, const FileDescriptorCallbacks *fdCallbacks) const; 74100ae2f9Sopenharmony_ci 75100ae2f9Sopenharmony_ci /** 76100ae2f9Sopenharmony_ci * Remove file descriptor listener for a file descriptor. 77100ae2f9Sopenharmony_ci * 78100ae2f9Sopenharmony_ci * @param fileDescriptor File descriptor. 79100ae2f9Sopenharmony_ci */ 80100ae2f9Sopenharmony_ci void RemoveFileDescriptorListener(int32_t fileDescriptor) const; 81100ae2f9Sopenharmony_ci 82100ae2f9Sopenharmony_ciprivate: 83100ae2f9Sopenharmony_ci std::shared_ptr<EventRunner> eventRunner_ = nullptr; 84100ae2f9Sopenharmony_ci}; 85100ae2f9Sopenharmony_ci 86100ae2f9Sopenharmony_ci#endif // AAFWK_APPEXECFWK_NATIVE_IMPLEMENT_EVENTHANDLER_H 87