On Mon, Sep 22, 2008 at 11:11:17AM -0400, David Lively wrote:
Okay - I'm looking at glib docs. You guys are suggesting I
create
something that's easy to plug into a glib main loop, right?
So ... something that's easy to "wrap" with a GSource via
g_source_new()? (Stop me now if I'm on the wrong track!) So ...
something that plugs into GSourceFuncs elements (in particular
prepare/check/dispatch/finalize) easily??
int virEventsNeedDelivering(virConnectionPtr conn)
int virEventsDispatch(virConnectionPtr conn)
int virEventsCleanup(virConnectionPtr conn)
and perhaps:
int virEventsRunOnce(virConnectionPtr conn)
to wrap them all for non-glib-ish implementations?
No, this the wrong approach. This is defining an event loop impl - we
don't want todo that. We need to define an API to let an application
provide a set of callback for libvirt to talk to an existing event
loop impl. ie a way for libvirt to register FD watches and timeouts,
not a way for apps to manually process libvirt events in this way this
example shows.
The public API for this is along the lines of that currently defined
in the src/events.h file.
There are a set of functions libvirt needs in order to register actions
for FDs, and/or timeouts. So the public API should consist of a way
to register impls of these APIs
typedef int (*virEventAddHandleFunc)(int, int, virEventHandleCallback, void *);
typedef void (*virEventUpdateHandleFunc)(int, int);
typedef int (*virEventRemoveHandleFunc)(int);
typedef int (*virEventAddTimeoutFunc)(int, virEventTimeoutCallback, void *);
typedef void (*virEventUpdateTimeoutFunc)(int, int);
typedef int (*virEventRemoveTimeoutFunc)(int);
void virEventRegisterImpl(virEventAddHandleFunc addHandle,
virEventUpdateHandleFunc updateHandle,
virEventRemoveHandleFunc removeHandle,
virEventAddTimeoutFunc addTimeout,
virEventUpdateTimeoutFunc updateTimeout,
virEventRemoveTimeoutFunc removeTimeout);
A separate libvirt-glib.so, would provide a API call
virEventRegisterGLib()
which calls virEventRegisterImpl() with a suitable implementation for
glib. An application like virt-manager which uses glib and wants events
would then calll virEventRegisterGLib(). If it had a custom event loop
of its own, then it could call virEventRegisterImpl() directly with its
special impl.
It may be worth making our public API even more closely aligned with
dbus - see dbus-connection.h and dbus-server.h - so people writing
glue functions for it could just reuse what they've already written
for dbus.
typedef dbus_bool_t (* DBusAddWatchFunction) (DBusWatch *watch,
void *data);
typedef void (* DBusWatchToggledFunction) (DBusWatch *watch,
void *data);
typedef void (* DBusRemoveWatchFunction) (DBusWatch *watch,
void *data);
typedef dbus_bool_t (* DBusAddTimeoutFunction) (DBusTimeout *timeout,
void *data);
typedef void (* DBusTimeoutToggledFunction) (DBusTimeout *timeout,
void *data);
typedef void (* DBusRemoveTimeoutFunction) (DBusTimeout *timeout,
void *data);
dbus_bool_t dbus_server_set_watch_functions (DBusServer *server,
DBusAddWatchFunction
add_function,
DBusRemoveWatchFunction
remove_function,
DBusWatchToggledFunction
toggled_function,
void *data,
DBusFreeFunction
free_data_function);
dbus_bool_t dbus_server_set_timeout_functions (DBusServer *server,
DBusAddTimeoutFunction
add_function,
DBusRemoveTimeoutFunction
remove_function,
DBusTimeoutToggledFunction
toggled_function,
void *data,
DBusFreeFunction
free_data_function);
A 'watch' in DBus terminology is a file descriptor monitor.
Daniel
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|