D-Bus
Encyclopedia
|
| Tutorials | Encyclopedia | Dictionary | Directory |
|
![]()
D-Bus
D-Bus is a free software project which offers a simple way for applications to communicate with one another. It is developed by Red Hat as part of the freedesktop.org project. D-Bus was heavily influenced by KDE2–3's DCOP system and has replaced it in the KDE 4 release; it is already implemented in Qt 4, GNOME, Windows, the maemo mobile platform, and the OLPC XO-1. In GNOME it has gradually replaced most parts of the earlier Bonobo mechanism.
IntroductionD-Bus (Desktop Bus) allows programs to register on it for offering services to others. It also offers client programs the possibility to look up which services are available. Programs can also register as waiting for events of the kernel like hot swapping hardware. D-Bus is implemented as a daemon. Users can run several instances of it, each called a channel. There will usually be a privileged system channel, and a private instance for each logged in user. The private instances are required because the system channel has access restrictions. The main mission of the system channel is to deliver the signals from the HAL (hardware abstraction layer) daemon to the processes interested in them. The mission of the private instances is to provide unrestricted communication among any applications of the user. ArchitectureD-Bus is an inter-process communication (IPC) system[1] with three architectural layers:
D-Bus is designed for two specific cases:
MechanismsEach application using D-Bus contains objects, which generally (but not necessarily) map to GObject, QObject, C++ objects, or Python objects. An object is an instance rather than a type. When messages are received over a D-Bus connection, they are sent to a specific object, not to the application as a whole. In this way, D-Bus resembles software componentry, as it appears to the user as if an object is serialized across the IPC connection, no matter if there is an object on the other side or not. To allow messages to specify their destination object, there has to be a way to refer to an object. In many programming languages, this is usually called a pointer or reference. However, these references are implemented as memory addresses relative to the address space of the application, and thus can't be passed from one application to another. To solve this, D-Bus introduces a name for each object. The name looks like a filesystem path, for example an object could be named /org/kde/kspread/sheets/3/cells/4/5. Human-readable paths are preferred, but developers are free to create an object named /com/mycompany/c5yo817y0c1y1c5b if it makes sense for their application. The D-Bus objects' names are namespaced to ensure different code modules are kept separated. Namespaces are generally prefixed with the developer's domain name components (eg. /org/kde). Implementations
ExamplesMost languages allow high-level access to D-Bus, hiding implementation details and optimizing marshalling, queuing and dispatching behind the scenes. In statically typed programming languages such as C# and Java, the interface to be used or exported must first be defined. To access HAL devices, a partial interface description in the C# language may look something like this: For the device interface:
/* an Interface attribute is applied to mark the D-Bus interface name */
[Interface ("org.freedesktop.Hal.Device")]
public interface Device
{
/* event definitions map to D-Bus signals */
event PropertyModifiedHandler PropertyModified;
/* properties and method calls map to D-Bus calls */
/* the D-Bus type system is capable of representing generic dictionaries */
IDictionary<string, object> AllProperties { get; }
/* further methods and signals omitted for brevity */
}
/* D-Bus supports arbitrary structures */
public struct PropertyModification
{
public string Key;
public bool Added;
public bool Removed;
}
public delegate void PropertyModifiedHandler (int modificationsLength,
PropertyModification[] modifications);
For the device manager interface:
[Interface ("org.freedesktop.Hal.Manager")]
public interface Manager
{
/* event definitions map to D-Bus signals */
event Action<Device> DeviceAdded;
event Action<Device> DeviceRemoved;
/* properties and method calls map to D-Bus calls */
Device[] AllDevices { get; }
bool DeviceExists (Device udi);
bool DeviceExists (ObjectPath udi);
Device[] FindDeviceStringMatch (string key, string value);
Device[] FindDeviceByCapability (string capability);
void Remove (Device udi);
/* further methods and signals omitted for brevity */
}
Once these interfaces have been defined, the programmer is able to obtain proxy objects mirroring remote counterparts and manipulate them directly as though they were in the local address space:
/* request a proxy object for the device manager from the system message bus */
Manager mgr = Bus.System.GetObject<Manager> ("org.freedesktop.Hal",
new ObjectPath ("/org/freedesktop/Hal/Manager"));
/* enumerate all devices */
foreach (Device dev in mgr.AllDevices) {
/* print the path of the object */
Console.WriteLine (dev.ToString ());
/* hook up to the PropertyModified signal of the device */
dev.PropertyModified += delegate (int modificationsLength,
PropertyModification[] modifications) {
/* when properties are modified, print the changes */
Console.WriteLine ("Properties changed on device {0}:", dev);
foreach (PropertyModification modification in modifications)
Console.WriteLine (modification.Key);
};
}
References
External links
ca:D-BUS cs:D-Bus de:D-Bus es:D-BUS fr:D-Bus it:D-Bus nl:D-Bus ja:D-Bus pl:D-BUS pt:D-Bus ru:D-Bus fi:D-Bus sv:D-Bus zh:D-BUS
Source: Wikipedia | The above article is available under the GNU FDL. | Edit this article
|
|
top
©2008-2009 TutorGig.com. All Rights Reserved. Privacy Statement