Mark Salyzyn | 6c6ec72 | 2015-10-24 16:20:18 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Tom Cherry | 905a5df | 2019-08-30 14:12:56 -0700 | [diff] [blame] | 17 | #pragma once |
Mark Salyzyn | 6c6ec72 | 2015-10-24 16:20:18 -0700 | [diff] [blame] | 18 | |
Mark Salyzyn | 37bbf80 | 2019-03-13 07:25:52 -0700 | [diff] [blame] | 19 | #include <stdint.h> |
| 20 | #include <sys/epoll.h> |
| 21 | |
Mark Salyzyn | 6c6ec72 | 2015-10-24 16:20:18 -0700 | [diff] [blame] | 22 | #include <chrono> |
| 23 | #include <functional> |
| 24 | #include <map> |
| 25 | #include <optional> |
Tom Cherry | 905a5df | 2019-08-30 14:12:56 -0700 | [diff] [blame] | 26 | #include <vector> |
Mark Salyzyn | 6c6ec72 | 2015-10-24 16:20:18 -0700 | [diff] [blame] | 27 | |
| 28 | #include <android-base/unique_fd.h> |
| 29 | |
| 30 | #include "result.h" |
| 31 | |
| 32 | namespace android { |
| 33 | namespace init { |
| 34 | |
| 35 | class Epoll { |
| 36 | public: |
| 37 | Epoll(); |
| 38 | |
Tom Cherry | bbcbc2f | 2019-06-10 11:08:01 -0700 | [diff] [blame] | 39 | Result<void> Open(); |
| 40 | Result<void> RegisterHandler(int fd, std::function<void()> handler, uint32_t events = EPOLLIN); |
| 41 | Result<void> UnregisterHandler(int fd); |
Tom Cherry | 905a5df | 2019-08-30 14:12:56 -0700 | [diff] [blame] | 42 | Result<std::vector<std::function<void()>*>> Wait( |
| 43 | std::optional<std::chrono::milliseconds> timeout); |
Mark Salyzyn | 6c6ec72 | 2015-10-24 16:20:18 -0700 | [diff] [blame] | 44 | |
| 45 | private: |
| 46 | android::base::unique_fd epoll_fd_; |
| 47 | std::map<int, std::function<void()>> epoll_handlers_; |
| 48 | }; |
| 49 | |
| 50 | } // namespace init |
| 51 | } // namespace android |