Re: [PATCH 5/7] test: Use virDomainEventState helpers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, May 12, 2011 at 01:14:29PM -0400, Cole Robinson wrote:
> v3:
>     Adjust for new virDomainEventStateNew argument
> 
> Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
> ---
>  src/test/test_driver.c |  105 +++++++++++++++---------------------------------
>  1 files changed, 32 insertions(+), 73 deletions(-)
> 
> diff --git a/src/test/test_driver.c b/src/test/test_driver.c
> index bf33d13..f244a0f 100644
> --- a/src/test/test_driver.c
> +++ b/src/test/test_driver.c
> @@ -90,12 +90,7 @@ struct _testConn {
>      int numCells;
>      testCell cells[MAX_CELLS];
>  
> -
> -    /* An array of callbacks */
> -    virDomainEventCallbackListPtr domainEventCallbacks;
> -    virDomainEventQueuePtr domainEventQueue;
> -    int domainEventTimer;
> -    int domainEventDispatching;
> +    virDomainEventStatePtr domainEventState;
>  };
>  typedef struct _testConn testConn;
>  typedef struct _testConn *testConnPtr;
> @@ -1124,6 +1119,7 @@ static virDrvOpenStatus testOpen(virConnectPtr conn,
>                      int flags ATTRIBUTE_UNUSED)
>  {
>      int ret;
> +    testConnPtr privconn;
>  
>      if (!conn->uri)
>          return VIR_DRV_OPEN_DECLINED;
> @@ -1150,26 +1146,25 @@ static virDrvOpenStatus testOpen(virConnectPtr conn,
>          ret = testOpenFromFile(conn,
>                                 conn->uri->path);
>  
> -    if (ret == VIR_DRV_OPEN_SUCCESS) {
> -        testConnPtr privconn = conn->privateData;
> -        testDriverLock(privconn);
> -        /* Init callback list */
> -        if (VIR_ALLOC(privconn->domainEventCallbacks) < 0 ||
> -            !(privconn->domainEventQueue = virDomainEventQueueNew())) {
> -            virReportOOMError();
> -            testDriverUnlock(privconn);
> -            testClose(conn);
> -            return VIR_DRV_OPEN_ERROR;
> -        }
> +    if (ret != VIR_DRV_OPEN_SUCCESS)
> +        return ret;
> +
> +    privconn = conn->privateData;
> +    testDriverLock(privconn);
>  
> -        if ((privconn->domainEventTimer =
> -             virEventAddTimeout(-1, testDomainEventFlush, privconn, NULL)) < 0)
> -            VIR_DEBUG("virEventAddTimeout failed: No addTimeoutImpl defined. "
> -                   "continuing without events.");
> +    privconn->domainEventState = virDomainEventStateNew(testDomainEventFlush,
> +                                                        privconn,
> +                                                        NULL,
> +                                                        false);
> +    if (!privconn->domainEventState) {
>          testDriverUnlock(privconn);
> +        testClose(conn);
> +        return VIR_DRV_OPEN_ERROR;
>      }
>  
> -    return (ret);
> +    testDriverUnlock(privconn);
> +
> +    return VIR_DRV_OPEN_SUCCESS;
>  }
>  
>  static int testClose(virConnectPtr conn)
> @@ -1182,12 +1177,7 @@ static int testClose(virConnectPtr conn)
>      virNetworkObjListFree(&privconn->networks);
>      virInterfaceObjListFree(&privconn->ifaces);
>      virStoragePoolObjListFree(&privconn->pools);
> -
> -    virDomainEventCallbackListFree(privconn->domainEventCallbacks);
> -    virDomainEventQueueFree(privconn->domainEventQueue);
> -
> -    if (privconn->domainEventTimer != -1)
> -        virEventRemoveTimeout(privconn->domainEventTimer);
> +    virDomainEventStateFree(privconn->domainEventState);
>  
>      testDriverUnlock(privconn);
>      virMutexDestroy(&privconn->lock);
> @@ -5177,7 +5167,8 @@ testDomainEventRegister(virConnectPtr conn,
>      int ret;
>  
>      testDriverLock(driver);
> -    ret = virDomainEventCallbackListAdd(conn, driver->domainEventCallbacks,
> +    ret = virDomainEventCallbackListAdd(conn,
> +                                        driver->domainEventState->callbacks,
>                                          callback, opaque, freecb);
>      testDriverUnlock(driver);
>  
> @@ -5193,12 +5184,9 @@ testDomainEventDeregister(virConnectPtr conn,
>      int ret;
>  
>      testDriverLock(driver);
> -    if (driver->domainEventDispatching)
> -        ret = virDomainEventCallbackListMarkDelete(conn, driver->domainEventCallbacks,
> -                                                   callback);
> -    else
> -        ret = virDomainEventCallbackListRemove(conn, driver->domainEventCallbacks,
> -                                               callback);
> +    ret = virDomainEventStateDeregister(conn,
> +                                        driver->domainEventState,
> +                                        callback);
>      testDriverUnlock(driver);
>  
>      return ret;
> @@ -5217,7 +5205,8 @@ testDomainEventRegisterAny(virConnectPtr conn,
>      int ret;
>  
>      testDriverLock(driver);
> -    ret = virDomainEventCallbackListAddID(conn, driver->domainEventCallbacks,
> +    ret = virDomainEventCallbackListAddID(conn,
> +                                          driver->domainEventState->callbacks,
>                                            dom, eventID,
>                                            callback, opaque, freecb);
>      testDriverUnlock(driver);
> @@ -5233,12 +5222,9 @@ testDomainEventDeregisterAny(virConnectPtr conn,
>      int ret;
>  
>      testDriverLock(driver);
> -    if (driver->domainEventDispatching)
> -        ret = virDomainEventCallbackListMarkDeleteID(conn, driver->domainEventCallbacks,
> -                                                     callbackID);
> -    else
> -        ret = virDomainEventCallbackListRemoveID(conn, driver->domainEventCallbacks,
> -                                                 callbackID);
> +    ret = virDomainEventStateDeregisterAny(conn,
> +                                           driver->domainEventState,
> +                                           callbackID);
>      testDriverUnlock(driver);
>  
>      return ret;
> @@ -5262,28 +5248,11 @@ static void testDomainEventDispatchFunc(virConnectPtr conn,
>  static void testDomainEventFlush(int timer ATTRIBUTE_UNUSED, void *opaque)
>  {
>      testConnPtr driver = opaque;
> -    virDomainEventQueue tempQueue;
>  
>      testDriverLock(driver);
> -
> -    driver->domainEventDispatching = 1;
> -
> -    /* Copy the queue, so we're reentrant safe */
> -    tempQueue.count = driver->domainEventQueue->count;
> -    tempQueue.events = driver->domainEventQueue->events;
> -    driver->domainEventQueue->count = 0;
> -    driver->domainEventQueue->events = NULL;
> -
> -    virEventUpdateTimeout(driver->domainEventTimer, -1);
> -    virDomainEventQueueDispatch(&tempQueue,
> -                                driver->domainEventCallbacks,
> -                                testDomainEventDispatchFunc,
> -                                driver);
> -
> -    /* Purge any deleted callbacks */
> -    virDomainEventCallbackListPurgeMarked(driver->domainEventCallbacks);
> -
> -    driver->domainEventDispatching = 0;
> +    virDomainEventStateFlush(driver->domainEventState,
> +                             testDomainEventDispatchFunc,
> +                             driver);
>      testDriverUnlock(driver);
>  }
>  
> @@ -5292,17 +5261,7 @@ static void testDomainEventFlush(int timer ATTRIBUTE_UNUSED, void *opaque)
>  static void testDomainEventQueue(testConnPtr driver,
>                                   virDomainEventPtr event)
>  {
> -    if (driver->domainEventTimer < 0) {
> -        virDomainEventFree(event);
> -        return;
> -    }
> -
> -    if (virDomainEventQueuePush(driver->domainEventQueue,
> -                                event) < 0)
> -        virDomainEventFree(event);
> -
> -    if (driver->domainEventQueue->count == 1)
> -        virEventUpdateTimeout(driver->domainEventTimer, 0);
> +    virDomainEventStateQueue(driver->domainEventState, event);
>  }
>  
>  static virDrvOpenStatus testSecretOpen(virConnectPtr conn,

ACK

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]