DCOPSection: User Contributed Perl Documentation (3)Updated: 2003-08-05 |
DCOPSection: User Contributed Perl Documentation (3)Updated: 2003-08-05 |
my $client = new DCOP; $client->attach(); $running_apps = $client->registeredApplications(); $client->send(``kmail'', ``KMailIface'', ``checkMail()'');
my $kmail = $client->createObject(``kmail'', ``KMailIface'');
$kmail->openComposer(``fred@outer.space'',
undef,
undef,
``This is a mail initiated by DCOP.pm'',
0,
``file:/home/joe/file/with/mail/to/send'');
http://developer.kde.org/documentation/library/2.0-api/dcop/HOWTO.html
This Perl extension can be used to send commands to any currently registered DCOP application, as well as query which apps are registered and what interfaces with what functions they offer. Additionally you can use DCOP::Object to trigger DCOP sends or calls as native methods of DCOP::Object (see the secion on Autoload Magic below).
use DCOP;
$client = new DCOP;
That's it. Some arguments to new are planned for future releases. After creation the client is not attached to the server. The easiest way to establish a connection is
$client->attach();
which registers your DCOP client anonymously. To register with a well known name use:
$client->registerAs("fred");
NOTE: registerAs is currently disabled
To close the connection, simply call
$client->detach();
$client->registeredApplications();
To retrieve the Qt object hierarchy of an application, call
$client->remoteObjects($appname);
Similarly you can get a list of supported interfaces with
$client->remoteIterfaces($appname, $objectname);
And to know what you can do with all these nice interfaces, learn about their functions:
$client->remoteFunctions($appname, $objectname);
$client->send($appname, $objectname, $function, ...);
If you're interested in the return value, consider call:
$client->call($appname, $objectname, $function, ...);
$obj = $client->createObject($appname [, $objectname]);
The returned $obj is a DCOP::Object ``bound'' to the specified application and object (or the app's default object if $objectname is omitted or undef). This DCOP::Object has only two known methods, _app() and _object() which return the application and object name respectively and are merely for internal use. Any other method you call will be looked up in the functions() list of the target object. So, if you created it e.g. with
$obj = $client->createObject("kmail", "KMailIface");
You can simply invoke
$obj->checkMail();
instead of
$client->send("kmail", "KMailIface", "checkMail()");
takes no arguments by now and returns a blessed reference to a new DCOP client.
sub attach();
returns a true value if the attachment succeeded or undef on error.
sub detach();
returns a true value if the client was successfully detached or undef on error.
sub isAttached();
returns true or undef whether the client is attached or not.
sub registerAs($appId [, $addPID]); CURRENTLY DISABLED
registers the client with the name $appId or $appId with a number appended if a client by that name already exists. If $addPID is true, the PID of the client is appended to the appId, seperated by a hyphen. If addPID is ommited, it defaults to true. To not add a PID, specify undef or zero. registerAs returns the actual appId after the PID or possibly a sequence number has been added. If you call this method on an already attached or registered client, the old appId will be replaced with the new one.
sub isRegistered(); CURRENTLY DISABLED
like isAttached but returns true only if the client used registerAs.
sub appId();
returns the appId the client is known as or undef if it's not registered or only attached anonymously.
sub send($app, $object, $function [, ...])
dispatches a function call without waiting for completion and thus without retrieving a return value. Returns true if a matching object has been found or undef otherwise. $app is the name of a registered application, $object the name of an object implemented by $app or undef for the default object, $function is the signature of the function to be called. Any following arguments are passed as parameters to the called function. Make sure that they match the function's signature in count and types (see Datatypes below) or your program will die. (This will be configurable in later versions)
sub call($app, $object, $function [, ...])
like send, but blocks until the called function returns and supplies the return value of that function (see Datatypes below). In scalar context, the value returned is the function's return value, in list context call returns a two element list with the first item set to the function's repturn value and the second set to true or undef according to success or failure of the DCOP call.
sub findObject
not really implemented, yet.
sub emitDCOPSignal
dito.
sub isApplicationRegistered($app)
returns true if an application with the given name is known to the DCOP server or otherwise undef.
sub registeredApplications()
returns a reference to an array with the names of all currently registered applications. On error it returns undef.
sub remoteObjects($app)
returns a reference to an array with the names of the objects supported by the named application. On error it returns undef.
sub remoteInterfaces($app, $object)
returns a reference to an array with the names of the interfaces supported by the given application and object. On error it returns undef.
sub remoteFunctions($app, $object)
returns a reference to an array with the names of the functions the specified interface supports. The functions are returned as their signatures with parameter names and return type like
QCStringList functions()
sub normalizeSignature($signature)
removes extraneous whitespace from a function signature.
sub canonicalizeSignature($signature)
mostly for internal use. Calls normalizeSignature and then strips parameter names and return type from it.