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

Submitted by Uri Lublin on Oct. 24, 2012, 10:23 a.m.

Details

Message ID bf71992dc34b1396e584c7e52ae290c218cdf49a.1351073647.git.uril@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Uri Lublin Oct. 24, 2012, 10:23 a.m.
---
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(-)

Patch hide | download patch | download mbox

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);

Comments

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);
>