blob: 85a791c6013a99ae4bd1c75e1ec4ec18d1918edd [file] [log] [blame]
Mark Salyzyn6c6ec722015-10-24 16:20:18 -07001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _INIT_EPOLL_H
18#define _INIT_EPOLL_H
19
20#include <chrono>
21#include <functional>
22#include <map>
23#include <optional>
24
25#include <android-base/unique_fd.h>
26
27#include "result.h"
28
29namespace android {
30namespace init {
31
32class Epoll {
33 public:
34 Epoll();
35
36 Result<Success> Open();
37 Result<Success> RegisterHandler(int fd, std::function<void()> handler);
38 Result<Success> UnregisterHandler(int fd);
39 Result<Success> Wait(std::optional<std::chrono::milliseconds> timeout);
40
41 private:
42 android::base::unique_fd epoll_fd_;
43 std::map<int, std::function<void()>> epoll_handlers_;
44};
45
46} // namespace init
47} // namespace android
48
49#endif