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

[libvirt] [PATCH 2/3] Support for vrdp/sdl/gui while dumping xml




Hi All,


I have added support for vrdp/sdl/gui modes for VirtualBox driver in libvirt. Tha patch's are as below:


[PATCH 1/3]: contains support for vrdp/sdl/gui while defining a machine.
[PATCH 2/3]: contains support for vrdp/sdl/gui while dumping xml
[PATCH 3/3]: contains support for vrdp/sdl/gui while starting the machine


Regards,
Pritesh

diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 87db6ab..223009a 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1365,9 +1365,7 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
                 PRBool PAEEnabled                   = PR_FALSE;
                 PRBool ACPIEnabled                  = PR_FALSE;
                 PRBool IOAPICEnabled                = PR_FALSE;
-#if 0
                 PRBool VRDPEnabled                  = PR_FALSE;
-#endif
                 PRInt32 hddNum                      = 0;
                 PRUint32 CPUCount                   = 0;
                 PRUint32 memorySize                 = 0;
@@ -1386,9 +1384,7 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
                 IHardDisk *hardDiskPS               = NULL;
                 IHardDisk *hardDiskSS               = NULL;
                 PRUnichar *hddBusUtf16              = NULL;
-#if 0
                 IVRDPServer *VRDPServer             = NULL;
-#endif
                 IFloppyDrive *floppyDrive           = NULL;
                 IAudioAdapter *audioAdapter         = NULL;
                 IUSBController *USBController       = NULL;
@@ -1481,83 +1477,142 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
                  * so locatime is always true here */
                 def->localtime = 1;
 
-#if 0
-                machine->vtbl->GetVRDPServer(machine, &VRDPServer);
-                if (VRDPServer) {
-                    VRDPServer->vtbl->GetEnabled(VRDPServer, &VRDPEnabled);
-                    if (VRDPEnabled) {
-                        if (VIR_ALLOC(def->graphics) >= 0) {
-                            PRUint32 VRDPport            = 0;
-                            PRUnichar *netAddressUtf16   = NULL;
-                            PRUnichar *sessionTypeUtf16  = NULL;
-                            char *sessionTypeUtf8        = NULL;
-                            char *netAddressUtf8         = NULL;
-                            PRUint32 authType            = VRDPAuthType_Null;
-                            PRBool allowMultiConnection  = PR_FALSE;
-                            PRBool reuseSingleConnection = PR_FALSE;
-
-                            def->graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_RDP;
-
-                            VRDPServer->vtbl->GetPort(VRDPServer, &VRDPport);
-                            if (VRDPport) {
-                                def->graphics->data.rdp.port = VRDPport;
+                {
+                    int vrdpPresent           = 0;
+                    int sdlPresent            = 0;
+                    int guiPresent            = 0;
+                    int totalPresent          = 0;
+                    char *guiDisplay          = NULL;
+                    char *sdlDisplay          = NULL;
+                    PRUnichar *keyTypeUtf16   = NULL;
+                    PRUnichar *valueTypeUtf16 = NULL;
+                    char      *valueTypeUtf8  = NULL;
+
+                    def->ngraphics = 0;
+
+                    data->pFuncs->pfnUtf8ToUtf16("FRONTEND/Type", &keyTypeUtf16);
+                    machine->vtbl->GetExtraData(machine, keyTypeUtf16, &valueTypeUtf16);
+                    data->pFuncs->pfnUtf16Free(keyTypeUtf16);
+
+                    if (valueTypeUtf16) {
+                        data->pFuncs->pfnUtf16ToUtf8(valueTypeUtf16, &valueTypeUtf8);
+                        data->pFuncs->pfnUtf16Free(valueTypeUtf16);
+
+                        if ( STREQ(valueTypeUtf8, "sdl") || STREQ(valueTypeUtf8, "gui") ) {
+                            PRUnichar *keyDislpayUtf16   = NULL;
+                            PRUnichar *valueDisplayUtf16 = NULL;
+                            char      *valueDisplayUtf8  = NULL;
+                            int valueDisplayFree         = 1;
+
+                            data->pFuncs->pfnUtf8ToUtf16("FRONTEND/Display", &keyDislpayUtf16);
+                            machine->vtbl->GetExtraData(machine, keyDislpayUtf16, &valueDisplayUtf16);
+                            data->pFuncs->pfnUtf16Free(keyDislpayUtf16);
+
+                            if (valueDisplayUtf16) {
+                                data->pFuncs->pfnUtf16ToUtf8(valueDisplayUtf16, &valueDisplayUtf8);
+                                data->pFuncs->pfnUtf16Free(valueDisplayUtf16);
+
+                                if (strlen(valueDisplayUtf8) <= 0) {
+                                    data->pFuncs->pfnUtf8Free(valueDisplayUtf8);
+                                    valueDisplayUtf8 = getenv("DISPLAY");
+                                    valueDisplayFree = 0;
+                                }
                             } else {
-                                def->graphics->data.rdp.autoport = 1;
+                                valueDisplayUtf8 = getenv("DISPLAY");
+                                valueDisplayFree = 0;
                             }
 
-                            VRDPServer->vtbl->GetNetAddress(VRDPServer, &netAddressUtf16);
-                            if (netAddressUtf16) {
-                                data->pFuncs->pfnUtf16ToUtf8(netAddressUtf16, &netAddressUtf8);
-                                if (STRNEQ(netAddressUtf8, ""))
-                                        def->graphics->data.rdp.listenAddr = strdup(netAddressUtf8);
-                                data->pFuncs->pfnUtf16Free(netAddressUtf16);
-                                data->pFuncs->pfnUtf8Free(netAddressUtf8);
+                            if (STREQ(valueTypeUtf8, "sdl")) {
+                                sdlPresent = 1;
+                                sdlDisplay = strdup(valueDisplayUtf8);
+                                totalPresent++;
                             }
 
-                            VRDPServer->vtbl->GetAuthType(VRDPServer, &authType);
-                            if (authType == VRDPAuthType_External) {
-                                PRUint32 authTimeout = 0;
+                            if (STREQ(valueTypeUtf8, "gui")) {
+                                guiPresent = 1;
+                                guiDisplay = strdup(valueDisplayUtf8);
+                                totalPresent++;
+                            }
+                            if (valueDisplayFree)
+                                data->pFuncs->pfnUtf8Free(valueDisplayUtf8);
+                        }
 
-                                VRDPServer->vtbl->GetAuthTimeout(VRDPServer, &authTimeout);
+                        if (STREQ(valueTypeUtf8, "vrdp"))
+                            vrdpPresent = 1;
 
-                                def->graphics->data.rdp.auth = strdup("external");
-                                def->graphics->data.rdp.authtimeout = authTimeout;
-                            } else if (authType == VRDPAuthType_Guest) {
-                                PRUint32 authTimeout = 0;
+                        data->pFuncs->pfnUtf8Free(valueTypeUtf8);
+                    }
 
-                                VRDPServer->vtbl->GetAuthTimeout(VRDPServer, &authTimeout);
+                    if ((totalPresent > 0) && (VIR_ALLOC_N(def->graphics, totalPresent) >= 0)) {
+                        if ((guiPresent) && (VIR_ALLOC(def->graphics[def->ngraphics]) >= 0)) {
+                            def->graphics[def->ngraphics]->type = VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP;
+                            def->graphics[def->ngraphics]->data.desktop.display = guiDisplay;
+                            def->ngraphics++;
+                        }
 
-                                def->graphics->data.rdp.auth = strdup("guest");
-                                def->graphics->data.rdp.authtimeout = authTimeout;
-                            }
+                        if ((sdlPresent) && (VIR_ALLOC(def->graphics[def->ngraphics]) >= 0)) {
+                            def->graphics[def->ngraphics]->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL;
+                            def->graphics[def->ngraphics]->data.sdl.display = sdlDisplay;
+                            def->ngraphics++;
+                        }
+                    } else if ((vrdpPresent != 1) && (totalPresent == 0) && (VIR_ALLOC_N(def->graphics, 1) >= 0)) {
+                        if (VIR_ALLOC(def->graphics[def->ngraphics]) >= 0) {
+                            def->graphics[def->ngraphics]->type = VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP;
+                            def->graphics[def->ngraphics]->data.desktop.display = strdup(getenv("DISPLAY"));
+                            totalPresent++;
+                            def->ngraphics++;
+                        }
+                    }
+
+                    machine->vtbl->GetVRDPServer(machine, &VRDPServer);
+                    if (VRDPServer) {
+                        VRDPServer->vtbl->GetEnabled(VRDPServer, &VRDPEnabled);
+                        if (VRDPEnabled) {
 
+                            totalPresent++;
 
-                            VRDPServer->vtbl->GetAllowMultiConnection(VRDPServer, &allowMultiConnection);
-                            if (allowMultiConnection) {
-                                def->graphics->data.rdp.multiconnections = 1;
-                            }
+                            if ((VIR_REALLOC_N(def->graphics, totalPresent) >= 0) &&
+                                (VIR_ALLOC(def->graphics[def->ngraphics]) >= 0)) {
+                                PRUint32 VRDPport            = 0;
+                                PRUnichar *netAddressUtf16   = NULL;
+                                char      *netAddressUtf8    = NULL;
+                                PRBool allowMultiConnection  = PR_FALSE;
+                                PRBool reuseSingleConnection = PR_FALSE;
 
-                            VRDPServer->vtbl->GetReuseSingleConnection(VRDPServer, &reuseSingleConnection);
-                            if (reuseSingleConnection) {
-                                def->graphics->data.rdp.reuseconnection = 1;
-                            }
+                                def->graphics[def->ngraphics]->type = VIR_DOMAIN_GRAPHICS_TYPE_RDP;
 
-                            machine->vtbl->GetSessionType(machine, &sessionTypeUtf16);
-                            DEBUG0("Session Type:");
-                            if (sessionTypeUtf16) {
-                                data->pFuncs->pfnUtf16ToUtf8(sessionTypeUtf16, &sessionTypeUtf8);
-                                DEBUG("Session Type: %s", sessionTypeUtf8);
-                                if (STREQ(sessionTypeUtf8, "vrdp")) {
-                                    def->graphics->data.rdp.headless = 1;
+                                VRDPServer->vtbl->GetPort(VRDPServer, &VRDPport);
+                                if (VRDPport) {
+                                    def->graphics[def->ngraphics]->data.rdp.port = VRDPport;
+                                } else {
+                                    def->graphics[def->ngraphics]->data.rdp.autoport = 1;
                                 }
-                                data->pFuncs->pfnUtf16Free(sessionTypeUtf16);
-                                data->pFuncs->pfnUtf8Free(sessionTypeUtf8);
+
+                                VRDPServer->vtbl->GetNetAddress(VRDPServer, &netAddressUtf16);
+                                if (netAddressUtf16) {
+                                    data->pFuncs->pfnUtf16ToUtf8(netAddressUtf16, &netAddressUtf8);
+                                    if (STRNEQ(netAddressUtf8, ""))
+                                            def->graphics[def->ngraphics]->data.rdp.listenAddr = strdup(netAddressUtf8);
+                                    data->pFuncs->pfnUtf16Free(netAddressUtf16);
+                                    data->pFuncs->pfnUtf8Free(netAddressUtf8);
+                                }
+
+                                VRDPServer->vtbl->GetAllowMultiConnection(VRDPServer, &allowMultiConnection);
+                                if (allowMultiConnection) {
+                                    def->graphics[def->ngraphics]->data.rdp.multiUser = 1;
+                                }
+
+                                VRDPServer->vtbl->GetReuseSingleConnection(VRDPServer, &reuseSingleConnection);
+                                if (reuseSingleConnection) {
+                                    def->graphics[def->ngraphics]->data.rdp.replaceUser = 1;
+                                }
+
+                                def->ngraphics++;
                             }
                         }
+                        VRDPServer->vtbl->nsisupports.Release((nsISupports *)VRDPServer);
                     }
-                    VRDPServer->vtbl->nsisupports.Release((nsISupports *)VRDPServer);
                 }
-#endif
 
                 /* dump IDE hdds if present */
                 data->pFuncs->pfnUtf8ToUtf16(hddBus, &hddBusUtf16);

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