25 #include "dbus-internals.h"
26 #include "dbus-watch.h"
27 #include "dbus-list.h"
57 _dbus_watch_get_enabled (
DBusWatch *watch)
63 _dbus_watch_get_oom_last_time (
DBusWatch *watch)
69 _dbus_watch_set_oom_last_time (
DBusWatch *watch,
97 #define VALID_WATCH_FLAGS (DBUS_WATCH_WRITABLE | DBUS_WATCH_READABLE)
107 watch->
flags = flags;
147 _dbus_warn (
"this watch should have been invalidated");
186 unsigned int *condition)
237 if (watch_list ==
NULL)
262 #ifdef DBUS_ENABLE_VERBOSE_MODE
264 watch_flags_to_string (
int flags)
266 const char *watch_type;
270 watch_type =
"readwrite";
271 else if (flags & DBUS_WATCH_READABLE)
273 else if (flags & DBUS_WATCH_WRITABLE)
274 watch_type =
"write";
276 watch_type =
"not read or write";
304 if (add_function !=
NULL)
314 _dbus_verbose (
"Adding a %s watch on fd %d using newly-set add watch function\n",
318 if (!(* add_function) (link->
data, data))
324 while (link2 != link)
329 _dbus_verbose (
"Removing watch on fd %d using newly-set remove function because initial add failed\n",
332 (* remove_function) (link2->
data, data);
348 _dbus_verbose (
"Removing all pre-existing watches\n");
386 _dbus_verbose (
"Adding watch on fd %d\n",
417 _dbus_verbose (
"Removing watch on fd %d\n",
449 _dbus_verbose (
"Toggling watch %p on fd %d to %d\n",
538 _dbus_return_val_if_fail (watch !=
NULL, -1);
559 _dbus_return_val_if_fail (watch !=
NULL, -1);
588 _dbus_return_val_if_fail (watch !=
NULL, -1);
609 _dbus_return_val_if_fail (watch !=
NULL, 0);
625 _dbus_return_val_if_fail (watch !=
NULL,
NULL);
646 _dbus_return_if_fail (watch !=
NULL);
648 _dbus_verbose (
"Setting watch fd %d data to data = %p function = %p from data = %p function = %p\n",
669 _dbus_return_val_if_fail (watch !=
NULL,
FALSE);
701 _dbus_return_val_if_fail (watch !=
NULL,
FALSE);
703 #ifndef DBUS_DISABLE_CHECKS
704 if (watch->
fd < 0 || watch->
flags == 0)
711 _dbus_return_val_if_fail (watch->
fd >= 0 ,
TRUE);
717 _dbus_verbose (
"After sanitization, watch flags on fd %d were 0\n",
722 return (* watch->
handler) (watch, flags,
Implementation of DBusWatch.
#define NULL
A null pointer, defined appropriately for C or C++.
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().
DBusWatchList * _dbus_watch_list_new(void)
Creates a new watch list.
void _dbus_watch_invalidate(DBusWatch *watch)
Clears the file descriptor from a now-invalid watch object so that no one tries to use it...
DBusFreeFunction watch_free_data_function
Free function for watch callback data.
void * handler_data
Watch handler data.
void(* DBusWatchToggledFunction)(DBusWatch *watch, void *data)
Called when dbus_watch_get_enabled() may return a different value than it did before.
DBUS_EXPORT dbus_bool_t dbus_watch_get_enabled(DBusWatch *watch)
Returns whether a watch is enabled or not.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
void * data
Data stored at this element.
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_warn_check_failed(const char *format,...)
Prints a "critical" warning to stderr when an assertion fails; differs from _dbus_warn primarily in t...
dbus_bool_t(* DBusWatchHandler)(DBusWatch *watch, unsigned int flags, void *data)
function to run when the watch is handled
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...
DBusAddWatchFunction add_watch_function
Callback for adding a watch.
DBusFreeFunction free_data_function
Free the application data.
DBusWatchToggledFunction watch_toggled_function
Callback on toggling enablement.
void * watch_data
Data for watch callbacks.
dbus_bool_t _dbus_list_remove(DBusList **list, void *data)
Removes a value from the list.
unsigned int flags
Conditions to watch.
#define _dbus_list_get_next_link(list, link)
Gets the next link in the list, or NULL if there are no more links.
dbus_bool_t _dbus_list_remove_last(DBusList **list, void *data)
Removes a value from the list.
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
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...
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
void _dbus_watch_sanitize_condition(DBusWatch *watch, unsigned int *condition)
Sanitizes the given condition so that it only contains flags that the DBusWatch requested.
void _dbus_list_foreach(DBusList **list, DBusForeachFunction function, void *data)
Calls the given function for each element in the list.
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...
unsigned int oom_last_time
Whether it was OOM last time.
void * data
Application data.
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...
int refcount
Reference count.
#define TRUE
Expands to "1".
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
DBUS_EXPORT DBUS_DEPRECATED int dbus_watch_get_fd(DBusWatch *watch)
Deprecated former name of dbus_watch_get_unix_fd().
dbus_bool_t(* DBusAddWatchFunction)(DBusWatch *watch, void *data)
Called when libdbus needs a new watch to be monitored by the main loop.
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().
void(* DBusRemoveWatchFunction)(DBusWatch *watch, void *data)
Called when libdbus no longer needs a watch to be monitored by the main loop.
DBusWatchList implementation details.
unsigned int enabled
Whether it's enabled.
DBUS_EXPORT void * dbus_watch_get_data(DBusWatch *watch)
Gets data previously set with dbus_watch_set_data() or NULL if none.
DBusWatch * _dbus_watch_ref(DBusWatch *watch)
Increments the reference count of a DBusWatch object.
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.
DBusWatch * _dbus_watch_new(int fd, unsigned int flags, dbus_bool_t enabled, DBusWatchHandler handler, void *data, DBusFreeFunction free_data_function)
Creates a new DBusWatch.
void(* DBusForeachFunction)(void *element, void *data)
Used to iterate over each item in a collection, such as a DBusList.
DBusList * _dbus_list_get_first_link(DBusList **list)
Gets the first link in the list.
#define FALSE
Expands to "0".
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...
void _dbus_watch_unref(DBusWatch *watch)
Decrements the reference count of a DBusWatch object and finalizes the object if the count reaches ze...
DBUS_EXPORT unsigned int dbus_watch_get_flags(DBusWatch *watch)
Gets flags from DBusWatchFlags indicating what conditions should be monitored on the file descriptor...
DBusFreeFunction free_handler_data_function
Free the watch handler data.
void _dbus_watch_list_free(DBusWatchList *watch_list)
Frees a DBusWatchList.
void _dbus_watch_set_handler(DBusWatch *watch, DBusWatchHandler handler, void *data, DBusFreeFunction free_data_function)
Sets the handler for the watch.
DBusRemoveWatchFunction remove_watch_function
Callback for removing a watch.
DBusWatchHandler handler
Watch handler.
DBusList * watches
Watch objects.
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_list_clear(DBusList **list)
Frees all links in the list and sets the list head to NULL.