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 b25e93b..87db6ab 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -3040,24 +3040,29 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
             }
         }   /* Finished:Block to attach the Parallel Port to the VM */
 
-#if 0
         {   /* Started:Block to attach the Remote Display to VM */
-            if (def->graphics) {
+            int vrdpPresent  = 0;
+            int sdlPresent   = 0;
+            int guiPresent   = 0;
+            char *guiDisplay = NULL;
+            char *sdlDisplay = NULL;
+            int i = 0;
+
+            for (i = 0; i < def->ngraphics; i++) {
                 IVRDPServer *VRDPServer = NULL;
 
-                /* TODO: include the support for headless stuff
-                 */
+                if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_RDP) && (vrdpPresent == 0)) {
 
-                if (def->graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_RDP) {
+                    vrdpPresent = 1;
                     machine->vtbl->GetVRDPServer(machine, &VRDPServer);
                     if (VRDPServer) {
                         VRDPServer->vtbl->SetEnabled(VRDPServer, PR_TRUE);
                         DEBUG0("VRDP Support turned ON on port: 3389");
 
-                        if (def->graphics->data.rdp.port) {
-                            VRDPServer->vtbl->SetPort(VRDPServer, def->graphics->data.rdp.port);
-                            DEBUG("VRDP Port changed to: %d", def->graphics->data.rdp.port);
-                        } else if (def->graphics->data.rdp.autoport) {
+                        if (def->graphics[i]->data.rdp.port) {
+                            VRDPServer->vtbl->SetPort(VRDPServer, def->graphics[i]->data.rdp.port);
+                            DEBUG("VRDP Port changed to: %d", def->graphics[i]->data.rdp.port);
+                        } else if (def->graphics[i]->data.rdp.autoport) {
                             /* Setting the port to 0 will reset its value to
                              * the default one which is 3389 currently
                              */
@@ -3065,37 +3070,22 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
                             DEBUG0("VRDP Port changed to default, which is 3389 currently");
                         }
 
-                        if (def->graphics->data.rdp.reuseconnection) {
+                        if (def->graphics[i]->data.rdp.replaceUser) {
                             VRDPServer->vtbl->SetReuseSingleConnection(VRDPServer, PR_TRUE);
                             DEBUG0("VRDP set to reuse single connection");
                         }
 
-                        if (def->graphics->data.rdp.multiconnections) {
+                        if (def->graphics[i]->data.rdp.multiUser) {
                             VRDPServer->vtbl->SetAllowMultiConnection(VRDPServer, PR_TRUE);
                             DEBUG0("VRDP set to allow multiple connection");
                         }
 
-                        if (def->graphics->data.rdp.auth) {
-                            if (STREQ(def->graphics->data.rdp.auth, "guest")) {
-                                VRDPServer->vtbl->SetAuthType(VRDPServer, VRDPAuthType_Guest);
-                                DEBUG0("VRDP authentication method set to Guest");
-                            } else if (STREQ(def->graphics->data.rdp.auth, "external")) {
-                                VRDPServer->vtbl->SetAuthType(VRDPServer, VRDPAuthType_External);
-                                DEBUG0("VRDP authentication method set to External");
-                            }
-
-                            if (def->graphics->data.rdp.authtimeout) {
-                                VRDPServer->vtbl->SetAuthTimeout(VRDPServer, def->graphics->data.rdp.authtimeout);
-                                DEBUG("VRDP authentication timeout is set to %llu", def->graphics->data.rdp.authtimeout);
-                            }
-                        }
-
-                        if (def->graphics->data.rdp.listenAddr) {
+                        if (def->graphics[i]->data.rdp.listenAddr) {
                             PRUnichar *netAddressUtf16 = NULL;
 
-                            data->pFuncs->pfnUtf8ToUtf16(def->graphics->data.rdp.listenAddr, &netAddressUtf16);
+                            data->pFuncs->pfnUtf8ToUtf16(def->graphics[i]->data.rdp.listenAddr, &netAddressUtf16);
                             VRDPServer->vtbl->SetNetAddress(VRDPServer, netAddressUtf16);
-                            DEBUG("VRDP listen address is set to: %s", def->graphics->data.rdp.listenAddr);
+                            DEBUG("VRDP listen address is set to: %s", def->graphics[i]->data.rdp.listenAddr);
 
                             data->pFuncs->pfnUtf16Free(netAddressUtf16);
                         }
@@ -3103,9 +3093,86 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
                         VRDPServer->vtbl->nsisupports.Release((nsISupports *)VRDPServer);
                     }
                 }
+
+                if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP) && (guiPresent == 0)) {
+                    guiPresent = 1;
+                    guiDisplay = strdup(def->graphics[i]->data.desktop.display);
+                }
+
+                if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) && (sdlPresent == 0)) {
+                    sdlPresent = 1;
+                    sdlDisplay = strdup(def->graphics[i]->data.sdl.display);
+                }
+            }
+
+            if ((vrdpPresent == 1) && (guiPresent == 0) && (sdlPresent == 0)) {
+                /* store extradata key that frontend is set to vrdp */
+                PRUnichar *keyTypeUtf16   = NULL;
+                PRUnichar *valueTypeUtf16 = NULL;
+
+                data->pFuncs->pfnUtf8ToUtf16("FRONTEND/Type", &keyTypeUtf16);
+                data->pFuncs->pfnUtf8ToUtf16("vrdp", &valueTypeUtf16);
+
+                machine->vtbl->SetExtraData(machine, keyTypeUtf16, valueTypeUtf16);
+
+                data->pFuncs->pfnUtf16Free(keyTypeUtf16);
+                data->pFuncs->pfnUtf16Free(valueTypeUtf16);
+
+            } else if ((guiPresent == 0) && (sdlPresent == 1)) {
+                /* store extradata key that frontend is set to sdl */
+                PRUnichar *keyTypeUtf16      = NULL;
+                PRUnichar *valueTypeUtf16    = NULL;
+                PRUnichar *keyDislpayUtf16   = NULL;
+                PRUnichar *valueDisplayUtf16 = NULL;
+
+                data->pFuncs->pfnUtf8ToUtf16("FRONTEND/Type", &keyTypeUtf16);
+                data->pFuncs->pfnUtf8ToUtf16("sdl", &valueTypeUtf16);
+
+                machine->vtbl->SetExtraData(machine, keyTypeUtf16, valueTypeUtf16);
+
+                data->pFuncs->pfnUtf16Free(keyTypeUtf16);
+                data->pFuncs->pfnUtf16Free(valueTypeUtf16);
+
+                if (sdlDisplay) {
+                    data->pFuncs->pfnUtf8ToUtf16("FRONTEND/Display", &keyDislpayUtf16);
+                    data->pFuncs->pfnUtf8ToUtf16(sdlDisplay, &valueDisplayUtf16);
+
+                    machine->vtbl->SetExtraData(machine, keyDislpayUtf16, valueDisplayUtf16);
+
+                    data->pFuncs->pfnUtf16Free(keyDislpayUtf16);
+                    data->pFuncs->pfnUtf16Free(valueDisplayUtf16);
+                }
+
+            } else {
+                /* if all are set then default is gui, with vrdp turned on */
+                PRUnichar *keyTypeUtf16      = NULL;
+                PRUnichar *valueTypeUtf16    = NULL;
+                PRUnichar *keyDislpayUtf16   = NULL;
+                PRUnichar *valueDisplayUtf16 = NULL;
+
+                data->pFuncs->pfnUtf8ToUtf16("FRONTEND/Type", &keyTypeUtf16);
+                data->pFuncs->pfnUtf8ToUtf16("gui", &valueTypeUtf16);
+
+                machine->vtbl->SetExtraData(machine, keyTypeUtf16, valueTypeUtf16);
+
+                data->pFuncs->pfnUtf16Free(keyTypeUtf16);
+                data->pFuncs->pfnUtf16Free(valueTypeUtf16);
+
+                if (guiDisplay) {
+                    data->pFuncs->pfnUtf8ToUtf16("FRONTEND/Display", &keyDislpayUtf16);
+                    data->pFuncs->pfnUtf8ToUtf16(guiDisplay, &valueDisplayUtf16);
+
+                    machine->vtbl->SetExtraData(machine, keyDislpayUtf16, valueDisplayUtf16);
+
+                    data->pFuncs->pfnUtf16Free(keyDislpayUtf16);
+                    data->pFuncs->pfnUtf16Free(valueDisplayUtf16);
+                }
             }
+
+            VIR_FREE(guiDisplay);
+            VIR_FREE(sdlDisplay);
+
         }   /* Finished:Block to attach the Remote Display to VM */
-#endif
 
         {   /* Started:Block to attach USB Devices to VM */
             if (def->nhostdevs > 0) {
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to