class DCOPClient

# class DCOPClient |
Internal Use Only
Definition | `#include <dcopclient.h>`
Inherits | QObject
Annotated List
Files
Globals
Hierarchy
Index
Main

#### Public Methods

- DCOPClient ()
- virtual ~ DCOPClient ()
- bool attach ()
- void bindToApp ()
- bool detach ()
- bool isAttached () const
- QCString registerAs ( const QCString &appId, bool addPID = true )
- bool isRegistered () const
- QCString appId () const
- int socket () const
- void suspend ()
- void resume ()
- bool send (const QCString &remApp, const QCString &remObj, const QCString &remFun, const QByteArray &data, bool fast=false)
- bool send (const QCString &remApp, const QCString &remObj, const QCString &remFun, const QString &data, bool fast=false)
- bool call (const QCString &remApp, const QCString &remObj, const QCString &remFun, const QByteArray &data, QCString& replyType, QByteArray &replyData, bool useEventLoop=false, bool fast=false)
- bool findObject (const QCString &remApp, const QCString &remObj, const QCString &remFun, const QByteArray &data, QCString &foundApp, QCString &foundObj, bool useEventLoop=false, bool fast=false)
- void emitDCOPSignal ( const QCString &object, const QCString &signal, const QByteArray &data)
- void emitDCOPSignal ( const QCString &signal, const QByteArray &data)
- bool connectDCOPSignal ( const QCString &sender, const QCString &senderObj, const QCString &signal, const QCString &receiverObj, const QCString &slot, bool Volatile)
- bool connectDCOPSignal ( const QCString &sender, const QCString &signal, const QCString &receiverObj, const QCString &slot, bool Volatile)
- bool disconnectDCOPSignal ( const QCString &sender, const QCString &senderObj, const QCString &signal, const QCString &receiverObj, const QCString &slot)
- bool disconnectDCOPSignal ( const QCString &sender, const QCString &signal, const QCString &receiverObj, const QCString &slot)
- virtual bool process (const QCString &fun, const QByteArray &data, QCString& replyType, QByteArray &replyData)
- DCOPClientTransaction * beginTransaction ( )
- void endTransaction ( DCOPClientTransaction *, QCString& replyType, QByteArray &replyData)
- Q_INT32 transactionId ()
- bool isApplicationRegistered ( const QCString& remApp)
- QCStringList registeredApplications ()
- QCStringList remoteObjects ( const QCString& remApp, bool *ok = 0 )
- QCStringList remoteInterfaces ( const QCString& remApp, const QCString& remObj , bool *ok = 0 )
- QCStringList remoteFunctions ( const QCString& remApp, const QCString& remObj , bool *ok = 0 )
- bool receive (const QCString &app, const QCString &obj, const QCString &fun, const QByteArray& data, QCString& replyType, QByteArray &replyData)
- bool find (const QCString &app, const QCString &obj, const QCString &fun, const QByteArray& data, QCString& replyType, QByteArray &replyData)
- QCString senderId () const
- void setDefaultObject ( const QCString& objId )
- QCString defaultObject () const
- void setNotifications ( bool enabled )

#### Public Slots

- protected slots: void processSocketData (int socknum)
- private slots: void processPostedMessagesInternal ()
- bool attachInternal ( bool registerAsAnonymous = TRUE )
- bool callInternal (const QCString &remApp, const QCString &remObj, const QCString &remFun, const QByteArray &data, QCString& replyType, QByteArray &replyData, bool useEventLoop, bool fast, int minor_opcode)

#### Signals

- void applicationRegistered ( const QCString& appId )
- void applicationRemoved ( const QCString& appId )
- void attachFailed (const QString &msg)
- void blockUserInput ( bool )

#### Public Static Methods

- static void setServerAddress (const QCString &addr)
- static QCString normalizeFunctionSignature ( const QCString& fun )
- static DCOPClient* mainClient ()
- static void setMainClient ( DCOPClient* )

## Detailed Description

DCOPClient ()

Create a new DCOP client, but do not attach to any server.

~ DCOPClient ()

[virtual]

Clean up any open connections and dynamic data.

void setServerAddress (const QCString &addr)

[static]

Specify the address of a server to use upon attaching.

If no server address is ever specified, attach will try its best to find the server anyway.

bool attach ()

Attach to the DCOP server.

If the connection was already attached, the connection will be re-established with the current server address.

Naturally, only attached application can use DCOP services.

If a QApplication object exists then client registers itself as QApplication->name() + "-" + <pid>. If no QApplication object exists the client registers itself as "anonymous".

If you want to register differently, you should use registerAs() instead.

Returns: `true` if attaching was successful.

void bindToApp ()

Internal function for KUniqueApplication to register the DCOPClient with the application in case the application didn't exist at the time the DCOPClient was created.

bool detach ()

Detach from the DCOP server.

bool isAttached ()

[const]

Query whether or not the client is attached to the server.

QCString registerAs ( const QCString &appId, bool addPID = true )

Register at the DCOP server.

If the application was already registered, the registration will be re-done with the new appId.

`appId` is a `unique` application/program id that the server will use to associate requests with. If there is already an application registered with the same name, the server will add a number to the id to unify it. If `addPID` is true, the PID of the current process will be added to id.

Registration is necessary if you want to allow other clients to talk to you. They can do so using your `appId` as first parameter for send() or call(). If you just want to talk to other clients, you do not need to register at the server. In that case attach() is enough. It will implicitly register you as "anonymous".

Returns: The actual `appId` used for the registration or a null string if the registration wasn't successful.

bool isRegistered ()

[const]

Query whether or not the client is registered at the server.

QCString appId ()

[const]

Returns the current app id or a null string if the application hasn't yet been registered.

int socket ()

[const]

Returns: The socket over which DCOP is communicating with the server.

void suspend ()

Temporarily suspend processing of DCOP events. This can be usefull if you need to show e.g. a dialog before your application is ready to accept DCOP requests. Normally the dialog would start an event loop and in this event loop DCOP requests will be handled.

Be aware that not responding to DCOP requests may cause other programs that want to communicate with your application, to hang.

void resume ()

Resume the processing of DCOP events. See suspend().

bool send (const QCString &remApp, const QCString &remObj, const QCString &remFun, const QByteArray &data, bool fast=false)

Send a data block to the server.

Parameters:

remApp | The remote application id.
remObj | The name of the remote object.
remFun | The remote function in the specified object to call.
data | The data to provide to the remote function.
fast | Tf set to `true,` a "fast" form of IPC will be used. Fast connections are not guaranteed to be implemented, but if they are they work only on the local machine, not across the network. "fast" is only a hint not an order.

Returns: Whether or not the server was able to accept the send.

bool send (const QCString &remApp, const QCString &remObj, const QCString &remFun, const QString &data, bool fast=false)

This function acts exactly the same as the above, but the data parameter can be specified as a QString for convenience.

bool call (const QCString &remApp, const QCString &remObj, const QCString &remFun, const QByteArray &data, QCString& replyType, QByteArray &replyData, bool useEventLoop=false, bool fast=false)

Perform a synchronous send and receive.

The parameters are the same as for send, with the exception of another QByteArray being provided for results to be (optionally) returned in.

A call blocks the application until the process receives the answer.

If `useEventLoop` is true, a local event loop will be started after 1/10th of a second in order to keep the user interface updated (by processing paint events and such) until an answer is received.

bool findObject (const QCString &remApp, const QCString &remObj, const QCString &remFun, const QByteArray &data, QCString &foundApp, QCString &foundObj, bool useEventLoop=false, bool fast=false)

Search for an object which matches a criteria.

findObject calls `remFun` in the applications and objects identified by `remApp` and `remObj` until `remFun` returns true. The name of the application and object that returned true are returned in `foundApp` and `foundObj` respectively.

If `remFun` is empty a default function is called in the object which always returns `true.`

A findObject blocks the application until the process receives the answer.

If `useEventLoop` is true, a local event loop will be started after 1/10th of a second in order to keep the user interface updated (by processing paint events and such) until an answer is received.

Parameters:

remApp | The remote application id.
remObj | The name of the remote object.
remFun | The remote function in the specified object to call. This function should return a bool and is used as criteria.
data | The data to provide to the remote function.
foundApp | The remote application id that matched the criteria.
foundObj | The remote object that matched the criteria.
fast | Tf set to true, a "fast" form of IPC will be used. Fast connections are not guaranteed to be implemented, but if they are they work only on the local machine, not across the network. "fast" is only a hint not an order.

Returns: true is returned when an object was found for which `remFun` returned true. If no such object is the function returns false.

void emitDCOPSignal ( const QCString &object, const QCString &signal, const QByteArray &data)

Emit `signal` as DCOP signal from object `object` with @data as arguments

void emitDCOPSignal ( const QCString &signal, const QByteArray &data)

bool connectDCOPSignal ( const QCString &sender, const QCString &senderObj, const QCString &signal, const QCString &receiverObj, const QCString &slot, bool Volatile)

Connect to a DCOP signal

- `Volatile` is true and `sender` does not exist.
- `signal` and `slot` do not have matching arguments.

Parameters:

sender | the name of the client that emits the signal. When empty the signal will be passed from any client.
senderObj | the name of the sending object that emits the signal.
signal | the name of the signal. The arguments should match with slot.
receiverObj | The name of the object to call
slot | The name of the slot to call. Its arguments should match with signal.
Volatile | If true, the connection will not be reestablished when `sender` unregisters and reregisters with DCOP. In this case the `sender` must be registered when the connection is made. If false, the connection will be reestablished when `sender` reregisters. In this case the connection can be made even if `sender` is not registered at that time.

Returns: false if a connection could not be established. This will be the case when

bool connectDCOPSignal ( const QCString &sender, const QCString &signal, const QCString &receiverObj, const QCString &slot, bool Volatile)

bool disconnectDCOPSignal ( const QCString &sender, const QCString &senderObj, const QCString &signal, const QCString &receiverObj, const QCString &slot)

Disconnect a DCOP signal

A special case is when both sender & signal are empty. In this case all connections related to @param receiverObj in the current client are disconnected. (Both connections from as well as to this object!)

Parameters:

sender | the name of the client that emits the signal.
senderObj | the name of the object that emits the signal. If empty all objects will be disconnected.
signal | the name of the signal. The arguments should match with slot.
receiverObj | The name of the object the signal is connected to. If empty all objects will be disconnected.
slot | The name of the slot the signal is connected to. If empty all slots will be disconnected.

Returns: false if no connection(s) where removed.

bool disconnectDCOPSignal ( const QCString &sender, const QCString &signal, const QCString &receiverObj, const QCString &slot)

bool process (const QCString &fun, const QByteArray &data, QCString& replyType, QByteArray &replyData)

[virtual]

Reimplement to handle app-wide function calls unassociated w/an object.

Note that `fun` is normalized. See normalizeFunctionSignature().

If you do not want to reimplement this function for whatever reason, you can also use a default object or a DCOPObjectProxy.

DCOPClientTransaction * beginTransaction ( )

Delay the reply of the current function call until endTransaction() is called.

This allows a server to queue requests.

Note: Should be called from inside process() only!

void endTransaction ( DCOPClientTransaction *, QCString& replyType, QByteArray &replyData)

Send the delayed reply of a function call.

Q_INT32 transactionId ()

Test whether the current function call is delayed.

Note: Should be called from inside process() only!

Returns: The ID of the current transaction or 0 if no transaction is going on.

bool isApplicationRegistered ( const QCString& remApp)

Check whether `remApp` is registered with the DCOPServer.

Returns: `true` if the remote application is registered, otherwise `false.`

QCStringList registeredApplications ()

Retrieves the list of all currently registered applications.

QCStringList remoteObjects ( const QCString& remApp, bool *ok = 0 )

Retrieves the list of objects of the remote application `remApp`

QCStringList remoteInterfaces ( const QCString& remApp, const QCString& remObj , bool *ok = 0 )

Retrieves the list of interfaces of the remote object `remObj` of application `remApp`

QCStringList remoteFunctions ( const QCString& remApp, const QCString& remObj , bool *ok = 0 )

Retrieves the list of functions of the remote object `remObj` of application `remApp`

bool receive (const QCString &app, const QCString &obj, const QCString &fun, const QByteArray& data, QCString& replyType, QByteArray &replyData)

Receive a DCOPSend or DCOPCall message from the server.

Parameters:

app | The application the message was intended for. Should be equal to our appId that we passed when the DCOPClient was created.
obj | The name of the object to pass the data on to.
fun | The name of the function in the object to call.
data | The arguments for the function.

bool find (const QCString &app, const QCString &obj, const QCString &fun, const QByteArray& data, QCString& replyType, QByteArray &replyData)

Receive a `DCOPFind` message from the server.

Parameters:

app | The application the message was intended for. Should be equal to our appId that we passed when the DCOPClient was created.
obj | The name of the object to pass the data on to.
fun | The name of the function in the object to call.
data | The arguments for the function.

QCString normalizeFunctionSignature ( const QCString& fun )

[static]

Normalize the function signature `fun.`

A normalized signature doesn't contain any unnecessary whitespace anymore. The remaining whitespace consists of single blanks only (0x20).

Example for a normalized signature:

       "someFunction(QString,int)"

When using send() or call(), normalization is done automatically for you.

QCString senderId ()

[const]

Retrieve the `appId` of the last application that talked to us.

void setDefaultObject ( const QCString& objId )

Installs object `objId` as application-wide default object.

All app-wide messages that have not been processed by the dcopclient will be send further to `objId.`

QCString defaultObject ()

[const]

Retrieve the current default object or an empty string if no object is installed as default object.

A default object receives application-wide messages that have not been processed by the DCOPClient itself.

void setNotifications ( bool enabled )

Enable / disable the applicationRegistered() / applicationRemoved() signals.

They are disabled by default.

DCOPClient* mainClient ()

[static]

Returns the application's main dcop client. The main client can be used by objects that do not have any specific access to a dcop client. In KDE applications, the main client usually is the same as KAppliction::dcopClient().

void setMainClient ( DCOPClient* )

[static]

Sets the application's main dcop client. The main client can be used by objects that do not have any specific access to a dcop client. In KDE applications, the main client usually is the same as KAppliction::dcopClient().

void applicationRegistered ( const QCString& appId )

[signal]

Indicate that the application `appId` has been registered with the server we are attached to.

You need to call setNotifications() first, to tell the DCOPServer that you want to get these events

void applicationRemoved ( const QCString& appId )

[signal]

Indicate that the formerly registered application `appId` has been removed.

You need to call setNotifications() first, to tell the DCOPServer that you want to get these events

void attachFailed (const QString &msg)

[signal]

Indicate that the process of establishing DCOP communications failed in some manner.

Usually attached to a dialog box or some other visual aid.

void blockUserInput ( bool )

[signal]

Indicate that user input shall be blocked or released, depending on the argument.

The signal is emitted whenever the client has to wait too long (i.e. more than 1/10 of a second) for an answer to a synchronous call. In that case, it will enter a local event loop to keep the GUI updated until finally an answer arrives.

In KDE, the KApplication object connects to this signal to be able to block any user input (i.e. mouse and key events) while we are waiting for an answer. If we did not do this, the application might end up in an illegal state, as a keyboard shortcut or a mouse action might cause another dcop call to be issued.

protected slots: void processSocketData (int socknum)

[slot]

private slots: void processPostedMessagesInternal ()

[slot]

bool attachInternal ( bool registerAsAnonymous = TRUE )

[slot]

bool callInternal (const QCString &remApp, const QCString &remObj, const QCString &remFun, const QByteArray &data, QCString& replyType, QByteArray &replyData, bool useEventLoop, bool fast, int minor_opcode)

[slot]