Beruflich Dokumente
Kultur Dokumente
Aboutme
Contents
WhatisInterProcessCommunication?
Process
Process
WhatIsInterProcessCommunication?
Exchanginginformationbetweenprocesses.
WhatIsInterProcessCommunication?
Techniques
WhatIsInterProcessCommunication?
Implementations
WhatisDBus?
AMessageBusSystem
10
WhatisDBus?
MessageBusDaemon
Process
Process
Process
11
WhatisDBus?
12
DBus
13
DBus
14
WhatisDBus?
SystemBus
systemwideservices peruserloginsessionservices
SessionBus
15
ExposingFunctionality
Service
Objects
Interfaces
16
ExposingFunctionality
Service
Representaprocessconnectedtoabus. Hasaunique(base)namechosenbythebus.
Hasawellknownnamechosenbytheprocess.
Multipleservicesperprocess
17
ExposingFunctionality
Object
Multipleobjectsperservice. Specifiedbyapath.
/path/to/ObjectName
Thepathstructureisarbitrary. Providesnamespacesforobjects.
18
ExposingFunctionality
Interface
Multipleinterfacesperobject. Dotseparatedname.
Definesasetofmethods,signalsandproperties.
CanbedescribedbyXML.
19
ExposingFunctionality
Methods
Signals
20
ExposingFunctionality
Properties
org.freedesktop.DBus.Properties ThePropertiesinterfacethatprovidesGetandSetmethods.
21
ExposingFunctionality
Address
22
DBusAddress
23
Activation
TheBuscanstartclientsautomatically
byexplicitlyrequestingtheBustoactivatetheclient. byinvokingamethodonanobjectbelongingtotheclient.
24
Introspection
Objectsmayprovidetheintrospectioninterface
org.freedesktop.DBus.Introspectable TheIntrospectmethodreturnsanXMLdescription.
25
26
WhatisQtDBus?
27
QtDBusTools
qdbus
CommandlineDBusexplorer. GraphicalDBusexplorer.
qdbusviewer
28
QtDBusTools
qdbusxml2cpp
qdbuscpp2xml
29
30
QtDBusApproaches
Highlevel
Midlevel
Lowlevel
31
ConnectingToDBus
QDBusConnection
RepresentsaconnectiontotheDBusbusdaemon. QDBusConnection::BusType
32
ConnectToTheSessionBus
intmain(intargc,char*argv[]) { QApplicationapp(argc,argv); ... QDBusConnectionconnection=QDBusConnection::sessionBus(); ... returnapp.exec(); }
33
RegisterTheService
intmain(intargc,char*argv[]) { QApplicationapp(argc,argv); ... QDBusConnectionconnection=QDBusConnection::sessionBus(); connection.registerService("com.trolltech.LineEdit"); ... returnapp.exec(); }
34
ExposingFunctionality
ExposeQObjectslotsdirectly Exposeinterfaces
doesn'thavetomapdirectlytoanyobject
35
ExposingAllSlots
intmain(intargc,char*argv[]) { QApplicationapp(argc,argv); QLineEditle; QDBusConnectionconnection=QDBusConnection::sessionBus(); connection.registerService("com.trolltech.LineEdit"); connection.registerObject("/LineEdit",&le, QDBusConnection::ExportAllSlots); le.show(); returnapp.exec(); }
36
ExposingInterfaces
AdaptorClass
37
ExposingInterfaces
Adaptor
Interface
QObject
Adaptor
Interface
MessageBus
Adaptor
Interface
38
ExposingAnInterface
intmain(intargc,char*argv[]) { QApplicationapp(argc,argv); QLineEditle; newLineEditAdaptor(&le); QDBusConnectionconnection=QDBusConnection::sessionBus(); connection.registerService("com.trolltech.LineEdit"); connection.registerObject("/LineEdit",&le, QDBusConnection::ExportAdaptors); le.show(); returnapp.exec(); }
39
ExposingMethods
classLineEditAdaptor:publicQDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("DBusInterface","com.trolltech.LineEdit.Test") LineEditAdaptor(QLineEdit*w):QDBusAbstractAdaptor(w),le(w){} ~LineEditAdaptor(){} publicslots: inlinevoidshow(){le>show();} inlinevoidhide(){le>hide();} private: QLineEdit*le; };
40
ExposingProperties
classLineEditAdaptor:publicQDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("DBusInterface","com.trolltech.LineEdit.Test") Q_PROPERTY(QStringtextREADtextWRITEsetText) public: LineEditAdaptor(QLineEdit*w):QDBusAbstractAdaptor(w),le(w){} ~LineEditAdaptor(){} inlineQStringtext()const{returnle>text();} inlinevoidsetText(constQString&text){le>setText(text);} ... };
41
ExposingSignals
classLineEditAdaptor:publicQDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("DBusInterface","com.trolltech.LineEdit.Test") Q_PROPERTY(QStringtextREADtextWRITEsetText) public: LineEditAdaptor(QLineEdit*w):QDBusAbstractAdaptor(w),le(w) { QDBusAbstractAdaptor::setAutoRelaySignals(true); } ... signals: voidtextChanged(constQString&text); ... };
42
XMLInterfaceDescription
<nodename="/com/trollech/LineEdit"> <interfacename="com.trolltech.LineEdit.Test"> <propertyname="text"type="s"access="readwrite"/> <methodname="show"/> <methodname="hide"/> <signalname="textChanged"> <argtype="s"name="text"/> </signal> </interface> </node>
43
XMLToAdaptor
test.xml
qdbusxml2cppaadaptortest.xml
adaptor.h
adaptor.cpp
44
XMLToProxy
test.xml
qdbusxml2cpppproxytest.xml
proxy.h
proxy.cpp
45
UsingInterfaces
Interface
Proxy
Interface
MessageBus
Proxy
Interface
Proxy
46
47
UsingInterfaces
ProxyClass
RepresentsaDBusinterface RepresentedasanormalQObject
InheritsQDBusAbstractInterface
48
TheGeneratedProxy
com::trolltech::LineEdit::Test*le= newcom::trolltech::LineEdit::Test(//interface "com.trolltech.LineEdit",//service "/LineEdit",//object QDBusConnection::sessionBus());//bus QComboBoxbox; box.setEditable(true); box.setEditText(le>isValid()?le>text():"empty"); QObject::connect(le,SIGNAL(textChanged(constQString&)), &box,SLOT(setEditText(constQString&)));
49
QDBusInterface
Genericaccessorclass
usedtoplacecallstoremoteinterfaces requiresorg.freedesktop.DBus.Introspectable
50
CallingMethods
intmain() { QDBusInterfaceiface("com.trolltech.LineEdit", "/LineEdit", "com.trolltech.LineEdit.Test", QDBusConnection::sessionBus()); iface.call("hide"); return0; }
51
ArgumentsAndReturnValues
intmain() { QStringservice="com.trolltech.Calculator"; QStringpath="/Calculator"; QStringinterface="com.trolltech.Calculator.Computation"; QDBusConnectionbus=QDBusConnection::sessionBus(); QDBusInterfaceiface(service,path,interface,bus); QDBusMessageresult=iface.call("multiply",4,3); QList<QVariant>values=result.arguments(); ... return0; }
52
Properties
intmain() { QStringservice="com.trolltech.Calculator"; QStringpath="/Calculator"; QStringinterface="com.trolltech.Calculator.Computation"; QDBusConnectionbus=QDBusConnection::sessionBus(); QDBusInterfaceiface(service,path,interface,bus); QVarianttext=iface.property(text); return0; }
53
SignalsAndSlots
intmain() { QStringservice="com.trolltech.Calculator"; QStringpath="/Calculator"; QStringinterface="com.trolltech.Calculator.Computation"; QDBusConnectionbus=QDBusConnection::sessionBus(); QDBusInterfaceiface(service,path,interface,bus); QObject::connect(&iface,SIGNAL(textChanged(constQString&)), &receiver,SLOT(textChanged(constQString&))); return0; }
54
55
QDBusMessage
RepresentsDBusmessage. MessageType
56
CreatingAMessage
Staticfunctions
Nonstaticfunctions
57
SendingAMessage
intmain() { QDBusMessagemsg=QDBusMessage::createMethodCall( com.trolltech.Calculator,//service /Calculator,//object com.trolltech.Calculator.Computation,//iface multiply);//method QList<QVariant>args; args<<4<<5; msg.setArguments(args); QDBusMessagereply=QDBusConnection::sessionBus().call(msg); ... return0; }
58
Synchronousvs.Asynchronous
QDBus::CallMode
59
SendingAMessageAsynchronously
intmain() { ... QDBusMessagemsg=QDBusMessage::createMethodCall( com.trolltech.LineEdit,//service /LineEdit,//object com.trolltech.LineEdit.Test,//interface hide);//method QDBusConnection::sessionBus().send(msg); ... return0; }
60
QtDBusApproaches
Highlevel
Midlevel
Lowlevel
61
62
MoreIPC
Techniques
63
MoreQtIPC(Qt4.4)
Synchronization
SharedMemory
LocalSockets
64
Resources
65