D-bus Learning (2): Basic Concepts

Source: Internet
Author: User
Tags unix domain socket

From: http://blog.csdn.net/flowingflying/article/details/5411124

The D-bus method is very important in mobile phone operating systems, including Linux-based operating systems such as maemo and moblin. It is estimated that andriod is also widely used. For more information about D-bus, see:Http://www.freedesktop.org/wiki/Software/dbus There is also a large amount of learning materials on the Internet. Http://blog.chinaunix.net/u3/111961/ There are a lot of Chinese materials and a lot of network information is collected. I decided to study hard and take notes. The main information is from the above two websites, especially the D-bus tutorial of freedesktop.Http://www.ibm.com/developerworks/cn/linux/l-dbus.html AndHttp://blog.csdn.net/cuijpus/archive/2008/01/30/2073962.aspx .

 

Native object and Object Path

All applications using D-BUSProgramContains objects that are sent to an object rather than the entire application when a message is received through a D-BUS connection. In development, the Program Framework defines such objects, such as Java, gobject, and qobject, as native objects in D-bus.

For the underlying D-bus protocol, namely the libscheme API, these native objects are ignored. They use an object path concept. Through object path, high-level programming can name object instances and allow remote applications to reference them. These names look like file system paths. For example, an object may be called "/org/KDE/kspread/sheets/3/cells/4/5 ". Easy-to-Read path names are encouraged, but can also be used, such as "/COM/mycompany/c5yo817y0c1y1c5b", as long as it can be used by your application. The object path of namespacing starts with all the developer's domain names (such as/org/KDE) to avoid system differencesCodeModule interference.

Simply put, an application creates an object instance for D-bus communication. All these object instances have a name, which is named in a similar way to a path, such as/COM/mycompany, this name is globally (session or system) unique and is used for message routing.

Methods and signals methods and Signals

Each object has two types of members: method and signal. The method is the same concept in Java. The method is a piece of function code with input and output. Signals are other entities broadcast to all interests. signals can carry data payload.

Tutorial is not clear here. There are four types of messages in the D-BUS: method calls, method returns, signals, and errors ). To execute methods for D-BUS objects, you need to send a method call message to the object. It completes some processing (that is, the method in the object is executed, and the method can contain input parameters .) And return the message or error message. The difference between signals is that they do not return any content: neither a "signal return" message nor any type of error message.

Interface

Each object supports one or more interfaces. An interface is a combination of methods and signals. An interface defines the type of an object. D-bus is used to name interfaces, similar to org. freedesktop. introspectable. Developers usually useProgramming LanguageClass name as the interface name.

Proxies proxy

The proxy object is used to represent remote objects in other yincheng cities. When we trigger the method of the proxy object, a method_call message will be sent on D-bus, and the response will be received based on the response. It is very convenient to use, just like calling a local object.

 

The above are some concepts that are often involved from the perspective of developer programming. Below are some concepts involved in D-bus's work or processing.

Bus names bus name

When an application is connected to bus daemon, daemon immediately assigns a name to the connection calledUnique connection name The name of this unique identifier starts with a colon (:), for example, 34-907. This name is unique throughout the life cycle of daemon. However, such names are always temporarily assigned, uncertain, and hard to remember. Therefore, an application may require another name.Well-known name To correspond to this unique identifier, just as we use the domain name to correspond to the IP address. For example, you can use Com. mycompany to map to 34-907. Applications may require additionalRegion name (Well-known name ). For example, you can write a specification to define a name called com. mycompany. texteditor. You can specify your own name for your protocol. An application should have an object supporting the org. freedesktop. filehandler interface in the path/COM/mycompany/textfilemanager. The application can send a message to the bus name, object, and interface for invocation.

When an application ends or crashes, the OS Kernel closes its bus connection. The bus sends a notification message to other applications, and the Application name has lost its owner. When this type of notification is detected, the application can know the lifecycle of other applications. This method can also be used for applications with only one instance, that is, the same two applications are not enabled.

Address

The connection is established with the server and client. For bus daemon, the application is the client, and the daemon is the server. A d-BUS address refers to the location where the server is used for listening and the client is used for connection, such as UNIX: path =/tmp/abcedf indicates that the server will listen on the Unix domain socket in the path/tmp/abcedf. The address can be a specified TCP/IP socket or another transmission mode defined in or in the D-bus protocol.

If you use bus daemon, libbench automatically obtains the address of session bus damon by reading the environment variable, and obtains the address of system bus by checking a specified Unix domain socket path. If D-bus is used, but not daemon, You need to define the application as a server, the client, and define a mechanism for them to recognize the server address. This is not the common practice.

Through the above description, we can get the following view:

Address-> [Bus name]-> path-> interface-> Method

The bus name is not necessary. It is only used for routing in the case of daemon. Point-to-Point direct connection is not required.

Simply put, address is the address that the server in D-bus uses to listen to the client. When a client connects to D-bus, it is usually daemo, this client has a bus name. Other applications can determine which application is relevant based on the bus name in the message. When a message is transmitted in the bus, it is transmitted to the application, and then to the specific object instance in the application based on the object path, that is, the object created based on the interface in the application. These interfaces have two types: method and singal, which are used to send, receive, and respond to messages.

 

These concepts may be confusing for beginners, but it is very clear to learn a small program later. This is an example later. Let's look back at the previous article.ArticleThis may be clearer.

 

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.