summaryrefslogtreecommitdiffstats
path: root/dcop/dcopclient.h
blob: 4cb4b2f6e7c8f98b8f782f1361687cac39008406 (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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
/*
Copyright (c) 1999 Preston Brown <pbrown@kde.org>
Copyright (c) 1999, 2000 Matthias Ettrich <ettrich@kde.org>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef _DCOPCLIENT_H
#define _DCOPCLIENT_H

#include <tqobject.h>
#include <tqcstring.h>
#include <tqvaluelist.h>
#include <tqstring.h>
#include <kdatastream.h> // needed for proper bool marshalling
#include <tdelibs_export.h>

class DCOPObjectProxy;
class DCOPClientPrivate;
class DCOPClientTransaction;

typedef TQValueList<TQCString> QCStringList;

/**
 * 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 TDEApplication
 * 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 TQDataStream which was
 * initialized with the TQByteArray that you actually intend to send
 * the data in.  An example of how you might do this:
 *
 * \code
 *   TQByteArray data;
 *   TQDataStream arg(data, IO_WriteOnly);
 *   arg << TQString("This is text I am serializing");
 *   client->send("someApp", "someObject", "someFunction(TQString)", data);
 * \endcode
 *
 * @see TDEApplication::dcopClient()
 * @author Preston Brown <pbrown@kde.org>, Matthias Ettrich <ettrich@kde.org>
 */
class DCOP_EXPORT DCOPClient : public TQObject
{
  Q_OBJECT
  

 public:
  /**
   * Constructs a new DCOP client, but does not attach to any server.  */
  DCOPClient();

  /**
   * Cleans up any open connections and dynamic data.
   */
  virtual ~DCOPClient();

  /**
   * 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.
   * @param addr the new address of the server
   */
  static void setServerAddress(const TQCString &addr);

  /**
   * 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 TQApplication object exists then client registers itself as
   * TQApplication::name() + "-" + \<pid\>.
   * If no TQApplication object exists the client registers itself as
   * "anonymous".
   *
   * If you want to register differently, you should use registerAs()
   * instead.
   *
   * @return true if attaching was successful.
   */
  bool attach();

  /**
   * @internal
   * 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.
   */
  void bindToApp();

  /**
   * Detaches from the DCOP server.
   * @return true if successful, false otherwise
   */
  bool detach();

  /**
   * Returns whether or not the client is attached to the server.
   * @return true if attached, false if not
   */
  bool isAttached() const;

  /**
   * Returns whether the client is attached to a server owned by
   * another user.
   * @return true if attached to a foreign server, false if not
   */
  bool isAttachedToForeignServer() const;

  /**
   * Returns whether the client handles incoming calls.
   * @return true if the client accepts calls
   */
  bool acceptCalls() const;

  /**
   * Specify whether the client should accept incoming calls.
   * By default clients accept incoming calls, but not when connected
   * to a foreign server.
   * @param b true to accept calls, false to reject them
   */
  void setAcceptCalls(bool b);

  /**
   * Returns whether the DCOP - Qt bridge is enabled.
   * By default the DCOP - Qt bridge is enabled.
   * @return true if Qt objects are accessible over DCOP
   * @since 3.0.2
   */
  bool qtBridgeEnabled(); // ### KDE 4.0: make const

  /**
   * Specify whether Qt objects of the application should be accessible
   * via DCOP.
   * By default the DCOP - Qt bridge is enabled.
   * @param b true to make Qt objects accessible over DCOP
   * @since 3.0.2
   */
  void setQtBridgeEnabled(bool b);

  /**
   * Registers at the DCOP server.
   *
   * If the application was already registered,
   * the registration will be re-done with the new appId.
   *
   * @p appId is a @p 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 @p 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 @p 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".
   *
   * @param appId the id of the application
   * @param addPID true to add the process id
   * @return The actual @p appId used for the registration or a null string
   * if the registration wasn't successful.
   */
  TQCString registerAs( const TQCString &appId, bool addPID = true );

  /**
   * Returns whether or not the client is registered at the server.
   * @return true if registered at the server
   */
  bool isRegistered() const;

  /**
   * Returns the current app id or a null string if the application
   * hasn't yet been registered.
   * @return the application id, or TQString::null if not registered
   */
  TQCString appId() const;

  /**
   * Returns the socket fd that is used for communication with the server.
   * @return The socket over which DCOP is communicating with the server.
   */
  int socket() const;

  /**
   * 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 resume()
   * @see isSuspended()
   */
  void suspend();

  /**
   * Resumes the processing of DCOP events.
   * @see suspend().
   * @see isSuspended()
   */
  void resume();

  /**
   * Returns whether DCOP events are being processed.
   * @see suspend()
   * @see resume().
   * @since 3.1
   */
  bool isSuspended() const;

  /**
   * Sends a data block to the server.
   *
   * @param remApp The remote application id.
   * @param remObj The name of the remote object.
   * @param remFun The remote function in the specified object to call.
   * @param data The data to provide to the remote function.
   *
   * @return Whether or not the server was able to accept the send.
   */
  bool send(const TQCString &remApp, const TQCString &remObj,
	    const TQCString &remFun, const TQByteArray &data);

  /**
   * This function acts exactly the same as the above, but the data
   * parameter can be specified as a TQString for convenience.
   *
   * @param remApp The remote application id.
   * @param remObj The name of the remote object.
   * @param remFun The remote function in the specified object to call.
   * @param data The data to provide to the remote function.
   *
   * @return Whether or not the server was able to accept the send.
   */
  bool send(const TQCString &remApp, const TQCString &remObj,
	    const TQCString &remFun, const TQString &data);

  /**
   * Performs a synchronous send and receive.
   *
   *  The parameters are the same as for send, with the exception of
   *  another TQByteArray being provided for results to be
   *  (optionally) returned in.
   *
   * A call blocks the application until the process receives the
   * answer.
   *
   * If @p 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.
   *
   * @param remApp the remote application's id
   * @param remObj the remote object id
   * @param remFun the remote function id
   * @param data the data to send
   * @param replyType the type of the reply will be written here
   * @param replyData the data of the reply will be written here
   * @param useEventLoop if true the event loop will be started when
   *         the call blocks too long
   * @param timeout timeout for the call in miliseconds, or -1 for no timeout
   * @param forceRemote if set do not allow calls within the current application
   *         to bypass the remote call mechanism
   * @return true if successful, false otherwise
   *
   * @since 3.2
   *
   * @see send()
   */

  bool call(const TQCString &remApp, const TQCString &remObj,
	    const TQCString &remFun, const TQByteArray &data,
	    TQCString& replyType, TQByteArray &replyData,
	    bool useEventLoop/*=false*/, int timeout/*=-1*/,
	    bool forceRemote/*=false*/);

  /**
   * @deprecated
   */
  // KDE4 merge with above
  bool call(const TQCString &remApp, const TQCString &remObj,
	    const TQCString &remFun, const TQByteArray &data,
	    TQCString& replyType, TQByteArray &replyData,
	    bool useEventLoop/*=false*/, int timeout/*=-1*/);
  /**
   * @deprecated
   */
  // KDE4 merge with above
  bool call(const TQCString &remApp, const TQCString &remObj,
	    const TQCString &remFun, const TQByteArray &data,
	    TQCString& replyType, TQByteArray &replyData,
	    bool useEventLoop=false);

  /**
   * Performs a asynchronous send with receive callback.
   *
   *  The first four parameters are the same as for send.
   *
   * @p callBackObj and @p callBackSlot specify a call back
   * slot that is called when an answer is received.
   *
   * The slot should have the following signature:
   * callBackSlot(int callId, const TQCString& replyType,
   *              const TQByteArray &replyData);
   *
   *
   * @param remApp the remote application's id
   * @param remObj the remote object id
   * @param remFun the remote function id
   * @param data the data to send
   * @param callBackObj object to call back
   * @param callBackSlot slot to call back
   * @return 0 on failure, on success a callId > 0 is
   * returned that will be passed as first argument of
   * the result call back
   *
   * @see send()
   * @see callback()
   *
   * @since 3.2
   */
  int callAsync(const TQCString &remApp, const TQCString &remObj,
                const TQCString &remFun, const TQByteArray &data,
                TQObject *callBackObj, const char *callBackSlot);

  /**
   * Searches for an object which matches a criteria.
   *
   * findObject calls @p remFun in the applications and objects identified
   * by @p remApp and @p remObj until @p remFun returns true. The name of
   * the application and object that returned true are returned in
   * @p foundApp and @p foundObj respectively.
   *
   * If @p remFun is empty a default function is called in the object
   * which always returns @p true.
   *
   * A findObject blocks the application until the process receives the
   * answer.
   *
   * If @p 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.
   *
   * @param remApp The remote application id.
   * @param remObj The name of the remote object.
   * @param remFun The remote function in the specified object to call.
   *               This function should return a bool and is used as
   *               criteria.
   * @param data The data to provide to the remote function.
   * @param foundApp The remote application id that matched the criteria.
   * @param foundObj The remote object that matched the criteria.
   * @param useEventLoop if true the event loop will be started when
   *         the call blocks too long
   * @param timeout timeout for the call in miliseconds, or -1 for no timeout
   * @return true is returned when an object was found for which @p remFun
   *         returned true. If no such object is the function returns false.
   *
   * @since 3.2
   *
   * @see send()
   */
  bool findObject(const TQCString &remApp, const TQCString &remObj,
	    const TQCString &remFun, const TQByteArray &data,
	    TQCString &foundApp, TQCString &foundObj,
	    bool useEventLoop/*=false*/, int timeout/*=-1*/);

  /**
   * @deprecated
   */
  // KDE4 merge with above
  bool findObject(const TQCString &remApp, const TQCString &remObj,
	    const TQCString &remFun, const TQByteArray &data,
	    TQCString &foundApp, TQCString &foundObj,
	    bool useEventLoop=false);


  /**
   * Emits @p signal as DCOP signal from object @p object with @p data as
   * arguments.
   */
  void emitDCOPSignal( const TQCString &object, const TQCString &signal,
                       const TQByteArray &data);

  /* For backwards compatibility */
  void emitDCOPSignal( const TQCString &signal, const TQByteArray &data);

  /**
   * Connects to a DCOP signal.
   * @param sender the name of the client that emits the signal. When empty
   * the signal will be passed from any client.
   * @param senderObj the name of the sending object that emits the signal.
   * @param signal the name of the signal. The arguments should match with slot.
   * @param receiverObj The name of the object to call
   * @param slot The name of the slot to call. Its arguments should match with signal.
   * @param Volatile If true, the connection will not be reestablished when
   * @p sender unregisters and reregisters with DCOP. In this case the @p sender
   * must be registered when the connection is made.
   * If false, the connection will be reestablished when @p sender reregisters.
   * In this case the connection can be made even if @p sender is not registered
   * at that time.
   *
   * @return false if a connection could not be established.
   * This will be the case when
   * @li @p Volatile is true and @p sender  does not exist.
   * @li @p signal and @p slot do not have matching arguments.
   */
  bool connectDCOPSignal( const TQCString &sender, const TQCString &senderObj,
                          const TQCString &signal,
                          const TQCString &receiverObj, const TQCString &slot,
                          bool Volatile);

  /**
   * @deprecated
   * For backwards compatibility
   */
  bool connectDCOPSignal( const TQCString &sender, const TQCString &signal,
                          const TQCString &receiverObj, const TQCString &slot,
                          bool Volatile) KDE_DEPRECATED;

  /**
   * Disconnects a DCOP signal.
   *
   * A special case is when both @p sender & @p signal are empty. In this
   * case all connections related to @p receiverObj in the current client
   * are disconnected. (Both connections from as well as to this object!)
   *
   * @param sender the name of the client that emits the signal.
   * @param senderObj the name of the object that emits the signal.
   * If empty all objects will be disconnected.
   * @param signal the name of the signal. The arguments should match with slot.
   * @param receiverObj The name of the object the signal is connected to.
   * If empty all objects will be disconnected.
   * @param slot The name of the slot the signal is connected to.
   * If empty all slots will be disconnected.
   * @return false if no connection(s) where removed.
   */
  bool disconnectDCOPSignal( const TQCString &sender, const TQCString &senderObj,
                          const TQCString &signal,
                          const TQCString &receiverObj, const TQCString &slot);

  /**
   * @deprecated
   * For backwards compatibility
   */
  bool disconnectDCOPSignal( const TQCString &sender, const TQCString &signal,
                          const TQCString &receiverObj, const TQCString &slot) KDE_DEPRECATED;

  /**
   * Reimplement this function to handle app-wide function calls unassociated w/an object.
   *
   * Note that @p 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.
   *
   * @param fun the normalized function signature
   * @param data the received data
   * @param replyType write the reply type in this string
   * @param replyData write the reply data in this array
   * @return true if successful, false otherwise
   * @see setDefaultObject()
   */
  virtual bool process(const TQCString &fun, const TQByteArray &data,
		       TQCString& replyType, TQByteArray &replyData);

  /**
   * Delays 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!
   * @see endTransaction()
   */
  DCOPClientTransaction *beginTransaction( );

  /**
   * Sends the delayed reply of a function call.
   * @param t the transaction as received from beginTransaction()
   * @param replyType write the reply type in this string
   * @param replyData write the reply data in this array
   * @see beginTransaction()
   */
  void endTransaction( DCOPClientTransaction *t, TQCString& replyType, TQByteArray &replyData);

  /**
   * Test whether the current function call is delayed.
   *
   * Note: Should be called from inside process() only!
   * @return The ID of the current transaction or
   *         0 if no transaction is going on.
   * @see process()
   * @see beginTransaction()
   */
  TQ_INT32 transactionId() const;

  /**
   * Checks whether @p remApp is registered with the DCOP server.
   * @param remApp the id of the remote application
   * @return true if the remote application is registered, otherwise @p false.
   */
  bool isApplicationRegistered( const TQCString& remApp);

  /**
   * Retrieves the list of all currently registered applications
   * from dcopserver.
   * @return a list of all regietered applications
   */
  QCStringList registeredApplications();

  /**
   * Retrieves the list of objects of the remote application @p remApp.
   * @param remApp he id of the application
   * @param ok if not null, the function sets @p ok to true if successful
   *           and false if an error occurred
   * @return the list of object ids
   */
  QCStringList remoteObjects( const TQCString& remApp, bool *ok = 0 );

  /**
   * Retrieves the list of interfaces of the remote object @p remObj
   * of application @p remApp.
   * @param remApp the id of the application
   * @param remObj the id of the object
   * @param ok if not null, the function sets @p ok to true if successful
   *           and false if an error occurred
   * @return the list of interfaces
  */
  QCStringList remoteInterfaces( const TQCString& remApp, const TQCString& remObj , bool *ok = 0 );

  /**
   * Retrieves the list of functions of the remote object @p remObj
   * of application @p remApp
   * @param remApp the id of the application
   * @param remObj the id of the object
   * @param ok if not null, the function sets @p ok to true if successful
   *           and false if an error occurred
   * @return the list of function ids
  */
  QCStringList remoteFunctions( const TQCString& remApp, const TQCString& remObj , bool *ok = 0 );

  /**
   * @internal
   * Receives a DCOPSend or DCOPCall message from the server.
   *
   * @param app The application the message was intended for.  Should be
   *        equal to our appId that we passed when the DCOPClient was
   *        created.
   * @param obj The name of the object to pass the data on to.
   * @param fun The name of the function in the object to call.
   * @param data The arguments for the function.
   * @param replyType write the reply type in this string
   * @param replyData write the reply data in this array
   * @return true if successful, false otherwise
   */
  bool receive(const TQCString &app, const TQCString &obj,
	       const TQCString &fun, const TQByteArray& data,
	       TQCString& replyType, TQByteArray &replyData);

  /**
   * @internal
   * Receives a @p DCOPFind message from the server.
   *
   * @param app The application the message was intended for.  Should be
   *        equal to our appId that we passed when the DCOPClient was
   *        created.
   * @param obj The name of the object to pass the data on to.
   * @param fun The name of the function in the object to call.
   * @param data The arguments for the function.
   * @param replyType write the reply type in this string
   * @param replyData write the reply data in this array
   */
  bool find(const TQCString &app, const TQCString &obj,
	    const TQCString &fun, const TQByteArray& data,
	    TQCString& replyType, TQByteArray &replyData);

  /**
   * Normalizes the function signature @p 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:
   * \code
   *   "someFunction(TQString,int)"
   * \endcode
   *
   * When using send() or call(), normalization is done
   * automatically for you.
   *
   * @param fun the function signature to normalize
   * @return the normalized function
   */
  static TQCString normalizeFunctionSignature( const TQCString& fun );


  /**
   * Returns the appId of the last application that talked to us.
   * @return the application id of the last application that send a message
   *         to this client
   */
  TQCString senderId() const;


   /**
    * Installs object @p objId as application-wide default object.
    *
    * All app-wide messages that have not been processed by the dcopclient
    * will be send further to @p objId.
    * @param objId the id of the new default object
    */
  void setDefaultObject( const TQCString& objId );

    /**
     * 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.
    * @return the id of the new default object
     */
  TQCString defaultObject() const;

  /**
   * 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 @p enabled set to
   * true, notifications will be enabled until it was called with
   * @p enabled set to false as often.
   *
   * They are disabled by default.
   * @param enabled true to enable notifications, false to disable
   */
  void setNotifications( bool enabled );

  /**
   * 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.
   * @param daemonMode true to enable daemon mode, false to disable
   */
  void setDaemonMode( bool daemonMode );

  /**
   * @internal
   *
   * Switch to priority call mode.
   */
  void setPriorityCall(bool);

  /**
   * 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 TDEApplication::dcopClient().
   * @return the application's main dcop client
   */
  static 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 TDEApplication::dcopClient().
   * @param mainClient the new main dcop client
   */
  static void setMainClient( DCOPClient* mainClient);

  /**
   * 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.
   */
  static DCOPClient* findLocalClient( const TQCString &_appId );

  /**
    * @internal Do not use.
    */
  static void emergencyClose();

  /**
    * @internal Do not use.
    *
    * Provides information about the last DCOP call for debugging purposes.
    */
  static const char *postMortemSender();
  /** @internal */
  static const char *postMortemObject();
  /** @internal */
  static const char *postMortemFunction();

  /**
    * File with information how to reach the dcopserver.
    * @param hostname Hostname to use, if empty current hostname of
    * the system is used.
    * @return Filename that contains information how to contact the
    * DCOPserver.
    */
  static TQCString dcopServerFile(const TQCString &hostname=0);

  /**
   * @deprecated
   * For backwards compatibility with KDE 2.x
   * // KDE4 remove
   */
  static TQCString dcopServerFileOld(const TQCString &hostname=0) KDE_DEPRECATED;

  /**
   * Return the path of iceauth or an empty string if not found.
   */
  static TQCString iceauthPath();

signals:
  /**
   * Indicates that the application @p appId has been registered with
   * the server we are attached to.
   *
   * You need to call setNotifications() first, to tell the DCOP server
   * that you want to get these events.
   * @param appId the id of the new application
   */
  void applicationRegistered( const TQCString& appId );
  /**
   * Indicates that the formerly registered application @p appId has
   * been removed.
   *
   * You need to call setNotifications() first, to tell the
   * DCOP server that you want to get these events.
   * @param appId the id of the removed application
   */
  void applicationRemoved( const TQCString& appId );

  /**
   * Indicates that the process of establishing DCOP communications failed
   * in some manner.
   *
   *  Usually attached to a dialog box or some other visual
   * aid.
   * @param msg the message tha contains further information
   */
  void attachFailed(const TQString &msg);

  /**
   * Indicates 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 TDEApplication 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.
   * @param block true to block user input, false otherwise
   */
  void blockUserInput( bool block );

  /**
   * @internal
   *
   * Signal used for callbacks of async calls.
   * This signal is automatically connected to the call back
   * slot specified in the async call.
   * @see callAsync()
   * @since 3.2
   */
  void callBack(int, const TQCString&, const TQByteArray &);

public slots:
  /**
   * Process data from the socket.
   * @param socknum the fd of the socket
   */
  void processSocketData(int socknum);

protected slots:

private slots:
  void processPostedMessagesInternal();
  void asyncReplyReady();
  void eventLoopTimeout();

public:
  class ReplyStruct;

  /**
   * @internal
   **/
  void handleAsyncReply(ReplyStruct *replyStruct);

private:

  bool isLocalTransactionFinished(TQ_INT32 id, TQCString &replyType, TQByteArray &replyData);

  bool attachInternal( bool registerAsAnonymous = true );

  bool callInternal(const TQCString &remApp, const TQCString &remObj,
	    const TQCString &remFun, const TQByteArray &data,
	    TQCString& replyType, TQByteArray &replyData,
	    bool useEventLoop, int timeout, int minor_opcode);


  bool callInternal(const TQCString &remApp, const TQCString &remObjId,
            const TQCString &remFun, const TQByteArray &data,
            ReplyStruct *replyStruct,
            bool useEventLoop, int timeout, int minor_opcode);

protected:
  virtual void virtual_hook( int id, void* data );
private:
  DCOPClientPrivate *d;
};

#endif