1 /*
2  * Copyright (c) 2021-2023 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 #ifndef BASE_EVENTHANDLER_FRAMEWORKS_EVENTHANDLER_INCLUDE_NONE_IO_WAITER_H
17 #define BASE_EVENTHANDLER_FRAMEWORKS_EVENTHANDLER_INCLUDE_NONE_IO_WAITER_H
18 
19 #include <condition_variable>
20 #include <mutex>
21 
22 #include "io_waiter.h"
23 #include "nocopyable.h"
24 
25 #define LOCAL_API __attribute__((visibility ("hidden")))
26 namespace OHOS {
27 namespace AppExecFwk {
28 // Io waiter which does not support listening file descriptor.
29 class NoneIoWaiter final : public IoWaiter {
30 public:
31     NoneIoWaiter() = default;
32     ~NoneIoWaiter() final;
33     DISALLOW_COPY_AND_MOVE(NoneIoWaiter);
34 
35     LOCAL_API bool WaitFor(std::unique_lock<std::mutex> &lock, int64_t nanoseconds) final;
36 
37     LOCAL_API void NotifyOne() final;
38     LOCAL_API void NotifyAll() final;
39 
40     LOCAL_API bool SupportListeningFileDescriptor() const final;
41 
42     bool AddFileDescriptor(int32_t fileDescriptor, uint32_t events, const std::string &taskName,
43         const std::shared_ptr<FileDescriptorListener>& listener, EventQueue::Priority priority) final;
44     void RemoveFileDescriptor(int32_t fileDescriptor) final;
45 
46     void SetFileDescriptorEventCallback(const FileDescriptorEventCallback &callback) final;
47 
48 private:
49     std::condition_variable condition_;
50     uint32_t waitingCount_ {0};
51     bool pred_ {false};
52 };
53 }  // namespace AppExecFwk
54 }  // namespace OHOS
55 
56 #endif  // #ifndef BASE_EVENTHANDLER_FRAMEWORKS_EVENTHANDLER_INCLUDE_NONE_IO_WAITER_H
57