Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 1 | /* |
| 2 | Copyright (c) 2018-2019 Nokia. |
| 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 SHAREDDATALAYER_TIMERFD_HPP_ |
| 18 | #define SHAREDDATALAYER_TIMERFD_HPP_ |
| 19 | |
| 20 | #include <sys/timerfd.h> |
| 21 | #include "private/timer.hpp" |
| 22 | #include "private/filedescriptor.hpp" |
| 23 | |
| 24 | namespace shareddatalayer |
| 25 | { |
| 26 | class Engine; |
| 27 | class System; |
| 28 | |
| 29 | class TimerFD |
| 30 | { |
| 31 | public: |
| 32 | explicit TimerFD(Engine& engine); |
| 33 | |
| 34 | TimerFD(System& system, Engine& engine); |
| 35 | |
| 36 | ~TimerFD(); |
| 37 | |
| 38 | void arm(Timer& timer, const Timer::Duration& duration, const Timer::Callback& cb); |
| 39 | |
| 40 | void disarm(const Timer& timer); |
| 41 | |
| 42 | TimerFD(TimerFD&&) = delete; |
| 43 | TimerFD(const TimerFD&) = delete; |
| 44 | TimerFD& operator = (TimerFD&&) = delete; |
| 45 | TimerFD& operator = (const TimerFD&) = delete; |
| 46 | |
| 47 | private: |
| 48 | using Queue = Timer::Queue; |
| 49 | |
| 50 | bool isFirst(Queue::iterator it) const; |
| 51 | |
| 52 | Timer::Duration toAbsolute(const Timer::Duration& duration); |
| 53 | |
| 54 | void handleEvents(); |
| 55 | |
| 56 | bool timerExpired() const; |
| 57 | |
| 58 | void handleExpiredTimers(); |
| 59 | |
| 60 | void popAndExecuteFirstTimer(); |
| 61 | |
| 62 | Timer::Duration nextTrigger() const; |
| 63 | |
| 64 | void disarmTimerFD(); |
| 65 | |
| 66 | void armTimerFD(const Timer::Duration& duration); |
| 67 | |
| 68 | void setTimeForTimerFD(time_t seconds, long int nanoseconds); |
| 69 | |
| 70 | System& system; |
| 71 | FileDescriptor fd; |
| 72 | Queue queue; |
| 73 | }; |
| 74 | } |
| 75 | |
| 76 | #endif |