On 4/26/07, Peter Stuge <stuge-libusb@cdy.org> wrote:
I also propose:
int libusb_rm_event_callback(handle,callback,arg);
int libusb_start_events(handle);
int libusb_stop_events(handle);

It should be possible to register several different callbacks per
handle and remove callbacks at any time, also without stopping
callbacks first.

No callbacks should happen until a successful start_events().
start_events() does not have to return before the first callback,
but it should return very soon after the first callback, and it must
return LIBUSB_SUCCESS.


We could also add a filter function parameter to set_event:

/* user function, return 0 = callback, return !0 = continue */
int filter(handle,farg,bus_id,usb_device_desc);

int libusb_set_event_callback(handle,type,filter,farg,callback,cbarg);
int libusb_rm_event_callback(handle,type,filter,farg,callback,cbarg);


Well I can see the utility in waiting to start the events, I'm not sure this is the way to do it. I think it's simpler just to say that events will start as soon as you have a callback for them. That way you can control when events start just controlling where you set the callback.

Also, you don't need a libusb_rm_event_callback, you can just use libusb_set_event_callback with NULL as the callback parameter. This is a pretty common practice and it simplifies this by not having as many functions.