D-Bus 1.14.10
Typedefs | Functions

Object representing a file descriptor to be watched. More...

Typedefs

typedef struct DBusWatch DBusWatch
 Opaque object representing a file descriptor to be watched for changes in readability, writability, or hangup. More...
 

Functions

DBUS_EXPORT DBUS_DEPRECATED int dbus_watch_get_fd (DBusWatch *watch)
 Deprecated former name of dbus_watch_get_unix_fd(). More...
 
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 descriptor. More...
 
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 dbus_watch_get_unix_fd() is preferred. More...
 
DBUS_EXPORT unsigned int dbus_watch_get_flags (DBusWatch *watch)
 Gets flags from DBusWatchFlags indicating what conditions should be monitored on the file descriptor. More...
 
DBUS_EXPORT void * dbus_watch_get_data (DBusWatch *watch)
 Gets data previously set with dbus_watch_set_data() or NULL if none. More...
 
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(). More...
 
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, or has an exception such as a hangup. More...
 
DBUS_EXPORT dbus_bool_t dbus_watch_get_enabled (DBusWatch *watch)
 Returns whether a watch is enabled or not. More...
 
DBusSocket _dbus_watch_get_socket (DBusWatch *watch)
 
DBusPollable _dbus_watch_get_pollable (DBusWatch *watch)
 

Detailed Description

Object representing a file descriptor to be watched.

Types and functions related to DBusWatch. A watch represents a file descriptor that the main loop needs to monitor, as in Qt's QSocketNotifier or GLib's g_io_add_watch().

Use dbus_connection_set_watch_functions() or dbus_server_set_watch_functions() to be notified when libdbus needs to add or remove watches.

Typedef Documentation

◆ DBusWatch

Opaque object representing a file descriptor to be watched for changes in readability, writability, or hangup.

Definition at line 44 of file dbus-connection.h.

Function Documentation

◆ _dbus_watch_get_pollable()

DBusPollable _dbus_watch_get_pollable ( DBusWatch watch)

Definition at line 621 of file dbus-watch.c.

◆ _dbus_watch_get_socket()

DBusSocket _dbus_watch_get_socket ( DBusWatch watch)

Definition at line 605 of file dbus-watch.c.

◆ dbus_watch_get_data()

void * dbus_watch_get_data ( DBusWatch watch)

Gets data previously set with dbus_watch_set_data() or NULL if none.

Parameters
watchthe DBusWatch object.
Returns
previously-set data.

Definition at line 658 of file dbus-watch.c.

References data, and NULL.

◆ dbus_watch_get_enabled()

dbus_bool_t dbus_watch_get_enabled ( DBusWatch watch)

Returns whether a watch is enabled or not.

If not enabled, it should not be polled by the main loop.

Parameters
watchthe DBusWatch object
Returns
TRUE if the watch is enabled

Definition at line 702 of file dbus-watch.c.

References enabled, FALSE, and NULL.

◆ dbus_watch_get_fd()

int dbus_watch_get_fd ( DBusWatch watch)

Deprecated former name of dbus_watch_get_unix_fd().

Parameters
watchthe DBusWatch object.
Returns
the file descriptor to watch.

Definition at line 543 of file dbus-watch.c.

References dbus_watch_get_unix_fd(), and NULL.

◆ dbus_watch_get_flags()

unsigned int dbus_watch_get_flags ( DBusWatch watch)

Gets flags from DBusWatchFlags indicating what conditions should be monitored on the file descriptor.

The flags returned will only contain DBUS_WATCH_READABLE and DBUS_WATCH_WRITABLE, never DBUS_WATCH_HANGUP or DBUS_WATCH_ERROR; all watches implicitly include a watch for hangups, errors, and other exceptional conditions.

Parameters
watchthe DBusWatch object.
Returns
the conditions to watch.

Definition at line 642 of file dbus-watch.c.

References _dbus_assert, flags, and NULL.

◆ dbus_watch_get_socket()

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 dbus_watch_get_unix_fd() is preferred.

On Windows, dbus_watch_get_unix_fd() returns -1 but this function returns a Winsock socket (assuming the transport is socket-based, as it always is for now).

Parameters
watchthe DBusWatch object.
Returns
the socket to watch.

Definition at line 593 of file dbus-watch.c.

References fd, and NULL.

Referenced by _dbus_transport_handle_watch(), and dbus_watch_get_unix_fd().

◆ dbus_watch_get_unix_fd()

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 descriptor.

On UNIX this is preferred to dbus_watch_get_socket() since it works with more kinds of DBusWatch.

Always returns -1 on Windows. On Windows you use dbus_watch_get_socket() to get a Winsock socket to watch.

Parameters
watchthe DBusWatch object.
Returns
the file descriptor to watch.

Definition at line 564 of file dbus-watch.c.

References dbus_watch_get_socket(), fd, and NULL.

Referenced by dbus_watch_get_fd().

◆ dbus_watch_handle()

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, or has an exception such as a hangup.

If this function returns FALSE, then the file descriptor may still be ready for reading or writing, but more memory is needed in order to do the reading or writing. If you ignore the FALSE return, your application may spin in a busy loop on the file descriptor until memory becomes available, but nothing more catastrophic should happen.

dbus_watch_handle() cannot be called during the DBusAddWatchFunction, as the connection will not be ready to handle that watch yet.

It is not allowed to reference a DBusWatch after it has been passed to remove_function.

Parameters
watchthe DBusWatch object.
flagsthe poll condition using DBusWatchFlags values
Returns
FALSE if there wasn't enough memory

Definition at line 733 of file dbus-watch.c.

References FALSE, and NULL.

◆ dbus_watch_set_data()

void dbus_watch_set_data ( DBusWatch watch,
void *  data,
DBusFreeFunction  free_data_function 
)

Sets data which can be retrieved with dbus_watch_get_data().

Intended for use by the DBusAddWatchFunction and DBusRemoveWatchFunction to store their own data. For example with Qt you might store the QSocketNotifier for this watch and with GLib you might store a GSource.

Parameters
watchthe DBusWatch object.
datathe data.
free_data_functionfunction to be called to free the data.

Definition at line 677 of file dbus-watch.c.

References NULL.