提交 7d5b9419 编写于 作者: T Taowei Luo 提交者: Michal Privoznik

vbox: move common codes to vbox_common.h

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.
上级 a6b1cde3
......@@ -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;
}
......@@ -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 */
......@@ -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;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册