D-Bus Basic in Linux

D-Bus详解
D-Bus是一种用于进程间通信的技术,支持系统事件总线及进程间的对等通信。本文介绍了D-Bus的基本概念、组件、对象模型和服务激活机制,并探讨了消息路由与认证协议。

最近在研究Linux上的新型技术,发现D-Bus是一个关于平台infrastructure方面的关键技术。这里就总结了一些技术要点作为一个basic的介绍。以后希望能有更多的时间来补充更多细节性的东西。本文其中大都是拷贝有关的英文原文按自己的理解重新编排而成。

What is D-Bus?

 

  1. a system for interprocess communication (IPC).
  2. an inter-process communication framework that lets applications interface with the system event bus
    as well as allowing them to talk to one another in a peer-to-peer configuration.

D-Bus usecases

1) within-desktop-session

在linux系统中,每个用户登录后就对应一个用户的Session,在该Session下所有的应用程序可以用此Session的D-Bus进行通信
2) communication-with-the-OS

在系统范围内,不同模块直接可以用系统范围的d-bus进行通信


D-Bus characters

  1. Binary protocol designed to be used asynchronously
  2. State, reliable connections held open over time
  3. The message bus is a daemon
  4. Many implementation and deployment issues are specified rather than left ambiguous/configurable/pluggable
  5. Semantics are similar to the existing DCOP system, allowing KDE to adopt it more easily
  6. Security features to support the systemwide mode of the message bus


D-Bus components

  • dbus library

one-to-one connections, just like a raw network socket
Messages have a header identifying the kind of message, and a body containing a data payload
abstracts the exact transport used (sockets vs. whatever else)
handles details such as authentication

  • message bus daemon
  1. A router
  2. Multiple instances
  3. first instance is a machine-global singleton, used for system wide communication
  4. Other instances are created one per user login session. Allow applications in the user's session to communicate with one another


Language Binding


1) C binding is based on GLib
2) Java, Perl and Python
3) Qt  http://doc.trolltech.com/4.2/intro-to-dbus.html

 http://www.freedesktop.org/wiki/Software/DBusBindings


D-Bus Object Model

  • Object (at the end point of D-Bus is object, object is for client offer its services on bus. One client can create any number  of objects)
    1.1)Object name (object path )
    looks like a filesystem path. for example an object could be named /org/kde/kspread/sheets/3/cells/4/5
    1.2)Methods and Signals
    1.2.1)Each object has two kinds of members: methods and signals 
    1.2.2)Methods are operations that can be invoked on an object
    1.2.3)Signals are broadcasts from the object to any interested observers of the object; signals may contain a data payload.
    1.3)Interfaces
    Each object supports one or more interfaces. a named group of methods and signals
    DBus identifies interfaces with a simple namespaced string, something like org.freedesktop.Introspectable
  • proxy object
    a convenient native object created to represent a remote object in another process
    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..

Address & Connection

  • Address
    Every bus has an address describing how to connect to it
    It can be:
    .)a domain socket file name unix:path=/tmp/abcdef
    .)TCP/IP Sockets
    .)Any other transport
  • Connection
    When each application connects to the bus daemon, the daemon immediately assigns it a name, called the unique connection name
    When a connection is set up, the bus immediately assigns it an immutable bus name that it will retain for as long as the bus exists.


Message

  • Types

a)Method call
messages ask to invoke a method on an object.
b)Method return
messages return the results of invoking a method.
c)Error messages
return an exception caused by invoking a method.
d)Signal messages
are notifications that a given signal has been emitted

  • message has a header, including fields, and a body, including arguments
    a) Header
    Hold the address info
    b) Body
    Zero or more arguments
  • The maximum length of a message, including header, header alignment padding, and body is 2 to the 27th power or 134217728


Service D-Bus activation

  • dbus daemon to automatically start a program that provide a given service
  • A service is a program that can be launched by the bus daemon to provide some functionality to other programs. Services are normally launched according to the bus name they will have.
  • To find an executable corresponding to a particular name, the bus daemon looks for service description files. Service description files define a mapping from names to executables.


Message Routing

  • When a message is routed through the bus it is compared to clients' match rules. If any of the rules match, the message is dispatched to the client. If none of the rules match the message never leaves the bus.
  • An example of a map rule:
    "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='Foo',path='/bar/foo',destination=':452345.34',arg2='bar'"


Differences with other IPC

  • it is not only an IPC system; it also includes lifecycle tracking, service activation, security policy, and other higher-level structure and assumptions.
  • Other IPCs
    Corba
    XML-RPC SOAP
    DCOM COM
    DCOP

Authentication protocol

  • Map from SASL

SASL is the Simple Authentication and Security Layer, a method for adding authentication support to connection-based protocols. To use SASL, a protocol includes a command for identifying and authenticating a user to a server and for optionally negotiating protection of subsequent protocol interactions. If its use is negotiated, a security layer is inserted between the protocol and the connection.

  • Commands

2.1)Commands from the client to the server are as follows:
AUTH [mechanism] [initial-response]
CANCEL
BEGIN
DATA <data in hex encoding>
ERROR [human-readable error explanation]
2.2)From server to client are as follows:
REJECTED <space-separated list of mechanism names>
OK <GUID in hex>
DATA <data in hex encoding>
ERROR
Unofficial extensions to the command set must begin with the letters "EXTENSION_", to avoid conflicts with future official commands. For example, "EXTENSION_COM_MYDOMAIN_DO_STUFF".


Standard Interfaces

  1. org.freedesktop.DBus.Peer
    org.freedesktop.DBus.Peer.Ping ()
    org.freedesktop.DBus.Peer.GetMachineId (out STRING machine_uuid)
  2. org.freedesktop.DBus.Introspectable
    org.freedesktop.DBus.Introspectable.Introspect (out STRING xml_data)
  3. org.freedesktop.DBus.Properties
    org.freedesktop.DBus.Properties.Get (in STRING interface_name, in STRING property_name, out VARIANT value);
    org.freedesktop.DBus.Properties.Set (in STRING interface_name, in STRING property_name, in VARIANT value);
    org.freedesktop.DBus.Properties.GetAll (in STRING interface_name, out DICT<STRING,VARIANT> props);  

Example of D-Bus Usage


http://dbus.freedesktop.org/doc/dbus/libdbus-tutorial.html

References


http://www.freedesktop.org/wiki/Software/dbus

http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide/DBus/DBus_Basics

 

 

 

本研究基于扩展卡尔曼滤波(EKF)方法,构建了一套用于航天器姿态与轨道协同控制的仿真系统。该系统采用参数化编程设计,具备清晰的逻辑结构和详细的代码注释,便于用户根据具体需求调整参数。所提供的案例数据可直接在MATLAB环境中运行,无需额外预处理步骤,适用于计算机科学、电子信息工程及数学等相关专业学生的课程设计、综合实践或毕业课题。 在航天工程实践中,精确的姿态与轨道控制是保障深空探测、卫星组网及空间设施建设等任务成功实施的基础。扩展卡尔曼滤波作为一种适用于非线性动态系统的状态估计算法,能够有效处理系统模型中的不确定性与测量噪声,因此在航天器耦合控制领域具有重要应用价值。本研究实现的系统通过模块化设计,支持用户针对不同航天器平台或任务场景进行灵活配置,例如卫星轨道维持、飞行器交会对接或地外天体定点着陆等控制问题。 为提升系统的易用性与教学适用性,代码中关键算法步骤均附有说明性注释,有助于用户理解滤波器的初始化、状态预测、观测更新等核心流程。同时,系统兼容多个MATLAB版本(包括2014a、2019b及2024b),可适应不同的软件环境。通过实际操作该仿真系统,学生不仅能够深化对航天动力学与控制理论的认识,还可培养工程编程能力与实际问题分析技能,为后续从事相关技术研究或工程开发奠定基础。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值