[PATCH 2/5] a sample of vbox_common function : vboxInitialize

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

 



This is a example of how common codes work.
The file vbox_commondef.h tells the common codes to treat vbox structs
defined in vbox_common.h as a void* type.

---
 src/vbox/vbox_common.c    |   89 +++++++++++++++++++++++++++++++++++++++++++++
 src/vbox/vbox_commondef.h |   32 ++++++++++++++++
 2 files changed, 121 insertions(+)
 create mode 100644 src/vbox/vbox_common.c
 create mode 100644 src/vbox/vbox_commondef.h

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
new file mode 100644
index 0000000..1bf4292
--- /dev/null
+++ b/src/vbox/vbox_common.c
@@ -0,0 +1,89 @@
+/*
+ * 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/>.
+ */
+
+#include <config.h>
+
+#include <unistd.h>
+
+#include "internal.h"
+#include "datatypes.h"
+#include "domain_conf.h"
+#include "network_conf.h"
+#include "virerror.h"
+#include "domain_event.h"
+#include "storage_conf.h"
+#include "virstoragefile.h"
+#include "viruuid.h"
+#include "viralloc.h"
+#include "nodeinfo.h"
+#include "virlog.h"
+#include "vbox_driver.h"
+#include "configmake.h"
+#include "virfile.h"
+#include "fdstream.h"
+#include "viruri.h"
+#include "virstring.h"
+#include "virtime.h"
+#include "virutil.h"
+
+#include "vbox_commondef.h"
+#include "vbox_common.h"
+
+/* Common codes for vbox driver. With the define of vbox_commondef.h,
+ * it treats vbox structs as a void*. Though vboxUniformedAPI
+ * it call vbox functions. This file is a high level implement about
+ * the vbox driver.
+ */
+
+#define VIR_FROM_THIS VIR_FROM_VBOX
+
+VIR_LOG_INIT("vbox.vbox_common");
+
+static vboxUniformedAPI *pVBoxAPI;
+
+void vboxRegisterUniformedAPI(vboxUniformedAPI *vboxAPI)
+{
+    VIR_DEBUG("VirtualBox Uniformed API has been registered");
+    pVBoxAPI = vboxAPI;
+}
+
+int vboxInitialize(vboxGlobalData *data)
+{
+    if (pVBoxAPI->pfnInitialize(data) != 0)
+        goto cleanup;
+
+    if (pVBoxAPI->fWatchNeedInitialize && pVBoxAPI->initializeFWatch(data) != 0)
+        goto cleanup;
+
+    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;
+}
diff --git a/src/vbox/vbox_commondef.h b/src/vbox/vbox_commondef.h
new file mode 100644
index 0000000..e54e729
--- /dev/null
+++ b/src/vbox/vbox_commondef.h
@@ -0,0 +1,32 @@
+/*
+ * 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/>.
+ */
+
+#include "internal.h"
+
+/* This is a pesudo-define of some types in vboxGlobalData
+ * It is ONLY used to generate vboxGlobalData for
+ * vbox_common.h. It can't be included with files such as
+ * vbox_CAPI_v*.h, which may cause type conflicts.
+ * You can see the more information in vbox_common.h
+ */
+
+typedef void IVirtualBox;
+typedef void ISession;
+typedef void const *PCVBOXXPCOM;
+typedef void IVirtualBoxCallback;
+typedef void nsIEventQueue;
-- 
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]