Friday, November 27, 2009

Binding keyboard shortcuts to Subclipse commands in Eclipse

I have just created a small screencast about how to bind keyboard shortcuts to Subclipse commands within Eclipse. Now I can add, commit, and diff files without having to use my mouse - and I'm using the same Emacs shortcuts that I know and love :-)



B.t.w., it is cool how products like iShowU HD makes it incredibly easy to create screencasts. I've probably spent more time writing this blog entry than actually creating and uploading the video ;-)

Tuesday, November 24, 2009

Presence2 beta 2 released

I found some bugs in the Python lib for the new version of Presence. These have now been fixed and therefore a second beta has been released. Grab it at the Presence Google Code page.

Friday, November 20, 2009

TeXlipse build that actually works...

I am currently writing an article - which under normal circumstances means that I am working in Emacs (Aquamacs f.t.w.!) using AUCTeX, RefTeX, flyspell etc. But this time around I wanted to try something new, so I installed the TeXlipse plugin for Eclipse and started writing.

I quickly faced a major problem though: If you, like any sane person, split up your document into smaller files and then \include or \input these files in some master file, then the auto completion of BiBTeX references does not work in TeXlipse. This is a known bug - it has been known for almost six months, and yet they haven't released a bugfix release!

I have therefore built TeXlipse from CVS instead, and that seems to be working so far. You can fetch this build here. It was built using the CVS head as of today...

Note: This build may have other bugs - it is _just_ a build of the TeXlipse CVS head.

Friday, November 6, 2009

Presence 2.0.0-b1 Released

I have just released the first beta of Presence2 (or qPresence as I also call it because of its Qt dependencies). I have put up downloadables for the daemon, the Python API, and the "daemonless" Python API (the one that allows for listening in on Presence announcements without running the Presence daemon).

Because of the new Qt dependencies you need to install the Qt library and SDK in order to build the daemon. You can fetch these at Nokia's Qt page.

Grab 'em while they're hot!

Thursday, November 5, 2009

Byte Order Conversion in Qt

For my recent re-writing of Presence to use the Qt library, I needed to be able to do byte order swapping on two and four byte integers (short and int). This I used when serializing/marshalling/packing stuff up before transmitting them over the wire. I know that the "right" way of doing that in Qt would be to use QDataStream, which will then handle stuff like byte order conversion, but I needed to be able to pack my own data, so that a QDataStream-capable reader was not required on the other side of the socket connection.

Byte order conversion is done using the four functions (macros really) called htons, ntohs, htonl, and ntohl that may be found in inet/arpa.h on any Unix system. So of course I included that file and went happily on with my coding. But... when I tried to compile my new version of Presence under Windows I realized that inet/arpa.h does not exist on Windows. It probably resides in winsock.h I guess, but I _really_ do not want to have platform specific code in my project, so I decided to implement them myself instead :-)

Using Qt you can ask for your systems endianness by using the QSysInfo class, so a portable implementation of the needed functions is easy to do:
#define BYTE_SWAP4(x) \
(((x & 0xFF000000) >> 24) | \
((x & 0x00FF0000) >> 8) | \
((x & 0x0000FF00) << 8) | \
((x & 0x000000FF) << 24))

#define BYTE_SWAP2(x) \
(((x & 0xFF00) >> 8) | \
((x & 0x00FF) << 8))

quint16 _htons(quint16 x) {
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
return x;
}
else {
return BYTE_SWAP2(x);
}
}

quint16 _ntohs(quint16 x) {
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
return x;
}
else {
return BYTE_SWAP2(x);
}
}

quint32 _htonl(quint32 x) {
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
return x;
}
else {
return BYTE_SWAP4(x);
}
}

quint32 _ntohl(quint32 x) {
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
return x;
}
else {
return BYTE_SWAP4(x);
}
}


Note that the functions have a '_' prepended - otherwise some compilers may get confused.

Using these functions I do not need to have any platform specific code in my project. This comes at the cost of actually doing a function call when byte order conversion is needed, as opposed to simply using a macro. So if your code is very performance critical you should not use this code - but then again, if your code is that performance critical you should probably not be using C++ ;-)

Wednesday, November 4, 2009

Complete rebuild of Presence

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.