summaryrefslogtreecommitdiffstats
path: root/dcopperl/DCOP.pm
blob: f5b7cddf112cd603e2f2f572385a298a5cb089fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
package DCOP;

use strict;
use vars qw($VERSION @ISA);

use DynaLoader;
use DCOP::Object;

@ISA = qw(DynaLoader);

$VERSION = '0.01';

bootstrap DCOP $VERSION;

# Returns a DCOP::Object that is logically bound to a specific object of a specific app
sub createObject
{
    my ($self, $app, $obj) = @_;
    $obj = "default" unless defined $obj;
    $self = {
        CLIENT  => $self,
        APP     => $app,
        OBJ     => $obj,
    };
    bless $self, "DCOP::Object";
}

# That's it :)

1;
__END__

=head1 NAME

DCOP - Perl extension for communcation with KDE's DCOP server

=head1 SYNOPSIS

use DCOP;

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");

=head1 DESCRIPTION

The Desktop COmmunication Protocol is used by almost every KDE application
and is a lightweight but powerful IPC mechanism. For more information look at

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

=head2 Creation, Attachment and Registration

Creating a DCOP client is as simple as it gets:

  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();

=head2 Hello World!

Now that you have your client registered with the server, either anonymously
or by name, you can use it to query information about other registered applications.
To get a list with names of all clients, use:

  $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);

=head2 Let them do something

To simply dispatch a command neglecting its return value, use

  $client->send($appname, $objectname, $function, ...);

If you're interested in the return value, consider call:

  $client->call($appname, $objectname, $function, ...);

=head2 Autoload Magic

A much more intuitive way to use send and call is via DCOP::Object. This class
is not intended for explicit instantiation and is merely a very small autoload stub.
To get a DCOP::Object, simply call

  $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()");

=head2 Detailed Reference

sub new(); [ class method ]

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.

=head2 Datatypes

The following datatypes are currently supported in arguments to send and call and as
return values:

=over 4

=item * int
mapped to scalar

=item * TQCString
mapped to scalar

=item * TQString (no Unicode support yet, just latin 1)
mapped to scalar

=item * QCStringList
mapped to a reference to an array of scalars.

=item * TQStringList
mapped to a reference to an array of scalars.

=item * TQPoint (untested)
mapped to a reference to a two elemtent array [$x, $y]
named value support via hash planned.

=item * TQSize (untested)
mapped to a reference to a two elemtent array [$width, $height]
named value support via hash planned.

=item * TQRect (untested)
mapped to a reference to a four elemtent array [$left, $top, $width, $height]
named value support via hash planned (including alternative right and bottom / width height)

=item * KURL (only TQString url() now)
mapped to scalar

=item * DCOPRef (partially)
mapped to DCOP::Object, methods like isNull() missing.

=back

=head1 BUGS
Most probably many. A lot of memory leaks I fear, but that has to be proven.
There are many important features missing also. By now, it is not possible to
use DCOP.pm to receive DCOP messages. That is planned.

=head1 AUTHOR

Malte Starostik, malte@kde.org

=head1 SEE ALSO

perl(1).

=cut