zoukankan      html  css  js  c++  java
  • 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通讯,因为它采用了二进制的数据交换协议,不需要转换成文本化的数据进行交换

    思考

    1. Dbus在进程间维持了一个长连接,但为何却不适合进程间长期保持通讯?
    2. 对于Message bus,作为守护进程,能否称之为MOM中间件?不能,但为什么?众所周知,DBus源于CORBA,这个问题可以引申为:ORB与RPC或是MOM之间的本质区别是什么?毕竟这几类产品从外观上(作用上)看都太相似了。
      答:注意,daemon并不包括消息队列——它只是实现了消息的转发——这是Message Dispatcher做的事儿,但这个过程中并没有对消息排队、存储。它只是在收到消息的第一时间保证消息被作为广播,或是路由到正确的进程上去。
    3. 类似router运行的daemon,在底层上是否就是一个broker?
      答:从其结构图上就能看出,daemon包含了一个Message Dispatcher,这个就是实现消息转发的router,当然router与broker还是有区别的。
    4. 如果Dbus的机制没有过多的依赖,且低延时、高效率,为何仅作为desktop的IPC?——它的底层用的是UNIX Domain Socket,那换成TCP/UDP不就可以联通Internet了?
      答:实际上DBus底层的通讯实现的方式由多种,包括了UDS或是TCP/UDP,但它没有将通讯拓展到Internet,这只能说明网络间的通讯还存在着某个层面的复杂度——当然这个问题有待深究,如果可以,我们可以试着将DBus用于网络消息传递和RPC应用,哈哈应该很有趣……
    5. SystemBus是否可以在终端中使用?如果是,SessionBus的区分仅仅是为了隔离不同Session传递的消息吗?
      答:是的,Debian系统默认会运行 dbus-daemon --system,即使系统没有安装桌面环境——说明SystemBus与桌面是没有关系的,它只是完成通用的系统层面的消息传递。所以,用户完全可以在终端下创建和调用SystemBus对象并进行操作。
  • 相关阅读:
    【uiautomator】Interfaces+Exception
    【uiautomator】UiDevice
    【uiautomator】Uiautomator API
    【uiautomator】运行命令
    [www.infoshare.cc]【uiautomator】输入中文(输入法安装+测试代码)
    MFC ,List使用
    VC控件DateTimePicker使用方法
    GitHub vs. Bitbucket 不只是功能不同
    免费的私人代码托管(bitbucket) 和 常用git指令
    修改android studio中的avd sdk路径、avd sdk找不到的解决方案
  • 原文地址:https://www.cnblogs.com/brt3/p/9612775.html
Copyright © 2011-2022 走看看