[PATCHv2] outline of writing vbox driver

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

 



Define the vboxUniformedAPI struct to handle version conflict.
The previous version and introduction is in
https://www.redhat.com/archives/libvir-list/2014-June/msg00773.html

---
 Diff to v1:
  * fix some code style and spell problems
 src/vbox/vbox_tmpl.c |   81 ++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 58 insertions(+), 23 deletions(-)

diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 4ba9ad7..ac91ff5 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -826,6 +826,62 @@ static PRUnichar *PRUnicharFromInt(int n) {
 
 #endif /* !(VBOX_API_VERSION == 2002000) */
 
+/* Begin of vboxUniformedAPI */
+
+static void _pfnComInitialize(vboxGlobalData *data)
+{
+#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) */
+}
+
+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;
+}
+
+typedef struct {
+    /* vbox API version */
+    uint32_t uVersion;
+    /* vbox APIs */
+    void  (*pfnComInitialize)(vboxGlobalData *data);
+    int (*initializeFWatch)(vboxGlobalData *data);
+    /* vbox API features */
+    bool fWatchNeedInitialize;
+} vboxUniformedAPI;
+
+static vboxUniformedAPI vboxAPI = {
+    .uVersion = VBOX_API_VERSION,
+    .pfnComInitialize = _pfnComInitialize,
+    .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) */
+};
+
+static vboxUniformedAPI *pVBoxAPI = &vboxAPI;
+
+/* End of vboxUniformedAPI and Begin of common codes */
+
 static PRUnichar *
 vboxSocketFormatAddrUtf16(vboxGlobalData *data, virSocketAddrPtr addr)
 {
@@ -923,31 +979,10 @@ vboxInitialize(vboxGlobalData *data)
     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);
+    pVBoxAPI->pfnComInitialize(data);
 
-    if (data->vboxQueue == NULL) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("nsIEventQueue object is null"));
+    if (pVBoxAPI->fWatchNeedInitialize && pVBoxAPI->initializeFWatch(data) != 0)
         goto cleanup;
-    }
-
-# endif /* !(VBOX_API_VERSION == 2002000) */
-#endif /* !(VBOX_XPCOMC_VERSION == 0x00010000U) */
 
     if (data->vboxObj == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-- 
1.7.9.5

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