Dugan Chen's Homepage

Various Things

The MPD Client Library Begins

2011-10-16

This is a follow-up from a post made a couple of days ago: I’m starting to write a reactive MPD client library for PyQt. Well, I’ve started. There has been some soul-searching since then about just how far I would like to go with this. Do I want to limited it to idle() calls (which are the only ones that aren’t expected to return data immediately) and then use python-mpd for everything else?

…in a GUI application, blocking sockets should only be used in non-GUI threads… We discourage the use of the blocking functions together with signals.

What made my decision was Nokia’s documentation. It was best, I eventually decided, to go all the way and do it right.

Here’s what I have as of now. Remember, I’ve only worked on it for a few days. My new client supports four commands: status(), update(), idle() and noidle(). As you would expect from an asynchronous data communication library, each of those commands takes a callback to handle any data sent back from the server. There is currently no error handling and no conversion of raw data into more programmer-friendly formats. It also doesn’t actually implement the Reactor pattern (although I would assume that the Qt services that I use do so underneath), and thus isn’t “reactive”. It does support both local (Unix socket) and TCP connections.

This is, enough to prove that the architecture works. The following demonstration program opens two connections. One sends commands at the request of the user (either “fetch status” or “update the server database”. The other listens for notifications that the server database has been updated. Here it is: