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

Submitted by Arnon Gilboa on July 24, 2011, 9:38 p.m.

Details

Message ID 1311518301-1446-5-git-send-email-agilboa@redhat.com
State New, archived
Headers show

Not browsing as part of any series.

Commit Message

Arnon Gilboa July 24, 2011, 9:38 p.m.
---
 vdservice/vdservice.cpp |   29 ++++++++++++++++-------------
 1 files changed, 16 insertions(+), 13 deletions(-)

Patch hide | download patch | download mbox

diff --git a/vdservice/vdservice.cpp b/vdservice/vdservice.cpp
index e09828a..bc7ec41 100644
--- a/vdservice/vdservice.cpp
+++ b/vdservice/vdservice.cpp
@@ -80,6 +80,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();
@@ -456,6 +457,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;
@@ -490,19 +505,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;