Re: [PATCHv4 1/4]vbox: Add definitions for vboxUniformedAPI

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

 



On 26.06.2014 15:51, Taowei wrote:
Introducing a new file vbox_uniformed_api to define the
uniformed API and some other common types used by the API.
All symbols defined in this file are treated
the same in vbox_common.c as well as vbox_tmpl.c.
Other specified defines will be put in vbox_CAPI_v*.h
, vbox_tmpl.c(version specified) and vbox_common.h
(only used for common code).

---
  src/Makefile.am               |    3 +-
  src/vbox/vbox_uniformed_api.h |  168 +++++++++++++++++++++++++++++++++++++++++
  2 files changed, 170 insertions(+), 1 deletion(-)
  create mode 100644 src/vbox/vbox_uniformed_api.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 2b9ac61..c1e3f45 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -673,7 +673,8 @@ VBOX_DRIVER_SOURCES =						\
  	vbox/vbox_V4_2.c vbox/vbox_CAPI_v4_2.h			\
  	vbox/vbox_V4_2_20.c vbox/vbox_CAPI_v4_2_20.h			\
  	vbox/vbox_V4_3.c vbox/vbox_CAPI_v4_3.h			\
-	vbox/vbox_V4_3_4.c vbox/vbox_CAPI_v4_3_4.h
+	vbox/vbox_V4_3_4.c vbox/vbox_CAPI_v4_3_4.h              \
+	vbox/vbox_uniformed_api.h

  VBOX_DRIVER_EXTRA_DIST =					\
  		vbox/vbox_tmpl.c vbox/README			\
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
new file mode 100644
index 0000000..dfd9497
--- /dev/null
+++ b/src/vbox/vbox_uniformed_api.h
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2014, Taowei Luo (uaedante@xxxxxxxxx)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef VBOX_UNIFORMED_API_H
+# define VBOX_UNIFORMED_API_H
+
+# include "internal.h"
+
+/* This file may be used in three place. That is vbox_tmpl.c,
+ * vbox_common.c and vbox_driver.c. The vboxUniformedAPI and some
+ * types used for vboxUniformedAPI is defined here.
+ *
+ * The vbox_tmpl.c is the only place where the driver knows the inside
+ * architecture of those vbox structs(vboxObj, vboxSession,
+ * pFuncs, vboxCallback and vboxQueue). The file should be included
+ * after the currect vbox_CAPI_v*.h, then we can use the vbox structs
+ * in vboxGlobalData. The vbox_tmpl.c should implement functions
+ * defined in vboxUniformedAPI.
+ *
+ * In vbox_driver.c, it is used to define the struct vboxUniformedAPI.
+ * The vbox_driver.c collects vboxUniformedAPI for all versions.
+ * Then vboxRegister calls the vboxRegisterUniformedAPI to register.
+ * Note: In vbox_driver.c, the vbox structs in vboxGlobalData is
+ * defined by vbox_CAPI_v2.2.h.
+ *
+ * The vbox_common.c, it is used to generate common codes for all vbox
+ * versions. Bacause the same member varible's offset in a vbox struct
+ * may change between different vbox versions. The vbox_common.c
+ * shouldn't directly use struct's member varibles defined in
+ * vbox_CAPI_v*.h. To make things safety, we include the
+ * vbox_common.h in vbox_common.c. In this case, we treat structs
+ * defined by vbox as a void*. The common codes don't concern about
+ * the inside of this structs(actually, we can't, in the common level).
+ * With the help of vboxUniformed API, we call VirtualBox's API and
+ * implement the vbox driver in a high level.
+ *
+ * In conclusion:
+ *  * In vbox_tmpl.c, this file is included after vbox_CAPI_v*.h
+ *  * In vbox_driver.c, this file is included after vbox_glue.h
+ *  * In vbox_common.c, this file is included after vbox_common.h
+ *
+ */
+
+/* Extracted define from vbox_tmpl.c */
+
+# ifdef WIN32
+struct _vboxIID_v2_x_WIN32 {
+    /* IID is represented by a GUID value. */
+    GUID value;
+};
+# endif /* !WIN32 */
+
+struct _vboxIID_v2_x {
+    /* IID is represented by a pointer to a nsID. */
+    nsID *value;
+
+    /* backing is used in cases where we need to create or copy an IID.
+     * We cannot allocate memory that can be freed by ComUnallocMem.
+     * Therefore, we use this stack allocated nsID instead. */
+    nsID backing;
+};
+
+struct _vboxIID_v3_x {
+    /* IID is represented by a UTF-16 encoded UUID in string form. */
+    PRUnichar *value;
+
+    /* owner indicates if we own the value and need to free it. */
+    bool owner;
+};
+
+typedef union {
+# ifdef WIN32
+    struct _vboxIID_v2_x_WIN32 vboxIID_v2_x_WIN32;
+# endif /* !WIN32 */
+    struct _vboxIID_v2_x vboxIID_v2_x;
+    struct _vboxIID_v3_x vboxIID_v3_x;
+} vboxIIDUnion;
+
+typedef union {
+    nsresult uResultCode;
+    PRInt32 resultCode;
+} resultCodeUnion;
+
+typedef struct {
+    virMutex lock;
+    unsigned long version;
+
+    virCapsPtr caps;
+    virDomainXMLOptionPtr xmlopt;
+
+    IVirtualBox *vboxObj;
+    ISession *vboxSession;
+
+    /** Our version specific API table pointer. */
+    PCVBOXXPCOM pFuncs;
+
+    /* The next is used when VBOX_API_VERSION > 2002000 */
+    /* Async event handling */
+    virObjectEventStatePtr domainEvents;
+    int fdWatch;
+# if defined(VBOX_API_VERSION) && VBOX_API_VERSION > 2002000 && VBOX_API_VERSION <= 3002000
+    /* IVirtualBoxCallback is used in VirtualBox 3.x only */
+    IVirtualBoxCallback *vboxCallback;
+# else /* VBOX_API_VERSION == 2002000 || VBOX_API_VERSION > 3002000 or VBOX_API_VERSION undefined */
+    void *vboxCallback;
+# endif /* VBOX_API_VERSION == 2002000 || VBOX_API_VERSION > 3002000 or VBOX_API_VERSION undefined */
+
+
+# if defined(VBOX_API_VERSION) && VBOX_API_VERSION > 2002000
+    nsIEventQueue  *vboxQueue;
+# else /* VBOX_API_VERSION == 2002000 or undefined */
+    void *vboxQueue;
+# endif /* VBOX_API_VERSION == 2002000 or undefined */
+    int volatile vboxCallBackRefCount;
+
+    /* pointer back to the connection */
+    virConnectPtr conn;
+
+} vboxGlobalData;
+
+/* vboxUniformedAPI gives vbox_common.c a uniformed layer to see
+ * vbox API.
+ */
+typedef struct {
+    /* vbox API version */
+    uint32_t APIVersion;
+    uint32_t XPCOMCVersion;
+    /* vbox APIs */
+    int (*pfnInitialize)(vboxGlobalData *data);
+    int (*initializeFWatch)(vboxGlobalData *data);
+    void (*initializeVboxIID)(vboxIIDUnion *iidu);
+    void (*vboxIIDUnalloc)(vboxGlobalData *data, vboxIIDUnion *iidu);
+    void (*vboxIIDFromUUID)(vboxGlobalData *data, vboxIIDUnion *iidu, const unsigned char *uuid);
+    void (*DEBUGIID)(const char *msg, vboxIIDUnion *iidu);
+    nsresult (*objectGetMachine)(vboxGlobalData *data, vboxIIDUnion *iidu, IMachine **machine);
+    nsresult (*sessionOpenExisting)(vboxGlobalData *data, vboxIIDUnion *iidu, IMachine *machine);
+    nsresult (*sessionGetConsole)(ISession *session, IConsole **console);
+    nsresult (*sessionClose)(ISession *session);
+    nsresult (*consoleSaveState)(IConsole *console, IProgress **progress);
+    nsresult (*progressWaitForCompletion)(IProgress *progress, PRInt32 timeout);
+    nsresult (*progressGetResultCode)(IProgress *progress, resultCodeUnion *resultCode);
+    nsresult (*nsisupportsRelease)(void *Ihandle);
+    /* vbox API features */
+    bool fWatchNeedInitialize;
+    bool getMachineForSession;
+} vboxUniformedAPI;
+
+int vboxInitialize(vboxGlobalData *data);
+int vboxDomainSave(virDomainPtr dom, const char *path);

The vboxDomainSave() should be introduced in the 3/4.

+
+void vboxRegisterUniformedAPI(vboxUniformedAPI *vboxAPI);
+
+#endif /* VBOX_UNIFORMED_API_H */


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