IPC机制学习---D-BUS

以下内容大部分是笔记。以后如果有机会接触D-BUS,这篇文章需要改写和完善。目前仅作一个整理吧,算是个自己一个提醒。

Basics

a full-featured IPC and object system

First, D-BUS can perform basic application IPC, allowing one process to shuttle data to another—think UNIX domain sockets on steroids. Second, D-BUS can facilitate sending events, or signals, through the system, allowing different components in the system to communicate and ultimately to integrate better. Finally, D-BUS implements a remote object system, letting one application request services and invoke methods from a different object—think CORBA without the complications.

First, the basic unit of IPC in D-BUS is a message, not a byte stream.

Second, D-BUS is bus-based. D-BUS, however, provides a dæmon, known as the message bus dæmon, that routes messages between processes on a specific bus.

A final unique feature is the creation of not one but two of these buses, the system bus and the session bus.

 

D-BUS supports multiple message types, such as signals, method calls, method returns and error messages.

 

Why D-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. The events are sent asynchronously, and without polling.

(之前,上层app如何监听底层硬件的改变呢?poll一个文件,这个文件由底层kernel或者module来写入东西,于是上层就可以从pollwait状态返回,得到下层的一个通知。例如Android中的Headset Observer。现在竟然可以直接通信!我了个擦!不过还是要看应用场合吧。马达马达哟~~)

The Kernel Event Layer

The Kernel Event Layer is a kernel-to-user communication mechanism that uses a high-speed netlink socket to communicate asynchronously with user space. This mechanism can be tied into D-BUS, allowing the kernel to send D-BUS signals!

sysfs is an object hierarchy exported as a filesystem.

 

   

 

How to use D-BUS?

The preferred use of D-BUS is definitely using language and environment-specific bindings, both for ease of use and improved functionality. 

  

 

References

http://www.linuxjournal.com/article/7744

Linux Device Driver (bus)

http://blog.csdn.net/nero_cie/article/details/6153804

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

http://en.wikipedia.org/wiki/D-Bus

 

 

 

你可能感兴趣的:(IPC机制学习---D-BUS)