Skip to content

DBUS and Mad scientists...

October 15th, 2004 - TutorialSoftware(1 min)

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:

0. 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

1. Some more services 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 >

2. 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.

3. Create 2 programs

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()

client.py

#!/usr/bin/env python

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!!!!

– This is a really old post published originally on my blogspot blog

Share on
Reddit
Linked in
Whatsapp

A little experiment: