[PATCH 03/19] vbox: move common codes to vbox_common.h

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

 



There are lots of macro declarations in vbox_common.c,
vbox_network.c, and the coming vbox_storage.c which simply the API
calling. Since they are totally the same. We shouldn't keep three
copies of that, so they are moved to vbox_common.h.

Note: The macros are quite different from those in vbox_tmpl.c,
      because they are using different API.
---
 src/vbox/vbox_common.c  |   91 +++-------------------------------------------
 src/vbox/vbox_common.h  |   92 +++++++++++++++++++++++++++++++++++++++++++++++
 src/vbox/vbox_network.c |   30 +++-------------
 3 files changed, 100 insertions(+), 113 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 46f6968..22f3198 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -52,67 +52,6 @@
 
 VIR_LOG_INIT("vbox.vbox_common");
 
-#define RC_SUCCEEDED(rc) NS_SUCCEEDED(rc.resultCode)
-#define RC_FAILED(rc) NS_FAILED(rc.resultCode)
-
-#define VBOX_UTF16_FREE(arg)                                            \
-    do {                                                                \
-        if (arg) {                                                      \
-            gVBoxAPI.UPFN.Utf16Free(data->pFuncs, arg);                 \
-            (arg) = NULL;                                               \
-        }                                                               \
-    } while (0)
-
-#define VBOX_UTF8_FREE(arg)                                             \
-    do {                                                                \
-        if (arg) {                                                      \
-            gVBoxAPI.UPFN.Utf8Free(data->pFuncs, arg);                  \
-            (arg) = NULL;                                               \
-        }                                                               \
-    } while (0)
-
-#define VBOX_COM_UNALLOC_MEM(arg)                                       \
-    do {                                                                \
-        if (arg) {                                                      \
-            gVBoxAPI.UPFN.ComUnallocMem(data->pFuncs, arg);             \
-            (arg) = NULL;                                               \
-        }                                                               \
-    } while (0)
-
-#define VBOX_UTF16_TO_UTF8(arg1, arg2)  gVBoxAPI.UPFN.Utf16ToUtf8(data->pFuncs, arg1, arg2)
-#define VBOX_UTF8_TO_UTF16(arg1, arg2)  gVBoxAPI.UPFN.Utf8ToUtf16(data->pFuncs, arg1, arg2)
-
-#define VBOX_ADDREF(arg)                gVBoxAPI.nsUISupports.AddRef((void *)(arg))
-
-#define VBOX_RELEASE(arg)                                                     \
-    do {                                                                      \
-        if (arg) {                                                            \
-            gVBoxAPI.nsUISupports.Release((void *)arg);                        \
-            (arg) = NULL;                                                     \
-        }                                                                     \
-    } while (0)
-
-#define VBOX_MEDIUM_RELEASE(arg)                                              \
-    do {                                                                      \
-        if (arg) {                                                            \
-            gVBoxAPI.UIMedium.Release(arg);                                   \
-            (arg) = NULL;                                                     \
-        }                                                                     \
-    } while (0)
-
-#define vboxIIDUnalloc(iid)                     gVBoxAPI.UIID.vboxIIDUnalloc(data, iid)
-#define vboxIIDToUUID(iid, uuid)                gVBoxAPI.UIID.vboxIIDToUUID(data, iid, uuid)
-#define vboxIIDFromUUID(iid, uuid)              gVBoxAPI.UIID.vboxIIDFromUUID(data, iid, uuid)
-#define vboxIIDIsEqual(iid1, iid2)              gVBoxAPI.UIID.vboxIIDIsEqual(data, iid1, iid2)
-#define DEBUGIID(msg, iid)                      gVBoxAPI.UIID.DEBUGIID(msg, iid)
-#define vboxIIDFromArrayItem(iid, array, idx) \
-    gVBoxAPI.UIID.vboxIIDFromArrayItem(data, iid, array, idx)
-
-#define VBOX_IID_INITIALIZE(iid)                gVBoxAPI.UIID.vboxIIDInitialize(iid)
-
-#define ARRAY_GET_MACHINES \
-    (gVBoxAPI.UArray.handleGetMachines(data->vboxObj))
-
 /* global vbox API, used for all common codes. */
 static vboxUniformedAPI gVBoxAPI;
 
@@ -7743,32 +7682,10 @@ static void updateDriver(void)
 
 virHypervisorDriverPtr vboxGetHypervisorDriver(uint32_t uVersion)
 {
-    /* Install gVBoxAPI according to the vbox API version.
-     * Return -1 for unsupported version.
-     */
-    if (uVersion >= 2001052 && uVersion < 2002051) {
-        vbox22InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 2002051 && uVersion < 3000051) {
-        vbox30InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 3000051 && uVersion < 3001051) {
-        vbox31InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 3001051 && uVersion < 3002051) {
-        vbox32InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 3002051 && uVersion < 4000051) {
-        vbox40InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 4000051 && uVersion < 4001051) {
-        vbox41InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 4001051 && uVersion < 4002020) {
-        vbox42InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 4002020 && uVersion < 4002051) {
-        vbox42_20InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 4002051 && uVersion < 4003004) {
-        vbox43InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 4003004 && uVersion < 4003051) {
-        vbox43_4InstallUniformedAPI(&gVBoxAPI);
-    } else {
-        return NULL;
-    }
+    /* Install gVBoxAPI according to the vbox API version. */
+    int result = 0;
+    installUniformedAPI(gVBoxAPI, result);
+    if (result < 0) return NULL;
     updateDriver();
     return &vboxCommonDriver;
 }
diff --git a/src/vbox/vbox_common.h b/src/vbox/vbox_common.h
index 52d47b2..98317b2 100644
--- a/src/vbox/vbox_common.h
+++ b/src/vbox/vbox_common.h
@@ -320,4 +320,96 @@ typedef nsISupports IHost;
 typedef nsISupports IHostNetworkInterface;
 typedef nsISupports IDHCPServer;
 
+/* Macros for all vbox drivers. */
+
+# define RC_SUCCEEDED(rc) NS_SUCCEEDED(rc.resultCode)
+# define RC_FAILED(rc) NS_FAILED(rc.resultCode)
+
+# define VBOX_UTF16_FREE(arg)                                            \
+    do {                                                                \
+        if (arg) {                                                      \
+            gVBoxAPI.UPFN.Utf16Free(data->pFuncs, arg);                 \
+            (arg) = NULL;                                               \
+        }                                                               \
+    } while (0)
+
+# define VBOX_UTF8_FREE(arg)                                             \
+    do {                                                                \
+        if (arg) {                                                      \
+            gVBoxAPI.UPFN.Utf8Free(data->pFuncs, arg);                  \
+            (arg) = NULL;                                               \
+        }                                                               \
+    } while (0)
+
+# define VBOX_COM_UNALLOC_MEM(arg)                                       \
+    do {                                                                \
+        if (arg) {                                                      \
+            gVBoxAPI.UPFN.ComUnallocMem(data->pFuncs, arg);             \
+            (arg) = NULL;                                               \
+        }                                                               \
+    } while (0)
+
+# define VBOX_UTF16_TO_UTF8(arg1, arg2)  gVBoxAPI.UPFN.Utf16ToUtf8(data->pFuncs, arg1, arg2)
+# define VBOX_UTF8_TO_UTF16(arg1, arg2)  gVBoxAPI.UPFN.Utf8ToUtf16(data->pFuncs, arg1, arg2)
+
+# define VBOX_ADDREF(arg)                gVBoxAPI.nsUISupports.AddRef((void *)(arg))
+
+# define VBOX_RELEASE(arg)                                                     \
+    do {                                                                      \
+        if (arg) {                                                            \
+            gVBoxAPI.nsUISupports.Release((void *)arg);                        \
+            (arg) = NULL;                                                     \
+        }                                                                     \
+    } while (0)
+
+# define VBOX_MEDIUM_RELEASE(arg)                                              \
+    do {                                                                      \
+        if (arg) {                                                            \
+            gVBoxAPI.UIMedium.Release(arg);                                   \
+            (arg) = NULL;                                                     \
+        }                                                                     \
+    } while (0)
+
+# define vboxIIDUnalloc(iid)                     gVBoxAPI.UIID.vboxIIDUnalloc(data, iid)
+# define vboxIIDToUUID(iid, uuid)                gVBoxAPI.UIID.vboxIIDToUUID(data, iid, uuid)
+# define vboxIIDFromUUID(iid, uuid)              gVBoxAPI.UIID.vboxIIDFromUUID(data, iid, uuid)
+# define vboxIIDIsEqual(iid1, iid2)              gVBoxAPI.UIID.vboxIIDIsEqual(data, iid1, iid2)
+# define DEBUGIID(msg, iid)                      gVBoxAPI.UIID.DEBUGIID(msg, iid)
+# define vboxIIDFromArrayItem(iid, array, idx) \
+    gVBoxAPI.UIID.vboxIIDFromArrayItem(data, iid, array, idx)
+
+# define VBOX_IID_INITIALIZE(iid)                gVBoxAPI.UIID.vboxIIDInitialize(iid)
+
+# define ARRAY_GET_MACHINES \
+    (gVBoxAPI.UArray.handleGetMachines(data->vboxObj))
+
+/* Set result to -1 in case of failure. */
+# define installUniformedAPI(gVBoxAPI, result)                          \
+    do {                                                                \
+        result = 0;                                                     \
+        if (uVersion >= 2001052 && uVersion < 2002051) {                \
+            vbox22InstallUniformedAPI(&gVBoxAPI);                       \
+        } else if (uVersion >= 2002051 && uVersion < 3000051) {         \
+            vbox30InstallUniformedAPI(&gVBoxAPI);                       \
+        } else if (uVersion >= 3000051 && uVersion < 3001051) {         \
+            vbox31InstallUniformedAPI(&gVBoxAPI);                       \
+        } else if (uVersion >= 3001051 && uVersion < 3002051) {         \
+            vbox32InstallUniformedAPI(&gVBoxAPI);                       \
+        } else if (uVersion >= 3002051 && uVersion < 4000051) {         \
+            vbox40InstallUniformedAPI(&gVBoxAPI);                       \
+        } else if (uVersion >= 4000051 && uVersion < 4001051) {         \
+            vbox41InstallUniformedAPI(&gVBoxAPI);                       \
+        } else if (uVersion >= 4001051 && uVersion < 4002020) {         \
+            vbox42InstallUniformedAPI(&gVBoxAPI);                       \
+        } else if (uVersion >= 4002020 && uVersion < 4002051) {         \
+            vbox42_20InstallUniformedAPI(&gVBoxAPI);                    \
+        } else if (uVersion >= 4002051 && uVersion < 4003004) {         \
+            vbox43InstallUniformedAPI(&gVBoxAPI);                       \
+        } else if (uVersion >= 4003004 && uVersion < 4003051) {         \
+            vbox43_4InstallUniformedAPI(&gVBoxAPI);                     \
+        } else {                                                        \
+            result = -1;                                                \
+        }                                                               \
+    } while(0)
+
 #endif /* VBOX_COMMON_H */
diff --git a/src/vbox/vbox_network.c b/src/vbox/vbox_network.c
index fa2a3ce..792e547 100644
--- a/src/vbox/vbox_network.c
+++ b/src/vbox/vbox_network.c
@@ -1022,31 +1022,9 @@ virNetworkDriver vboxNetworkDriver = {
 
 virNetworkDriverPtr vboxGetNetworkDriver(uint32_t uVersion)
 {
-    /* Install gVBoxAPI according to the vbox API version.
-     * Return -1 for unsupported version.
-     */
-    if (uVersion >= 2001052 && uVersion < 2002051) {
-        vbox22InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 2002051 && uVersion < 3000051) {
-        vbox30InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 3000051 && uVersion < 3001051) {
-        vbox31InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 3001051 && uVersion < 3002051) {
-        vbox32InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 3002051 && uVersion < 4000051) {
-        vbox40InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 4000051 && uVersion < 4001051) {
-        vbox41InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 4001051 && uVersion < 4002020) {
-        vbox42InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 4002020 && uVersion < 4002051) {
-        vbox42_20InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 4002051 && uVersion < 4003004) {
-        vbox43InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 4003004 && uVersion < 4003051) {
-        vbox43_4InstallUniformedAPI(&gVBoxAPI);
-    } else {
-        return NULL;
-    }
+    /* Install gVBoxAPI according to the vbox API version. */
+    int result = 0;
+    installUniformedAPI(gVBoxAPI, result);
+    if (result < 0) return NULL;
     return &vboxNetworkDriver;
 }
-- 
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]