TL;DR: This post is about an experience I had in 2004 and it’s part of my consolidating technical posts I wrote in time. It may or may not be relevant to today’s technologies.

For the last while I was poking around with the glorious D-BUS... As it's always the case with new cutting edge technology, it's done by one or more very good, brilliant one might say (posh british accent here) people. I always have this image of "mad scientist" associated with that :).

DBUS is great, is monumental, but it took me 2 weeks to make the darn thing work with suse (stand-alone I mean). So I'm writing a tiny bit of a tutorial to show what you need to make DBUS work on SuSE:

Install

Install Guru's dbus stuff, then add a file: /etc/rc.d/dbus:

#! /bin/sh
### BEGIN INIT INFO
# Provides:       dbus
# Default-Start:  3 4 5
# Default-Stop:   0 1 2 6
# Description: dbus, a message bus daemon
### END INIT INFO

. /lib/lsb/init-functions
. /etc/rc.status
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DBUS_OPT=--system
DBUS_BIN=/usr/bin/dbus-daemon-1
test -x $DBUS_BIN || exit 5

case "$1" in
    start)
        echo -n "Starting the Message Bus Daemon"
        startproc $DBUS_BIN $DBUS_OPT && log_success_msg
        ;;
    stop)
        echo -n "Shutting down the Message Bus Daemon"
        killproc -TERM $DBUS_BIN && log_success_msg
        rm -f /var/run/dbus/pid
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    force-reload)
        echo "Reloading the Message Bus Daemon"
        killproc -HUP $DBUS_BIN
        ;;
    reload)
        echo -n "Reloading the Message Bus Daemon"
        killproc -HUP $DBUS_BIN
        ;;
    status)
        echo -n "Checking for the Message Bus Daemon: "
        checkproc $DBUS_BIN
        rc_status -v
        ;;
    *)
        echo "Usage: $0 {start|stop|status|restart|force-reload|reload|probe}"
        exit 1
        ;;
esac

More services

Some more services need to be allowed... In /etc/dbus-1/system.d add a file named "netapplet.conf":

<!DOCTYPE busconfig PUBLIC
    "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
    "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy context="mandatory">
        <allow send_interface="laur.netconfig"/>
        <allow own="laur.netconfig"/>
</policy>
</busconfig>

Run

To start dbus run /etc/rc.d/dbus start. If you don't see a green "done", then something is wrong.

NOTE: this will start the system bus!!!! one should be VERY restrictive with this.

Programming

To demo the dbuss process, I created 2 programs in python, using the dbus and gtk bindings.

The server

The server program is designed to be actually a provider (i.e. generate objects and send them via dbus).

#!/usr/bin/env python
#
# server.py

import dbus

import pygtk
import gtk

class SomeObject(dbus.Object):
    def __init__(self, service):
        dbus.Object.__init__(self, "/", service, [self.HelloWorld])

    def HelloWorld(self, message, hello_message):
        print (hello_message)
        return ["Hello", "from example-service.py"]

messagebus = dbus.SystemBus()
service = dbus.Service("laur.netconfig", bus=messagebus)
object = SomeObject(service)

gtk.main()

The client

The client is designed to consume such objects.

#! /usr/bin/env python
#
# client.py

import dbus

bus = dbus.SystemBus()
remote_service = bus.get_service("laur.netconfig")
remote_object = remote_service.get_object(
    "/",
    "laur.netconfig"
)

hello_reply_list = remote_object.HelloWorld(
    "Hello from example-client.py!"
)

print (hello_reply_list)

Run them and WATCH DA MAGIC!!!!

Original post is here.

HTH,