NAME
wleventsource - An abstract event source. SYNOPSIS
#include
Public Types typedef int(* wleventloopfdfunct )(int fd, uint32t mask, void *data) typedef int(* wleventlooptimerfunct )(void *data) typedef int(* wleventloopsignalfunct )(int signalnumber, void *data) typedef void(* wleventloopidlefunct )(void *data) Public Member Functions struct wleventsource * wleventloopaddfd (struct wleventloop *loop, int fd, uint32t mask, wleventloopfdfunct func, void *data) int wleventsourcefdupdate (struct wleventsource *source, uint32t mask) struct wleventsource * wleventloopaddtimer (struct wleventloop *loop, wleventlooptimerfunct func, void *data) int wleventsourcetimerupdate (struct wleventsource *source, int msdelay) struct wleventsource * wleventloopaddsignal (struct wleventloop *loop, int signalnumber, wleventloopsignalfunct func, void *data) struct wleventsource * wleventloopaddidle (struct wleventloop *loop, wleventloopidlefunct func, void *data) void wleventsourcecheck (struct wleventsource *source) int wleventsourceremove (struct wleventsource *source) Detailed Description An abstract event source. This is the generic type for fd, timer, signal, and idle sources. Functions that operate on specific source types must not be used with a different type, even if the function signature allows it. Member Typedef Documentation typedef int(* wleventloopfdfunct)(int fd, uint32t mask, void *data) File descriptor dispatch function type Functions of this type are used as callbacks for file descriptor events. Parameters: fd The file descriptor delivering the event. mask Describes the kind of the event as a bitwise-or of: WLEVENTREADABLE, WLEVENTWRITABLE, WLEVENTHANGUP, WLEVENTERROR. data The user data argument of the related wleventloopaddfd() call. Returns:
If the event source is registered for re-check with
wleventsourcecheck(): 0 for all done, 1 for needing a re-check. If not registered, the return value is ignored and should be zero. See Also: wleventloopaddfd() typedef void(* wleventloopidlefunct)(void *data) Idle task function type Functions of this type are used as callbacks before blocking in wleventloopdispatch(). Parameters: data The user data argument of the related wleventloopaddidle() call. See Also: wleventloopaddidle() wleventloopdispatch() typedef int(* wleventloopsignalfunct)(int signalnumber, void *data) Signal dispatch function type Functions of this type are used as callbacks for (POSIX) signals. Parameters: signalnumber data The user data argument of the related wleventloopaddsignal() call. Returns:
If the event source is registered for re-check with
wleventsourcecheck(): 0 for all done, 1 for needing a re-check. If not registered, the return value is ignored and should be zero. See Also: wleventloopaddsignal() typedef int(* wleventlooptimerfunct)(void *data) Timer dispatch function type Functions of this type are used as callbacks for timer expiry. Parameters: data The user data argument of the related wleventloopaddtimer() call. Returns:
If the event source is registered for re-check with
wleventsourcecheck(): 0 for all done, 1 for needing a re-check. If not registered, the return value is ignored and should be zero. See Also: wleventloopaddtimer() Member Function Documentation struct wleventsource * wleventloopaddfd (struct wleventloop *loop, intfd, uint32tmask, wleventloopfdfunctfunc, void *data) Create a file descriptor event source Parameters: loop The event loop that will process the new source. fd The file descriptor to watch.
mask A bitwise-or of which events to watch for: WLEVENTREADABLE, WLEVENTWRITABLE. func The file descriptor dispatch function. data User data. Returns: A new file descriptor event source. The given file descriptor is initially watched for the events given in mask. This can be changed as needed with wleventsourcefdupdate(). If it is possible that program execution causes the file descriptor to be read while leaving the data in a buffer without actually processing it, it may be necessary to register the file descriptor source to be
re-checked, see wleventsourcecheck(). This will ensure that the dispatch function gets called even if the file descriptor is not readable or writable anymore. This is especially useful with IPC
libraries that automatically buffer incoming data, possibly as a side- effect of other operations. See Also: wleventloopfdfunct struct wleventsource * wleventloopaddidle (struct wleventloop *loop, wleventloopidlefunctfunc, void *data) Create an idle task Parameters: loop The event loop that will process the new task. func The idle task dispatch function. data User data. Returns: A new idle task (an event source). Idle tasks are dispatched before wleventloopdispatch() goes to sleep. See wleventloopdispatch() for more details. Idle tasks fire once, and are automatically destroyed right after the callback function has been called. An idle task can be cancelled before the callback has been called by wleventsourceremove(). Calling wleventsourceremove() after or from within the callback results in undefined behaviour. See Also: wleventloopidlefunct struct wleventsource * wleventloopaddsignal (struct wleventloop *loop, intsignalnumber, wleventloopsignalfunctfunc, void *data) Create a POSIX signal event source Parameters: loop The event loop that will process the new source. signalnumber Number of the signal to watch for. func The signal dispatch function. data User data. Returns: A new signal event source. This function blocks the normal delivery of the given signal in the calling thread, and creates a 'watch' for it. Signal delivery no longer happens asynchronously, but by wleventloopdispatch() calling the dispatch callback function func. It is the caller's responsibility to ensure that all other threads have also blocked the signal. See Also: wleventloopsignalfunct struct wleventsource * wleventloopaddtimer (struct wleventloop *loop, wleventlooptimerfunctfunc, void *data) Create a timer event source Parameters: loop The event loop that will process the new source. func The timer dispatch function. data User data. Returns: A new timer event source. The timer is initially disarmed. It needs to be armed with a call to wleventsourcetimerupdate() before it can trigger a dispatch call. See Also: wleventlooptimerfunct void wleventsourcecheck (struct wleventsource *source)
Mark event source to be re-checked Parameters:
source The event source to be re-checked.
This function permanently marks the event source to be re-checked after
the normal dispatch of sources in wleventloopdispatch(). Re-checking will keep iterating over all such event sources until the dispatch function for them all returns zero.
Re-checking is used on sources that may become ready to dispatch as a
side-effect of dispatching themselves or other event sources, including
idle sources. Re-checking ensures all the incoming events have been fully drained before wleventloopdispatch() returns. int wleventsourcefdupdate (struct wleventsource *source, uint32tmask) Update a file descriptor source's event mask Parameters: source The file descriptor event source to update.
mask The new mask, a bitwise-or of: WLEVENTREADABLE, WLEVENTWRITABLE. Returns:
0 on success, -1 on failure. This changes which events, readable and/or writable, cause the dispatch callback to be called on. File descriptors are usually writable to begin with, so they do not need to be polled for writable until a write actually fails. When a write fails, the event mask can be changed to poll for readable and writable, delivering a dispatch callback when it is possible to write more. Once all data has been written, the mask can be changed to poll
only for readable to avoid busy-looping on dispatch. See Also: wleventloopaddfd() int wleventsourceremove (struct wleventsource *source) Remove an event source from its event loop Parameters: source The event source to be removed. Returns: Zero. The event source is removed from the event loop it was created for, and is effectively destroyed. This invalidates source . The dispatch function of the source will no longer be called through this source. int wleventsourcetimerupdate (struct wleventsource *source, intmsdelay) Arm or disarm a timer Parameters: source The timer event source to modify. msdelay The timeout in milliseconds. Returns:
0 on success, -1 on failure. If the timeout is zero, the timer is disarmed.
If the timeout is non-zero, the timer is set to expire after the given timeout in milliseconds. When the timer expires, the dispatch function set with wleventloopaddtimer() is called once from wleventloopdispatch(). If another dispatch is desired after another expiry, wleventsourcetimerupdate() needs to be called again. Author Generated automatically by Doxygen for Wayland from the source code. Version 1.15.0 Tue Oct 30 2018 wleventsource(3)