Pidgin, Network Manager, Dbus, Ruby, oh my!

A few weeks ago I was chatting with Dan about my one great annoyance with Pidgin: it takes up to 15 minutes to realize that it's network connection isn't valid any more and to automatically reconnect. With NetworkManager and dbus, this should be a reasonably simple feat. Dan got curious about this and wrote himself a python program that sets pidgin status in this way.

D-What?

A bit of background. One of the Freedesktop.org standards is d-bus:

D-Bus is a message bus system, a simple way for applications to talk to one another. In addition to interprocess communication, D-Bus helps coordinate process lifecycle; it makes it simple and reliable to code a "single instance" application or daemon, and to launch applications and daemons on demand when their services are needed.

The basic idea is that d-bus allows applications to publish interfaces that other applications on the desktop can interface with. Right now, only a few applications really support d-bus in a significant way. Fortunately, one of those is pidgin, which has an extremely rich d-bus interface.

Ruby & DBUS

Here's a place where I know I'll draw Dan's ire. I've been on a Ruby kick recently, so my first reaction to Dan's post was "great, I'll have to figure out how to do this in ruby now." It sounds like typical language bias, but I'll try to justify it at least a little.

Right now I'm writing code on a weekly basis in 3 languages: C# (OpenSim), Java (Grad School Project), and Ruby (side web projects done in Rails). 3 languages is a lot to remain fluent in, and causes some interesting syntax errors when jumping back and forth between them. One less context switch seemed like a good idea. At some point I'll bother writing up why ruby has seduced me, but that is for another day.

While finding python-dbus bindings are extremely straight forward, the ruby-dbus front is a little more of a wandering path. After finding a couple of abandoned efforts, I finally came to the active ruby-dbus project. Make sure to grab the latest and greatest code from there before proceeding.

Connecting to DBUS

Before I get into actually using dbus, I need to set up connections to it. There are 2 different buses, the system bus (which is shared for all users), and the session bus, which is unique per login session. Pidgin uses the session bus: it's a user application. Network Manager uses the system bus: it's events are system wide and affect all users.

Basically the pattern is clear. Get a service handle, get an object definition from that service handle, then get an interface from that object. There are 2 flavors for this, one where we've got introspection information, and one where we've got to go blind because introspection isn't supported.

DBUS Introspection

DBUS interfaces come in 2 flavors, those that support introspection, and those that don't. If an interface supports introspection you can get an interface definition off the dbus wire itself, otherwise you need to know the interface a priori. Pidgin supports introspection, Network Manager does not. The major short coming of the ars technica article on Pidgin and DBUS was the lack of information on using introspection to show all the other pidgin interface functions (of which there are > 600). Python dbus introspection throws an exception on my Ubuntu 7.10 environment, so it wasn't helpful here. However, ruby, as usual, came to the rescue.

The ruby-dbus code contains an example application called gd-bus, which performs introspection on all dbus interfaces it can find, and prints them out nicely. The cheat sheet goes something like so:

M PurpleAccountsFind(in name:s, in protocol:s, out RESULT:i)

  • M - DBUS Method, aka Function (might also be S meaning it's a Signal you can register to listen to)
  • PurpleAccountsFind - the method name
  • in / out - whether this is an input or output parameter
  • NAME:type - the name and type of the parameter. Types can be s - string, i - integer, u - unsigned int, ai - array of integers

Note: the ruby interface seems to always wrap arrays around the output parameters. I have no idea why, but it's consistent, so a few extra "[0]"s get you a long ways. If you know why, please comment.

The translation of this interface specification into ruby gives you something like this:

This cycles through all pidgin accounts, disconnects all the connected ones, and then attempts to connect all accounts. This is effectively what I end up doing by hand every time I switch networks with my laptop.

Bringing it all together

I now had connections to the 2 buses, and code to cycle the pidgin accounts. Last bit is actually watching for the Network Manager signal that I've got a new active network device.

Network manager doesn't support introspection. However, it does have pretty decent docs to figure out what the interface is. I'm still sad it doesn't show up nicely in gd-bus though.

The proxy interface object sets up a signal using 2 parameters and a code block. Every time there is a DeviceNowActive signal on the system bus, I recycle pidgin. Pretty straight forward.

The last little bit is making this thing go into a loop. Ruby dbus contains it's own main loop for just this task. I created a new main loop, tell it to watch the system bus, and then start it. And, we're done.

The future's so bright...

DBUS has been on my list of "I need to go figure this out" for a while. A morning of reading docs, hacking a bit, and crashing network manager a few times, and voila, you've got this blog post.

I've got lots of ideas floating around in my head now for other things that I can do with dbus to make my applications work better for me. As I bang a few of those out into code, expect to see more here about it. Pidgin is an especially target rich environment given how rich and interface they expose (nice job guys!).

Give the gift of Open Software this holiday season

In the spring I came across The Open Disc, which is a collection of the best open source software for Microsoft Windows. This includes things such as: The Gimp, OpenOffice, Firefox, Thunderbird, Scribus, a bunch of Astronomy programs, and many more very useful applications. All are Open Source, and freely redistributable. This is a great additional gift to add into your holiday traditions!

I've made the following label (based on an early OpenCD design). Feel free to use or modify to your hearts content. Scribus source files are available as well:

Linux native Logitech Harmony software

While looking for a solution to my VMWare / USB issue, I came across a Linux.com article:
Developer crafts Linux support for Logitech Harmony remote controls.

Instead of using the Windows GUI to program the remote, you use the Logitech website (the windows gui is basically a fancy version of that). When you are done, you download a .EZHex file which you can then sync in Linux to your remote.

I haven't tried it yet, though it is on my list of things to do. For those who have stayed away from the Logitech Harmony remotes because they required Windows, you need no longer live in the dark ages of remote controls.

USB Passthrough with VMWare and Ubuntu 7.10

While I don't run windows on any physical hardware, I have a VMWare windows xp guest on my laptop that I use for a couple of applications. One of which is the programming software for my Logitech Harmony remote.

In my recent laptop update to Ubuntu 7.10, VMWare Server lost the ability to pass through the USB bus to the guest. Fortunately, a quick search on the VMWare forums came up with the following:

Please open the following file: /etc/init.d/mountdevsubfs.sh by following command - gksudo gedit /etc/init.d/mountdevsubfs.sh

Find the following lines:
#mkdir -p /dev/bus/usb/.usbfs
#domount usbfs "" /dev/bus/usb/.usbfs -obusmode=0700,devmode=0600,listmode=0644
#ln -s .usbfs/devices /dev/bus/usb/devices
#mount --rbind /dev/bus/usb /proc/bus/usb

Unmark them so that look like this:
mkdir -p /dev/bus/usb/.usbfs
domount usbfs "" /dev/bus/usb/.usbfs -obusmode=0700,devmode=0600,listmode=0644
ln -s .usbfs/devices /dev/bus/usb/devices
mount --rbind /dev/bus/usb /proc/bus/usb

Restart and your usb devices will be recognised

This worked like a champ, and now I can do the rest of my pre thanksgiving tweaks on the remote. 🙂

Eben Moglen's invited talk at IBM Research

About 3 weeks ago Eben gave an invited talk at IBM Research about Copyleft Capitalism, which I'm kicking myself for not driving down to see in person. Fortunately it has been posted to Google Videos:

(direct link for those whose RSS viewer doesn't do flash)

The talk weighs in at 91 minutes, and is really worth watching the whole thing. Unfortunately the audience isn't miked, so there are some areas of silence which are a little awkward, but that doesn't detract much from the talk. Eben is an incredibly engaging speaker, and weaves a wonderful narative around free software, and the software commons.

While there are so many interesting points that Eben makes, I found the most fascinating one to be about how creativity can not be contained and controlled. When the industry attempts to do so you get bursts of irrational creativity, such as Perl. Perl is about getting things done, and it does so by hook or crook, based on whatever made sense to go into the language during last saturday's hack fest. While it disgusts many of the purists in language design, it shows that sometimes "just get it done" does work. Beauty isn't everything. (Steve Yegge's take on perl is also hillarious and dead on.)

This is one nugget of dozens in the talk. I think I'll need to go back and watch the thing at least once more to make sure I've absorbed it all.

Dague's Rule 47: if Eben Moglen is speaking anywhere within driving distance, I must travel to the talk.

A google mystery

Over the summer I moved my blog from livejournal to wordpress.  There were a lot of reasons to do this, and overall my experience has been very good with wordpress.

Once google indexed me, it came up with the following:

Dague, Sean

Includes personal information, photographs, family, and friends.
dague.net/ - 34k - Cached - Similar pages - Note this

Which was odd.  That description didn't show up anywhere on my site.  At first I marked it up to finding a new wordpress installation, but others didn't seem to have it.  Then I marked it up to the xfn tag in the headers, but removing that didn't seem to help either.

Then, today, I found something that makes this officially declared as a mystery.  I did a google search on the phrase If you search google on the phrase "Includes personal information, photographs, family, and friends.".  Guess how many hits are found?

No... really... guess.

I don't think you actually guessed yet...

Seriously, this is more fun if you play along.

Web  Results 1 - 6 of 6 for "Includes personal information, photographs, family, and friends.". (0.24 seconds) 


6... 6 ?!?!

And I am 5 of the 6 hits.  Ok, what is going on here?  Anyone with any theories would be appreciated.  While it is amusing, I'd love to actually get real content indexed for dague.net again.  Feedback appreciated as comments.

The Chumby

After reading cote's blog post on the chumby, I got intrigued.  The chumby is a small linux device, specifically designed to run flash based widgets, served up from the chumby servers.  It looks like and interesting device, priced at a reasonable price point, and eminently hackable.

The only dig seems to be the Developers Agreement, especially section 3.1:

...

Your Modified Device and/or Licensee Applications must comply with the following: (i) your Modified Device and Licensee Applications must not enable you or anyone else to access the Chumby Service and/or servers without an active network ID issued by Chumby; (ii) your Modified Device and Licensee Applications must not block or interfere with any advertisement that is served by or distributed through the Chumby Service and/or servers; and (iii) any Modified Device or Licensee Application that connects to a Consumer Content Network must also enable the end user to connect the Modified Device and Licensee Application to the Chumby Service in substantially the same manner as the Modified Device or Licensee Application connects to the Consumer Content Network.

Which pretty much counts me out.  The license which is "you can only write software for our device that registers with our service, and that serves our ads" seems to completely miss the mark of having a fun, openly hackable device.  It's frustrating when a consumer electronics company comes so close to making an open piece of hardware, but then freaks out at the last minute with their licensing and substantially shuts down their community growth in the process.  Hopefully they'll realize that and adjust their license in the future to be actually open.

Giving of a different nature for the holiday season

"We have so much... stuff.  None of us really need any more of it this year.  And yet all of the world there  are people that don't have enough.  Wouldn't it be better if we got someone a goat than giving each other more stuff?"    

      - my mother, 4 years ago

That was the beginning of changing our Dague family Christmas traditions.  We don't do gifts to each other any more, but instead give something to some cause that each of us cares about.  It takes a major stress point out of the holidays, leaving only what is important behind: spending quality time with people you love.

This year my contributions are coming in two forms, and as time is running out on one, it seemed a good idea to post soon.

One Laptop Per Child

The One Laptop Per Child project has been nothing if not ambitious.  The idea is to develop a portable computer specifically designed for developing countries, and distribute millions of them to children in these countries.  It has wireless, mesh networking, and a set of base applications that let you do email, web browsing, instant messaging, simple programing, and a whole host of specific educational software to boot. 

From now until November 26 you can Give One Get One, where you purchase 2 laptops, you get one sent to you, and one goes to a child in one of the participating countries.  I purchased mine the other day.  It runs all Linux and open source software, so I'm pretty excited to get mine, and that some possibly budding geek in another part of the world is going to get one because of me.

I'm also looking forward to ways in which I may be able to contribute to the software environment on the XO pc.  With any luck it will even get here prior to my trip to India, as it would be interesting to bring along on that adventure.

Kiva

Kiva is a microfinance organization, which lends small scale loans (usually a couple hundred US dollars) to individuals through out the developing world.  When you participate in kiva you transfer money into their system, then you decide which loans you would like to support.  Once the loan is repayed, you get your money back.  You can reloan it to other individuals, or withdraw it from the system.  It isn't a gift, per say, but it does enable individuals to bootstrap themselves.

Chris has been active with Kiva for a while, selling Kiva products to help raise money for the core organization.  I need to thank him for making me aware of the organization, and micro lending in general.