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)   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)
   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)
   313 #ifdef DBUS_ENABLE_VERBOSE_MODE   316           _dbus_verbose (
"Adding a %s watch on fd %" DBUS_POLLABLE_FORMAT 
" using newly-set add watch function\n",
   318                          _dbus_pollable_printable (watch->
fd));
   321           if (!(* add_function) (link->
data, data))
   327               while (link2 != link)
   331 #ifdef DBUS_ENABLE_VERBOSE_MODE   334                   _dbus_verbose (
"Removing watch on fd %" DBUS_POLLABLE_FORMAT 
" using newly-set remove function because initial add failed\n",
   335                                  _dbus_pollable_printable (watch2->
fd));
   338                   (* remove_function) (link2->
data, 
data);
   354       _dbus_verbose (
"Removing all pre-existing watches\n");
   392       _dbus_verbose (
"Adding watch on fd %" DBUS_POLLABLE_FORMAT 
"\n",
   393                      _dbus_pollable_printable (watch->
fd));
   423       _dbus_verbose (
"Removing watch on fd %" DBUS_POLLABLE_FORMAT 
"\n",
   424                      _dbus_pollable_printable (watch->
fd));
   455       _dbus_verbose (
"Toggling watch %p on fd %" DBUS_POLLABLE_FORMAT 
" to %d\n",
   457                      _dbus_pollable_printable (watch->
fd),
   546   _dbus_return_val_if_fail (watch != 
NULL, -1);
   567   _dbus_return_val_if_fail (watch != 
NULL, -1);
   596   _dbus_return_val_if_fail (watch != 
NULL, -1);
   601   return _dbus_socket_get_int (watch->
fd);
   606 _dbus_watch_get_socket (
DBusWatch *watch)
   622 _dbus_watch_get_pollable (
DBusWatch *watch)
   645   _dbus_return_val_if_fail (watch != 
NULL, 0);
   661   _dbus_return_val_if_fail (watch != 
NULL, 
NULL);
   682   _dbus_return_if_fail (watch != 
NULL);
   684   _dbus_verbose (
"Setting watch fd %" DBUS_POLLABLE_FORMAT 
" data to data = %p function = %p from data = %p function = %p\n",
   685                  _dbus_pollable_printable (watch->
fd),
   705   _dbus_return_val_if_fail (watch != 
NULL, 
FALSE);
   737   _dbus_return_val_if_fail (watch != 
NULL, 
FALSE);
   739 #ifndef DBUS_DISABLE_CHECKS   740   if (!_dbus_pollable_is_valid (watch->
fd) || watch->
flags == 0)
   747   _dbus_return_val_if_fail (_dbus_pollable_is_valid (watch->
fd) , 
TRUE);
   753       _dbus_verbose (
"After sanitization, watch flags on fd %" DBUS_POLLABLE_FORMAT 
" were 0\n",
   754                      _dbus_pollable_printable (watch->
fd));
 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. 
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(). 
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. 
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. 
void _dbus_watch_list_free(DBusWatchList *watch_list)
Frees a DBusWatchList. 
DBusWatchToggledFunction watch_toggled_function
Callback on toggling enablement. 
DBusWatchList * _dbus_watch_list_new(void)
Creates a new watch list. 
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_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. 
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...
void _dbus_watch_invalidate(DBusWatch *watch)
Clears the file descriptor from a now-invalid watch object so that no one tries to use it...
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_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...
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. 
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_unref(DBusWatch *watch)
Decrements the reference count of a DBusWatch object and finalizes the object if the count reaches ze...
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...
DBusWatch * _dbus_watch_ref(DBusWatch *watch)
Increments the reference count of a DBusWatch object. 
DBusPollable fd
File descriptor. 
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_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_list_clear(DBusList **list)
Frees all links in the list and sets the list head to NULL.