[Twisted-Python] twisted.positioning: status report and request for comments/feedback

Laurens Van Houtven lvh at laurensvh.be
Wed Jul 29 18:08:24 EDT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi!


Most of you might remember that I was working on a twisted generic
positioning (GPS and things like it) framework, and here's a
preliminary status report. First of all, we've moved from
twisted.protocols.positioning to twisted.positioning. Yay! Seriously
though: work is mostly coming along nicely, and a serious patch for
separate review is probably only a few days' work away.

For those interested, the ticket is here:
http://twistedmatrix.com/trac/ticket/3926
And you can check out work in progress from launchpad:
https://code.launchpad.net/~lvh/twisted/positioning

As you might remember, we (thanks to the adhoc code reviews from
glyph, tazle, dash andexarkun) decided on an implementation slightly
different from the original one, using:
    - an NMEAReceiver class, which *only* does the receiving bit and
is perfectly stateless: this does things like unpacking the sentence
and checking the checksum
    - an IPositioningReceiver (now renamed IPositioningProvider, but
I'm not sure that's the right name yet) interface that has a bunch of
*sane* callbacks -- ones you actually want instead of ones that are
directly a consequence of NMEA being a steaming pile of dung
    - an NMEAAdapter that would adapt the receiver and keep as much
state as necessary internally to produce the meaningful callbacks as
defined in the interface

I'm having a bit of trouble implementing this this way, and I'd love
to hear your comments or suggestions on the topic.

Here's the code right now: http://bit.ly/1azA5q
The interface lives in this file: http://bit.ly/3wWL2c

I originally thought that the NMEAAdapter (which adapts an
NMEAReceiver to the  IPositioningReceiver interface) was really an
adapter in the twisted.python.components sense of the word, so that
you could do something like  PositioningReceiver(NMEAReceiver()) and
you'd get and NMEAAdapter object, as described in the Twisted
components howto.

The problem is attaching the method stubs in NMEAReceiver (nmea_GPGGA,
nmea_GPRMC, nmea_GPGSV) to the methods in the NMEAAdapter that
actually interpret these sentences. Ordinarily, you'd subclass that
class to override those stubs. How do you feel this should be done
while keeping the adapter? Should we keep the adapter at all?

Of course, I could do ugly things in the adapters' __init__ like:

def __init__(self, receiver):
   receiver.nmea_GPGGA = self.nmea_GPGGA
   receiver.nmea_GPRMC = self.nmea_GPRMC
   receiver.nmea_GPGSV = self.nmea_GPGSV

But that looks like a really bad idea: it's like I'm subverting
inheritance. Instead, I'm currently doing this by subclassing the
receiver (thanks to exarkun for this suggestion):

class NMEAAdapter(NMEAReceiver):

This fixes the method stubs being correctly assigned (I suppose the
correct term would be overriding, through plain old inheritance). The
problem is that neither the interface nor components/adapters are
involved in any way, so I feel like I'm missing something important.


Thanks for reading
Laurens
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Use GnuPG with Firefox : http://getfiregpg.org (Version: 0.7.7)

iEYEARECAAYFAkpwyB4ACgkQT5v5zGkvKT5zPwCbB9IXwaUhP4mr33961ifG7Q92
exMAoLMh5pMXgBT0Q6kvkppCQCWJ26eZ
=9Rfs
-----END PGP SIGNATURE-----



More information about the Twisted-Python mailing list