Document directory
- 2.1. Starting from the example
- 2.2 terms
- Conclusion 2.3
There are many articles about NLP on the Internet. The goal of this article is to add some simple examples.
1. What is ghost?
There is an article on the Internet called"D-bus tutorialIs widely spread. Many documents about NLP are referenced in the paragraphs. In fact, compared with this article, I suggest you read"D-bus specification", The length is not long, and the text is not boring.
D-bus is an IPC (interprocess communication) mechanism optimized for desktop environments. It is used for inter-process communication or communication between processes and the kernel. The most basic D-bus protocol is one-to-one communication protocol. However, in many cases, the communication side is the message bus. The message bus is a special application that communicates with multiple applications at the same time and transmits messages between applications. Next we will observe the role of the message bus in the instance. The role of the message bus is a bit similar to the window manager in the X system. The window manager is both the X customer and the Management window.
All systems that support compaction have two standard message Bus: system bus and session bus. The system bus is used for communication between systems and applications. The session bus is used for communications between applications. There is a python program named D-Feet on the Internet. We can use it to observe the Ghost World in the system.
Figure 1. D-bus world observed by D-feet
D-bus is a program. It provides APIs. However, we generally do not directly use the callback interface. Producer-glib is the producer interface encapsulation of the GTK version. This article assumes that the Reader installed unzip-glib, And I installed the dbus-glib-0.76. Later, we will see how easy it is to manipulate the handler using python.
2. Basic concepts of D-Bus 2.1. Starting from the example
I wrote a simple ingress server, which provides an addition interface through the ingress. You canDownloadThis example. This is an autotool project. After unpacking, run:
./autogen.sh./configuremake
Then run the following command in the src directory:
./example-service
Then run D-feet to connect to the session bus. In the "Bus name" window, a connection name named "org. fmddlmyy. Test" is displayed.
Figure 2. org. fmddlmyy. Test
Select Org. fmddlmyy. test, click "Object paths"-> "/testobj"-> "interfaces"-> "org. fmddlmyy. test. basic "->" methods ", you can see an add method. Double-click the add method. The following dialog box is displayed:
Figure 3. Calculate 1 + 2 = 3 through the D-Bus Interface
Enter "1, 2" in the parameters window, click "execute", and then we can see the output result in the "output" window. We just created an ingress service and called it.
2.2 terms
Let's explain the terms in D-feet.
2.2.1. Bus name
You can understand the bus name as the connection name. A bus name always represents the connection between an application and the message bus. There are two different bus names: well-known names and unique connection name ).
2.2.1.1. There may be multiple public names for alternative connections
Public names provide well-known services. Other applications use the service with the corresponding name. Multiple connections may require services with the same public name, that is, services with the same public name must be provided when multiple applications are connected to the Message bus. The message bus will arrange these connections in the linked list and select a connection to provide services represented by a public name. It can be said that the connection that provides the service has this public name. If the connection exits, the message bus selects the next connection from the linked list to provide services. A common name is composed of multiple lowercase symbols separated by dots, such as org. fmddlmyy. Test and org. bluez ".
2.2.1.2. Each connection has a unique name.
When an application is connected to the Message bus, the message bus assigns a unique name to each application. The unique name starts with ":", and ":" is usually followed by two numbers separated by dots, for example, ": 1.0 ". Each connection has a unique name. During the life cycle of a message bus, no two connections have the same unique names. Connections with public names also have unique names. For example, in the preceding figure, the unique name of "org. fmddlmyy. Test" is ": 1.17 ".
Some connections only have a unique name and no public name. These names can be called Private connections because they do not provide services that can be accessed by public names. The D-feet interface has an "Hide private" button to hide private connections.
2.2.2. Object paths
The bus name determines the connection from an application to the Message bus. An application can have multiple objects that provide services. These objects are organized in a tree structure. Each object has a unique path (Object paths ). Or, in an application, an object path indicates a unique object.
"Org. fmddlmyy. Test" has only one object called "/testobj. In Figure 1, "org. bluez" has multiple object paths.
2.2.3. Interfaces
Through the object path, we find an object in the application. Each object can implement multiple interfaces. For example, "/testobj" of "org. fmddlmyy. Test" implements the following interfaces:
- Org. fmddlmyy. Test. Basic
- Org. freedesktop. Large. introspectable
- Org. freedesktop. Producer. Properties
Later, we will see that in the code, we only implement the "org. fmddlmyy. Test. Basic" interface. Interfaces org. freedesktop. Detail. introspectable and org. freedesktop. Detail. properties are the standard interfaces provided by the message bus.
2.2.4, methods, and signals
Interfaces include methods and signals. For example, the "org. fmddlmyy. Test. Test. Basic" interface of the "/testobj" object of "org. fmddlmyy. Test. Basic" has an add method. In the following example, we will introduce the signal.
The "org. freedesktop. Detail. introspectable" introspect method of the standard interface is a very useful method. Similar to the Java reflection interface, calling the introspect method can return the XML Description of the interface. Double-click Org. fmddlmyy. test "->"/testobj "->" org. fmddlmyy. test. basic "->" org. freedesktop. invalid. introspectable introspect method. This method does not input parameters. We directly click the "execute" button. What do you see in the "output" window?
Figure 4. Call the introspect Method
We will call the introspect method in another way later.
Conclusion 2.3
"Org. fmddlmyy. test "->"/testobj "->" org. fmddlmyy. test. basic "->" org. freedesktop. invalid. introspectable "introspect method, this description is not very troublesome. In fact, we need to add "session bus ".
Later, when we look at the C code of the client, we will see the same process: Use dbus_g_bus_get to get the connection to the session bus. In this connection, use the dbus_g_proxy_new_for_name function to obtain the proxy of the specified interface of the specified object for the connection with the specified public name. Finally, use the dbus_g_proxy_call function to call the methods provided by the interface through the interface proxy.
3 next episode notice
Although D-feet is convenient, it uses the GTK module of Python and may not be used in some embedded environments. Later, we will see that using a command line tool named sending-send or writing several lines of Python scripts can do the same job. We will also use a command line tool called consumer-monitor to observe what happened during the pipeline call process?