Utility object to handle installing / removing dbus watches from the poll loop.
More...
|
dbus_bool_t | addWatch (DBusWatch *watch) |
| Callback from dbus to add a new watch to poll on. More...
|
|
void | toggleWatch (DBusWatch *watch) |
| Toggles the watch flags on the given watch. More...
|
|
void | removeWatch (DBusWatch *watch) |
| Removes the watch from the epoll loop and our local array. More...
|
|
uint64_t | createWatch (DBusWatch *watch, int duppedFd) |
| Tries to find a slot to put the watch into. More...
|
|
void | deleteWatch (uint64_t tag) |
| Removes a watch from our internal array. More...
|
|
Utility object to handle installing / removing dbus watches from the poll loop.
- Warning
- This class is not thread safe, it is designed to only be called from one thread which is the same thread the libdbus callbacks will be called from. On debug builds an error will be reported if called from an invalid thread.
Internally it creates an epoll object that has watches (which are just fds) added to / removed from it. The epoll fd is returned by this object, and the dispatch poll loop will poll on this. So in effect this is a second level of poll file descriptors.
This code automatically installs the dbus callbacks on the connection at construction time, and removes the callbacks at destruction.
When watches are added we dup the file descriptors, and add the dupped fd to epoll. The reason for this is that libdbus tends to have more than one watch associated with a single fd and you can't add the same fd more once to an epoll event loop. By dup'ing the file descriptors it means we can have one epoll event entry per dbus watch.
uint64_t DbusWatches::createWatch |
( |
DBusWatch * |
watch, |
|
|
int |
duppedFd |
|
) |
| |
|
private |
Tries to find a slot to put the watch into.
We store the watches in an internal array, each watch has a unique 64-bit tag number, this tag is added to the epoll event so we can quickly find the watch that triggered the event.
The lower bits of the tag number are the index into the internal array.
- Parameters
-
[in] | watch | The dbus watch object |
[in] | duppedFd | The dup'ed file descriptor for the watch |
- Returns
- on success a non-zero tag number, on failure 0.