D-Bus

From Openmoko

(Difference between revisions)
Jump to: navigation, search
(topsort)
m (remove link to outdated page)
 
(9 intermediate revisions by 8 users not shown)
Line 1: Line 1:
[[Openmoko]] uses '''D-Bus''', a message bus system which provides a simple way for applications to talk to one another and to be available as services in the system. If the application providing the service is not running when a message is sent, the application will be started.
+
Openmoko uses '''[http://www.freedesktop.org/wiki/DBus D-Bus]''', a [http://en.wikipedia.org/wiki/Middleware middleware] message bus system which provides a simple way for applications to talk to one another and to be available as services in the system. If the application providing the service is not running when a message is sent, the application will be started.
  
 
There are two separate busses:
 
There are two separate busses:
Line 9: Line 9:
 
These can at least be defined in /usr/share/dbus-1.0/services/ and /usr/share/dbus-1/services/
 
These can at least be defined in /usr/share/dbus-1.0/services/ and /usr/share/dbus-1/services/
  
* org.openmoko.Dialer
 
 
* org.gnome.evolution.dataserver.AddressBook
 
* org.gnome.evolution.dataserver.AddressBook
 
* org.gnome.evolution.dataserver.Calendar
 
* org.gnome.evolution.dataserver.Calendar
Line 19: Line 18:
 
There is information about these in /etc/dbus-1/system.d/
 
There is information about these in /etc/dbus-1/system.d/
  
 +
* org.freesmartphone.*
 
* org.freedesktop.Avahi
 
* org.freedesktop.Avahi
 
* org.bluez.*
 
* org.bluez.*
Line 27: Line 27:
 
=== Command line ===
 
=== Command line ===
  
For simple uses, there's a command dbus-send.  
+
For simple uses, there's a command mdbus. Try
 +
<pre>
 +
mdbus -s
 +
</pre>
 +
to explore the DBus environment.
  
For example, to dial a number:
+
For example, to dial a number (using FSO milestone 3):
dbus-send --print-reply --dest="org.openmoko.Dialer" /org/openmoko/Dialer org.openmoko.Dialer.Dial string:12345
+
<pre>
 +
mdbus -s org.freesmartphone.ogsmd /org/freesmartphone/GSM/Device org.freesmartphone.GSM.Call.Initiate \'12345\' 'voice'
 +
</pre>
  
 
=== Python ===
 
=== Python ===
  
To use D-Bus in [[Python]], the package python-dbus needs to be compiled and installed.
+
To use D-Bus in [[Python]], the package python-dbus needs to be compiled and installed. Note that since the interfaces change over time you might want to read the source code of zhone from git.freesmartphone.org to get examples of current API.
  
 
To dial a number:
 
To dial a number:
Line 40: Line 46:
 
#!/usr/bin/env python
 
#!/usr/bin/env python
 
import dbus
 
import dbus
bus = dbus.SessionBus()
+
bus = dbus.SystemBus()
 +
gsm_device_obj = bus.get_object("org.freesmartphone.ogsmd", "/org/freesmartphone/GSM/Device")
 +
gsm_call_iface = dbus.Interface(gsm_device_obj,'org.freesmartphone.GSM.Call')
 
proxy = bus.get_object("org.openmoko.Dialer", "/org/openmoko/Dialer")
 
proxy = bus.get_object("org.openmoko.Dialer", "/org/openmoko/Dialer")
interface = dbus.Interface(object, "org.openmoko.Dialer")
+
gsm_call_iface.Initiate("12345", "voice")
interface.Dial("12345")
+
# or this: proxy.Dial("12345", dbus_interface="org.openmoko.Dialer")
+
 
</pre>
 
</pre>
  
The first "org.openmoko.Dialer" is the ''bus name'' of the service on the bus and "/org/openmoko/Dialer" is an ''object path'' in the service. Before calling a method on the object via the ''proxy object'' we still need to specify which ''interface'' the method belongs to: the second (and third) "org.openmoko.Dialer". Finally "Dial" is the method in the interface.
+
To run the program use the following:
 +
<pre>
 +
dbus-launch python my_program.py
 +
</pre>
  
 
== See also ==
 
== See also ==
* [[Dbus device API]]
+
* [[OpenmokoFramework/mdbus]]
  
 
== External links ==
 
== External links ==
* [http://www.freedesktop.org/wiki/Software/dbus dbus homepage]
+
* [http://docs.freesmartphone.org/ DBus API documentation]
 +
* [http://dbus.freedesktop.org/doc/dbus-python/api/ DBus Python API]
 
* [http://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html dbus-python tutorial]
 
* [http://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html dbus-python tutorial]
  
 
[[Category:D-Bus| ]]
 
[[Category:D-Bus| ]]
[[Category:Application Developer]]
 

Latest revision as of 11:48, 12 September 2009

Openmoko uses D-Bus, a middleware message bus system which provides a simple way for applications to talk to one another and to be available as services in the system. If the application providing the service is not running when a message is sent, the application will be started.

There are two separate busses:

  • a system bus for root which runs whenever the phone is on
  • a session bus which is started for the user when X starts

Contents

[edit] Session bus services

These can at least be defined in /usr/share/dbus-1.0/services/ and /usr/share/dbus-1/services/

  • org.gnome.evolution.dataserver.AddressBook
  • org.gnome.evolution.dataserver.Calendar
  • org.gnome.GConf
  • ...

[edit] System bus services

There is information about these in /etc/dbus-1/system.d/

  • org.freesmartphone.*
  • org.freedesktop.Avahi
  • org.bluez.*
  • ...

[edit] Accessing the services

[edit] Command line

For simple uses, there's a command mdbus. Try

mdbus -s 

to explore the DBus environment.

For example, to dial a number (using FSO milestone 3):

mdbus -s org.freesmartphone.ogsmd /org/freesmartphone/GSM/Device org.freesmartphone.GSM.Call.Initiate \'12345\' 'voice'

[edit] Python

To use D-Bus in Python, the package python-dbus needs to be compiled and installed. Note that since the interfaces change over time you might want to read the source code of zhone from git.freesmartphone.org to get examples of current API.

To dial a number:

#!/usr/bin/env python
import dbus
bus = dbus.SystemBus()
gsm_device_obj = bus.get_object("org.freesmartphone.ogsmd", "/org/freesmartphone/GSM/Device")
gsm_call_iface = dbus.Interface(gsm_device_obj,'org.freesmartphone.GSM.Call')
proxy = bus.get_object("org.openmoko.Dialer", "/org/openmoko/Dialer")
gsm_call_iface.Initiate("12345", "voice")

To run the program use the following:

dbus-launch python my_program.py

[edit] See also

[edit] External links

Personal tools

Openmoko uses D-Bus, a message bus system which provides a simple way for applications to talk to one another and to be available as services in the system. If the application providing the service is not running when a message is sent, the application will be started.

There are two separate busses:

  • a system bus for root which runs whenever the phone is on
  • a session bus which is started for the user when X starts

Session bus services

These can at least be defined in /usr/share/dbus-1.0/services/ and /usr/share/dbus-1/services/

  • org.openmoko.Dialer
  • org.gnome.evolution.dataserver.AddressBook
  • org.gnome.evolution.dataserver.Calendar
  • org.gnome.GConf
  • ...

System bus services

There is information about these in /etc/dbus-1/system.d/

  • org.freedesktop.Avahi
  • org.bluez.*
  • ...

Accessing the services

Command line

For simple uses, there's a command dbus-send.

For example, to dial a number:

dbus-send --print-reply --dest="org.openmoko.Dialer" /org/openmoko/Dialer org.openmoko.Dialer.Dial string:12345

Python

To use D-Bus in Python, the package python-dbus needs to be compiled and installed.

To dial a number:

#!/usr/bin/env python
import dbus
bus = dbus.SessionBus()
proxy = bus.get_object("org.openmoko.Dialer", "/org/openmoko/Dialer")
interface = dbus.Interface(object, "org.openmoko.Dialer")
interface.Dial("12345")
# or this: proxy.Dial("12345", dbus_interface="org.openmoko.Dialer")

The first "org.openmoko.Dialer" is the bus name of the service on the bus and "/org/openmoko/Dialer" is an object path in the service. Before calling a method on the object via the proxy object we still need to specify which interface the method belongs to: the second (and third) "org.openmoko.Dialer". Finally "Dial" is the method in the interface.

See also

External links