[PATCH] vdservice: don't start when no qxl device present

Alon Levy alevy at redhat.com
Tue Aug 24 04:53:03 PDT 2010


---
 common/vdcommon.h          |    2 ++
 vdagent/desktop_layout.cpp |   19 +------------------
 vdagent/desktop_layout.h   |    1 -
 vdagent/vdagent.vcproj     |    8 ++++++++
 vdservice/vdservice.cpp    |   31 +++++++++++++++++++++++++++++--
 vdservice/vdservice.vcproj |    4 ++++
 6 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/common/vdcommon.h b/common/vdcommon.h
index 1097720..24d18d6 100644
--- a/common/vdcommon.h
+++ b/common/vdcommon.h
@@ -63,5 +63,7 @@ typedef struct VDPipeState {
     VDPipeBuffer read;
 } VDPipeState;
 
+bool get_qxl_device_id(TCHAR* device_key, DWORD* device_id);
+
 #endif
 
diff --git a/vdagent/desktop_layout.cpp b/vdagent/desktop_layout.cpp
index 32502bc..b7a6b9c 100644
--- a/vdagent/desktop_layout.cpp
+++ b/vdagent/desktop_layout.cpp
@@ -17,6 +17,7 @@
 
 #include "desktop_layout.h"
 #include "vdlog.h"
+#include "vdcommon.h"
 
 void DisplayMode::set_res(DWORD width, DWORD height, DWORD depth)
 {
@@ -155,24 +156,6 @@ bool DesktopLayout::is_attached(LPCTSTR dev_name)
     return !!dev_mode.dmBitsPerPel;
 }
 
-bool DesktopLayout::get_qxl_device_id(WCHAR* device_key, DWORD* device_id)
-{
-    DWORD type = REG_BINARY;
-    DWORD size = sizeof(*device_id);
-    bool key_found = false;
-    HKEY key;
-
-    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, wcsstr(device_key, L"System"),
-                     0L, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS) {
-        if (RegQueryValueEx(key, L"QxlDeviceID", NULL, &type, (LPBYTE)device_id, &size) ==
-                                                                             ERROR_SUCCESS) {
-            key_found = true;
-        }
-        RegCloseKey(key);
-    }
-    return key_found;
-}
-
 void DesktopLayout::init_dev_mode(DEVMODE* dev_mode, DisplayMode* mode, bool set_pos)
 {
     ZeroMemory(dev_mode, sizeof(DEVMODE));
diff --git a/vdagent/desktop_layout.h b/vdagent/desktop_layout.h
index a43ee49..fe70e36 100644
--- a/vdagent/desktop_layout.h
+++ b/vdagent/desktop_layout.h
@@ -72,7 +72,6 @@ public:
 private:
     void clean_displays();
     static bool is_attached(LPCTSTR dev_name);
-    static bool get_qxl_device_id(WCHAR* device_key, DWORD* device_id);
     static void init_dev_mode(DEVMODE* dev_mode, DisplayMode* mode, bool set_pos);
 
 private:
diff --git a/vdagent/vdagent.vcproj b/vdagent/vdagent.vcproj
index 108728b..2c91185 100644
--- a/vdagent/vdagent.vcproj
+++ b/vdagent/vdagent.vcproj
@@ -509,6 +509,10 @@
 				RelativePath="..\common\vdlog.cpp"

 				>

 			</File>

+			<File

+				RelativePath="..\common\vdcommon.cpp"

+				>

+			</File>

 		</Filter>

 		<Filter

 			Name="Header Files"

@@ -535,6 +539,10 @@
 				RelativePath="..\common\vdlog.h"

 				>

 			</File>

+			<File

+				RelativePath="..\common\vdcommon.cpp"

+				>

+			</File>

 		</Filter>

 		<Filter

 			Name="Resource Files"

diff --git a/vdservice/vdservice.cpp b/vdservice/vdservice.cpp
index 6fec0c1..8cd485e 100644
--- a/vdservice/vdservice.cpp
+++ b/vdservice/vdservice.cpp
@@ -140,6 +140,27 @@ int supported_system_version()
     return 0;
 }
 
+bool has_qxl_device()
+{
+    DISPLAY_DEVICE dev_info;
+    bool ret = false;
+    DWORD dev_id = 0;
+    DWORD qxl_id;
+
+    ZeroMemory(&dev_info, sizeof(dev_info));
+    dev_info.cb = sizeof(dev_info);
+    while (EnumDisplayDevices(NULL, dev_id, &dev_info, 0)) {
+        if (wcsstr(dev_info.DeviceString, L"QXL") != NULL
+            && get_qxl_device_id(dev_info.DeviceKey, &qxl_id)) {
+            vd_printf("found QXL device at id %d, qxl_id %d", dev_id, qxl_id);
+            ret = true;
+            break;
+        }
+        dev_id++;
+    }
+    return ret;
+}
+
 VDService::VDService()
     : _status_handle (0)
     , _vdi_port (NULL)
@@ -338,8 +359,10 @@ VOID WINAPI VDService::main(DWORD argc, TCHAR* argv[])
         swprintf_s(log_path, MAX_PATH, VD_SERVICE_LOG_PATH, temp_path);
         s->_log = VDLog::get(log_path);
     }
+
     vd_printf("***Service started***");
     log_version();
+
     if (!SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS)) {
         vd_printf("SetPriorityClass failed %u", GetLastError());
     }
@@ -369,8 +392,12 @@ VOID WINAPI VDService::main(DWORD argc, TCHAR* argv[])
     status->dwCurrentState = SERVICE_RUNNING;
     SetServiceStatus(s->_status_handle, status);
 
-    s->_running = true;
-    s->execute();
+    if (has_qxl_device()) {
+        s->_running = true;
+        s->execute();
+    } else {
+        vd_printf("didn't find any qxl devices\n");
+    }
 
     // service was stopped
     status->dwCurrentState = SERVICE_STOP_PENDING;
diff --git a/vdservice/vdservice.vcproj b/vdservice/vdservice.vcproj
index 85d5c8e..61fbedc 100644
--- a/vdservice/vdservice.vcproj
+++ b/vdservice/vdservice.vcproj
@@ -531,6 +531,10 @@
 				>

 			</File>

 			<File

+				RelativePath="..\common\vdcommon.cpp"

+				>

+			</File>

+			<File

 				RelativePath=".\vdservice.cpp"

 				>

 			</File>

-- 
1.7.2



More information about the Spice-devel mailing list