I have spent the past week re-writing Presence from scratch using Qt. "Why?" you may ask. The previous version of Presence has been working very well for a long time, but it had a bug that only appeared on 64-bit operating systems. I spent a small amount of time debugging the old code base to find that bug, and then finally decided that a complete re-write would be better. Not that the old code base was that horrible, it was just written in a mixture of C and C++ that made it a bit hard to maintain. E.g., the network related code was written in pure C using a large select() statement and multiplexing over a large number of sockets - it seems obvious that this could be coded _much_ nicer using an event based architecture.
So I decided to recode it in Qt, and let me tell you: Qt = happiness! I am no fan of C++, but when using Qt it is actually a nice language to work with. The new version of Presence is easily maintainable, because it is so simple to read and understand Qt code (at least compared to reading and understanding C). No more waiting for data on a bunch of sockets, finding out which socket has activity, forwarding the task of handling the activity to someone else, and then back to the listening... In Qt all socket activity can of course be subscribed to as callbacks, so now the Announcer class takes care of all announcement packets, the ControlConnection class talks to application(s), and so forth.
In the process of porting the daemon I have altered the protocol slightly, which means that I also had to update the Python libraries. In doing this these have also been redesigned, making them a bit easier to read as well. They both work now, though I must admit that I am not completely satisfied with the main Python lib - but seeing as it works I will probably not get to updating it any time soon.
No comments:
Post a Comment