[Spice-devel] [RFC PATCH] usbclerk: remove device from devs list upon driver removal

Arnon Gilboa agilboa at redhat.com
Wed Oct 24 05:06:04 PDT 2012


nice, but too many lines for a single remove() in the code :)
fixed by naive iterator in patch v2.

Uri Lublin wrote:
> ---
> This implements comment 1.
>
> Maybe better to remove it from the list only if driver uninstall was successful
> (check reply->status)
>
> ---
>  usbclerk.cpp |   11 +++++++++++
>  1 files changed, 11 insertions(+), 0 deletions(-)
>
> diff --git a/usbclerk.cpp b/usbclerk.cpp
> index b5771b7..c95766f 100644
> --- a/usbclerk.cpp
> +++ b/usbclerk.cpp
> @@ -34,6 +34,16 @@ typedef struct USBDev {
>  
>  typedef std::list<USBDev> USBDevs;
>  
> +// compare two USBDevs
> +class USBDevCompare
> +{
> +public:
> +	USBDevCompare(USBDev &ud) : d(ud) {}
> +	bool operator() (const USBDev& o) { return (d.vid == o.vid && d.pid == o.pid); }
> +private:
> +	const UsbDev& d;
> +};
> +
>  class USBClerk {
>  public:
>      static USBClerk* get();
> @@ -398,6 +408,7 @@ bool USBClerk::dispatch_message(CHAR *buffer, DWORD bytes, USBClerkReply *reply,
>      case USB_CLERK_DRIVER_REMOVE:
>          vd_printf("Removing winusb driver for %04x:%04x", dev.vid, dev.pid);
>          reply->status = remove_winusb_driver(dev.vid, dev.pid);        
> +        devs->remove_if((USBDevCompare(dev)));
>          break;
>      default:
>          vd_printf("Unknown message received, type %u", hdr->type);
>   



More information about the Spice-devel mailing list