コード例 #1
0
ファイル: domain_event.c プロジェクト: intgr/libvirt
/**
 * virDomainEventStateNew:
 */
virDomainEventStatePtr
virDomainEventStateNew(void)
{
    virDomainEventStatePtr state = NULL;

    if (VIR_ALLOC(state) < 0) {
        virReportOOMError();
        goto error;
    }

    if (virMutexInit(&state->lock) < 0) {
        virReportSystemError(errno, "%s",
                             _("unable to initialize state mutex"));
        VIR_FREE(state);
        goto error;
    }

    if (VIR_ALLOC(state->callbacks) < 0) {
        virReportOOMError();
        goto error;
    }

    if (!(state->queue = virDomainEventQueueNew()))
        goto error;

    state->timer = -1;

    return state;

error:
    virDomainEventStateFree(state);
    return NULL;
}
コード例 #2
0
ファイル: domain_event.c プロジェクト: hw-claudio/libvirt
/**
 * virDomainEventStateNew:
 * @timeout_cb: virEventTimeoutCallback to call when timer expires
 * @timeout_opaque: Data for timeout_cb
 * @timeout_free: Optional virFreeCallback for freeing timeout_opaque
 * @requireTimer: If true, return an error if registering the timer fails.
 *                This is fatal for drivers that sit behind the daemon
 *                (qemu, lxc), since there should always be a event impl
 *                registered.
 */
virDomainEventStatePtr
virDomainEventStateNew(virEventTimeoutCallback timeout_cb,
                       void *timeout_opaque,
                       virFreeCallback timeout_free,
                       bool requireTimer)
{
    virDomainEventStatePtr state = NULL;

    if (VIR_ALLOC(state) < 0) {
        virReportOOMError();
        goto error;
    }

    if (VIR_ALLOC(state->callbacks) < 0) {
        virReportOOMError();
        goto error;
    }

    if (!(state->queue = virDomainEventQueueNew())) {
        goto error;
    }

    if ((state->timer = virEventAddTimeout(-1,
                                           timeout_cb,
                                           timeout_opaque,
                                           timeout_free)) < 0) {
        if (requireTimer == false) {
            VIR_DEBUG("virEventAddTimeout failed: No addTimeoutImpl defined. "
                      "continuing without events.");
        } else {
            eventReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                             _("could not initialize domain event timer"));
            goto error;
        }
    }

    return state;

error:
    virDomainEventStateFree(state);
    return NULL;
}