Product SiteDocumentation Site

3.5. Event loop integration

The purpose of the libvirt event loop APIs is so that libvirt can be easily integrated into event driven applications, such as GUIs. These methods provide a way for the libvirt library to notify an application that there are events that need servicing; the application can then service these events during it's normal event loop.
In order to accomplish this, there are callbacks in both directions, from the application to libvirt, and from libvirt to the application. When initially registering the event callback, the application should provide various callbacks to libvirt; these functions will be called when libvirt adds, deletes, or otherwise modifies a handle. When libvirt calls these functions, they should update internal application state regarding the handles to be monitored.
Eventually a libvirt handle will need servicing. When this happens, the application should call the callback previously provided by libvirt to service the handle in question.

3.5.1. Event Types

The event types define what types of events an event loop should monitor a particular handle for. The event types are specific to libvirt, and must be translated by the application to and from poll() events.
VIR_EVENT_HANDLE_READABLE - the handle has data to read VIR_EVENT_HANDLE_WRITABLE - writing to the handle will not block VIR_EVENT_HANDLE_ERROR - the handle has had some kind of error VIR_EVENT_HANDLE_HANGUP - the handle has hung up. This typically means the handle has been closed.