Re: [PATCH 3/5] implement vboxUniformedAPI in vbox_tmpl.c

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

 



On 23.06.2014 06:25, Taowei wrote:
Version specified codes for vboxUniformedAPI is implemented here,
almost the same as PATCHv2.
Common codes are moved to vbox_common.h and vbox_common.c.

---
  src/vbox/vbox_tmpl.c |  142 ++++++++++++++++++--------------------------------
  1 file changed, 52 insertions(+), 90 deletions(-)

See? we can even shrink the code size. Isn't that just nice?


diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 4ba9ad7..c2a83d1 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -87,9 +87,9 @@
  # error "Unsupport VBOX_API_VERSION"
  #endif

-/* Include this *last* or we'll get the wrong vbox_CAPI_*.h. */
+/* Include thses *last* or we'll get the wrong vbox_CAPI_*.h. */

s/thses/these/

  #include "vbox_glue.h"
-
+#include "vbox_common.h"

  #define VIR_FROM_THIS                   VIR_FROM_VBOX

@@ -203,42 +203,6 @@ if (strUtf16) {\
            (unsigned)(iid)->m3[7]);\
  }\

-typedef struct {
-    virMutex lock;
-    unsigned long version;
-
-    virCapsPtr caps;
-    virDomainXMLOptionPtr xmlopt;
-
-    IVirtualBox *vboxObj;
-    ISession *vboxSession;
-
-    /** Our version specific API table pointer. */
-    PCVBOXXPCOM pFuncs;
-
-#if VBOX_API_VERSION == 2002000
-
-} vboxGlobalData;
-
-#else /* !(VBOX_API_VERSION == 2002000) */
-
-    /* Async event handling */
-    virObjectEventStatePtr domainEvents;
-    int fdWatch;
-
-# if VBOX_API_VERSION <= 3002000
-    /* IVirtualBoxCallback is used in VirtualBox 3.x only */
-    IVirtualBoxCallback *vboxCallback;
-# endif /* VBOX_API_VERSION <= 3002000 */
-
-    nsIEventQueue  *vboxQueue;
-    int volatile vboxCallBackRefCount;
-
-    /* pointer back to the connection */
-    virConnectPtr conn;
-
-} vboxGlobalData;
-
  /* g_pVBoxGlobalData has to be global variable,
   * there is no other way to make the callbacks
   * work other then having g_pVBoxGlobalData as
@@ -249,6 +213,8 @@ typedef struct {
   * them that way
   */

+#if VBOX_API_VERSION > 2002000
+
  static vboxGlobalData *g_pVBoxGlobalData = NULL;

  #endif /* !(VBOX_API_VERSION == 2002000) */
@@ -826,6 +792,54 @@ static PRUnichar *PRUnicharFromInt(int n) {

  #endif /* !(VBOX_API_VERSION == 2002000) */

+/* Begin of vboxUniformedAPI */
+
+static int _pfnInitialize(vboxGlobalData *data)
+{
+    data->pFuncs = g_pfnGetFunctions(VBOX_XPCOMC_VERSION);
+    if (data->pFuncs == NULL)
+        return -1;
+#if VBOX_XPCOMC_VERSION == 0x00010000U
+    data->pFuncs->pfnComInitialize(&data->vboxObj, &data->vboxSession);
+#else  /* !(VBOX_XPCOMC_VERSION == 0x00010000U) */
+    data->pFuncs->pfnComInitialize(IVIRTUALBOX_IID_STR, &data->vboxObj, ISESSION_IID_STR, &data->vboxSession);
+#endif /* !(VBOX_XPCOMC_VERSION == 0x00010000U) */
+    return 0;
+}
+
+static int
+_initializeFWatch(vboxGlobalData *data ATTRIBUTE_UNUSED)
+{
+#if (VBOX_XPCOMC_VERSION == 0x00010000U) || (VBOX_API_VERSION == 2002000)
+    /* No event queue functionality in 2.2.* as of now */
+    VIR_WARN("There is no fWatch initical in current version");
+#else /* (VBOX_XPCOMC_VERSION != 0x00010000U && VBOX_API_VERSION != 2002000) */
+    /* Initialize the fWatch needed for Event Callbacks */
+    data->fdWatch = -1;
+    data->pFuncs->pfnGetEventQueue(&data->vboxQueue);
+    if (data->vboxQueue == NULL) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("nsIEventQueue object is null"));
+        return -1;
+    }
+#endif /* (VBOX_XPCOMC_VERSION != 0x00010000U && VBOX_API_VERSION != 2002000) */
+    return 0;
+}
+
+vboxUniformedAPI NAME(UniformedAPI) = {
+    .uVersion = VBOX_API_VERSION,
+    .pfnInitialize = _pfnInitialize,
+    .initializeFWatch = _initializeFWatch,
+#if (VBOX_XPCOMC_VERSION == 0x00010000U) || (VBOX_API_VERSION == 2002000)
+    /* No event queue functionality in 2.2.* as of now */
+    .fWatchNeedInitialize = 0,
+#else /* (VBOX_XPCOMC_VERSION != 0x00010000U && VBOX_API_VERSION != 2002000) */
+    .fWatchNeedInitialize = 1,
+#endif /* (VBOX_XPCOMC_VERSION != 0x00010000U && VBOX_API_VERSION != 2002000) */
+};
+
+/* End of vboxUniformedAPI and Begin of common codes */
+
  static PRUnichar *
  vboxSocketFormatAddrUtf16(vboxGlobalData *data, virSocketAddrPtr addr)
  {
@@ -915,58 +929,6 @@ static virCapsPtr vboxCapsInit(void)
      return NULL;
  }

-static int
-vboxInitialize(vboxGlobalData *data)
-{
-    data->pFuncs = g_pfnGetFunctions(VBOX_XPCOMC_VERSION);
-
-    if (data->pFuncs == NULL)
-        goto cleanup;
-
-#if VBOX_XPCOMC_VERSION == 0x00010000U
-    data->pFuncs->pfnComInitialize(&data->vboxObj, &data->vboxSession);
-#else  /* !(VBOX_XPCOMC_VERSION == 0x00010000U) */
-    data->pFuncs->pfnComInitialize(IVIRTUALBOX_IID_STR, &data->vboxObj,
-                               ISESSION_IID_STR, &data->vboxSession);
-
-# if VBOX_API_VERSION == 2002000
-
-    /* No event queue functionality in 2.2.* as of now */
-
-# else  /* !(VBOX_API_VERSION == 2002000) */
-
-    /* Initial the fWatch needed for Event Callbacks */
-    data->fdWatch = -1;
-
-    data->pFuncs->pfnGetEventQueue(&data->vboxQueue);
-
-    if (data->vboxQueue == NULL) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("nsIEventQueue object is null"));
-        goto cleanup;
-    }
-
-# endif /* !(VBOX_API_VERSION == 2002000) */
-#endif /* !(VBOX_XPCOMC_VERSION == 0x00010000U) */
-
-    if (data->vboxObj == NULL) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("IVirtualBox object is null"));
-        goto cleanup;
-    }
-
-    if (data->vboxSession == NULL) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("ISession object is null"));
-        goto cleanup;
-    }
-
-    return 0;
-
- cleanup:
-    return -1;
-}
-
  static int vboxExtractVersion(vboxGlobalData *data)
  {
      int ret = -1;


--
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]