Why dbus
However, rather than sending byte streams over the connection, you send messages. Messages have a header identifying the kind of message, and a body containing a data payload. The message bus daemon forms the hub of a wheel. Each spoke of the wheel is a one-to-one connection to an application using libdbus.
An application sends a message to the bus daemon over its spoke, and the bus daemon forwards the message to other connected applications as appropriate. Think of the daemon as a router. The bus daemon has multiple instances on a typical computer. The first instance is a machine-global singleton, that is, a system daemon similar to sendmail or Apache. This instance has heavy security restrictions on what messages it will accept, and is used for systemwide communication.
The other instances are created one per user login session. These instances allow applications in the user's session to communicate with one another. The systemwide and per-user daemons are separate. Normal within-session IPC does not involve the systemwide message bus process and vice versa.
Each of these is tailored for particular kinds of application. D-Bus is designed for two specific cases:. Communication between desktop applications in the same desktop session; to allow integration of the desktop session as a whole, and address issues of process lifecycle when do desktop components start and stop running.
Communication between the desktop session and the operating system, where the operating system would typically include the kernel and any system daemons or processes. D-Bus is built on that experience and carefully tailored to meet the needs of these desktop projects in particular. The problem solved by the systemwide or communication-with-the-OS case is explained well by the following text from the Linux Hotplug project:.
A gap in current Linux support is that policies with any sort of dynamic "interact with user" component aren't currently supported. For example, that's often needed the first time a network adapter or printer is connected, and to determine appropriate places to mount disk drives.
It would seem that such actions could be supported for any case where a responsible human can be identified: single user workstations, or any system which is remotely administered.
This is a classic "remote sysadmin" problem, where in this case hotplugging needs to deliver an event from one security domain operating system kernel, in this case to another desktop for logged-in user, or remote sysadmin. Any effective response must go the other way: the remote domain taking some action that lets the kernel expose the desired device capabilities.
The action can often be taken asynchronously, for example letting new hardware be idle until a meeting finishes. At this writing, Linux doesn't have widely adopted solutions to such problems. However, the new D-Bus work may begin to solve that problem. D-Bus may happen to be useful for purposes other than the one it was designed for. Its general properties that distinguish it from other forms of IPC are:. Binary protocol designed to be used asynchronously similar in spirit to the X Window System protocol.
The message bus is a daemon, not a "swarm" or distributed architecture. Security features to support the systemwide mode of the message bus. Some basic concepts apply no matter what application framework you're using to write a D-Bus application.
The exact code you write will be different for GLib vs. Qt vs. Python applications, however. Here is a diagram png svg that may help you visualize the concepts that follow. Your programming framework probably defines what an "object" is like; usually with a base class. For example: java.
Let's call this a native object. However, it provides a concept called an object path. The idea of an object path is that higher-level bindings can name native object instances, and allow remote applications to refer to them. Namespacing object paths is smart, by starting them with the components of a domain name you own e. This keeps different code modules in the same process from stepping on one another's toes. Each object has members ; the two kinds of member are methods and signals. Methods are operations that can be invoked on an object, with optional input aka arguments or "in parameters" and output aka return values or "out parameters".
Signals are broadcasts from the object to any interested observers of the object; signals may contain a data payload. Both methods and signals are referred to by name, such as "Frobate" or "OnClicked". Each object supports one or more interfaces. Think of an interface as a named group of methods and signals, just as it is in GLib or Qt or Java.
Interfaces define the type of an object instance. DBus identifies interfaces with a simple namespaced string, something like org. A proxy object is a convenient native object created to represent a remote object in another process. The low-level DBus API involves manually creating a method call message, sending it, then manually receiving and processing the method reply message.
Higher-level bindings provide proxies as an alternative. Proxies look like a normal native object; but when you invoke a method on the proxy object, the binding converts it into a DBus method call message, waits for the reply message, unpacks the return value, and returns it from the native method..
When each application connects to the bus daemon, the daemon immediately assigns it a name, called the unique connection name. A unique name begins with a ':' colon character. These names are never reused during the lifetime of the bus daemon - that is, you know a given name will always refer to the same application.
An example of a unique name might be The numbers after the colon have no meaning other than their uniqueness. When a name is mapped to a particular application's connection, that application is said to own that name.
The low-level libdbus reference library has no required dependencies; the reference bus daemon's only required dependency is an XML parser expat. The bindings evolve separately from the low-level libdbus, so some are more mature and ABI-stable than others; check the docs for the binding you plan to use.
There are also some reimplementations of the D-Bus protocol for languages such as C , Java, and Ruby. These do not use the libdbus reference implementation. It should be noted that the low-level implementation is not primarily designed for application authors to use.
Rather, it is a basis for binding authors and a reference for reimplementations. If you are able to do so it is recommended that you use one of the higher level bindings or implementations. A list of these can be found on the bindings page.
The list of projects using D-Bus is growing and they provide a wealth of examples of using the various APIs to learn from. If you have any trouble with D-Bus or suggestions for improvement, bug reports and comments are very welcome.
All D-Bus discussion is currently on dbus lists. For other implementations and bindings, please use the bug tracker for the appropriate implementation. Ideally, include test suite coverage with your patch; or if you report a bug, it's good to add a test that fails even if you don't have a patch otherwise.
A final unique feature is the creation of not one but two of these buses, the system bus and the session bus. The system bus is global, system-wide and runs at the system level. All users of the system can communicate over this bus with the proper permissions, allowing the concept of system-wide events. The session bus, however, is created during user login and runs at the user, or session, level. This bus is used solely by a particular user, in a particular login session, as an IPC and remote object system for the user's applications.
Messages are sent to objects. Processes on the message bus are associated with objects and implemented interfaces on that object. D-BUS supports multiple message types, such as signals, method calls, method returns and error messages. Signals are notification that a specific event has occurred. They are simple, asynchronous, one-way heads-up messages. Method call messages allow an application to request the invocation of a method on a remote object.
Method return messages provide the return value resulting from a method invocation. Error messages provide exceptions in response to a method invocation. D-BUS is fully typed and type-safe.
Both a message's header and payload are fully typed. Valid types include byte, Boolean, bit integer, bit unsigned integer, bit integer, bit unsigned integer, double-precision floating point and string. A special array type allows for the grouping of types. D-BUS is secure. It implements a simple protocol based on SASL profiles for authenticating one-to-one connections. On a bus-wide level, the reading of and the writing to messages from a specific interface are controlled by a security system.
An administrator can control access to any interface on the bus. These concepts make nice talk, but what is the benefit? First, the system-wide message bus is a new concept. A single bus shared by the entire system allows for propagation of events, from the kernel see The Kernel Event Layer sidebar to the uppermost applications on the system. Linux, with its well-defined interfaces and clear separation of layers, is not very integrated.
D-BUS' system message bus improves integration without compromising fine engineering practices. Now, events such as disk full and printer queue empty or even battery power low can bubble up the system stack, available for whatever application cares, allowing the system to respond and react.
0コメント