Re: [libvirt] Re: [PATCH 02/12] Domain Events - Internal API

2008-10-23 Thread Daniel P. Berrange
On Tue, Oct 21, 2008 at 03:11:36PM -0400, Ben Guthro wrote:
> [PATCH 02/12] Domain Events - Internal API
> This patch
>-Removes EventImpl from being a private function
>-Introduces the virDomainEventCallbackListPtr, and virDomainEventQueuePtr 
> objects

> diff --git a/src/event.c b/src/event.c
> index 49a9e61..1e2b234 100644
> --- a/src/event.c
> +++ b/src/event.c
> @@ -34,14 +34,15 @@ static virEventAddTimeoutFunc addTimeoutImpl = NULL;
>  static virEventUpdateTimeoutFunc updateTimeoutImpl = NULL;
>  static virEventRemoveTimeoutFunc removeTimeoutImpl = NULL;
>  
> -int virEventAddHandle(int fd, int events, virEventHandleCallback cb, void 
> *opaque) {
> +int virEventAddHandle(int fd, virEventHandleType events,
> +  virEventHandleCallback cb, void *opaque) {
>  if (!addHandleImpl)
>  return -1;
>  
>  return addHandleImpl(fd, events, cb, opaque);
>  }
>  
> -void virEventUpdateHandle(int fd, int events) {
> +void virEventUpdateHandle(int fd, virEventHandleType events) {
>  updateHandleImpl(fd, events);
>  }

This signature change isn't needed - it should still be just an int,
since we're using the enum as a bitset.

ACK, to the rest of the patch.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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


[libvirt] Re: [PATCH 02/12] Domain Events - Internal API

2008-10-21 Thread Ben Guthro
[PATCH 02/12] Domain Events - Internal API
This patch
   -Removes EventImpl from being a private function
   -Introduces the virDomainEventCallbackListPtr, and virDomainEventQueuePtr 
objects

diff --git a/proxy/Makefile.am b/proxy/Makefile.am
index 5902cab..75ba6b4 100644
--- a/proxy/Makefile.am
+++ b/proxy/Makefile.am
@@ -17,6 +17,7 @@ libvirt_proxy_SOURCES = libvirt_proxy.c @top_srcdir@/src/xend_internal.c \
 @top_srcdir@/src/memory.c \
 @top_srcdir@/src/domain_conf.c \
 @top_srcdir@/src/util.c \
+	@top_srcdir@/src/event.c \
 	@top_srcdir@/src/uuid.c
 libvirt_proxy_LDFLAGS = $(WARN_CFLAGS)
 libvirt_proxy_DEPENDENCIES =
diff --git a/src/event.c b/src/event.c
index 49a9e61..1e2b234 100644
--- a/src/event.c
+++ b/src/event.c
@@ -34,14 +34,15 @@ static virEventAddTimeoutFunc addTimeoutImpl = NULL;
 static virEventUpdateTimeoutFunc updateTimeoutImpl = NULL;
 static virEventRemoveTimeoutFunc removeTimeoutImpl = NULL;
 
-int virEventAddHandle(int fd, int events, virEventHandleCallback cb, void *opaque) {
+int virEventAddHandle(int fd, virEventHandleType events,
+  virEventHandleCallback cb, void *opaque) {
 if (!addHandleImpl)
 return -1;
 
 return addHandleImpl(fd, events, cb, opaque);
 }
 
-void virEventUpdateHandle(int fd, int events) {
+void virEventUpdateHandle(int fd, virEventHandleType events) {
 updateHandleImpl(fd, events);
 }
 
@@ -70,12 +71,22 @@ int virEventRemoveTimeout(int timer) {
 return removeTimeoutImpl(timer);
 }
 
-void __virEventRegisterImpl(virEventAddHandleFunc addHandle,
-virEventUpdateHandleFunc updateHandle,
-virEventRemoveHandleFunc removeHandle,
-virEventAddTimeoutFunc addTimeout,
-virEventUpdateTimeoutFunc updateTimeout,
-virEventRemoveTimeoutFunc removeTimeout) {
+/**
+ * virEventRegisterImpl:
+ * Register an EventImpl
+ * @addHandle: the callback to add fd handles
+ * @updateHandle: the callback to update fd handles
+ * @removeHandle: the callback to remove fd handles
+ * @addTimeout: the callback to add a timeout
+ * @updateTimeout: the callback to update a timeout
+ * @removeTimeout: the callback to remove a timeout
+ */
+void virEventRegisterImpl(virEventAddHandleFunc addHandle,
+  virEventUpdateHandleFunc updateHandle,
+  virEventRemoveHandleFunc removeHandle,
+  virEventAddTimeoutFunc addTimeout,
+  virEventUpdateTimeoutFunc updateTimeout,
+  virEventRemoveTimeoutFunc removeTimeout) {
 addHandleImpl = addHandle;
 updateHandleImpl = updateHandle;
 removeHandleImpl = removeHandle;
diff --git a/src/event.h b/src/event.h
index 758573c..5cd6310 100644
--- a/src/event.h
+++ b/src/event.h
@@ -23,38 +23,29 @@
 
 #ifndef __VIR_EVENT_H__
 #define __VIR_EVENT_H__
-
-
-/**
- * virEventHandleCallback: callback for receiving file handle events
- *
- * @fd: file handle on which the event occurred
- * @events: bitset of events from POLLnnn constants
- * @opaque: user data registered with handle
- */
-typedef void (*virEventHandleCallback)(int fd, int events, void *opaque);
-
+#include "internal.h"
 /**
  * virEventAddHandle: register a callback for monitoring file handle events
  *
  * @fd: file handle to monitor for events
- * @events: bitset of events to watch from POLLnnn constants
+ * @events: bitset of events to watch from virEventHandleType constants
  * @cb: callback to invoke when an event occurs
  * @opaque: user data to pass to callback
  *
  * returns -1 if the file handle cannot be registered, 0 upon success
  */
-int virEventAddHandle(int fd, int events, virEventHandleCallback cb, void *opaque);
+int virEventAddHandle(int fd, virEventHandleType events,
+  virEventHandleCallback cb, void *opaque);
 
 /**
  * virEventUpdateHandle: change event set for a monitored file handle
  *
  * @fd: file handle to monitor for events
- * @events: bitset of events to watch from POLLnnn constants
+ * @events: bitset of events to watch from virEventHandleType constants
  *
  * Will not fail if fd exists
  */
-void virEventUpdateHandle(int fd, int events);
+void virEventUpdateHandle(int fd, virEventHandleType events);
 
 /**
  * virEventRemoveHandle: unregister a callback from a file handle
@@ -66,14 +57,6 @@ void virEventUpdateHandle(int fd, int events);
 int virEventRemoveHandle(int fd);
 
 /**
- * virEventTimeoutCallback: callback for receiving timer events
- *
- * @timer: timer id emitting the event
- * @opaque: user data registered with handle
- */
-typedef void (*virEventTimeoutCallback)(int timer, void *opaque);
-
-/**
  * virEventAddTimeout: register a callback for a timer event
  *
  * @frequency: time between events in milliseconds
@@ -110,21 +93,4 @@ void virEventUpdateTimeout(int timer, int frequency);
  */
 int

[libvirt] Re: [PATCH 02/12] Domain Events - Internal API

2008-10-21 Thread Ben Guthro
[PATCH 02/12] Domain Events - Internal API
This patch
   -Removes EventImpl from being a private function
   -Introduces the virDomainEventCallbackListPtr, and virDomainEventQueuePtr 
objects
diff --git a/proxy/Makefile.am b/proxy/Makefile.am
index 5902cab..75ba6b4 100644
--- a/proxy/Makefile.am
+++ b/proxy/Makefile.am
@@ -17,6 +17,7 @@ libvirt_proxy_SOURCES = libvirt_proxy.c @top_srcdir@/src/xend_internal.c \
 @top_srcdir@/src/memory.c \
 @top_srcdir@/src/domain_conf.c \
 @top_srcdir@/src/util.c \
+	@top_srcdir@/src/event.c \
 	@top_srcdir@/src/uuid.c
 libvirt_proxy_LDFLAGS = $(WARN_CFLAGS)
 libvirt_proxy_DEPENDENCIES =
diff --git a/src/event.c b/src/event.c
index 49a9e61..1e2b234 100644
--- a/src/event.c
+++ b/src/event.c
@@ -34,14 +34,15 @@ static virEventAddTimeoutFunc addTimeoutImpl = NULL;
 static virEventUpdateTimeoutFunc updateTimeoutImpl = NULL;
 static virEventRemoveTimeoutFunc removeTimeoutImpl = NULL;
 
-int virEventAddHandle(int fd, int events, virEventHandleCallback cb, void *opaque) {
+int virEventAddHandle(int fd, virEventHandleType events,
+  virEventHandleCallback cb, void *opaque) {
 if (!addHandleImpl)
 return -1;
 
 return addHandleImpl(fd, events, cb, opaque);
 }
 
-void virEventUpdateHandle(int fd, int events) {
+void virEventUpdateHandle(int fd, virEventHandleType events) {
 updateHandleImpl(fd, events);
 }
 
@@ -70,12 +71,22 @@ int virEventRemoveTimeout(int timer) {
 return removeTimeoutImpl(timer);
 }
 
-void __virEventRegisterImpl(virEventAddHandleFunc addHandle,
-virEventUpdateHandleFunc updateHandle,
-virEventRemoveHandleFunc removeHandle,
-virEventAddTimeoutFunc addTimeout,
-virEventUpdateTimeoutFunc updateTimeout,
-virEventRemoveTimeoutFunc removeTimeout) {
+/**
+ * virEventRegisterImpl:
+ * Register an EventImpl
+ * @addHandle: the callback to add fd handles
+ * @updateHandle: the callback to update fd handles
+ * @removeHandle: the callback to remove fd handles
+ * @addTimeout: the callback to add a timeout
+ * @updateTimeout: the callback to update a timeout
+ * @removeTimeout: the callback to remove a timeout
+ */
+void virEventRegisterImpl(virEventAddHandleFunc addHandle,
+  virEventUpdateHandleFunc updateHandle,
+  virEventRemoveHandleFunc removeHandle,
+  virEventAddTimeoutFunc addTimeout,
+  virEventUpdateTimeoutFunc updateTimeout,
+  virEventRemoveTimeoutFunc removeTimeout) {
 addHandleImpl = addHandle;
 updateHandleImpl = updateHandle;
 removeHandleImpl = removeHandle;
diff --git a/src/event.h b/src/event.h
index 758573c..5cd6310 100644
--- a/src/event.h
+++ b/src/event.h
@@ -23,38 +23,29 @@
 
 #ifndef __VIR_EVENT_H__
 #define __VIR_EVENT_H__
-
-
-/**
- * virEventHandleCallback: callback for receiving file handle events
- *
- * @fd: file handle on which the event occurred
- * @events: bitset of events from POLLnnn constants
- * @opaque: user data registered with handle
- */
-typedef void (*virEventHandleCallback)(int fd, int events, void *opaque);
-
+#include "internal.h"
 /**
  * virEventAddHandle: register a callback for monitoring file handle events
  *
  * @fd: file handle to monitor for events
- * @events: bitset of events to watch from POLLnnn constants
+ * @events: bitset of events to watch from virEventHandleType constants
  * @cb: callback to invoke when an event occurs
  * @opaque: user data to pass to callback
  *
  * returns -1 if the file handle cannot be registered, 0 upon success
  */
-int virEventAddHandle(int fd, int events, virEventHandleCallback cb, void *opaque);
+int virEventAddHandle(int fd, virEventHandleType events,
+  virEventHandleCallback cb, void *opaque);
 
 /**
  * virEventUpdateHandle: change event set for a monitored file handle
  *
  * @fd: file handle to monitor for events
- * @events: bitset of events to watch from POLLnnn constants
+ * @events: bitset of events to watch from virEventHandleType constants
  *
  * Will not fail if fd exists
  */
-void virEventUpdateHandle(int fd, int events);
+void virEventUpdateHandle(int fd, virEventHandleType events);
 
 /**
  * virEventRemoveHandle: unregister a callback from a file handle
@@ -66,14 +57,6 @@ void virEventUpdateHandle(int fd, int events);
 int virEventRemoveHandle(int fd);
 
 /**
- * virEventTimeoutCallback: callback for receiving timer events
- *
- * @timer: timer id emitting the event
- * @opaque: user data registered with handle
- */
-typedef void (*virEventTimeoutCallback)(int timer, void *opaque);
-
-/**
  * virEventAddTimeout: register a callback for a timer event
  *
  * @frequency: time between events in milliseconds
@@ -110,21 +93,4 @@ void virEventUpdateTimeout(int timer, int frequency);
  */
 int 

Re: [libvirt] Re: [PATCH 02/12] Domain Events - Internal API

2008-10-19 Thread Daniel P. Berrange
On Fri, Oct 17, 2008 at 11:56:54AM -0400, Ben Guthro wrote:
> This patch
>-Removes EventImpl from being a private function
>-Introduces the virDomainEventCallbackListPtr, and virDomainEventQueuePtr 
> objects
> 
>  proxy/Makefile.am |1
>  src/event.c   |   12 +-
>  src/event.h   |   37 ---
>  src/internal.h|   63 
> ++
>  4 files changed, 71 insertions(+), 42 deletions(-)

This patch looks OK to me.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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


[libvirt] Re: [PATCH 02/12] Domain Events - Internal API

2008-10-17 Thread Ben Guthro
This patch
   -Removes EventImpl from being a private function
   -Introduces the virDomainEventCallbackListPtr, and virDomainEventQueuePtr 
objects

 proxy/Makefile.am |1
 src/event.c   |   12 +-
 src/event.h   |   37 ---
 src/internal.h|   63 ++
 4 files changed, 71 insertions(+), 42 deletions(-)


diff --git a/proxy/Makefile.am b/proxy/Makefile.am
index 5902cab..75ba6b4 100644
--- a/proxy/Makefile.am
+++ b/proxy/Makefile.am
@@ -17,6 +17,7 @@ libvirt_proxy_SOURCES = libvirt_proxy.c @top_srcdir@/src/xend_internal.c \
 @top_srcdir@/src/memory.c \
 @top_srcdir@/src/domain_conf.c \
 @top_srcdir@/src/util.c \
+	@top_srcdir@/src/event.c \
 	@top_srcdir@/src/uuid.c
 libvirt_proxy_LDFLAGS = $(WARN_CFLAGS)
 libvirt_proxy_DEPENDENCIES =
diff --git a/src/event.c b/src/event.c
index 49a9e61..7ce70ec 100644
--- a/src/event.c
+++ b/src/event.c
@@ -70,12 +70,12 @@ int virEventRemoveTimeout(int timer) {
 return removeTimeoutImpl(timer);
 }
 
-void __virEventRegisterImpl(virEventAddHandleFunc addHandle,
-virEventUpdateHandleFunc updateHandle,
-virEventRemoveHandleFunc removeHandle,
-virEventAddTimeoutFunc addTimeout,
-virEventUpdateTimeoutFunc updateTimeout,
-virEventRemoveTimeoutFunc removeTimeout) {
+void virEventRegisterImpl(virEventAddHandleFunc addHandle,
+  virEventUpdateHandleFunc updateHandle,
+  virEventRemoveHandleFunc removeHandle,
+  virEventAddTimeoutFunc addTimeout,
+  virEventUpdateTimeoutFunc updateTimeout,
+  virEventRemoveTimeoutFunc removeTimeout) {
 addHandleImpl = addHandle;
 updateHandleImpl = updateHandle;
 removeHandleImpl = removeHandle;
diff --git a/src/event.h b/src/event.h
index 758573c..fbff0e8 100644
--- a/src/event.h
+++ b/src/event.h
@@ -23,17 +23,7 @@
 
 #ifndef __VIR_EVENT_H__
 #define __VIR_EVENT_H__
-
-
-/**
- * virEventHandleCallback: callback for receiving file handle events
- *
- * @fd: file handle on which the event occurred
- * @events: bitset of events from POLLnnn constants
- * @opaque: user data registered with handle
- */
-typedef void (*virEventHandleCallback)(int fd, int events, void *opaque);
-
+#include "internal.h"
 /**
  * virEventAddHandle: register a callback for monitoring file handle events
  *
@@ -66,14 +56,6 @@ void virEventUpdateHandle(int fd, int events);
 int virEventRemoveHandle(int fd);
 
 /**
- * virEventTimeoutCallback: callback for receiving timer events
- *
- * @timer: timer id emitting the event
- * @opaque: user data registered with handle
- */
-typedef void (*virEventTimeoutCallback)(int timer, void *opaque);
-
-/**
  * virEventAddTimeout: register a callback for a timer event
  *
  * @frequency: time between events in milliseconds
@@ -110,21 +92,4 @@ void virEventUpdateTimeout(int timer, int frequency);
  */
 int virEventRemoveTimeout(int timer);
 
-typedef int (*virEventAddHandleFunc)(int, int, virEventHandleCallback, void *);
-typedef void (*virEventUpdateHandleFunc)(int, int);
-typedef int (*virEventRemoveHandleFunc)(int);
-
-typedef int (*virEventAddTimeoutFunc)(int, virEventTimeoutCallback, void *);
-typedef void (*virEventUpdateTimeoutFunc)(int, int);
-typedef int (*virEventRemoveTimeoutFunc)(int);
-
-void __virEventRegisterImpl(virEventAddHandleFunc addHandle,
-virEventUpdateHandleFunc updateHandle,
-virEventRemoveHandleFunc removeHandle,
-virEventAddTimeoutFunc addTimeout,
-virEventUpdateTimeoutFunc updateTimeout,
-virEventRemoveTimeoutFunc removeTimeout);
-
-#define virEventRegisterImpl(ah,rh,at,rt) __virEventRegisterImpl(ah,rh,at,rt)
-
 #endif /* __VIR_EVENT_H__ */
diff --git a/src/internal.h b/src/internal.h
index 2ae764d..e996eea 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -383,4 +383,67 @@ char *virStringListJoin(const virStringList *list, const char *pre,
 const char *post, const char *sep);
 void virStringListFree(virStringList *list);
 
+/**
+ * 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 v