Dbus Composition and principle

Source: Internet
Author: User

The programmer who writes open source code under the Linux system should be no stranger to Dbus. Its low latency and lower consumption and other advantages attract a lot of people's eyes, because we now develop the platform, many design to dbus this communication mechanism, so I spent more time to become familiar with it. Through this period of study, take notes also do, today first introduce what dbus.

what is Dbus.

Dbus is essentially a communication mechanism between processes that apply to desktop applications, known as the IPC mechanism. An IPC mechanism suitable for the same machine and unsuitable for the internet. Dbus is not a common IPC mechanism for all possible applications and does not support many of the features of other IPC mechanisms. Dbus provides a low latency, low-cost IPC communication, because it uses a binary data exchange protocol, do not need to convert to the text of the data exchange, Dbus provides a multiple-object system packaging, can be used in the original object-oriented application framework for the use of Dbus, No need to learn new concepts and norms.

The Dbus is to support one-to-one and many-to-many peer-to-peer communication, with two applications connected together in one-to-one direct communication, which is the simplest way to work. In Many-to-many communication, this requires a role called Dbus backstage to split, one application to send messages to another application, first to the background, and then to the background to send information to the destination application. Here Dbus the background to act as a router role.

Dbus includes system update notifications, such as inserting new device notifications, new software installation notices, and interactive collaboration with desktop applications that can be used as file system monitors and configuration servers.

The Dbus consists of objects, messages, connections, Dbus background parts.

An object is an independent entity that processes messages. An object has one or more interfaces, one or more methods per interface, and each method implements a specific message processing. In one-to-one communication, an object is connected directly to another client application through one connection. In Many-to-many communications, objects are connected through a connection and a dbus background process. Object has a path that indicates where the object is stored, and it is found by the path when the message is passed.

The client application is a desktop application that is the initiator of the request message. A client application sends a request message through a connection to itself, and also receives a response message, error message, System Update message, and so on through the connection. In one-to-one communication, the request message arrives directly at the object. In Many-to-many communication, the request message first arrives in the Dbus background, and Dbus forwards the message to the destination object in the background.

A connection is a two-way message-passing channel. A connection connects the object to the Dbus background or client application, and the connection supports non-blocking asynchronous message sending and blocking synchronous message sending. When a message arrives at the destination through a connection, the connection wakes up the process that is pending on the connection, and the process takes the message away. Each connection has a unique name and an optional number of other names used to indicate the sender and receiver of the message in a Many-to-many communication.

Connect the communication port based on the operating system to implement the exchange of messages, now based on the communication port has three kinds, is the UNIX socket, TCP/IP, pipeline (for debugging). The communication port has an address on which the server listens and the client connects to this address.

The message is an information transmission medium in the Dbus IPC mechanism. The caller packs the parameters of the invoked method and method into a message, and the receiver takes the method and parameters out of the message and executes the method call. After execution, the results are packaged into the return message and returned to the caller. There are four types of messages, namely method invocation messages, result return messages, error messages, and signal messages. The signal messages Here are unsolicited events, such as new device inserts, file change events, and so on.

The Dbus background is a background process that is used to forward messages and manage connections in Many-to-many communication. Each Dbus background is associated with multiple connections, internally maintaining the mapping relationship between the connection name and the connection entity. The Dbus background is like a router that forwards messages from the sender connection to the recipient connection specified by the recipient connection name in the message.

There are multiple Dbus backstage. There is a dbus background for communicating with the system, monitoring the System update event, and its type is dbus_bus_system. Each desktop session has a Dbus background that communicates with each other for multiple desktop applications with a type of dbus_bus_session. There are generally at least two dbus backstage, a system used, a desktop session. The system uses the Dbus background only to process the system message, the desktop session uses the Dbus background only to be able to handle the desktop session application the message.

1, the client .

It is simpler to use Dbus on the client, first of all, to get a connection from the Dbus_bus_session type Dbus background, and then to create a proxy for an object from this connection, all subsequent operations on the object will be done through this agent.

After you get the Service Broker, you can use the object proxy method in various places of the application to make a message that the object makes a method call. A service that requests an object, either by sending an asynchronous method (an asynchronous service) or by sending a synchronization method (the synchronization service) by synchronizing or asynchronously having an object definition.

2, service side .

After the server process starts, the calling function Dbus_g_object_type_install_info tells Dbus the installation information structure of the object, then obtains a connection from the Dbus_bus_session type Dbus. And then from this connection get a proxy for the Dbus object. Through this Dbus proxy invocation method Requestname gets a name for the connection that the client application can use to send the request message to the connection. The server process then creates an object of the specified type (the GLib object).

The installation information is converted from an XML file through Dbus-binding-tool to an object's header file.

3, News.

The message consists of a message header and a message body. The header is made up of the message's intrinsic field information. The body of a message consists of a string of values. The meaning of each string value of the message body is specified by the description in the message header, the message header must be a multiple of 8, and the message body begins at a multiple of 8.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.