• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #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 namespace OHOS {
26 namespace AppExecFwk {
27 // Io waiter which does not support listening file descriptor.
28 class NoneIoWaiter final : public IoWaiter {
29 public:
30     NoneIoWaiter() = default;
31     ~NoneIoWaiter() final;
32     DISALLOW_COPY_AND_MOVE(NoneIoWaiter);
33 
34     bool WaitFor(std::unique_lock<std::mutex> &lock, int64_t nanoseconds) final;
35 
36     void NotifyOne() final;
37     void NotifyAll() final;
38 
39     bool SupportListeningFileDescriptor() const final;
40 
41     bool AddFileDescriptor(int32_t fileDescriptor, uint32_t events) final;
42     void RemoveFileDescriptor(int32_t fileDescriptor) final;
43 
44     void SetFileDescriptorEventCallback(const FileDescriptorEventCallback &callback) final;
45 
46 private:
47     std::condition_variable condition_;
48     uint32_t waitingCount_ {0};
49     bool pred_ {false};
50 };
51 }  // namespace AppExecFwk
52 }  // namespace OHOS
53 
54 #endif  // #ifndef BASE_EVENTHANDLER_FRAMEWORKS_EVENTHANDLER_INCLUDE_NONE_IO_WAITER_H
55