27#include "dbus-internals.h"
28#include "dbus-watch.h"
65_dbus_watch_get_oom_last_time (
DBusWatch *watch)
71_dbus_watch_set_oom_last_time (
DBusWatch *watch,
99#define VALID_WATCH_FLAGS (DBUS_WATCH_WRITABLE | DBUS_WATCH_READABLE)
109 watch->
flags = flags;
148 if (_dbus_pollable_is_valid (watch->
fd))
149 _dbus_warn (
"this watch should have been invalidated");
173 _dbus_pollable_invalidate (&watch->
fd);
188 unsigned int *condition)
191 *condition &= ~DBUS_WATCH_READABLE;
193 *condition &= ~DBUS_WATCH_WRITABLE;
239 if (watch_list ==
NULL)
263#ifdef DBUS_ENABLE_VERBOSE_MODE
265watch_flags_to_string (
int flags)
267 const char *watch_type;
271 watch_type =
"readwrite";
275 watch_type =
"write";
277 watch_type =
"not read or write";
305 if (add_function !=
NULL)
314#ifdef DBUS_ENABLE_VERBOSE_MODE
317 _dbus_verbose (
"Adding a %s watch on fd %" DBUS_POLLABLE_FORMAT
" using newly-set add watch function\n",
319 _dbus_pollable_printable (watch->
fd));
322 if (!(* add_function) (link->
data, data))
328 while (link2 != link)
332#ifdef DBUS_ENABLE_VERBOSE_MODE
335 _dbus_verbose (
"Removing watch on fd %" DBUS_POLLABLE_FORMAT
" using newly-set remove function because initial add failed\n",
336 _dbus_pollable_printable (watch2->
fd));
339 (* remove_function) (link2->
data, data);
355 _dbus_verbose (
"Removing all pre-existing watches\n");
393 _dbus_verbose (
"Adding watch on fd %" DBUS_POLLABLE_FORMAT
"\n",
394 _dbus_pollable_printable (watch->
fd));
424 _dbus_verbose (
"Removing watch on fd %" DBUS_POLLABLE_FORMAT
"\n",
425 _dbus_pollable_printable (watch->
fd));
456 _dbus_verbose (
"Toggling watch %p on fd %" DBUS_POLLABLE_FORMAT
" to %d\n",
458 _dbus_pollable_printable (watch->
fd),
547 _dbus_return_val_if_fail (watch !=
NULL, -1);
568 _dbus_return_val_if_fail (watch !=
NULL, -1);
597 _dbus_return_val_if_fail (watch !=
NULL, -1);
602 return _dbus_socket_get_int (watch->
fd);
623_dbus_watch_get_pollable (
DBusWatch *watch)
646 _dbus_return_val_if_fail (watch !=
NULL, 0);
662 _dbus_return_val_if_fail (watch !=
NULL,
NULL);
683 _dbus_return_if_fail (watch !=
NULL);
685 _dbus_verbose (
"Setting watch fd %" DBUS_POLLABLE_FORMAT
" data to data = %p function = %p from data = %p function = %p\n",
686 _dbus_pollable_printable (watch->
fd),
706 _dbus_return_val_if_fail (watch !=
NULL,
FALSE);
738 _dbus_return_val_if_fail (watch !=
NULL,
FALSE);
740#ifndef DBUS_DISABLE_CHECKS
741 if (!_dbus_pollable_is_valid (watch->
fd) || watch->
flags == 0)
748 _dbus_return_val_if_fail (_dbus_pollable_is_valid (watch->
fd) ,
TRUE);
754 _dbus_verbose (
"After sanitization, watch flags on fd %" DBUS_POLLABLE_FORMAT
" were 0\n",
755 _dbus_pollable_printable (watch->
fd));
759 return (* watch->
handler) (watch, flags,
void(* DBusWatchToggledFunction)(DBusWatch *watch, void *data)
Called when dbus_watch_get_enabled() may return a different value than it did before.
dbus_bool_t(* DBusAddWatchFunction)(DBusWatch *watch, void *data)
Called when libdbus needs a new watch to be monitored by the main loop.
void(* DBusRemoveWatchFunction)(DBusWatch *watch, void *data)
Called when libdbus no longer needs a watch to be monitored by the main loop.
@ DBUS_WATCH_READABLE
As in POLLIN.
@ DBUS_WATCH_WRITABLE
As in POLLOUT.
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
void _dbus_warn_check_failed(const char *format,...)
Prints a "critical" warning to stderr when an assertion fails; differs from _dbus_warn primarily in t...
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
DBusList * _dbus_list_get_first_link(DBusList **list)
Gets the first link in the list.
dbus_bool_t _dbus_list_remove(DBusList **list, void *data)
Removes a value from the list.
void _dbus_list_clear_full(DBusList **list, DBusFreeFunction function)
Free every link and every element in the list.
void _dbus_list_foreach(DBusList **list, DBusForeachFunction function, void *data)
Calls the given function for each element in the list.
dbus_bool_t _dbus_list_remove_last(DBusList **list, void *data)
Removes a value from the list.
dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
#define _dbus_list_get_next_link(list, link)
Gets the next link in the list, or NULL if there are no more links.
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
void(* DBusFreeFunction)(void *memory)
The type of a function which frees a block of memory.
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
dbus_bool_t _dbus_watch_list_add_watch(DBusWatchList *watch_list, DBusWatch *watch)
Adds a new watch to the watch list, invoking the application DBusAddWatchFunction if appropriate.
void _dbus_watch_list_toggle_watch(DBusWatchList *watch_list, DBusWatch *watch, dbus_bool_t enabled)
Sets a watch to the given enabled state, invoking the application's DBusWatchToggledFunction if appro...
DBusWatchList * _dbus_watch_list_new(void)
Creates a new watch list.
void _dbus_watch_list_free(DBusWatchList *watch_list)
Frees a DBusWatchList.
dbus_bool_t _dbus_watch_list_set_functions(DBusWatchList *watch_list, DBusAddWatchFunction add_function, DBusRemoveWatchFunction remove_function, DBusWatchToggledFunction toggled_function, void *data, DBusFreeFunction free_data_function)
Sets the watch functions.
void _dbus_watch_set_handler(DBusWatch *watch, DBusWatchHandler handler, void *data, DBusFreeFunction free_data_function)
Sets the handler for the watch.
void _dbus_watch_list_toggle_all_watches(DBusWatchList *watch_list, dbus_bool_t enabled)
Sets all watches to the given enabled state, invoking the application's DBusWatchToggledFunction if a...
void _dbus_watch_sanitize_condition(DBusWatch *watch, unsigned int *condition)
Sanitizes the given condition so that it only contains flags that the DBusWatch requested.
DBusWatch * _dbus_watch_new(DBusPollable fd, unsigned int flags, dbus_bool_t enabled, DBusWatchHandler handler, void *data, DBusFreeFunction free_data_function)
Creates a new DBusWatch.
dbus_bool_t(* DBusWatchHandler)(DBusWatch *watch, unsigned int flags, void *data)
function to run when the watch is handled
DBusWatch * _dbus_watch_ref(DBusWatch *watch)
Increments the reference count of a DBusWatch object.
void _dbus_watch_unref(DBusWatch *watch)
Decrements the reference count of a DBusWatch object and finalizes the object if the count reaches ze...
void _dbus_watch_list_remove_watch(DBusWatchList *watch_list, DBusWatch *watch)
Removes a watch from the watch list, invoking the application's DBusRemoveWatchFunction if appropriat...
void _dbus_watch_invalidate(DBusWatch *watch)
Clears the file descriptor from a now-invalid watch object so that no one tries to use it.
DBUS_EXPORT int dbus_watch_get_unix_fd(DBusWatch *watch)
Returns a UNIX file descriptor to be watched, which may be a pipe, socket, or other type of descripto...
DBUS_EXPORT void dbus_watch_set_data(DBusWatch *watch, void *data, DBusFreeFunction free_data_function)
Sets data which can be retrieved with dbus_watch_get_data().
DBUS_EXPORT DBUS_DEPRECATED int dbus_watch_get_fd(DBusWatch *watch)
Deprecated former name of dbus_watch_get_unix_fd().
DBUS_EXPORT void * dbus_watch_get_data(DBusWatch *watch)
Gets data previously set with dbus_watch_set_data() or NULL if none.
DBUS_EXPORT int dbus_watch_get_socket(DBusWatch *watch)
Returns a socket to be watched, on UNIX this will return -1 if our transport is not socket-based so d...
DBUS_EXPORT dbus_bool_t dbus_watch_handle(DBusWatch *watch, unsigned int flags)
Called to notify the D-Bus library when a previously-added watch is ready for reading or writing,...
DBUS_EXPORT dbus_bool_t dbus_watch_get_enabled(DBusWatch *watch)
Returns whether a watch is enabled or not.
DBUS_EXPORT unsigned int dbus_watch_get_flags(DBusWatch *watch)
Gets flags from DBusWatchFlags indicating what conditions should be monitored on the file descriptor.
void * data
Data stored at this element.
DBusWatchList implementation details.
DBusFreeFunction watch_free_data_function
Free function for watch callback data.
DBusRemoveWatchFunction remove_watch_function
Callback for removing a watch.
void * watch_data
Data for watch callbacks.
DBusList * watches
Watch objects.
DBusAddWatchFunction add_watch_function
Callback for adding a watch.
DBusWatchToggledFunction watch_toggled_function
Callback on toggling enablement.
Implementation of DBusWatch.
unsigned int enabled
Whether it's enabled.
unsigned int oom_last_time
Whether it was OOM last time.
int refcount
Reference count.
DBusFreeFunction free_handler_data_function
Free the watch handler data.
void * data
Application data.
DBusPollable fd
File descriptor.
unsigned int flags
Conditions to watch.
DBusWatchHandler handler
Watch handler.
DBusFreeFunction free_data_function
Free the application data.
void * handler_data
Watch handler data.