What is D-Bus?

from:https://dbus.freedesktop.org/doc/dbus-tutorial.html

What is D-Bus?

D-Bus is a system for interprocess communication (IPC). Architecturally, it has several layers: (网络通讯+消息路由+功能接口)
  • A library, libdbus, that allows two applications to connect to each other and exchange messages.
  • A message bus daemon executable, built on libdbus, that multiple applications can connect to. The daemon can route messages from one application to zero or more other applications.
  • Wrapper libraries or bindings based on particular application frameworks. For example, libdbus-glib and libdbus-qt. There are also bindings to languages such as Python. These wrapper libraries are the API most people should use, as they simplify the details of D-Bus programming. libdbus is intended to be a low-level backend for the higher level bindings. Much of the libdbus API is only useful for binding implementation.
libdbus only supports one-to-one connections, just like a raw network socket. 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. libdbus also abstracts the exact transport used (sockets vs. whatever else), and handles details such as authentication.
 
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 (SystemBus), 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 (SessionBus). 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.
 

https://dbus.freedesktop.org/doc/diagram.svg

Why is D-Bus?

There are many, many technologies in the world that have "Inter-process communication" or "networking" in their stated purpose: CORBA, DCE, DCOM, DCOP, XML-RPC, SOAP, MBUS, Internet Communications Engine (ICE), and probably hundreds more. 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.
For the within-desktop-session use case, the GNOME and KDE desktops have significant previous experience with different IPC solutions such as CORBA and DCOP. D-Bus is built on that experience and carefully tailored to meet the needs of these desktop projects in particular. D-Bus may or may not be appropriate for other applications; the FAQ has some comparisons to other IPC systems.
 
The problem solved by the systemwide or communication-with-the-OS case is explained well by the following text from the Linux Hotplug project(DBUS用以解决传统Linux IPC不能应付的远端系统管理员问题):
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).
  • Stateful, reliable connections held open over time.
  • The message bus is a daemon, not a "swarm" or distributed architecture.
  • Many implementation and deployment issues are specified rather than left ambiguous/configurable/pluggable.
  • Semantics are similar to the existing DCOP system, allowing KDE to adopt it more easily.
  • Security features to support the systemwide mode of the message bus.

思考:

  1. Dbus是实质上一个适用于桌面应用的进程间的通讯机制,即所谓的IPC机制。适合在同一台机器,不适合于Internet的IPC机制。
  2. Dbus提供了一个低时延、低消耗的IPC通讯,因为它采用了二进制的数据交换协议,不需要转换成文本化的数据进行交换
  3. Dbus在进程间维持了一个长连接,但为何却不适合进程间长期保持通讯?
  4. 对于Message bus,作为守护进程,能否称之为MOM中间件?不能,但为什么?
  5. 类似router运行的daemon,在底层上是否就是一个broker?
  6. 如果Dbus的机制没有过多的依赖,且低延时、高效率,为何仅作为desktop的IPC?——它的底层用的是UNIX Domain Socket,那换成TCP/UDP不就可以了?

猜你喜欢

转载自www.cnblogs.com/brt3/p/9612775.html