]> xenbits.xensource.com Git - libvirt.git/commitdiff
Move domain events helpers into dedicated file
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 4 Nov 2008 23:33:57 +0000 (23:33 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 4 Nov 2008 23:33:57 +0000 (23:33 +0000)
ChangeLog
qemud/event.c
qemud/event.h
src/Makefile.am
src/domain_event.c [new file with mode: 0644]
src/domain_event.h [new file with mode: 0644]
src/internal.h
src/libvirt.c
src/qemu_conf.h
src/remote_internal.c

index a6f78688010f18b247bc39eb0db5fdb8d7b42bf2..3d384772f58f98a2156ef28efa922e6d23c1a03a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+Tue Nov  4 23:33:31 UTC 2008 Daniel P. Berrange <berrange@redhat.com>
+
+       Move domain events helpers into domain_events.c
+       * qemud/event.c: Remove __ prefix on poll event
+       convertors
+       * qemud/event.h: Add virEventHandleTypeToPollEvent and
+       virPollEventToEventHandleType declarations
+       * src/Makefile.am, src/domain_event.c, src/domain_event.h:
+       Add dedicated file for internal domain events helpers
+       * src/internal.h, src/libvirt.c: Remove domain events
+       helpers
+       * src/qemu_conf.h, src/remote_internal.c: Add includs
+       of domain_event.h
+
 Tue Nov  4 23:08:31 UTC 2008 Daniel P. Berrange <berrange@redhat.com>
 
        Move internal API declarations from generic internal.h file
index 1e2a5f584fb0ab3c17bc46aa7092fc72f07ff6e6..9b4dee71bf2920a92aacaf58908ae1c70d4b215f 100644 (file)
@@ -489,7 +489,7 @@ int virEventRunOnce(void) {
 }
 
 int
-__virEventHandleTypeToPollEvent(virEventHandleType events)
+virEventHandleTypeToPollEvent(int events)
 {
     int ret = 0;
     if(events & VIR_EVENT_HANDLE_READABLE)
@@ -503,10 +503,10 @@ __virEventHandleTypeToPollEvent(virEventHandleType events)
     return ret;
 }
 
-virEventHandleType
-__virPollEventToEventHandleType(int events)
+int
+virPollEventToEventHandleType(int events)
 {
-    virEventHandleType ret = 0;
+    int ret = 0;
     if(events & POLLIN)
         ret |= VIR_EVENT_HANDLE_READABLE;
     if(events & POLLOUT)
index 1729c339245d2e5be1725399c5e2ba7e8472e0b0..c359089b55e4584ae7140f821b4e3de6ab29a0f6 100644 (file)
@@ -105,4 +105,11 @@ int virEventRemoveTimeoutImpl(int timer);
  */
 int virEventRunOnce(void);
 
+int
+virEventHandleTypeToPollEvent(int events);
+int
+virPollEventToEventHandleType(int events);
+
+
+
 #endif /* __VIRTD_EVENT_H__ */
index f83fb358851b4a68c04b4dcf8c2ef6285ce9c908..2c61d922ba567428acbda984d0461d4de581f4a7 100644 (file)
@@ -150,6 +150,7 @@ libvirt_la_SOURCES =                                                \
                driver.h                                        \
                internal.h                                      \
                datatypes.c datatypes.h                         \
+               domain_event.c domain_event.h                   \
                libvirt.c libvirt_internal.h                    \
                $(GENERIC_LIB_SOURCES)                          \
                $(DOMAIN_CONF_SOURCES)                          \
diff --git a/src/domain_event.c b/src/domain_event.c
new file mode 100644 (file)
index 0000000..a84fa74
--- /dev/null
@@ -0,0 +1,229 @@
+/*
+ * domain_event.c: domain event queue processing helpers
+ *
+ * Copyright (C) 2008 VirtualIron
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ * Author: Ben Guthro
+ */
+
+#include <config.h>
+
+#include "domain_event.h"
+#include "datatypes.h"
+#include "memory.h"
+
+
+/**
+ * virDomainEventCallbackListFree:
+ * @list: event callback list head
+ *
+ * Free the memory in the domain event callback list
+ */
+void
+virDomainEventCallbackListFree(virDomainEventCallbackListPtr list)
+{
+    int i;
+    for (i=0; i<list->count; i++) {
+        VIR_FREE(list->callbacks[i]);
+    }
+    VIR_FREE(list);
+}
+/**
+ * virDomainEventCallbackListRemove:
+ * @conn: pointer to the connection
+ * @cbList: the list
+ * @callback: the callback to remove
+ *
+ * Internal function to remove a callback from a virDomainEventCallbackListPtr
+ */
+int
+virDomainEventCallbackListRemove(virConnectPtr conn,
+                                 virDomainEventCallbackListPtr cbList,
+                                 virConnectDomainEventCallback callback)
+{
+    int i;
+    for (i = 0 ; i < cbList->count ; i++) {
+        if(cbList->callbacks[i]->cb == callback &&
+           cbList->callbacks[i]->conn == conn) {
+            virUnrefConnect(cbList->callbacks[i]->conn);
+            VIR_FREE(cbList->callbacks[i]);
+
+            if (i < (cbList->count - 1))
+                memmove(cbList->callbacks + i,
+                        cbList->callbacks + i + 1,
+                        sizeof(*(cbList->callbacks)) *
+                                (cbList->count - (i + 1)));
+
+            if (VIR_REALLOC_N(cbList->callbacks,
+                              cbList->count - 1) < 0) {
+                ; /* Failure to reduce memory allocation isn't fatal */
+            }
+            cbList->count--;
+
+            return 0;
+        }
+    }
+    return -1;
+}
+
+/**
+ * virDomainEventCallbackListAdd:
+ * @conn: pointer to the connection
+ * @cbList: the list
+ * @callback: the callback to add
+ * @opaque: opaque data tio pass to callback
+ *
+ * Internal function to add a callback from a virDomainEventCallbackListPtr
+ */
+int
+virDomainEventCallbackListAdd(virConnectPtr conn,
+                              virDomainEventCallbackListPtr cbList,
+                              virConnectDomainEventCallback callback,
+                              void *opaque)
+{
+    virDomainEventCallbackPtr event;
+    int n;
+
+    /* Check incoming */
+    if ( !cbList ) {
+        return -1;
+    }
+
+    /* check if we already have this callback on our list */
+    for (n=0; n < cbList->count; n++) {
+        if(cbList->callbacks[n]->cb == callback &&
+           conn == cbList->callbacks[n]->conn) {
+            DEBUG0("WARNING: Callback already tracked");
+            return -1;
+        }
+    }
+    /* Allocate new event */
+    if (VIR_ALLOC(event) < 0) {
+        DEBUG0("Error allocating event");
+        return -1;
+    }
+    event->conn = conn;
+    event->cb = callback;
+    event->opaque = opaque;
+
+    /* Make space on list */
+    n = cbList->count;
+    if (VIR_REALLOC_N(cbList->callbacks, n + 1) < 0) {
+        DEBUG0("Error reallocating list");
+        VIR_FREE(event);
+        return -1;
+    }
+
+    event->conn->refs++;
+
+    cbList->callbacks[n] = event;
+    cbList->count++;
+    return 0;
+}
+
+/**
+ * virDomainEventQueueFree:
+ * @queue: pointer to the queue
+ *
+ * Free the memory in the queue. We process this like a list here
+ */
+void
+virDomainEventQueueFree(virDomainEventQueuePtr queue)
+{
+    int i;
+    for ( i=0 ; i<queue->count ; i++ ) {
+        VIR_FREE(queue->events[i]);
+    }
+    VIR_FREE(queue);
+}
+
+/**
+ * virDomainEventCallbackQueuePop:
+ * @evtQueue: the queue of events
+ *
+ * Internal function to pop off, and return the front of the queue
+ * NOTE: The caller is responsible for freeing the returned object
+ *
+ * Returns: virDomainEventPtr on success NULL on failure.
+ */
+virDomainEventPtr
+virDomainEventCallbackQueuePop(virDomainEventQueuePtr evtQueue)
+{
+    virDomainEventPtr ret;
+
+    if(!evtQueue || evtQueue->count == 0 )
+        return NULL;
+
+    ret = evtQueue->events[0];
+
+    memmove(evtQueue->events,
+            evtQueue->events + 1,
+            sizeof(*(evtQueue->events)) *
+                    (evtQueue->count - 1));
+
+    if (VIR_REALLOC_N(evtQueue->events,
+                        evtQueue->count - 1) < 0) {
+        ; /* Failure to reduce memory allocation isn't fatal */
+    }
+    evtQueue->count--;
+
+    return ret;
+}
+
+/**
+ * virDomainEventCallbackQueuePush:
+ * @evtQueue: the dom event queue
+ * @dom: the domain to add
+ * @event: the event to add
+ *
+ * Internal function to push onto the back of an virDomainEventQueue
+ *
+ * Returns: 0 on success, -1 on failure
+ */
+int
+virDomainEventCallbackQueuePush(virDomainEventQueuePtr evtQueue,
+                                virDomainPtr dom,
+                                virDomainEventType event)
+{
+    virDomainEventPtr domEvent;
+
+    /* Check incoming */
+    if ( !evtQueue ) {
+        return -1;
+    }
+
+    /* Allocate new event */
+    if (VIR_ALLOC(domEvent) < 0) {
+        DEBUG0("Error allocating event");
+        return -1;
+    }
+    domEvent->dom = dom;
+    domEvent->event = event;
+
+    /* Make space on queue */
+    if (VIR_REALLOC_N(evtQueue->events,
+                      evtQueue->count + 1) < 0) {
+        DEBUG0("Error reallocating queue");
+        VIR_FREE(domEvent);
+        return -1;
+    }
+
+    evtQueue->events[evtQueue->count] = domEvent;
+    evtQueue->count++;
+    return 0;
+}
+
diff --git a/src/domain_event.h b/src/domain_event.h
new file mode 100644 (file)
index 0000000..6b0eeb4
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * domain_event.h: domain event queue processing helpers
+ *
+ * Copyright (C) 2008 VirtualIron
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ * Author: Ben Guthro
+ */
+
+#include "internal.h"
+
+
+#ifndef __DOMAIN_EVENT_H__
+#define __DOMAIN_EVENT_H__
+
+struct _virDomainEventCallback {
+    virConnectPtr conn;
+    virConnectDomainEventCallback cb;
+    void *opaque;
+};
+typedef struct _virDomainEventCallback virDomainEventCallback;
+typedef virDomainEventCallback *virDomainEventCallbackPtr;
+
+struct _virDomainEventCallbackList {
+    unsigned int count;
+    virDomainEventCallbackPtr *callbacks;
+};
+typedef struct _virDomainEventCallbackList virDomainEventCallbackList;
+typedef virDomainEventCallbackList *virDomainEventCallbackListPtr;
+
+void virDomainEventCallbackListFree(virDomainEventCallbackListPtr list);
+
+int virDomainEventCallbackListAdd(virConnectPtr conn,
+                                  virDomainEventCallbackListPtr cbList,
+                                  virConnectDomainEventCallback callback,
+                                  void *opaque);
+
+int virDomainEventCallbackListRemove(virConnectPtr conn,
+                                     virDomainEventCallbackListPtr cbList,
+                                     virConnectDomainEventCallback callback);
+
+/**
+ * Dispatching domain events that come in while
+ * in a call / response rpc
+ */
+struct _virDomainEvent {
+    virDomainPtr dom;
+    virDomainEventType event;
+};
+typedef struct _virDomainEvent virDomainEvent;
+typedef virDomainEvent *virDomainEventPtr;
+
+struct _virDomainEventQueue {
+    unsigned int count;
+    virDomainEventPtr *events;
+};
+typedef struct _virDomainEventQueue virDomainEventQueue;
+typedef virDomainEventQueue *virDomainEventQueuePtr;
+
+int virDomainEventCallbackQueuePush(virDomainEventQueuePtr evtQueue,
+                                    virDomainPtr dom,
+                                    virDomainEventType event);
+
+virDomainEventPtr
+virDomainEventCallbackQueuePop(virDomainEventQueuePtr evtQueue);
+
+void virDomainEventQueueFree(virDomainEventQueuePtr queue);
+
+
+#endif
index 283459219efb9a84ed7ad9e1ebfc64536f729732..926594f48ce5bc37efcfbe88fee73fd6672f5e0b 100644 (file)
@@ -139,76 +139,4 @@ extern int debugFlag;
     fprintf(stderr, "Unimplemented block at %s:%d\n",                  \
             __FILE__, __LINE__);
 
-/**
- * Domain Event Notification
- */
-
-struct _virDomainEventCallback {
-    virConnectPtr conn;
-    virConnectDomainEventCallback cb;
-    void *opaque;
-};
-typedef struct _virDomainEventCallback virDomainEventCallback;
-typedef virDomainEventCallback *virDomainEventCallbackPtr;
-
-struct _virDomainEventCallbackList {
-    unsigned int count;
-    virDomainEventCallbackPtr *callbacks;
-};
-typedef struct _virDomainEventCallbackList virDomainEventCallbackList;
-typedef virDomainEventCallbackList *virDomainEventCallbackListPtr;
-
-void __virDomainEventCallbackListFree(virDomainEventCallbackListPtr list);
-#define virDomainEventCallbackListFree(x) __virDomainEventCallbackListFree(x)
-
-int  __virDomainEventCallbackListAdd(virConnectPtr conn,
-                                  virDomainEventCallbackListPtr cbList,
-                                  virConnectDomainEventCallback callback,
-                                  void *opaque);
-#define virDomainEventCallbackListAdd(a,b,c,d) \
-        __virDomainEventCallbackListAdd((a),(b),(c),(d))
-
-int  __virDomainEventCallbackListRemove(virConnectPtr conn,
-                                      virDomainEventCallbackListPtr cbList,
-                                      virConnectDomainEventCallback callback);
-#define virDomainEventCallbackListRemove(a,b,c) \
-        __virDomainEventCallbackListRemove((a),(b),(c))
-
-int __virEventHandleTypeToPollEvent(virEventHandleType events);
-#define virEventHandleTypeToPollEvent(x) __virEventHandleTypeToPollEvent(x)
-
-virEventHandleType __virPollEventToEventHandleType(int events);
-#define virPollEventToEventHandleType(x) __virPollEventToEventHandleType(x)
-
-/**
- * Dispatching domain events that come in while
- * in a call / response rpc
- */
-struct _virDomainEvent {
-    virDomainPtr dom;
-    virDomainEventType event;
-};
-typedef struct _virDomainEvent virDomainEvent;
-typedef virDomainEvent *virDomainEventPtr;
-
-struct _virDomainEventQueue {
-    unsigned int count;
-    virDomainEventPtr *events;
-};
-typedef struct _virDomainEventQueue virDomainEventQueue;
-typedef virDomainEventQueue *virDomainEventQueuePtr;
-
-int __virDomainEventCallbackQueuePush(virDomainEventQueuePtr evtQueue,
-                                      virDomainPtr dom,
-                                      virDomainEventType event);
-#define virDomainEventCallbackQueuePush(a,b,c) \
-        __virDomainEventCallbackQueuePush((a),(b),(c))
-
-virDomainEventPtr
-__virDomainEventCallbackQueuePop(virDomainEventQueuePtr evtQueue);
-#define virDomainEventCallbackQueuePop(x) __virDomainEventCallbackQueuePop(x)
-
-void __virDomainEventQueueFree(virDomainEventQueuePtr queue);
-#define virDomainEventQueueFree(x) __virDomainEventQueueFree(x)
-
 #endif                          /* __VIR_INTERNAL_H__ */
index 53ab061bf9639739985dfe73b03edc52169eb2c9..88a54de5c36817d2255a09849e1d19a627585d88 100644 (file)
@@ -5364,205 +5364,4 @@ virConnectDomainEventDeregister(virConnectPtr conn,
     return -1;
 }
 
-/**
- * __virDomainEventCallbackListFree:
- * @list: event callback list head
- *
- * Free the memory in the domain event callback list
- */
-void
-__virDomainEventCallbackListFree(virDomainEventCallbackListPtr list)
-{
-    int i;
-    for (i=0; i<list->count; i++) {
-        VIR_FREE(list->callbacks[i]);
-    }
-    VIR_FREE(list);
-}
-/**
- * __virDomainEventCallbackListRemove:
- * @conn: pointer to the connection
- * @cbList: the list
- * @callback: the callback to remove
- *
- * Internal function to remove a callback from a virDomainEventCallbackListPtr
- */
-int
-__virDomainEventCallbackListRemove(virConnectPtr conn,
-                                   virDomainEventCallbackListPtr cbList,
-                                   virConnectDomainEventCallback callback)
-{
-    int i;
-    for (i = 0 ; i < cbList->count ; i++) {
-        if(cbList->callbacks[i]->cb == callback &&
-           cbList->callbacks[i]->conn == conn) {
-            virUnrefConnect(cbList->callbacks[i]->conn);
-            VIR_FREE(cbList->callbacks[i]);
-
-            if (i < (cbList->count - 1))
-                memmove(cbList->callbacks + i,
-                        cbList->callbacks + i + 1,
-                        sizeof(*(cbList->callbacks)) *
-                                (cbList->count - (i + 1)));
-
-            if (VIR_REALLOC_N(cbList->callbacks,
-                              cbList->count - 1) < 0) {
-                ; /* Failure to reduce memory allocation isn't fatal */
-            }
-            cbList->count--;
-
-            return 0;
-        }
-    }
-    return -1;
-}
-
-/**
- * __virDomainEventCallbackListAdd:
- * @conn: pointer to the connection
- * @cbList: the list
- * @callback: the callback to add
- * @opaque: opaque data tio pass to callback
- *
- * Internal function to add a callback from a virDomainEventCallbackListPtr
- */
-int
-__virDomainEventCallbackListAdd(virConnectPtr conn,
-                                virDomainEventCallbackListPtr cbList,
-                                virConnectDomainEventCallback callback,
-                                void *opaque)
-{
-    virDomainEventCallbackPtr event;
-    int n;
-
-    /* Check incoming */
-    if ( !cbList ) {
-        return -1;
-    }
-
-    /* check if we already have this callback on our list */
-    for (n=0; n < cbList->count; n++) {
-        if(cbList->callbacks[n]->cb == callback &&
-           conn == cbList->callbacks[n]->conn) {
-            DEBUG0("WARNING: Callback already tracked");
-            return -1;
-        }
-    }
-    /* Allocate new event */
-    if (VIR_ALLOC(event) < 0) {
-        DEBUG0("Error allocating event");
-        return -1;
-    }
-    event->conn = conn;
-    event->cb = callback;
-    event->opaque = opaque;
-
-    /* Make space on list */
-    n = cbList->count;
-    if (VIR_REALLOC_N(cbList->callbacks, n + 1) < 0) {
-        DEBUG0("Error reallocating list");
-        VIR_FREE(event);
-        return -1;
-    }
-
-    event->conn->refs++;
-
-    cbList->callbacks[n] = event;
-    cbList->count++;
-    return 0;
-}
-
-/**
- * __virDomainEventQueueFree:
- * @queue: pointer to the queue
- *
- * Free the memory in the queue. We process this like a list here
- */
-void
-__virDomainEventQueueFree(virDomainEventQueuePtr queue)
-{
-    int i;
-    for ( i=0 ; i<queue->count ; i++ ) {
-        VIR_FREE(queue->events[i]);
-    }
-    VIR_FREE(queue);
-}
-
-/**
- * __virDomainEventCallbackQueuePop:
- * @evtQueue: the queue of events
- *
- * Internal function to pop off, and return the front of the queue
- * NOTE: The caller is responsible for freeing the returned object
- *
- * Returns: virDomainEventPtr on success NULL on failure.
- */
-virDomainEventPtr
-__virDomainEventCallbackQueuePop(virDomainEventQueuePtr evtQueue)
-{
-    virDomainEventPtr ret;
-
-    if(!evtQueue || evtQueue->count == 0 )
-        return NULL;
-
-    ret = evtQueue->events[0];
-
-    memmove(evtQueue->events,
-            evtQueue->events + 1,
-            sizeof(*(evtQueue->events)) *
-                    (evtQueue->count - 1));
-
-    if (VIR_REALLOC_N(evtQueue->events,
-                        evtQueue->count - 1) < 0) {
-        ; /* Failure to reduce memory allocation isn't fatal */
-    }
-    evtQueue->count--;
-
-    return ret;
-}
-
-/**
- * __virDomainEventCallbackQueuePush:
- * @evtQueue: the dom event queue
- * @dom: the domain to add
- * @event: the event to add
- *
- * Internal function to push onto the back of an virDomainEventQueue
- *
- * Returns: 0 on success, -1 on failure
- */
-int
-__virDomainEventCallbackQueuePush(virDomainEventQueuePtr evtQueue,
-                                  virDomainPtr dom,
-                                  virDomainEventType event)
-{
-    virDomainEventPtr domEvent;
-
-    /* Check incoming */
-    if ( !evtQueue ) {
-        return -1;
-    }
-
-    /* Allocate new event */
-    if (VIR_ALLOC(domEvent) < 0) {
-        DEBUG0("Error allocating event");
-        return -1;
-    }
-    domEvent->dom = dom;
-    domEvent->event = event;
-
-    /* Make space on queue */
-    if (VIR_REALLOC_N(evtQueue->events,
-                      evtQueue->count + 1) < 0) {
-        DEBUG0("Error reallocating queue");
-        VIR_FREE(domEvent);
-        return -1;
-    }
-
-    evtQueue->events[evtQueue->count] = domEvent;
-    evtQueue->count++;
-    return 0;
-}
-
-
 
index 055f37b0c9f325ac2469aa5617395feb34d31a15..90b9448c9c9b49cd13c14948afcc992a5c514ee5 100644 (file)
@@ -31,6 +31,7 @@
 #include "capabilities.h"
 #include "network_conf.h"
 #include "domain_conf.h"
+#include "domain_event.h"
 
 #define qemudDebug(fmt, ...) do {} while(0)
 
index 04fe46e7331279f617d27b3c56582a8d0891cb18..03462b47aa93f708a9c1aa48ab641f32c2f78d44 100644 (file)
@@ -75,6 +75,7 @@
 
 #include "virterror_internal.h"
 #include "datatypes.h"
+#include "domain_event.h"
 #include "driver.h"
 #include "buf.h"
 #include "qparams.h"