<br><br><div class="gmail_quote">On Sun, Feb 12, 2012 at 7:10 PM, Phil Mayers <span dir="ltr"><<a href="mailto:p.mayers@imperial.ac.uk">p.mayers@imperial.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 02/12/2012 04:13 AM, Donal McMullan wrote:<br>
> I'm trying to integrate Twisted with libusb-1<br>
><br>
> The libusb-1 Python wrapper offers a USBPoller class to "allow<br>
> integration of USB event polling in a file-descriptor monitoring event<br>
> loop." The class expects to receive a 'poller' object, again quoting<br>
> from the documentation:<br>
><br>
> poller is a polling instance implementing the following methods:<br>
> - register(fd, event_flags)<br>
</div>> event_flags have the same meaning as in poll API (POLLIN& POLLOUT)<br>
<div class="im">> - unregister(fd)<br>
> - poll(timeout)<br>
> timeout being a float in seconds, or None if there is no timeout.<br>
> It must return a list of (descriptor, event) pairs.<br>
> Note: USBPoller is itself a valid poller.<br>
><br>
> I feel like it should be obvious, but I can't see what would be the<br>
> correct way to integrate this with Twisted. My particular application<br>
> is to enable networking over the ANT+ protocol via a small USB key.<br>
<br>
</div>I've only quickly scanned it, but actually it doesn't look obvious to me<br>
at all.<br>
<br>
I *think* that you want to ignore USBPoller entirely; it looks like it's<br>
some sort of mini reactor thing, although it's not obvious to me how it<br>
ever DOES anything.<br>
<br>
USBContext looks to be the "thing" that you plug in an event loop to.<br>
<br>
However, I'm not certain (perhaps others will comment) that it makes<br>
sense to integrate it into the Twisted event loop - the file descriptor<br>
"ready" events don't seem to trigger corresponding "read" events, and<br>
the USB protocol implementation isn't accessible, so the Twisted model of:<br>
<br>
file ready event -> transport does read -> protocol dataReceived<br>
<br>
...doesn't really apply.<br>
<br>
It may be just as easy to write wrapper around your protocol in plain<br>
non-Twisted python, and talk to it from Twisted over a<br>
pipe/process/whatever.<br>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div> the most simplest way is probably to use another thread to handle all possible events and use twisted's thread functions to </div><div>leverage the whole system though it is inefficient. </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</div></div></blockquote></div><br>