Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
DbusTimeouts.h
1/*
2* If not stated otherwise in this file or this component's LICENSE file the
3* following copyright and licenses apply:
4*
5* Copyright 2020 Sky UK
6*
7* Licensed under the Apache License, Version 2.0 (the "License");
8* you may not use this file except in compliance with the License.
9* You may obtain a copy of the License at
10*
11* http://www.apache.org/licenses/LICENSE-2.0
12*
13* Unless required by applicable law or agreed to in writing, software
14* distributed under the License is distributed on an "AS IS" BASIS,
15* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16* See the License for the specific language governing permissions and
17* limitations under the License.
18*/
19/*
20 * DbusTimeouts.h
21 *
22 */
23#ifndef AI_IPC_DBUSTIMEOUTS_H
24#define AI_IPC_DBUSTIMEOUTS_H
25
26#include <list>
27#include <thread>
28
29#include <time.h>
30
31#include <dbus/dbus.h>
32
33
34namespace AI_IPC
35{
36
37
38// -----------------------------------------------------------------------------
58{
59public:
60 DbusTimeouts(DBusConnection *conn);
62
63public:
64 int fd() const;
65 void processEvent(unsigned int pollEvents);
66
67private:
68 static dbus_bool_t addTimeOutCb(DBusTimeout *timeout, void *userData);
69 static void toggleTimeOutCb(DBusTimeout *timeout, void *userData);
70 static void removeTimeOutCb(DBusTimeout *timeout, void *userData);
71
72 dbus_bool_t addTimeOut(DBusTimeout *timeout);
73 void toggleTimeOut(DBusTimeout *timeout);
74 void removeTimeOut(DBusTimeout *timeout);
75
76private:
77 struct timespec calcAbsTime(const struct timespec& base,
78 int milliseconds) const;
79
80 void updateTimerFd() const;
81
82 inline bool hasExpired(const struct timespec& expiryTime,
83 const struct timespec& currentTime) const;
84
85private:
86 int mTimerFd;
87 DBusConnection* const mDbusConnection;
88 bool mWithinEventHandler;
89
90private:
91 typedef struct _TimeoutEntry
92 {
93 struct timespec expiry;
94 DBusTimeout* timeout;
95
96 bool operator< (const struct _TimeoutEntry& rhs) const
97 {
98 return (expiry.tv_sec < rhs.expiry.tv_sec) ||
99 ((expiry.tv_sec == rhs.expiry.tv_sec) &&
100 (expiry.tv_nsec < rhs.expiry.tv_nsec));
101 }
102
103 } TimeoutEntry;
104
105 std::list<TimeoutEntry> mTimeouts;
106
107#if (AI_BUILD_TYPE == AI_DEBUG)
108private:
109 const std::thread::id mExpectedThreadId;
110#endif
111};
112
113
114
115} // namespace AI_IPC
116
117#endif // !defined(AI_IPC_DBUSTIMEOUTS_H)
Object that manages the timeouts for a given dbus connection.
Definition DbusTimeouts.h:58
struct timespec calcAbsTime(const struct timespec &base, int milliseconds) const
Calculates a new time value based on the time now and the supplied millisecond offset.
Definition DbusTimeouts.cpp:214
int fd() const
Returns the timerfd that the dispatcher should poll on.
Definition DbusTimeouts.cpp:106
void processEvent(unsigned int pollEvents)
Called when something has happened on the timerfd event loop.
Definition DbusTimeouts.cpp:121
dbus_bool_t addTimeOut(DBusTimeout *timeout)
Adds the given timeout to the timerfd to poll on.
Definition DbusTimeouts.cpp:306
bool hasExpired(const struct timespec &expiryTime, const struct timespec &currentTime) const
Utility function that simply checks if a timespec is after or equal to another timespec.
Definition DbusTimeouts.cpp:256
void toggleTimeOut(DBusTimeout *timeout)
Toggles the enable / disable state of a timeout.
Definition DbusTimeouts.cpp:436
void updateTimerFd() const
Writes the item on the head of the expiry queue into the timerfd for the next wake-up time.
Definition DbusTimeouts.cpp:273
void removeTimeOut(DBusTimeout *timeout)
Removes the timeout from the timerfd.
Definition DbusTimeouts.cpp:379
Definition DbusTimeouts.h:92