Today I want to describe how to use D-Bus in Qt and more in detail how to use the Ofono-D-Bus-API in a Qt-Application. The Qt-Application is separated in two parts, the C++ part and the QML part. I’m going to describe how you can get the Ofono-D-Bus-API into a Qt application and how you can connect your QML part to the methods ands signals.
For all who don’t know D-Bus, it’s a interprocess communication system which is the standard on linux desktop systems and used on embedded platforms as well. It has replaced Bonobo/Corba on GNOME and DCOP on KDE. D-Bus has language bindings to all the major programming languages. For Qt you don’t need any additional library.
Ofono is an abstraction layer for GSM-Modems. It’s mainly developed by Intel and Nokia to use it in the upcoming MeeGo-Distribution.
So how to use these components to create great new phone applications? Let’s describe that in a few steps.
First of all, I assume you don’t have a GSM-Modem connected to your development computer. Therefore we use a tool the simulate this part. Phonesim is a great tool for that and it’s fairly easy to install:
git clone git://git.freesmartphone.org/phonesim.git cd phonesim qmake make ./phonesim -p 12345 -gui modems/generic.xml
After executing the last line, you won’t see anything. Phonesim will wait until it gets a connection through the given port (-p) and the right AT-Commands to activate the simulated GSM-Modem. But our intention is not to do this manually! We want Ofono to do this for us, so let’s install it.
Hint: There is also a Ofono-Branch of Phonesim. It’s located at: git://git.kernel.org/pub/scm/network/ofono/phonesim.git
git clone git://git.kernel.org/pub/scm/network/ofono/ofono.git cd ofono ./bootstrap ./configure make make install
The bootstrap command creates the configure script with the autotools. Without any additional configure parameters, the installed configuration file will be located in /usr/local/etc/ofono/modem.conf. There we need to add our simulated GSM-Modem Phonesim.
[phonesim] Driver=phonesim Address=127.0.0.1 Port=12345
Ok, now let’s run Ofono:
export OFONO_AT_DEBUG=1 ofonod -nd '*'
The exported variable and the given arguments give you a reasonably output to detect errors. The command must be run as root because it creates a service on the D-Bus system bus. If you don’t want Ofono to run as root, change the policy in /etc/dbus-1/system.d/ofono.conf:
<policy user="devel"> <allow own="org.ofono"/> <allow send_destination="org.ofono"/> </policy>
Change the user= entry accordingly.
Activate the modem
Now it’s time to activate the modem to see if everything is working well. Therefore we need dbus-send to send the suitable command to the Ofono-D-Bus-API:
dbus-send --print-reply --system --dest=org.ofono /phonesim org.ofono.Modem.SetProperty string:"Powered" variant:boolean:"true"
Now you should see the Phonesim application window popping up.
With dbus-send you can execute further methods on the Ofono-D-Bus-API. In part 2 I’ll describe how to connect to the API from within Qt.
- Necessary bootstrap command added to the ofono install listing.
- Hint to the Ofono-Branch of Phonesim added.