/** * virObjectEventStateRegisterID: * @conn: connection to associate with callback * @state: domain event state * @uuid: uuid of the object for event filtering * @klass: the base event class * @eventID: ID of the event type to register for * @cb: function to invoke when event occurs * @opaque: data blob to pass to @callback * @freecb: callback to free @opaque * @legacy: true if callback is tracked by function instead of callbackID * @callbackID: filled with callback ID * @serverFilter: true if server supports object filtering * * Register the function @cb with connection @conn, from @state, for * events of type @eventID, and return the registration handle in * @callbackID. * * The return value is only important when registering client-side * mirroring of remote events (since the public API is documented to * return the callbackID rather than a count). A return of 1 means * that this is the first use of this type of event, so a remote event * must be enabled; a return larger than 1 means that an existing * remote event can already feed this callback. If @serverFilter is * false, the return count assumes that a single global remote feeds * both generic and per-object callbacks, and that the event queue * will be fed with virObjectEventStateQueue(). If it is true, then * the return count assumes that the remote side is capable of per- * object filtering; the user must call virObjectEventStateSetRemote() * to record the remote id, and queue events with * virObjectEventStateQueueRemote(). * * Returns: the number of callbacks now registered, or -1 on error. */ int virObjectEventStateRegisterID(virConnectPtr conn, virObjectEventStatePtr state, unsigned char *uuid, virObjectEventCallbackFilter filter, void *filter_opaque, virClassPtr klass, int eventID, virConnectObjectEventGenericCallback cb, void *opaque, virFreeCallback freecb, bool legacy, int *callbackID, bool serverFilter) { int ret = -1; virObjectEventStateLock(state); if ((state->callbacks->count == 0) && (state->timer == -1) && (state->timer = virEventAddTimeout(-1, virObjectEventTimer, state, NULL)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("could not initialize domain event timer")); goto cleanup; } ret = virObjectEventCallbackListAddID(conn, state->callbacks, uuid, filter, filter_opaque, klass, eventID, cb, opaque, freecb, legacy, callbackID, serverFilter); if (ret == -1 && state->callbacks->count == 0 && state->timer != -1) { virEventRemoveTimeout(state->timer); state->timer = -1; } cleanup: virObjectEventStateUnlock(state); return ret; }
/** * virObjectEventStateRegisterID: * @conn: connection to associate with callback * @state: domain event state * @key: key of the object for event filtering * @klass: the base event class * @eventID: ID of the event type to register for * @cb: function to invoke when event occurs * @opaque: data blob to pass to @callback * @freecb: callback to free @opaque * @legacy: true if callback is tracked by function instead of callbackID * @callbackID: filled with callback ID * @serverFilter: true if server supports object filtering * * Register the function @cb with connection @conn, from @state, for * events of type @eventID, and return the registration handle in * @callbackID. * * The return value is only important when registering client-side * mirroring of remote events (since the public API is documented to * return the callbackID rather than a count). A return of 1 means * that this is the first use of this type of event, so a remote event * must be enabled; a return larger than 1 means that an existing * remote event can already feed this callback. If @serverFilter is * false, the return count assumes that a single global remote feeds * both generic and per-object callbacks, and that the event queue * will be fed with virObjectEventStateQueue(). If it is true, then * the return count assumes that the remote side is capable of per- * object filtering; the user must call virObjectEventStateSetRemote() * to record the remote id, and queue events with * virObjectEventStateQueueRemote(). * * Returns: the number of callbacks now registered, or -1 on error. */ int virObjectEventStateRegisterID(virConnectPtr conn, virObjectEventStatePtr state, const char *key, virObjectEventCallbackFilter filter, void *filter_opaque, virClassPtr klass, int eventID, virConnectObjectEventGenericCallback cb, void *opaque, virFreeCallback freecb, bool legacy, int *callbackID, bool serverFilter) { int ret = -1; virObjectLock(state); if ((state->callbacks->count == 0) && (state->timer == -1) && (state->timer = virEventAddTimeout(-1, virObjectEventTimer, state, virObjectFreeCallback)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("could not initialize domain event timer")); goto cleanup; } /* event loop has one reference, but we need one more for the * timer's opaque argument */ virObjectRef(state); ret = virObjectEventCallbackListAddID(conn, state->callbacks, key, filter, filter_opaque, klass, eventID, cb, opaque, freecb, legacy, callbackID, serverFilter); if (ret < 0) virObjectEventStateCleanupTimer(state, false); cleanup: virObjectUnlock(state); return ret; }