[Spice-devel] [PATCH vdagent-win 4/6] vdservice: extract init_vdi_port()

Arnon Gilboa agilboa at redhat.com
Sun Jul 24 03:48:16 PDT 2011


---
 vdservice/vdservice.cpp |   29 ++++++++++++++++-------------
 1 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/vdservice/vdservice.cpp b/vdservice/vdservice.cpp
index f61c318..3abc146 100644
--- a/vdservice/vdservice.cpp
+++ b/vdservice/vdservice.cpp
@@ -77,6 +77,7 @@ private:
     static DWORD WINAPI control_handler(DWORD control, DWORD event_type,
                                         LPVOID event_data, LPVOID context);
     static VOID WINAPI main(DWORD argc, TCHAR * argv[]);
+    bool init_vdi_port();
     void set_control_event(int control_command);
     void handle_control_event();
     void pipe_write_completion();
@@ -444,6 +445,20 @@ VDIPort *create_pci_vdi_port()
     return new PCIVDIPort();
 }
 
+bool VDService::init_vdi_port()
+{
+    VDIPort* (*creators[])(void) = { create_virtio_vdi_port, create_pci_vdi_port };
+
+    for (int i = 0 ; i < sizeof(creators)/sizeof(creators[0]); ++i) {
+        _vdi_port = creators[i]();
+        if (_vdi_port->init()) {
+            return true;
+        }
+        delete _vdi_port;
+    }
+    return false;
+}
+
 bool VDService::execute()
 {
     SECURITY_ATTRIBUTES sec_attr;
@@ -478,19 +493,7 @@ bool VDService::execute()
         return false;
     }
 
-    bool init = false;
-    {
-        VDIPort* (*creators[])(void) = { create_virtio_vdi_port, create_pci_vdi_port };
-        for (int i = 0 ; i < sizeof(creators)/sizeof(creators[0]); ++i) {
-            _vdi_port = creators[i]();
-            init = _vdi_port->init();
-            if (init) {
-                break;
-            }
-            delete _vdi_port;
-        }
-    }
-    if (!init) {
+    if (!init_vdi_port()) {
         vd_printf("Failed to create VDIPort instance");
         CloseHandle(pipe);
         return false;
-- 
1.7.4.1



More information about the Spice-devel mailing list