Learn how to evaluate and integrate the VNC SDK
EventLoopFd.h¶
Implement a custom file-descriptor-based event loop. (more...)
Data structures
Modifier and Type | Name and Description |
---|---|
struct |
Callback receiving notifications for a file-descriptor-based event loop. |
Enums
Modifier and Type | Name and Description |
---|---|
enum |
Enumeration of file descriptor events for event selection. |
Functions
Modifier and Type | Name and Description |
---|---|
function vnc_status_t | vnc_EventLoopFd_setCallback(const vnc_EventLoopFd_Callback *callback, void *userData) Sets the event loop callback. |
function vnc_status_t | vnc_EventLoopFd_markEvents(int fd, int events) Marks event(s) that occurred on the specified file descriptor. |
function int | vnc_EventLoopFd_handleEvents() Handles events on the file descriptors and process expired timers. |
Detailed description
Implement a custom file-descriptor-based event loop.
The following functions are used for integrating the VNC SDK into an existing file-descriptor-based event loop. This could either be an application’s event loop implemented directly using poll or select, or a third party event loop where the SDK’s file descriptors can be registered (for example using Qt’s QSocketNotifier).
The functions in this file are all only available on Linux, OS X, iOS, and Android, and an assertion is used to verify that vnc_init() was used to create a file-descriptor event loop.
See the basicViewerX11 sample for an example of how to integrate this into an existing application event loop using select.
To integrate into a third-party event loop (e.g. using a framework such as Qt), implement the vnc_EventLoopFd_Callback::eventUpdated and vnc_EventLoopFd_Callback::timerUpdated callbacks to create, update or destroy the appropriate notifiers for the framework. On receiving notifications, call vnc_EventLoopFd_markEvents() (in the case of an fd event) and then call vnc_EventLoopFd_handleEvents().
Enums
-
enum
vnc_EventLoopFd_Event
¶ Enumeration of file descriptor events for event selection.
Values:
-
vnc_EventLoopFd_Read
= 0x01¶ Monitor using
readfds
withselect()
(the second argument), orPOLLIN
withpoll()
.
-
vnc_EventLoopFd_Write
= 0x02¶ Monitor using
writefds
withselect()
(the third argument), orPOLLOUT
withpoll()
.
-
vnc_EventLoopFd_Except
= 0x04¶ Monitor using
exceptfds
withselect()
(the fourth argument), orPOLLPRI
withpoll()
.
-
Functions
-
vnc_status_t
vnc_EventLoopFd_setCallback
(const vnc_EventLoopFd_Callback *callback, void *userData)¶ Sets the event loop callback.
- Return
- vnc_success or vnc_failure, in which case call vnc_getLastError() to get the error code.
- Parameters
callback
-The new event loop callback.
- Return Value
InvalidArgument
-The vnc_EventLoopFd_Callback::eventUpdated callback is NULL
-
vnc_status_t
vnc_EventLoopFd_markEvents
(int fd, int events)¶ Marks event(s) that occurred on the specified file descriptor.
- Return
- vnc_success or vnc_failure, in which case call vnc_getLastError() to get the error code.
- Parameters
fd
-The file descriptor.
events
-A mask of events to be marked for handling.
- Return Value
InvalidArgument
-fd
is not recognized by the SDK
-
int
vnc_EventLoopFd_handleEvents
(void)¶ Handles events on the file descriptors and process expired timers.
- Return
- The number of milliseconds until the next timer expires
-
struct
vnc_EventLoopFd_Callback
¶ - #include <EventLoopFd.h>
Callback receiving notifications for a file-descriptor-based event loop.
Public Members
-
void(* vnc_EventLoopFd_Callback::eventUpdated) (void *userData, int fd, int eventMask)
Notification that a file descriptor’s event mask has changed.
This callback is required.
- Parameters
fd
-The file descriptor whose event mask has changed.
eventMask
-Specifies the events we are interested in for this descriptor. When one of the specified events occurs, the implementation should call vnc_EventLoopFd_markEvents() to mark which event(s) occurred, then call vnc_EventLoopFd_handleEvents(). An
eventMask
of 0 indicates the SDK is no longer using this file descriptor; it should be removed immediately from the monitored set of descriptors.
-
void(* vnc_EventLoopFd_Callback::timerUpdated) (void *userData, int expiryMs)
Notification that the timer expiry period has been updated.
When the specified expiry time has passed, the implementation should call vnc_EventLoopFd_handleEvents().
This callback is optional, and is only needed if integrating with a third-party event loop rather than calling vnc_EventLoopFd_handleEvents() directly to a create a custom blocking event loop.
- Parameters
expiryMs
-The maximum time that should be allowed to pass before the next call to vnc_EventLoopFd_handleEvents(), in milliseconds
-