Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
DbusWatches.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  * DbusWatches.h
21  *
22  */
23 #ifndef AI_IPC_DBUSWATCHES_H
24 #define AI_IPC_DBUSWATCHES_H
25 
26 #include <thread>
27 #include <cstdint>
28 
29 #include <sys/epoll.h>
30 
31 #include <dbus/dbus.h>
32 
33 
34 namespace AI_IPC
35 {
36 
37 
38 // -----------------------------------------------------------------------------
65 {
66 public:
67  DbusWatches(DBusConnection *conn);
68  ~DbusWatches();
69 
70 public:
71  int fd() const;
72  void processEvent(unsigned int pollEvents);
73 
74 private:
75  static dbus_bool_t addWatchCb(DBusWatch *watch, void *userData);
76  static void toggleWatchCb(DBusWatch *watch, void *userData);
77  static void removeWatchCb(DBusWatch *watch, void *userData);
78 
79  dbus_bool_t addWatch(DBusWatch *watch);
80  void toggleWatch(DBusWatch *watch);
81  void removeWatch(DBusWatch *watch);
82 
83  uint64_t createWatch(DBusWatch *watch, int duppedFd);
84  void deleteWatch(uint64_t tag);
85 
86 private:
87  DBusConnection* const mDbusConnection;
88  int mEpollFd;
89 
90 private:
91  static const unsigned mMaxWatches = 128;
92  uint64_t mTagCounter;
93 
94  typedef struct _WatchEntry
95  {
96  int fd;
97  uint64_t tag;
98  DBusWatch* watch;
99  DbusWatches* manager;
100  } WatchEntry;
101  WatchEntry mWatches[mMaxWatches];
102 
103 private:
104  struct epoll_event mEpollEvents[mMaxWatches];
105 
106 #if (AI_BUILD_TYPE == AI_DEBUG)
107 private:
108  const std::thread::id mExpectedThreadId;
109 #endif
110 };
111 
112 
113 
114 } // namespace AI_IPC
115 
116 #endif // !defined(AI_IPC_DBUSWATCHES_H)
Utility object to handle installing / removing dbus watches from the poll loop.
Definition: DbusWatches.h:65
void toggleWatch(DBusWatch *watch)
Toggles the watch flags on the given watch.
Definition: DbusWatches.cpp:441
void processEvent(unsigned int pollEvents)
Called when something has happened on the epoll event loop.
Definition: DbusWatches.cpp:144
dbus_bool_t addWatch(DBusWatch *watch)
Callback from dbus to add a new watch to poll on.
Definition: DbusWatches.cpp:300
void removeWatch(DBusWatch *watch)
Removes the watch from the epoll loop and our local array.
Definition: DbusWatches.cpp:387
uint64_t createWatch(DBusWatch *watch, int duppedFd)
Tries to find a slot to put the watch into.
Definition: DbusWatches.cpp:223
void deleteWatch(uint64_t tag)
Removes a watch from our internal array.
Definition: DbusWatches.cpp:254
int fd() const
Returns the epoll fd that the dispatcher should poll on.
Definition: DbusWatches.cpp:129
Definition: DbusWatches.h:95