source: trunk/doc/src/frameworks-technologies/dbus-intro.qdoc@ 846

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 8.9 KB
RevLine 
[556]1/****************************************************************************
2**
[846]3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
[556]4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
[846]9** $QT_BEGIN_LICENSE:FDL$
[556]10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
[846]13** Software or, alternatively, in accordance with the terms contained in a
14** written agreement between you and Nokia.
[556]15**
[846]16** GNU Free Documentation License
17** Alternatively, this file may be used under the terms of the GNU Free
18** Documentation License version 1.3 as published by the Free Software
19** Foundation and appearing in the file included in the packaging of this
20** file.
[556]21**
22** If you have questions regarding the use of this file, please contact
23** Nokia at [email protected].
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29 \page intro-to-dbus.html
[846]30 \title D-Bus
[556]31 \brief An introduction to Inter-Process Communication and Remote Procedure Calling with D-Bus.
32
33 \keyword QtDBus
[846]34 \ingroup technology-apis
[556]35
36 \section1 Introduction
37
38 D-Bus is an Inter-Process Communication (IPC) and Remote Procedure
39 Calling (RPC) mechanism originally developed for Linux to replace
40 existing and competing IPC solutions with one unified protocol. It
41 has also been designed to allow communication between system-level
42 processes (such as printer and hardware driver services) and
43 normal user processes.
44
45 It uses a fast, binary message-passing protocol, which is suitable
46 for same-machine communication due to its low latency and low
47 overhead. Its specification is currently defined by the
48 \tt{freedesktop.org} project, and is available to all parties.
49
50 Communication in general happens through a central server
51 application, called the "bus" (hence the name), but direct
52 application-to-application communication is also possible. When
53 communicating on a bus, applications can query which other
54 applications and services are available, as well as activate one
55 on demand.
56
57 \section1 The Buses
58
59 D-Bus buses are used to when many-to-many communication is
60 desired. In order to achieve that, a central server is launched
61 before any applications can connect to the bus: this server is
62 responsible for keeping track of the applications that are
63 connected and for properly routing messages from their source to
64 their destination.
65
66 In addition, D-Bus defines two well-known buses, called the
67 system bus and the session bus. These buses are special in the
68 sense that they have well-defined semantics: some services are
69 defined to be found in one or both of these buses.
70
71 For example, an application wishing to query the list of hardware
72 devices attached to the computer will probably communicate to a
73 service available on the system bus, while the service providing
74 opening of the user's web browser will be probably found on the
75 session bus.
76
77 On the system bus, one can also expect to find restrictions on
78 what services each application is allowed to offer. Therefore, one
79 can be reasonably certain that, if a certain service is present,
80 it is being offered by a trusted application.
81
82 \section1 Concepts
83
84 \section2 Messages
85
86 On the low level, applications communicate over D-Bus by sending
87 messages to one another. Messages are used to relay the remote
88 procedure calls as well as the replies and errors associated
89 with them. When used over a bus, messages have a destination,
90 which means they are routed only to the interested parties,
91 avoiding congestion due to "swarming" or broadcasting.
92
93 A special kind of message called a "signal message"
94 (a concept based on Qt's \l {Signals and Slots} mechanism),
95 however, does not have a pre-defined destination. Since its
96 purpose is to be used in a one-to-many context, signal messages
97 are designed to work over an "opt-in" mechanism.
98
99 The QtDBus module fully encapsulates the low-level concept of
100 messages into a simpler, object-oriented approach familiar to Qt
101 developers. In most cases, the developer need not worry about
102 sending or receiving messages.
103
104 \section2 Service Names
105
106 When communicating over a bus, applications obtain what is
107 called a "service name": it is how that application chooses to be
108 known by other applications on the same bus. The service names
109 are brokered by the D-Bus bus daemon and are used to
110 route messages from one application to another. An analogous
111 concept to service names are IP addresses and hostnames: a
112 computer normally has one IP address and may have one or more
113 hostnames associated with it, according to the services that it
114 provides to the network.
115
116 On the other hand, if a bus is not used, service names are also
117 not used. If we compare this to a computer network again, this
118 would equate to a point-to-point network: since the peer is
119 known, there is no need to use hostnames to find it or its IP
120 address.
121
122 The format of a D-Bus service name is in fact very similar to a
123 host name: it is a dot-separated sequence of letters and
124 digits. The common practice is even to name one's service name
125 according to the domain name of the organization that defined
126 that service.
127
128 For example, the D-Bus service is defined by
129 \tt{freedesktop.org} and can be found on the bus under the
130 service name:
131
132 \snippet doc/src/snippets/code/doc_src_introtodbus.qdoc 0
133
134 \section2 Object Paths
135
136 Like network hosts, applications provide specific services to
137 other applications by exporting objects. Those objects are
138 hierarchically organised, much like the parent-child
139 relationship that classes derived from QObject possess. One
140 difference, however, is that there is the concept of "root
141 object", that all objects have as ultimate parent.