[Spice-devel] [PATCH] vdservice: use "com.redhat.spice.0" symbolic link as virtio-serial port path
Arnon Gilboa
agilboa at redhat.com
Tue Sep 21 23:53:24 PDT 2010
remove get_device_path() by GUID & dependency on setupapi.lib
---
vdservice/vdi_port.cpp | 64 +------------------------------------------
vdservice/vdservice.vcproj | 8 +++---
2 files changed, 6 insertions(+), 66 deletions(-)
diff --git a/vdservice/vdi_port.cpp b/vdservice/vdi_port.cpp
index 8af95b2..e36ff86 100644
--- a/vdservice/vdi_port.cpp
+++ b/vdservice/vdi_port.cpp
@@ -15,23 +15,15 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <windows.h>
-#include <setupapi.h>
#include "stdio.h"
#include "vdi_port.h"
#include "vdlog.h"
-const GUID GUID_VIOSERIAL_PORT =
- {0x6fde7521, 0x1b65, 0x48ae, 0xb6, 0x28, 0x80, 0xbe, 0x62, 0x1, 0x60, 0x26};
+#define VIOSERIAL_PORT_PATH L"\\\\.\\Global\\com.redhat.spice.0"
// Current limitation of virtio-serial windows driver (RHBZ 617000)
#define VIOSERIAL_PORT_MAX_WRITE_BYTES 2048
-// Retry initial connection to device. On boot when vdservice is started the device is
-// not immediately available (takes 2 seconds, 30 is for extreme load).
-#define VIOSERIAL_PORT_DEVICE_OPEN_MAX_RETRIES 30
-#define VIOSERIAL_PORT_DEVICE_OPEN_RETRY_INTERVAL_MS 1000
-
#define MIN(a, b) ((a) > (b) ? (b) : (a))
VDIPort* VDIPort::_singleton;
@@ -59,61 +51,9 @@ VDIPort::~VDIPort()
}
}
-//Based on device.cpp from vioserial test app
-//FIXME: remove this call & lib?
-PTCHAR get_device_path(IN LPGUID interface_guid)
-{
- HDEVINFO dev_info;
- SP_DEVICE_INTERFACE_DATA dev_interface;
- PSP_DEVICE_INTERFACE_DETAIL_DATA dev_interface_detail = NULL;
- ULONG len, req_len = 0;
-
- dev_info = SetupDiGetClassDevs(interface_guid, NULL, NULL,
- DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
- if (dev_info == INVALID_HANDLE_VALUE) {
- vd_printf("Cannot get class devices");
- return NULL;
- }
- dev_interface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
- if (!SetupDiEnumDeviceInterfaces(dev_info, 0, interface_guid, 0, &dev_interface)) {
- vd_printf("Cannot get enumerate device interfaces");
- SetupDiDestroyDeviceInfoList(dev_info);
- return NULL;
- }
- SetupDiGetDeviceInterfaceDetail(dev_info, &dev_interface, NULL, 0, &req_len, NULL);
- dev_interface_detail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LMEM_FIXED, req_len);
- if (dev_interface_detail == NULL) {
- vd_printf("Cannot allocate memory");
- SetupDiDestroyDeviceInfoList(dev_info);
- return NULL;
- }
- dev_interface_detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
- len = req_len;
- if (!SetupDiGetDeviceInterfaceDetail(dev_info, &dev_interface, dev_interface_detail, len,
- &req_len, NULL)) {
- vd_printf("Cannot get device interface details");
- SetupDiDestroyDeviceInfoList(dev_info);
- LocalFree(dev_interface_detail);
- return NULL;
- }
- return dev_interface_detail->DevicePath;
-}
-
bool VDIPort::init()
{
- PTCHAR path = NULL;
-
- for (int retry = 0; retry < VIOSERIAL_PORT_DEVICE_OPEN_MAX_RETRIES && path == NULL; retry++) {
- if (path = get_device_path((LPGUID)&GUID_VIOSERIAL_PORT)) {
- break;
- }
- Sleep(VIOSERIAL_PORT_DEVICE_OPEN_RETRY_INTERVAL_MS);
- }
- if (path == NULL) {
- vd_printf("GetDevicePath failed - device/driver missing?");
- return false;
- }
- _handle = CreateFile(path, GENERIC_READ | GENERIC_WRITE , 0, NULL,
+ _handle = CreateFile(VIOSERIAL_PORT_PATH, GENERIC_READ | GENERIC_WRITE , 0, NULL,
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
if (_handle == INVALID_HANDLE_VALUE) {
vd_printf("CreateFile() failed: %u", GetLastError());
diff --git a/vdservice/vdservice.vcproj b/vdservice/vdservice.vcproj
index f7aa4a8..e23d235 100644
--- a/vdservice/vdservice.vcproj
+++ b/vdservice/vdservice.vcproj
@@ -65,7 +65,7 @@
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="WtsApi32.lib Userenv.lib Version.lib setupapi.lib"
+ AdditionalDependencies="WtsApi32.lib Userenv.lib Version.lib"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
@@ -142,7 +142,7 @@
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="WtsApi32.lib Userenv.lib Version.lib setupapi.lib"
+ AdditionalDependencies="WtsApi32.lib Userenv.lib Version.lib"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
@@ -216,7 +216,7 @@
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="WtsApi32.lib Userenv.lib Version.lib setupapi.lib"
+ AdditionalDependencies="WtsApi32.lib Userenv.lib Version.lib"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
@@ -293,7 +293,7 @@
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="WtsApi32.lib Userenv.lib Version.lib setupapi.lib"
+ AdditionalDependencies="WtsApi32.lib Userenv.lib Version.lib"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
--
1.5.5.6
More information about the Spice-devel
mailing list