示例#1
0
static int
testNetworkStartStopEvent(const void *data)
{
    const objecteventTest *test = data;
    lifecycleEventCounter counter;
    int id;
    int ret = 0;

    lifecycleEventCounter_reset(&counter);

    id = virConnectNetworkEventRegisterAny(test->conn, test->net,
                           VIR_NETWORK_EVENT_ID_LIFECYCLE,
                           VIR_NETWORK_EVENT_CALLBACK(&networkLifecycleCb),
                           &counter, NULL);
    virNetworkCreate(test->net);
    virNetworkDestroy(test->net);

    if (virEventRunDefaultImpl() < 0) {
        ret = -1;
        goto cleanup;
    }

    if (counter.startEvents != 1 || counter.stopEvents != 1 ||
            counter.unexpectedEvents > 0) {
        ret = -1;
        goto cleanup;
    }
cleanup:
    virConnectNetworkEventDeregisterAny(test->conn, id);

    return ret;
}
void ConnAliveThread::registerConnEvents()
{
    int ret = virConnectRegisterCloseCallback(
                *ptr_ConnPtr,
                connEventCallBack,
                this,
    // don't register freeData, because it remove this thread
                NULL);
    closeCallbackRegistered = !(ret<0);
    if (ret<0) sendConnErrors();
    domainsLifeCycleCallback = virConnectDomainEventRegisterAny(
                *ptr_ConnPtr,
                NULL,
    // set domainsLifeCycleCallback signature
                VIR_DOMAIN_EVENT_ID_LIFECYCLE,
                VIR_DOMAIN_EVENT_CALLBACK(domEventCallback),
                this,
    // don't register freeData, because it remove this thread
                NULL);
    if (ret<0) sendConnErrors();
    networkLifeCycleCallback = virConnectNetworkEventRegisterAny(
                *ptr_ConnPtr,
                NULL,
    // set networksLifeCycleCallback signature
                VIR_NETWORK_EVENT_ID_LIFECYCLE,
                VIR_NETWORK_EVENT_CALLBACK(netEventCallback),
                this,
    // don't register freeData, because it remove this thread
                NULL);
    if (ret<0) sendConnErrors();
}
示例#3
0
static int
testNetworkDefine(const void *data)
{
    const objecteventTest *test = data;
    lifecycleEventCounter counter;
    virNetworkPtr net;
    int id;
    int ret = 0;

    lifecycleEventCounter_reset(&counter);

    id = virConnectNetworkEventRegisterAny(test->conn, NULL,
                           VIR_NETWORK_EVENT_ID_LIFECYCLE,
                           VIR_NETWORK_EVENT_CALLBACK(&networkLifecycleCb),
                           &counter, NULL);

    /* Make sure the define event is triggered */
    net = virNetworkDefineXML(test->conn, networkDef);

    if (virEventRunDefaultImpl() < 0) {
        ret = -1;
        goto cleanup;
    }

    if (counter.defineEvents != 1 || counter.unexpectedEvents > 0) {
        ret = -1;
        goto cleanup;
    }

    /* Make sure the undefine event is triggered */
    virNetworkUndefine(net);

    if (virEventRunDefaultImpl() < 0) {
        ret = -1;
        goto cleanup;
    }

    if (counter.undefineEvents != 1 || counter.unexpectedEvents > 0) {
        ret = -1;
        goto cleanup;
    }


cleanup:
    virConnectNetworkEventDeregisterAny(test->conn, id);
    virNetworkFree(net);

    return ret;
}