In the ongoing effort to enhance Podtique for mere mortals, I’m building a web server within the device to aid in configuration. I’ve chosen node.js (really, locomotive) for this. But the main code is written in C++, and I needed a way for the node.js code to communicate with the C++ process.

For now, I’ve settled on dbus for this. While the actual device runs Linux, making dbus a natural choice, I prefer to do as much development as possible on OS X, and dbus also works on OS X when installed via brew. But before you do that, there are a few caveats to getting d-bus to build and run on Yosemite (probably true of the last few OS X releases) that aren’t handled by brew out-of-the box.

Setting up dbus

Note: Be sure to remove any leftover launchd files that might’ve been installed by MacPorts. My system had symlinks pointing into /opt, but /opt did not exist.

/Library/LaunchAgents/org.freedesktop.dbus-session.plist
/Library/LaunchDaemons/org.freedesktop.dbus-system.plist
~/Library/LaunchAgents/org.freedesktop.dbus-session.plist
~/Library/LaunchDaemons/org.freedesktop.dbus-system.plist

A Google search turns up a lot of information showing both of these plist files being used, but the latest version only provides one of them, and that’s all that seems necessary.

Now install dbus:

$ brew install d-bus

As of this writing, this installs dbus 1.8.14.

dbus requires a dæmon process to be running. Thew brew formula for dbus doesn’t set that up automatically, but has some instructions to set it up. Execute the following commands to configure the dbus dæmon to run automatically:1

$ ln -sfv /usr/local/opt/d-bus/*.plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/org.freedesktop.dbus-session.plist

If launchctl reports the following:

/usr/local/Cellar/d-bus/1.8.14/org.freedesktop.dbus-session.plist: File exists

it means that it is already loaded and running (perhaps from a previous install). Try the following (you might need to sudo):

$ launchctl remove org.freedesktop.dbus-session

Note: It’s important to note that the user that starts the dbus dæmon should be the same user that will own the processes that want to communicate with that dæmon.

Setting up Xcode

Setting up Xcode is relatively straightforward. Select the appropriate target, choose the “General” tab, and click the “+” under “Linked Frameworks and Libraries.” This will open a sheet. Click “Other…” and begin typing

/usr/local/lib

Then find libdbus-1.dylib and click “Add.”

Next, click on the “Build Settings” tab and ensure that you have the following search paths added to “Header Search Paths”:

/usr/local/include/dbus-1.0
/usr/local/lib/dbus-1.0/include

Include dbus headers like this in your code:

#include <dbus/dbus.h>

  1. Note that the launchd plist provided by dbus 1.8.14 has a key that’s no longer used (not sure when it was deprecated; a google search is little help). You can just remove the ServiceIPC and associated value from the file if you see

    com.apple.xpc.launchd[1]: (org.freedesktop.dbus-session) The ServiceIPC key is no longer respected. Please remove it.
    

    printed in the Console.app log.