]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
vbox: Rewrite vboxConnectGetMaxVcpus
authorTaowei <uaedante@gmail.com>
Mon, 11 Aug 2014 10:06:12 +0000 (18:06 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 15 Aug 2014 07:25:10 +0000 (09:25 +0200)
src/vbox/vbox_common.c
src/vbox/vbox_common.h
src/vbox/vbox_tmpl.c
src/vbox/vbox_uniformed_api.h

index 4a75b88a11fb6c68a13e7073492c91dc35800dcc..cb73f97dcdbf8ef5f4d8bb695f22554f0c749931 100644 (file)
@@ -439,3 +439,27 @@ int vboxConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
     return 1;
 }
+
+int
+vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type ATTRIBUTE_UNUSED)
+{
+    VBOX_OBJECT_CHECK(conn, int, -1);
+    PRUint32 maxCPUCount = 0;
+
+    /* VirtualBox Supports only hvm and thus the type passed to it
+     * has no meaning, setting it to ATTRIBUTE_UNUSED
+     */
+    ISystemProperties *systemProperties = NULL;
+
+    gVBoxAPI.UIVirtualBox.GetSystemProperties(data->vboxObj, &systemProperties);
+    if (!systemProperties)
+        goto cleanup;
+    gVBoxAPI.UISystemProperties.GetMaxGuestCPUCount(systemProperties, &maxCPUCount);
+
+    if (maxCPUCount > 0)
+        ret = maxCPUCount;
+
+ cleanup:
+    VBOX_RELEASE(systemProperties);
+    return ret;
+}
index 800e7ccf404d3911155b1bb712f4faa12e89bf7c..c4147a1519b37424c7a6bd12ea3ed7a82a79c25d 100644 (file)
@@ -167,5 +167,6 @@ typedef nsISupports ISession;
 typedef nsISupports IConsole;
 typedef nsISupports IProgress;
 typedef nsISupports IMachine;
+typedef nsISupports ISystemProperties;
 
 #endif /* VBOX_COMMON_H */
index af7180945b1e46162d1f3005497f46dfad1691ea..954bc5c577f0e5fbb41925a7cbdafdd650681a5c 100644 (file)
@@ -914,30 +914,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16,
     return result;
 }
 
-static int
-vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type ATTRIBUTE_UNUSED)
-{
-    VBOX_OBJECT_CHECK(conn, int, -1);
-    PRUint32 maxCPUCount = 0;
-
-    /* VirtualBox Supports only hvm and thus the type passed to it
-     * has no meaning, setting it to ATTRIBUTE_UNUSED
-     */
-    ISystemProperties *systemProperties = NULL;
-
-    data->vboxObj->vtbl->GetSystemProperties(data->vboxObj, &systemProperties);
-    if (systemProperties) {
-        systemProperties->vtbl->GetMaxGuestCPUCount(systemProperties, &maxCPUCount);
-        VBOX_RELEASE(systemProperties);
-    }
-
-    if (maxCPUCount > 0)
-        ret = maxCPUCount;
-
-    return ret;
-}
-
-
 static char *vboxConnectGetCapabilities(virConnectPtr conn) {
     VBOX_OBJECT_CHECK(conn, char *, NULL);
 
@@ -11346,6 +11322,12 @@ _virtualboxGetMachine(IVirtualBox *vboxObj, vboxIIDUnion *iidu, IMachine **machi
 
 #endif /* VBOX_API_VERSION >= 4000000 */
 
+static nsresult
+_virtualboxGetSystemProperties(IVirtualBox *vboxObj, ISystemProperties **systemProperties)
+{
+    return vboxObj->vtbl->GetSystemProperties(vboxObj, systemProperties);
+}
+
 #if VBOX_API_VERSION < 4000000
 
 static nsresult
@@ -11404,6 +11386,12 @@ _progressGetResultCode(IProgress *progress, resultCodeUnion *resultCode)
 #endif /* VBOX_API_VERSION != 2002000 */
 }
 
+static nsresult
+_systemPropertiesGetMaxGuestCPUCount(ISystemProperties *systemProperties, PRUint32 *maxCPUCount)
+{
+    return systemProperties->vtbl->GetMaxGuestCPUCount(systemProperties, maxCPUCount);
+}
+
 static vboxUniformedPFN _UPFN = {
     .Initialize = _pfnInitialize,
     .Uninitialize = _pfnUninitialize,
@@ -11431,6 +11419,7 @@ static vboxUniformednsISupports _nsUISupports = {
 static vboxUniformedIVirtualBox _UIVirtualBox = {
     .GetVersion = _virtualboxGetVersion,
     .GetMachine = _virtualboxGetMachine,
+    .GetSystemProperties = _virtualboxGetSystemProperties,
 };
 
 static vboxUniformedISession _UISession = {
@@ -11448,6 +11437,10 @@ static vboxUniformedIProgress _UIProgress = {
     .GetResultCode = _progressGetResultCode,
 };
 
+static vboxUniformedISystemProperties _UISystemProperties = {
+    .GetMaxGuestCPUCount = _systemPropertiesGetMaxGuestCPUCount,
+};
+
 void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
 {
     pVBoxAPI->APIVersion = VBOX_API_VERSION;
@@ -11461,6 +11454,7 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
     pVBoxAPI->UISession = _UISession;
     pVBoxAPI->UIConsole = _UIConsole;
     pVBoxAPI->UIProgress = _UIProgress;
+    pVBoxAPI->UISystemProperties = _UISystemProperties;
 
 #if VBOX_API_VERSION <= 2002000 || VBOX_API_VERSION >= 4000000
     pVBoxAPI->domainEventCallbacks = 0;
index 434b8d795f4034448551a4645aa974890e687edc..2cc0674fc68dab72afc6f7cb86e77b10cb5a2578 100644 (file)
@@ -171,6 +171,7 @@ typedef struct {
 typedef struct {
     nsresult (*GetVersion)(IVirtualBox *vboxObj, PRUnichar **versionUtf16);
     nsresult (*GetMachine)(IVirtualBox *vboxObj, vboxIIDUnion *iidu, IMachine **machine);
+    nsresult (*GetSystemProperties)(IVirtualBox *vboxObj, ISystemProperties **systemProperties);
 } vboxUniformedIVirtualBox;
 
 /* Functions for ISession */
@@ -191,6 +192,11 @@ typedef struct {
     nsresult (*GetResultCode)(IProgress *progress, resultCodeUnion *resultCode);
 } vboxUniformedIProgress;
 
+/* Functions for ISystemProperties */
+typedef struct {
+    nsresult (*GetMaxGuestCPUCount)(ISystemProperties *systemProperties, PRUint32 *maxCPUCount);
+} vboxUniformedISystemProperties;
+
 typedef struct {
     /* vbox API version */
     uint32_t APIVersion;
@@ -205,6 +211,7 @@ typedef struct {
     vboxUniformedISession UISession;
     vboxUniformedIConsole UIConsole;
     vboxUniformedIProgress UIProgress;
+    vboxUniformedISystemProperties UISystemProperties;
     /* vbox API features */
     bool domainEventCallbacks;
     bool hasStaticGlobalData;
@@ -225,6 +232,7 @@ char *vboxConnectGetHostname(virConnectPtr conn);
 int vboxConnectIsSecure(virConnectPtr conn);
 int vboxConnectIsEncrypted(virConnectPtr conn);
 int vboxConnectIsAlive(virConnectPtr conn);
+int vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);