org.kde.koala

Class DCOPClient

public class DCOPClient extends QObject

Inter-process communication and remote procedure calls for KDE applications. This class provides IPC and RPC for KDE applications. Usually you will not have to instantiate one yourself because KApplication contains a method to return a pointer to a DCOPClient object which can be used for your whole application. Before being able to send or receive any DCOP messages, you will have to attach your client object to the DCOP server, and then register your application with a specific name. See attach() and registerAs() for more information. Data to be sent should be serialized into a QDataStream which was initialized with the byte[] that you actually intend to send the data in. An example of how you might do this:
   byte[] data;
   QDataStream arg(data, IO_WriteOnly);
   arg << String("This is text I am serializing");
   client.send("someApp", "someObject", "someFunction(String)", data);
 
See DCOPClientSignals for signals emitted by DCOPClient

Author: Preston Brown , Matthias Ettrich

See Also: KApplication

UNKNOWN: Inter-process communication and remote procedure calls for KDE applications.

Constructor Summary
protected DCOPClient(Class dummy)
DCOPClient()
Constructs a new DCOP client, but does not attach to any server.
Method Summary
booleanacceptCalls()
Returns whether the client handles incoming calls.
StringappId()
Returns the current app id or a null string if the application hasn't yet been registered.
booleanattach()
Attaches to the DCOP server.
voidbindToApp()
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.
booleancall(String remApp, String remObj, String remFun, byte[] data, StringBuffer replyType, byte[] replyData, boolean useEventLoop, int timeout)
Performs a synchronous send and receive.
intcallAsync(String remApp, String remObj, String remFun, byte[] data, QObject callBackObj, String callBackSlot)
Performs a asynchronous send with receive callback.
StringclassName()
booleanconnectDCOPSignal(String sender, String senderObj, String signal, String receiverObj, String slot, boolean Volatile)
Connects to a DCOP signal.
static StringdcopServerFile(String hostname)
File with information how to reach the dcopserver.
static StringdcopServerFile()
StringdefaultObject()
Returns the current default object or an empty string if no object is installed as default object.
booleandetach()
Detaches from the DCOP server.
booleandisconnectDCOPSignal(String sender, String senderObj, String signal, String receiverObj, String slot)
Disconnects a DCOP signal.
voiddispose()
Delete the wrapped C++ instance ahead of finalize()
static voidemergencyClose()
voidemitDCOPSignal(String object, String signal, byte[] data)
Emits signal as DCOP signal from object object with data as arguments.
voidemitDCOPSignal(String signal, byte[] data)
protected voidfinalize()
Deletes the wrapped C++ instance
booleanfind(String app, String arg2, String fun, byte[] data, StringBuffer replyType, byte[] replyData)
Receives a DCOPFind message from the server.
static DCOPClientfindLocalClient(String _appId)
Look for the given client only in this process.
booleanfindObject(String remApp, String remObj, String remFun, byte[] data, StringBuffer foundApp, StringBuffer foundObj, boolean useEventLoop, int timeout)
Searches for an object which matches a criteria. findObject calls remFun in the applications and objects identified by remApp and remObj until remFun returns true.
static StringiceauthPath()
Return the path of iceauth or an empty string if not found.
booleanisApplicationRegistered(String remApp)
Checks whether remApp is registered with the DCOP server.
booleanisAttached()
Returns whether or not the client is attached to the server.
booleanisAttachedToForeignServer()
Returns whether the client is attached to a server owned by another user.
booleanisDisposed()
Has the wrapped C++ instance been deleted?
booleanisRegistered()
Returns whether or not the client is registered at the server.
booleanisSuspended()
Returns whether DCOP events are being processed.
static DCOPClientmainClient()
Returns the application's main dcop client.
QMetaObjectmetaObject()
static StringnormalizeFunctionSignature(String fun)
Normalizes the function signature fun. A normalized signature doesn't contain any unnecessary whitespace anymore.
static StringpostMortemFunction()
static StringpostMortemObject()
static StringpostMortemSender()
Provides information about the last DCOP call for debugging purposes.
booleanprocess(String fun, byte[] data, StringBuffer replyType, byte[] replyData)
Reimplement this function to handle app-wide function calls unassociated w/an object.
protected voidprocessSocketData(int socknum)
Process data from the socket.
booleanqtBridgeEnabled()
Returns whether the DCOP - Qt bridge is enabled.
booleanreceive(String app, String arg2, String fun, byte[] data, StringBuffer replyType, byte[] replyData)
Receives a DCOPSend or DCOPCall message from the server.
StringregisterAs(String appId, boolean addPID)
Registers at the DCOP server.
StringregisterAs(String appId)
ArrayListregisteredApplications()
Retrieves the list of all currently registered applications from dcopserver.
ArrayListremoteFunctions(String remApp, String remObj, boolean[] ok)
Retrieves the list of functions of the remote object remObj of application remApp
ArrayListremoteFunctions(String remApp, String remObj)
ArrayListremoteInterfaces(String remApp, String remObj, boolean[] ok)
Retrieves the list of interfaces of the remote object remObj of application remApp.
ArrayListremoteInterfaces(String remApp, String remObj)
ArrayListremoteObjects(String remApp, boolean[] ok)
Retrieves the list of objects of the remote application remApp.
ArrayListremoteObjects(String remApp)
voidresume()
Resumes the processing of DCOP events.
booleansend(String remApp, String remObj, String remFun, byte[] data)
Sends a data block to the server.
booleansend(String remApp, String remObj, String remFun, String data)
This function acts exactly the same as the above, but the data parameter can be specified as a String for convenience.
StringsenderId()
Returns the appId of the last application that talked to us.
voidsetAcceptCalls(boolean b)
Specify whether the client should accept incoming calls.
voidsetDaemonMode(boolean daemonMode)
Tells the dcopserver to treat the client as daemon client, not as regular client.
voidsetDefaultObject(String objId)
Installs object objId as application-wide default object.
static voidsetMainClient(DCOPClient mainClient)
Sets the application's main dcop client.
voidsetNotifications(boolean enabled)
Enables / disables the applicationRegistered() / applicationRemoved() signals.
voidsetPriorityCall(boolean arg1)
Switch to priority call mode.
voidsetQtBridgeEnabled(boolean b)
Specify whether Qt objects of the application should be accessible via DCOP.
static voidsetServerAddress(String addr)
Sets the address of a server to use upon attaching.
intsocket()
Returns the socket fd that is used for communication with the server.
voidsuspend()
Temporarily suspends processing of DCOP events.
inttransactionId()
Test whether the current function call is delayed.

Constructor Detail

DCOPClient

protected DCOPClient(Class dummy)

DCOPClient

public DCOPClient()
Constructs a new DCOP client, but does not attach to any server. @short Constructs a new DCOP client, but does not attach to any server.

Method Detail

acceptCalls

public boolean acceptCalls()
Returns whether the client handles incoming calls.

Returns: true if the client accepts calls

UNKNOWN: Returns whether the client handles incoming calls.

appId

public String appId()
Returns the current app id or a null string if the application hasn't yet been registered.

Returns: the application id, or null if not registered

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

attach

public boolean attach()
Attaches 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() + "-" + \. 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.

UNKNOWN: Attaches to the DCOP server.

bindToApp

public 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.

UNKNOWN:

call

public boolean call(String remApp, String remObj, String remFun, byte[] data, StringBuffer replyType, byte[] replyData, boolean useEventLoop, int timeout)
Performs a synchronous send and receive. The parameters are the same as for send, with the exception of another byte[] 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.

Parameters: remApp the remote application's id remObj the remote object id remFun the remote function id data the data to send replyType the type of the reply will be written here replyData the data of the reply will be written here useEventLoop if true the event loop will be started when the call blocks too long timeout timeout for the call in miliseconds, or -1 for no timeout

Returns: true if successful, false otherwise

See Also: DCOPClient

UNKNOWN: Performs a synchronous send and receive.

callAsync

public int callAsync(String remApp, String remObj, String remFun, byte[] data, QObject callBackObj, String callBackSlot)
Performs a asynchronous send with receive callback. The first four parameters are the same as for send. callBackObj and callBackSlot specify a call back slot that is called when an answer is received. The slot should have the following signature: callBackSlot(int callId, String replyType, const byte[] &replyData);

Parameters: remApp the remote application's id remObj the remote object id remFun the remote function id data the data to send callBackObj object to call back callBackSlot slot to call back

Returns: 0 on failure, on success a callId > 0 is returned that will be passed as first argument of the result call back

See Also: DCOPClient DCOPClient

UNKNOWN: Performs a asynchronous send with receive callback.

className

public String className()

connectDCOPSignal

public boolean connectDCOPSignal(String sender, String senderObj, String signal, String receiverObj, String slot, boolean Volatile)
Connects to a DCOP signal.

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.

  • Volatile is true and sender does not exist.
  • signal and slot do not have matching arguments.
  • @return false if a connection could not be established. This will be the case when

    UNKNOWN: Connects to a DCOP signal.

    dcopServerFile

    public static String dcopServerFile(String hostname)
    File with information how to reach the dcopserver.

    Parameters: hostname Hostname to use, if empty current hostname of the system is used.

    Returns: Filename that contains information how to contact the DCOPserver.

    UNKNOWN: File with information how to reach the dcopserver.

    dcopServerFile

    public static String dcopServerFile()

    defaultObject

    public String defaultObject()
    Returns 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.

    Returns: the id of the new default object

    UNKNOWN: Returns the current default object or an empty string if no object is installed as default object.

    detach

    public boolean detach()
    Detaches from the DCOP server.

    Returns: true if successful, false otherwise

    UNKNOWN: Detaches from the DCOP server.

    disconnectDCOPSignal

    public boolean disconnectDCOPSignal(String sender, String senderObj, String signal, String receiverObj, String slot)
    Disconnects a DCOP signal. A special case is when both sender & signal are empty. In this case all connections related to 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.

    UNKNOWN: Disconnects a DCOP signal.

    dispose

    public void dispose()
    Delete the wrapped C++ instance ahead of finalize()

    emergencyClose

    public static void emergencyClose()

    UNKNOWN:

    emitDCOPSignal

    public void emitDCOPSignal(String object, String signal, byte[] data)
    Emits signal as DCOP signal from object object with data as arguments.

    UNKNOWN: Emits signal as DCOP signal from object object with data as arguments.

    emitDCOPSignal

    public void emitDCOPSignal(String signal, byte[] data)

    finalize

    protected void finalize()
    Deletes the wrapped C++ instance

    find

    public boolean find(String app, String arg2, String fun, byte[] data, StringBuffer replyType, byte[] replyData)
    Receives 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. replyType write the reply type in this string replyData write the reply data in this array

    UNKNOWN:

    findLocalClient

    public static DCOPClient findLocalClient(String _appId)
    Look for the given client only in this process. This can be used to check whether a given client (by name) is running in the same process or in another one.

    UNKNOWN: Look for the given client only in this process.

    findObject

    public boolean findObject(String remApp, String remObj, String remFun, byte[] data, StringBuffer foundApp, StringBuffer foundObj, boolean useEventLoop, int timeout)
    Searches 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 boolean 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. useEventLoop if true the event loop will be started when the call blocks too long timeout timeout for the call in miliseconds, or -1 for no timeout

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

    See Also: DCOPClient

    UNKNOWN: Searches for an object which matches a criteria.

    iceauthPath

    public static String iceauthPath()
    Return the path of iceauth or an empty string if not found.

    UNKNOWN: Return the path of iceauth or an empty string if not found.

    isApplicationRegistered

    public boolean isApplicationRegistered(String remApp)
    Checks whether remApp is registered with the DCOP server.

    Parameters: remApp the id of the remote application

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

    UNKNOWN: Checks whether remApp is registered with the DCOP server.

    isAttached

    public boolean isAttached()
    Returns whether or not the client is attached to the server.

    Returns: true if attached, false if not

    UNKNOWN: Returns whether or not the client is attached to the server.

    isAttachedToForeignServer

    public boolean isAttachedToForeignServer()
    Returns whether the client is attached to a server owned by another user.

    Returns: true if attached to a foreign server, false if not

    UNKNOWN: Returns whether the client is attached to a server owned by another user.

    isDisposed

    public boolean isDisposed()
    Has the wrapped C++ instance been deleted?

    isRegistered

    public boolean isRegistered()
    Returns whether or not the client is registered at the server.

    Returns: true if registered at the server

    UNKNOWN: Returns whether or not the client is registered at the server.

    isSuspended

    public boolean isSuspended()
    Returns whether DCOP events are being processed.

    See Also: DCOPClient #

    UNKNOWN: Returns whether DCOP events are being processed.

    mainClient

    public static DCOPClient mainClient()
    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 KApplication.dcopClient().

    Returns: the application's main dcop client

    UNKNOWN: Returns the application's main dcop client.

    metaObject

    public QMetaObject metaObject()

    normalizeFunctionSignature

    public static String normalizeFunctionSignature(String fun)
    Normalizes 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(String,int)"
    		 
    When using send() or call(), normalization is done automatically for you.

    Parameters: fun the function signature to normalize

    Returns: the normalized function

    UNKNOWN: Normalizes the function signature fun.

    postMortemFunction

    public static String postMortemFunction()

    UNKNOWN: @short @internal

    postMortemObject

    public static String postMortemObject()

    UNKNOWN: @short @internal

    postMortemSender

    public static String postMortemSender()
    Provides information about the last DCOP call for debugging purposes.

    UNKNOWN:

    process

    public boolean process(String fun, byte[] data, StringBuffer replyType, byte[] replyData)
    Reimplement this function 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.

    Parameters: fun the normalized function signature data the received data replyType write the reply type in this string replyData write the reply data in this array

    Returns: true if successful, false otherwise

    See Also: DCOPClient

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

    processSocketData

    protected void processSocketData(int socknum)
    Process data from the socket.

    Parameters: socknum the fd of the socket

    UNKNOWN: Process data from the socket.

    qtBridgeEnabled

    public boolean qtBridgeEnabled()
    Returns whether the DCOP - Qt bridge is enabled. By default the DCOP - Qt bridge is enabled.

    Returns: true if Qt objects are accessible over DCOP

    UNKNOWN: Returns whether the DCOP - Qt bridge is enabled.

    receive

    public boolean receive(String app, String arg2, String fun, byte[] data, StringBuffer replyType, byte[] replyData)
    Receives 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. replyType write the reply type in this string replyData write the reply data in this array

    Returns: true if successful, false otherwise

    UNKNOWN:

    registerAs

    public String registerAs(String appId, boolean addPID)
    Registers 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".

    Parameters: appId the id of the application addPID true to add the process id

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

    UNKNOWN: Registers at the DCOP server.

    registerAs

    public String registerAs(String appId)

    registeredApplications

    public ArrayList registeredApplications()
    Retrieves the list of all currently registered applications from dcopserver.

    Returns: a list of all regietered applications

    UNKNOWN: Retrieves the list of all currently registered applications from dcopserver.

    remoteFunctions

    public ArrayList remoteFunctions(String remApp, String remObj, boolean[] ok)
    Retrieves the list of functions of the remote object remObj of application remApp

    Parameters: remApp the id of the application remObj the id of the object ok if not null, the function sets ok to true if successful and false if an error occurred

    Returns: the list of function ids

    UNKNOWN: Retrieves the list of functions of the remote object remObj of application remApp

    remoteFunctions

    public ArrayList remoteFunctions(String remApp, String remObj)

    remoteInterfaces

    public ArrayList remoteInterfaces(String remApp, String remObj, boolean[] ok)
    Retrieves the list of interfaces of the remote object remObj of application remApp.

    Parameters: remApp the id of the application remObj the id of the object ok if not null, the function sets ok to true if successful and false if an error occurred

    Returns: the list of interfaces

    UNKNOWN: Retrieves the list of interfaces of the remote object remObj of application remApp.

    remoteInterfaces

    public ArrayList remoteInterfaces(String remApp, String remObj)

    remoteObjects

    public ArrayList remoteObjects(String remApp, boolean[] ok)
    Retrieves the list of objects of the remote application remApp.

    Parameters: remApp he id of the application ok if not null, the function sets ok to true if successful and false if an error occurred

    Returns: the list of object ids

    UNKNOWN: Retrieves the list of objects of the remote application remApp.

    remoteObjects

    public ArrayList remoteObjects(String remApp)

    resume

    public void resume()
    Resumes the processing of DCOP events.

    See Also: # DCOPClient

    UNKNOWN: Resumes the processing of DCOP events.

    send

    public boolean send(String remApp, String remObj, String remFun, byte[] data)
    Sends 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.

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

    UNKNOWN: Sends a data block to the server.

    send

    public boolean send(String remApp, String remObj, String remFun, String data)
    This function acts exactly the same as the above, but the data parameter can be specified as a String for convenience.

    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.

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

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

    senderId

    public String senderId()
    Returns the appId of the last application that talked to us.

    Returns: the application id of the last application that send a message to this client

    UNKNOWN: Returns the appId of the last application that talked to us.

    setAcceptCalls

    public void setAcceptCalls(boolean b)
    Specify whether the client should accept incoming calls. By default clients accept incoming calls, but not when connected to a foreign server.

    Parameters: b true to accept calls, false to reject them

    UNKNOWN: Specify whether the client should accept incoming calls.

    setDaemonMode

    public void setDaemonMode(boolean daemonMode)
    Tells the dcopserver to treat the client as daemon client, not as regular client. If the number of regular clients drops down to zero, the dcopserver will emit a KDE termination signal after 10 seconds.

    Parameters: daemonMode true to enable daemon mode, false to disable

    UNKNOWN: Tells the dcopserver to treat the client as daemon client, not as regular client.

    setDefaultObject

    public void setDefaultObject(String 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.

    Parameters: objId the id of the new default object

    UNKNOWN: Installs object objId as application-wide default object.

    setMainClient

    public static void setMainClient(DCOPClient mainClient)
    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 KApplication.dcopClient().

    Parameters: mainClient the new main dcop client

    UNKNOWN: Sets the application's main dcop client.

    setNotifications

    public void setNotifications(boolean enabled)
    Enables / disables the applicationRegistered() / applicationRemoved() signals. Note that a counter is maintained about how often this method was called. If this method is called twice with enabled set to true, notifications will be enabled until it was called with enabled set to false as often. They are disabled by default.

    Parameters: enabled true to enable notifications, false to disable

    UNKNOWN: Enables / disables the applicationRegistered() / applicationRemoved() signals.

    setPriorityCall

    public void setPriorityCall(boolean arg1)
    Switch to priority call mode.

    UNKNOWN:

    setQtBridgeEnabled

    public void setQtBridgeEnabled(boolean b)
    Specify whether Qt objects of the application should be accessible via DCOP. By default the DCOP - Qt bridge is enabled.

    Parameters: b true to make Qt objects accessible over DCOP

    UNKNOWN: Specify whether Qt objects of the application should be accessible via DCOP.

    setServerAddress

    public static void setServerAddress(String addr)
    Sets 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.

    Parameters: addr the new address of the server

    UNKNOWN: Sets the address of a server to use upon attaching.

    socket

    public int socket()
    Returns the socket fd that is used for communication with the server.

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

    UNKNOWN: Returns the socket fd that is used for communication with the server.

    suspend

    public void suspend()
    Temporarily suspends processing of DCOP events. This can be useful 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.

    See Also: DCOPClient DCOPClient

    UNKNOWN: Temporarily suspends processing of DCOP events.

    transactionId

    public int 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.

    See Also: DCOPClient DCOPClient

    UNKNOWN: Test whether the current function call is delayed.