GDBus
1.
https://en.wikipedia.org/wiki/D-Bus
In computing, D-Bus (for "Desktop Bus"[4]), a software bus, is an inter-process communication (IPC) and remote procedure call (RPC) mechanism that allows communication between multiple computer programs(that is, processes) concurrently running on the same machine.[5][6] D-Bus was developed as part of the freedesktop.org project, initiated by Havoc Pennington from Red Hat to standardize services provided by Linux desktop environments such as GNOME and KDE.[7][8][dead link]
The freedesktop.org project also developed a free and open-source software library called libdbus, as a reference implementation of the specification. This library should not be confused with the D-Bus itself; indeed, other implementations of the D-Bus client library also exist, such as GDBus (GNOME),[9] QtDBus (Qt/KDE),[10] dbus-java[11] and sd-bus (part of systemd).[12]
Overview[edit]
D-Bus is an IPC mechanism initially designed to replace the software component communications systems used by the GNOME and KDE Linux desktop environments(CORBA and DCOP respectively).[13][14] The components of these desktop environments are normally distributed in many processes, each one providing only a few —usually one— services. These services may be used by regular client applications or by other components of the desktop environment to perform their tasks.
Due to the large number of processes involved —adding up processes providing the services and clients accessing them— establishing one-to-one IPC communications between all of them becomes an inefficient and quite unreliable[citation needed] approach. Instead, D-Bus provides a software-busabstraction that gathers all the communications between a group of processes over a single shared virtual channel.[6] Processes connected to a bus don't know how it is internally implemented, but D-Bus specification guarantees that all processes connected to the bus can communicate with each other through it.
Linux desktop environments take advantage of the D-Bus facilities by instancing not one bus but many[15][6][16]:
- a single system bus, available to all users and processes of the system, that provides access to system services (i.e. services provided by the operating system and also by any system daemons)
- a session bus for each user login session, that provides desktop services to user applications in the same desktop session, and allows the integration of the desktop session as a whole
A process can connect to any number of buses, provided that it has been granted access to them. In practice, this means that any user process can connect to the system bus and to its current session bus, but not to another users' session buses, or even to a different session bus owned by the same user. The latter restriction may change in the future if all user sessions are combined into a single user bus.[17]
D-Bus provides additional or simplifies existing functionality to the applications, including information-sharing, modularity and privilege separation. For example, information on an incoming voice-call received through Bluetooth or Skype can be propagated and interpreted by any currently-running music player, which can react by muting the volume or by pausing playback until the call is finished.[18]
D-Bus can also be used as a framework to integrate different components of a user application. For instance, an office suite can communicate through the session bus to share data between a word processor and a spreadsheet.
D-Bus specification[edit]
Bus model[edit]
Every connection to a bus is identified in the context of D-Bus by what is called a bus name.[5] A bus name consists of two or more dot-separated strings of letters, digits, dashes, and underscores. An example of a valid bus name is org.freedesktop.NetworkManager
.[6]
When a process sets up a connection to a bus, the bus assigns to the connection a special bus name called unique connection name.[16][6] Bus names of this type are immutable—it's guaranteed they won't change as long as the connection exists—and, more importantly, they can't be reused during the bus lifetime.[5][16][6] This means that no other connection to that bus will ever have assigned such unique connection name, even if the same process closes down the connection to the bus and creates a new one. Unique connection names are easily recognizable because they start with the—otherwise forbidden—colon character.[16][6] An example of a unique connection name is :1.1553
(the characters after the colon have no particular meaning[16]).
A process can ask for additional bus names for its connection,[16] provided that any requested name is not already being used by another connection to the bus. In D-Bus parlance, when a bus name is assigned to a connection, it is said the connection owns the bus name.[5][16] In that sense, a bus name can't be owned by two connections at the same time, but, unlike unique connection names, these names can be reused if they are available: a process may reclaim a bus name released —purposely or not— by another process.[5][6]
The idea behind these additional bus names, commonly called well-known names, is to provide a way to refer to a service using a prearranged bus name.[16][6] For instance, the service that reports the current time and date in the system bus lies in the process whose connection owns the org.freedesktop.timedate1 bus name, regardless of which process it is.
Bus names can be used as a simple way to implement single instance applications (second instances detect that the bus name is already taken).[16] It can also be used to track a service process lifecycle, since the bus sends a notification when a bus name is released due to a process termination.[16]
Object model[edit]
Because of its original conception as a replacement for several component oriented communications systems, D-Bus shares with its predecessors an object model in which to express the semantics of the communications between clients and services. The terms used in the D-Bus object model mimic those used by some object oriented programming languages. That doesn't mean that D-Bus is somehow limited to OOP languages —in fact, the most used implementation (libdbus) is written in C, a procedural programming language.
A process connected to a D-Bus bus can request it to export as many D-Bus objects as it wants. Each object is identified by an object path, a string of numbers, letters and underscores separated and prefixed by the slash character, called that because of their resemblance to Unix filesystem paths.[5][16] The object path is selected by the requesting process, and must be unique in the context of that bus connection. An example of a valid object path is /org/kde/kspread/sheets/3/cells/4/5
.[16] However, it's not enforced —but also not discouraged— to form hierarchies within object paths.[6] The particular naming convention for the objects of a service is entirely up to the developers of such service, but many developers choose to namespace them using the reserved domain name of the project as a prefix (e.g. /org/kde).[16]
Every object is inextricably associated to the particular bus connection where it was exported, and, from the D-Bus point of view, only lives in the context of such connection. Therefore, in order to be able to use a certain service, a client must indicate not only the object path providing the desired service, but also the bus name under which the service process is connected to the bus.[5] This in turn allows that several processes connected to the bus can export different objects with identical object paths unambiguously.
Members —methods and signals— that can be used with an object are specified by an interface.[16] An interface is a set of declarations of methods (including its passing and returning parameters) and signals (including its parameters) identified by a dot-separated name resembling the Java language interfaces notation.[16][6]An example of a valid interface name is org.freedesktop.Introspectable
.[6] Despite their similarity, interface names and bus names should not be mistaken. A D-Bus object can implement several interfaces, but at least must implement one, providing support for every method and signal defined by it. The combination of all interfaces implemented by an object is called the object type.[5][16]
When using an object, it's a good practice for the client process to provide the member's interface name besides the member's name, but is only mandatory when there is an ambiguity caused by duplicated member names available from different interfaces implemented by the object[5][16] —otherwise, the selected member is undefined or erroneous. An emitted signal, on the other hand, must always indicate to which interface it belongs.
The D-Bus specification also defines several standard interfaces that objects may want to implement in addition to its own interfaces.[15] Although technically optional, most D-Bus service developers choose to support them in their exported objects since they offer important additional features to D-Bus clients, such as introspection.[6] These standard interfaces are:[15][6]
- org.freedesktop.DBus.Peer: provides a way to test if a D-Bus connection is alive.[6]
- org.freedesktop.DBus.Introspectable: provides an introspection mechanism by which a client process can get in run-time a description (in XML format) of the interfaces, methods and signals that the object implements.[16][15]
- org.freedesktop.DBus.Properties: allows a D-Bus object to expose the underlying native object properties or attributes, or simulate them if it doesn't exist.[15]
- org.freedesktop.DBus.ObjectManager: when a D-Bus service arranges its objects hierarchically, this interface provides a way to query an object about all sub-objects under its path, as well as their interfaces and properties, using a single method call.[15]
The D-Bus specification defines a number of administrative bus operations (called "bus services") to be performed using the /org/freedesktop/DBus object that resides in the org.freedesktop.DBus bus name.[15] Each bus reserves this special bus name for itself, and manages any requests made specifically to this combination of bus name and object path. The administrative operations provided by the bus are those defined by the object's interface org.freedesktop.DBus. These operations are used for example to provide information about the status of the bus,[5] or to manage the request and release of additional well-known bus names.[15][6]
Communications model[edit]
D-Bus was conceived as a generic, high-level inter-process communication system. To accomplish such goals, D-Bus communications are based on the exchange of messages between processes instead of "raw bytes".[5][16] D-Bus messages are high-level discrete items that a process can send through the bus to another connected process. Messages have a well-defined structure (even the types of the data carried in their payload are defined), allowing the bus to validate them and to reject any ill-formed message. In this regard, D-Bus is closer to an RPC mechanism than to a classic IPC mechanism, with its own type definition system and its own marshaling.[5]
Example of one-to-one request-response message exchange to invoke a method over D-Bus. Here the client process invokes the SetFoo() method of the /org/example/object1 object from the service process named org.example.foo (or :1.14
) in the bus.
The bus supports two modes of interchanging messages between a client and a service process[5]:
- One-to-one request-response: This is the way for a client to invoke an object's method. The client sends a message to the service process exporting the object, and the service in turn replies with a message back to the client process.[16] The message sent by the client must contain the object path, the name of the invoked method (and optionally the name of its interface), and the values of the input parameters (if any) as defined by the object's selected interface. The reply message carries the result of the request, including the values of the output parameters returned by the object's method invocation, or exceptioninformation if there was an error.[5][16]
- Publish/subscribe: This is the way for an object to announce the occurrence of a signal to the interested parties. The object's service process broadcasts a message that the bus passes only to the connected clients subscribed to the object's signal.[16]The message carries the object path, the name of the signal, the interface to which the signal belongs, and also the values of the signal's parameters (if any). The communication is one-way: there are no response messages to the original message from any client process, since the sender knows neither the identities nor the number of the recipients.[5][16]
Every D-Bus message consists of a header and a body.[16] The header is formed by several fields that identifies the type of message, the sender, as well as information required to deliver the message to its recipient (destination bus name, object path, method or signal name, interface name, etc.).[16][15] The body contains the data payload that the receiver process interprets —for instance the input or output arguments. All the data is encoded in a well known binary format called the wire format which supports the serialization of various types, such as integers and floating-point numbers, strings, compound types, and so on,[15] also referred to as marshaling.
The D-Bus specification defines the wire protocol: how to build the D-Bus messages to be exchanged between processes within a D-Bus connection. However, it does not define the underlying transport method for delivering these messages.
2.
https://aleksander.es/data/GNOMEASIA2014%20-%20Introduction%20to%20DBus.pdf
3.
https://developer.gnome.org/gio/stable/gdbus-convenience.html
4.
https://github.com/open-iscsi/tcmu-runner/blob/master/main.c
GDBus的更多相关文章
- dbus-glib 和 GDBus 的区别
http://people.freedesktop.org/~david/gio-gdbus-codegen-20110412/ch29.html Conceptual differences(概念上 ...
- DBus send byte array over gdbus ----Send dbus data
遇到一个问题,如何通过dbus传送uint8数组元素 有3种方法, 1.直接传 ay 2.传 a(y) 3.xml定义为 ay,但是通过annotation 强行将 guchar 转为GVarian ...
- Fedora20安装fcitx输入法
Fedora20安装fcitx输入法 Fedora20默认安装的是ibus输入法,总有一些原因让我们选择fcitx输入法: ibus出词顺序有bug 在输入人名的时候,有些名字输入两三次后还是不会出现 ...
- Ubuntu下修改hosts文件
Ubuntu系统的Hosts只需修改/etc/hosts文件,修改完之后要重启网络.具体过程如下:1.修改hostssudo gedit /etc/hosts2.添加解析记录( . )或者从githu ...
- [fedora21]给fedora21安装fcitx输入法
如果已经安装了ibus,需要卸载ibus: sudo yum remove ibus; 安装fcitx: sudo yum install fcitx fcitx-pinyin fcitx-con ...
- 【Android】源码external/目录中在编译过程中生成的文件列表
=> external/eyes-free: accessibilityvalidator.jar (host,share) => external/mesa3d: libMesa ...
- lnmp安装--php安装
版本:php5.6.4 x86_64 centos 6.6 x86_64 安装php之所以难,是因为要安装的扩展多,依赖关系复杂. 安装前的准备: 先看你想要安装哪些扩展.需要哪些包.下载地址:htt ...
- 13_FCITX输入法安装及问题排查解决
使用linux最沮丧的事情莫过于中文输入法切换不出来,甚至有人错误地认为,要使用中文输入法,必须把“区域和语言”(Region & Language)设置为中国-中文.输入法只是一个软件,和区 ...
- sudo gedit xx warning
When I sue command "sudo gedit xx", it appeas several warning: gedit:): IBUS-WARNING **: T ...
随机推荐
- hdu 2461(AC) & poj 3695(TLE)(离散化+矩形并)
Rectangles Time Limit: 5000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Jekyll搭建个人博客
网上也有HEXO 搭建的博客,有人说使用 HEXO 在多台电脑上发布博客,操作起来并不是那么方便,所以使用Jekyll 来搭建. Jekyll配置 1,安装ruby环境 Windows系统使用Ruby ...
- (3)C#基本语法
1.C#标识符 标识符是用来识别类.变量.函数或任何其它用户定义的项目. 在 C# 中,类的命名必须遵循如下基本规则: 标识符必须以字母开头,后面可以跟一系列的字母.数字.下划线.标识符中的第一个字符 ...
- 洛谷—— P3908 异或之和
https://www.luogu.org/problemnew/show/P3908 题目描述 求1 \bigoplus 2 \bigoplus\cdots\bigoplus N1⨁2⨁⋯⨁N 的值 ...
- JD
General Description: The role is responsible for China COE Operations Team’s data and cost analysis, ...
- POJ 2686 Traveling by Stagecoach(状压DP)
[题目链接] http://poj.org/problem?id=2686 [题目大意] 给出一张无向图,你有n张马车票每张车票可以租用ti匹马, 用一张马车票从一个城市到另一个城市所用的时间为这两个 ...
- Parse error: syntax error, unexpected end of file in *.php on line * 解决方法
Parse error: syntax error, unexpected end of file in *.php on line * 解决方法 这篇文章主要介绍了PHP错误Parse erro ...
- /usr/local/lib/libz.a: could not read symbols: Bad value(64 位 Linux)
/usr/local/lib/libz.a: could not read symbols: Bad value(64 位 Linux) /usr/bin/ld: /usr/local/lib/lib ...
- centos更改文件所属用户和用户组
使用命令为chown和chgrp 更改文件夹或者文件的所属用户 chown -R username dirname chown username filename 更改文件夹或者文件的所属用户组 ch ...
- ES6里关于函数的拓展(二)
一.构造函数 Function构造函数是JS语法中很少被用到的一部分,通常我们用它来动态创建新的函数.这种构造函数接受字符串形式的参数,分别为函数参数及函数体 var add = new Functi ...