[Spice-devel] [PATCH 1/6] usbclerk: dos2unix

Hans de Goede hdegoede at redhat.com
Mon Jul 23 08:58:16 PDT 2012


Hi,

Series looks good, only remark I have is that with 6/6
you're not passing in interface information, that really is
not a good idea, since for almost all devices if you want to filter
on usb classes (which you usually do) the interesting bits are in
the interface info.

Now it might be that when usbclerk runs you don't know the configuration,
but most devices have only 1 config, so for those that is not a problem :)

For multi config devices, you can do as you do now and not pass in any
interface info, or simply pass in the interface info for the currently
active config. Note that what happens on the host side is that the filter
gets run for the current config, and if the config changes it gets re-run
with the new interface info.

Regards,

Hans



On 07/23/2012 11:23 AM, Arnon Gilboa wrote:
> ---
>   usbclerk.cpp |   72 +++++++++++++++++++++++++++++-----------------------------
>   1 files changed, 36 insertions(+), 36 deletions(-)
>
> diff --git a/usbclerk.cpp b/usbclerk.cpp
> index 792f544..441f4a1 100644
> --- a/usbclerk.cpp
> +++ b/usbclerk.cpp
> @@ -1,6 +1,6 @@
>   #include <windows.h>
>   #include <setupapi.h>
> -#include <cfgmgr32.h>
> +#include <cfgmgr32.h>
>   #include <stdio.h>
>   #include <string.h>
>   #include <tchar.h>
> @@ -37,8 +37,8 @@ private:
>       bool dispatch_message(CHAR *buffer, DWORD bytes, USBClerkReply *reply);
>       bool install_winusb_driver(int vid, int pid);
>       bool remove_winusb_driver(int vid, int pid);
> -    bool remove_dev(HDEVINFO devs, PSP_DEVINFO_DATA dev_info);
> -    bool rescan();
> +    bool remove_dev(HDEVINFO devs, PSP_DEVINFO_DATA dev_info);
> +    bool rescan();
>       static DWORD WINAPI control_handler(DWORD control, DWORD event_type,
>                                           LPVOID event_data, LPVOID context);
>       static VOID WINAPI main(DWORD argc, TCHAR * argv[]);
> @@ -289,7 +289,7 @@ bool USBClerk::execute()
>           if (!ConnectNamedPipe(_pipe, NULL) && GetLastError() != ERROR_PIPE_CONNECTED) {
>               vd_printf("ConnectNamedPipe() failed: %u", GetLastError());
>               break;
> -        }
> +        }
>           if (!ReadFile(_pipe, &buffer, sizeof(buffer), &bytes, NULL)) {
>               vd_printf("ReadFile() failed: %d", GetLastError());
>               goto disconnect;
> @@ -433,52 +433,52 @@ cleanup:
>   bool USBClerk::remove_winusb_driver(int vid, int pid)
>   {
>       HDEVINFO devs;
> -    DWORD dev_index;
> -    SP_DEVINFO_DATA dev_info;
> +    DWORD dev_index;
> +    SP_DEVINFO_DATA dev_info;
>       TCHAR dev_prefix[MAX_DEVICE_ID_LEN];
> -    TCHAR dev_id[MAX_DEVICE_ID_LEN];
> -    bool ret = false;
> +    TCHAR dev_id[MAX_DEVICE_ID_LEN];
> +    bool ret = false;
>
> -    devs = SetupDiGetClassDevs(NULL, L"USB", NULL, DIGCF_ALLCLASSES);
> +    devs = SetupDiGetClassDevs(NULL, L"USB", NULL, DIGCF_ALLCLASSES);
>       if (devs == INVALID_HANDLE_VALUE) {
>           vd_printf("SetupDiGetClassDevsEx failed: %u", GetLastError());
>           return false;
>       }
>
>       swprintf(dev_prefix, MAX_DEVICE_ID_LEN, L"USB\\VID_%04x&PID_%04x", vid, pid);
> -    dev_info.cbSize = sizeof(dev_info);
> -    for (dev_index = 0; SetupDiEnumDeviceInfo(devs, dev_index, &dev_info); dev_index++) {
> -        if (SetupDiGetDeviceInstanceId(devs, &dev_info, dev_id, MAX_DEVICE_ID_LEN, NULL) &&
> -                wcsstr(dev_id, dev_prefix)) {
> -            vd_printf("Removing %S", dev_id);
> -            ret = remove_dev(devs, &dev_info);
> -            break;
> -        }
> -    }
> +    dev_info.cbSize = sizeof(dev_info);
> +    for (dev_index = 0; SetupDiEnumDeviceInfo(devs, dev_index, &dev_info); dev_index++) {
> +        if (SetupDiGetDeviceInstanceId(devs, &dev_info, dev_id, MAX_DEVICE_ID_LEN, NULL) &&
> +                wcsstr(dev_id, dev_prefix)) {
> +            vd_printf("Removing %S", dev_id);
> +            ret = remove_dev(devs, &dev_info);
> +            break;
> +        }
> +    }
>       SetupDiDestroyDeviceInfoList(devs);
> -    ret = ret && rescan();
> +    ret = ret && rescan();
>       return ret;
>   }
>
> -bool USBClerk::remove_dev(HDEVINFO devs, PSP_DEVINFO_DATA dev_info)
> -{
> -    SP_REMOVEDEVICE_PARAMS rmd_params;
> -
> -    rmd_params.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
> -    rmd_params.ClassInstallHeader.InstallFunction = DIF_REMOVE;
> -    rmd_params.Scope = DI_REMOVEDEVICE_GLOBAL;
> -    rmd_params.HwProfile = 0;
> -    return (SetupDiSetClassInstallParams(devs, dev_info,
> -                &rmd_params.ClassInstallHeader, sizeof(rmd_params)) &&
> -            SetupDiCallClassInstaller(DIF_REMOVE, devs, dev_info));
> +bool USBClerk::remove_dev(HDEVINFO devs, PSP_DEVINFO_DATA dev_info)
> +{
> +    SP_REMOVEDEVICE_PARAMS rmd_params;
> +
> +    rmd_params.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
> +    rmd_params.ClassInstallHeader.InstallFunction = DIF_REMOVE;
> +    rmd_params.Scope = DI_REMOVEDEVICE_GLOBAL;
> +    rmd_params.HwProfile = 0;
> +    return (SetupDiSetClassInstallParams(devs, dev_info,
> +                &rmd_params.ClassInstallHeader, sizeof(rmd_params)) &&
> +            SetupDiCallClassInstaller(DIF_REMOVE, devs, dev_info));
>   }
>
> -bool USBClerk::rescan()
> -{
> -    DEVINST dev_root;
> -
> -    return (CM_Locate_DevNode_Ex(&dev_root, NULL, CM_LOCATE_DEVNODE_NORMAL, NULL) == CR_SUCCESS &&
> -            CM_Reenumerate_DevNode_Ex(dev_root, 0, NULL) == CR_SUCCESS);
> +bool USBClerk::rescan()
> +{
> +    DEVINST dev_root;
> +
> +    return (CM_Locate_DevNode_Ex(&dev_root, NULL, CM_LOCATE_DEVNODE_NORMAL, NULL) == CR_SUCCESS &&
> +            CM_Reenumerate_DevNode_Ex(dev_root, 0, NULL) == CR_SUCCESS);
>   }
>
>   int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
>


More information about the Spice-devel mailing list