25#include "dbus-internals.h"
26#include "dbus-watch.h"
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;
146 if (_dbus_pollable_is_valid (watch->
fd))
147 _dbus_warn (
"this watch should have been invalidated");
171 _dbus_pollable_invalidate (&watch->
fd);
186 unsigned int *condition)
189 *condition &= ~DBUS_WATCH_READABLE;
191 *condition &= ~DBUS_WATCH_WRITABLE;
237 if (watch_list ==
NULL)
261#ifdef DBUS_ENABLE_VERBOSE_MODE
263watch_flags_to_string (
int flags)
265 const char *watch_type;
269 watch_type =
"readwrite";
273 watch_type =
"write";
275 watch_type =
"not read or write";
303 if (add_function !=
NULL)
312#ifdef DBUS_ENABLE_VERBOSE_MODE
315 _dbus_verbose (
"Adding a %s watch on fd %" DBUS_POLLABLE_FORMAT
" using newly-set add watch function\n",
317 _dbus_pollable_printable (watch->
fd));
320 if (!(* add_function) (link->
data, data))
326 while (link2 != link)
330#ifdef DBUS_ENABLE_VERBOSE_MODE
333 _dbus_verbose (
"Removing watch on fd %" DBUS_POLLABLE_FORMAT
" using newly-set remove function because initial add failed\n",
334 _dbus_pollable_printable (watch2->
fd));
337 (* remove_function) (link2->
data, data);
353 _dbus_verbose (
"Removing all pre-existing watches\n");
391 _dbus_verbose (
"Adding watch on fd %" DBUS_POLLABLE_FORMAT
"\n",
392 _dbus_pollable_printable (watch->
fd));
422 _dbus_verbose (
"Removing watch on fd %" DBUS_POLLABLE_FORMAT
"\n",
423 _dbus_pollable_printable (watch->
fd));
454 _dbus_verbose (
"Toggling watch %p on fd %" DBUS_POLLABLE_FORMAT
" to %d\n",
456 _dbus_pollable_printable (watch->
fd),
545 _dbus_return_val_if_fail (watch !=
NULL, -1);
566 _dbus_return_val_if_fail (watch !=
NULL, -1);
595 _dbus_return_val_if_fail (watch !=
NULL, -1);
600 return _dbus_socket_get_int (watch->
fd);
621_dbus_watch_get_pollable (
DBusWatch *watch)
644 _dbus_return_val_if_fail (watch !=
NULL, 0);
660 _dbus_return_val_if_fail (watch !=
NULL,
NULL);
681 _dbus_return_if_fail (watch !=
NULL);
683 _dbus_verbose (
"Setting watch fd %" DBUS_POLLABLE_FORMAT
" data to data = %p function = %p from data = %p function = %p\n",
684 _dbus_pollable_printable (watch->
fd),
704 _dbus_return_val_if_fail (watch !=
NULL,
FALSE);
736 _dbus_return_val_if_fail (watch !=
NULL,
FALSE);
738#ifndef DBUS_DISABLE_CHECKS
739 if (!_dbus_pollable_is_valid (watch->
fd) || watch->
flags == 0)
746 _dbus_return_val_if_fail (_dbus_pollable_is_valid (watch->
fd) ,
TRUE);
752 _dbus_verbose (
"After sanitization, watch flags on fd %" DBUS_POLLABLE_FORMAT
" were 0\n",
753 _dbus_pollable_printable (watch->
fd));
757 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(* DBusForeachFunction)(void *element, void *data)
Used to iterate over each item in a collection, such as a DBusList.
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_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
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.