1/*
2 * Copyright (c) 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 EPOLL_MANAGER_H
17#define EPOLL_MANAGER_H
18
19#include <cinttypes>
20#include <memory>
21#include <vector>
22
23#include "nocopyable.h"
24
25#include "i_epoll_event_source.h"
26
27namespace OHOS {
28namespace Msdp {
29namespace DeviceStatus {
30class EpollManager final : public IEpollEventSource {
31public:
32    EpollManager() = default;
33    ~EpollManager();
34    DISALLOW_COPY_AND_MOVE(EpollManager);
35
36    int32_t Open();
37    void Close();
38
39    int32_t Add(IEpollEventSource &source);
40    void Remove(IEpollEventSource &source);
41    int32_t Update(IEpollEventSource &source);
42    int32_t Wait(struct epoll_event *events, int32_t maxevents);
43    int32_t WaitTimeout(struct epoll_event *events, int32_t maxevents, int32_t timeout);
44
45    int32_t GetFd() const override;
46    void Dispatch(const struct epoll_event &ev) override;
47
48private:
49    void DispatchOne(const struct epoll_event &ev);
50
51private:
52    int32_t epollFd_ { -1 };
53};
54
55inline int32_t EpollManager::GetFd() const
56{
57    return epollFd_;
58}
59} // namespace DeviceStatus
60} // namespace Msdp
61} // namespace OHOS
62#endif // EPOLL_MANAGER_H