Sie sind auf Seite 1von 65

IPCwithQt

Aboutme

MariusBuggeMonsen SeniorSoftwareEngineer 5yearsforTT Msc.comp.sci.NTNU Projects


Itemviews QtDBus WebKit

Contents

WhatisInterProcessCommunication? WhatisDBus? WhatisQtDBus? ExposingInterfaces CallingInterfaces Messages MoreIPC

WhatisInterProcessCommunication? WhatisDBus? WhatisQtDBus? ExposingInterfaces CallingInterfaces Messages MoreIPC

WhatisInterProcessCommunication?

Iama process! SoamI!

Process

Process

WhatIsInterProcessCommunication?

Exchanginginformationbetweenprocesses.

WhatIsInterProcessCommunication?

Techniques

remoteprocedurecalls(RPC) messagepassing synchronization sharedmemory

WhatIsInterProcessCommunication?

Implementations

CORBA SOAP/XMLRPC DCOM DCOP DBus ...

WhatisInterProcessCommunication? WhatisDBus? WhatisQtDBus? ExposingInterfaces CallingInterfaces Messages MoreIPC

WhatisDBus?

AMessageBusSystem

10

WhatisDBus?

MessageBusDaemon

Process

Process

Process

11

WhatisDBus?

Protocol Library Messagebusframework

12

DBus

Generalonetoonemessagepassingframework Singlecomputer ComputertocomputerthroughunencryptedTCP/IP

13

DBus

Portabletoany*NIXsystem Windowsportinprogress StandardIPCmechanismforGnomeandKDE

14

WhatisDBus?

SystemBus

systemwideservices peruserloginsessionservices

SessionBus

15

ExposingFunctionality

Service

Objects

Interfaces

Methods Signals Properties

16

ExposingFunctionality

Service

Representaprocessconnectedtoabus. Hasaunique(base)namechosenbythebus.

Usesa:n.nnnnamingscheme(e.g.:1.32). Usesreversedomainnamenamingscheme(e.g. com.trolltech.appname).

Hasawellknownnamechosenbytheprocess.

Multipleservicesperprocess

17

ExposingFunctionality

Object

Multipleobjectsperservice. Specifiedbyapath.

/path/to/ObjectName

Thepathstructureisarbitrary. Providesnamespacesforobjects.

18

ExposingFunctionality

Interface

Multipleinterfacesperobject. Dotseparatedname.

com.trolltech.Assistant.HelpViewer names parameters returnvalues

Definesasetofmethods,signalsandproperties.

CanbedescribedbyXML.
19

ExposingFunctionality

Methods

Amethodcanbecalledbysendingamessagetotheprocess exposingthefunctionality(thecallerdoesnothavetoregister aservice). Manytoone. Asignalisemittedbytheprocesswhichisexposingthe interfaceandisavailabletoanyapplicationonthesamebus. Onetomany.

Signals

20

ExposingFunctionality

Properties

org.freedesktop.DBus.Properties ThePropertiesinterfacethatprovidesGetandSetmethods.

21

ExposingFunctionality

Address

Service Object Interface MethodorSignal

22

DBusAddress

com.trolltech.Assistant/Assistantcom.trolltech.Assistant.HelpViewershowLink service objectpath interface method

23

Activation

TheBuscanstartclientsautomatically

byexplicitlyrequestingtheBustoactivatetheclient. byinvokingamethodonanobjectbelongingtotheclient.

24

Introspection

Objectsmayprovidetheintrospectioninterface

org.freedesktop.DBus.Introspectable TheIntrospectmethodreturnsanXMLdescription.

25

WhatisInterProcessCommunication? WhatisDBus? WhatisQtDBus? ExposingInterfaces CallingInterfaces Messages MoreIPC

26

WhatisQtDBus?

ObjectorientedQtAPIforDBus. MapsQtproperties,signalsandslotstoDBus. MapsDBusproperties,signalsandmethodstoQt.

27

QtDBusTools

qdbus

CommandlineDBusexplorer. GraphicalDBusexplorer.

qdbusviewer

28

QtDBusTools

qdbusxml2cpp

CompilesXMLinterfacedescriptiontoaninterfaceoradaptor class. CompilesaninterfaceoradaptorclasstoanXMLinterface descriptionfile.

qdbuscpp2xml

29

WhatisInterProcessCommunication? WhatisDBus? WhatisQtDBus? ExposingInterfaces CallingInterfaces Messages MoreIPC

30

QtDBusApproaches

Highlevel

InterfacerepresentationsgeneratedfromXMLdescriptions Directcallstoagenericinterfaceclass Constructingandsendingmessages

Midlevel

Lowlevel

31

ConnectingToDBus

QDBusConnection

RepresentsaconnectiontotheDBusbusdaemon. QDBusConnection::BusType

QDBusConnection::SessionBus QDBusConnection::SystemBus QDBusConnection::ActivationBus

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

SpecialclassattachedtoaQObject Exposesaninterfacetothebus Lightweight InheritsQDBusAbstractAdaptor

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

WhatisInterProcessCommunication? WhatisDBus? WhatisQtDBus? ExposingInterfaces CallingInterfaces Messages MoreIPC

47

UsingInterfaces

ProxyClass

RepresentsaDBusinterface RepresentedasanormalQObject

signals slots properties

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

WhatisInterProcessCommunication? WhatisDBus? WhatisQtDBus? ExposingInterfaces CallingInterfaces Messages MoreIPC

55

QDBusMessage

RepresentsDBusmessage. MessageType

MethodCallMessage SignalMessage ReplyMessage ErrorMessage InvalidMessage

56

CreatingAMessage

Staticfunctions

createError(...) createMethodCall(...) createSignal(...) createErrorReply(...) createReply(...)

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

NoBlock Block BlockWithGui AutoDetect

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

XMLInterfaceDescription Adaptorclass Proxyclass QDBusInterface QDBusMessage

Midlevel

Lowlevel

61

WhatisInterProcessCommunication? WhatisDBus? WhatisQtDBus? ExposingInterfaces CallingInterfaces Messages MoreIPC

62

MoreIPC

Techniques

remoteprocedurecalls(RPC) messagepassing synchronization sharedmemory

63

MoreQtIPC(Qt4.4)

Synchronization

QSystemSemaphore QSharedMemory QLocalSocket QLocalServer

SharedMemory

LocalSockets

64

Resources

http://doc.trolltech.com/4.3/introtodbus.html http://www.freedesktop.org/wiki/Software/dbus http://sourceforge.net/projects/windbus

65

Das könnte Ihnen auch gefallen