summaryrefslogtreecommitdiffstats
path: root/dcop/dcopsignals.h
blob: 8a930b85fb616ae13a7204d91350821ee414918b (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
/*
Copyright (c) 2000 Waldo Bastian <bastian@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 DCOPSIGNALS_H
#define DCOPSIGNALS_H "$Id$"

#include <tqdict.h>
#include <tqasciidict.h>
#include <tqptrlist.h>
#include <tqstring.h>
#include "tdelibs_export.h"

class DCOPConnection;

/** \internal
  * This requires:
  * DCOPSignalConnectionList * DCOPConnection::signalConnectionList()
*/
class DCOP_EXPORT DCOPSignalConnection
{
public:
   TQCString sender;      // Sender client, empty means any client
   DCOPConnection *senderConn; //Sender client.
   TQCString senderObj;   // Object that sends the signal.
   TQCString signal;      // Signal name. Connections are sorted on signal name.

   DCOPConnection *recvConn; // Client that wants to receive the signal
   TQCString recvObj;     // Object that wants to receive the signal
   TQCString slot;        // Function to send to in the object.
};

/** \internal */
class DCOP_EXPORT DCOPSignalConnectionList : public TQPtrList<DCOPSignalConnection>
{
public:
   DCOPSignalConnectionList() { };
};

/**
 * @internal
 */
class DCOP_EXPORT DCOPSignals
{
public:
   DCOPSignals();

   /**
    * Client "conn" emits the signal "fun" with "data" as arguments.
    * conn is 0L if the dcopserver sends the signal itself
    *
    * The emitting object is encoded in "fun".
    *
    * If "excludeSelf" is true, signal is never send to "conn" itself.
    */
   void emitSignal( DCOPConnection *conn, const TQCString &fun, const TQByteArray &data, bool excludeSelf);

   /**
    * Connects "signal" of the client named "sender" with the "slot" of
    * "receiverObj" in the "conn" client.
    *
    * If "Volatile" is true the connection will be removed when either
    * "sender" or "conn" unregisters.
    *
    * If "Volatile" is false the connection will only be removed when
    * "conn" unregisters.
    *
    * Returns true if succesfull. False on failure.
    * An attempt to create a Volatile connection to a non-existing client
    * results in a failure.
    */
   bool connectSignal( const TQCString &sender, const TQCString &senderObj,
                       const TQCString &signal,
                       DCOPConnection *conn, const TQCString &receiverObj,
                       const TQCString &slot, bool Volatile);

   /**
    * Disconnects "signal" of the client named "sender" from the "slot" of
    * "receiverObj" in the "conn" client.
    *
    * If "receiverObj" is empty, every object is disconnected.
    * If "slot" is empty, every slot is disconnected.
    *
    * Returns true if successful, false if no connection was found.
    */
   bool disconnectSignal( const TQCString &sender, const TQCString &senderObj,
                       const TQCString &signal,
                       DCOPConnection *conn, const TQCString &receiverObj,
                       const TQCString &slot);

   /**
    * Removes all connections related to the "conn" client.
    * This means:
    *   All connections for which "conn" is the receiver.
    *   All volatile connections for which "conn" is the sender.
    */
   void removeConnections(DCOPConnection *conn, const TQCString &obj=0);


   /*
    * The administration.
    *
    * All connections are sorted by "signal" and then inserted in the
    * administration as a list.
    *
    * connections[signal] gives a list of all connections related to
    * a given signal. The connections in this list may specify different
    * senders and receiving clients/objects.
    */
   TQAsciiDict<DCOPSignalConnectionList> connections;
};

//
// connectSignal:
//
// Check whether signal and slot match wrt arguments.
// A slot may ignore arguments from the signal.
//
// If volatile
//    then lookup senderConn...
//         If not found?
//            then return false
// Create DCOPSignalConnection.
// Add DCOPSignalConnection to "connections".
// Add DCOPSignalConnection to conn->connectionList()
// If volatile
//    then Add DCOPSignalConnection to senderConn->connectionList()
// Return true


// removeConnections:
//
// For each DCOPSignalConnection in conn->connectionList
//    if DCOPSignalConnection->sender == conn->appId
//        then remove DCOPSignalConnection from DCOPSIgnalConnection->conn
//    if DCOPSignalConnection->conn == conn
//       then.. this is ugly.. remove DCOPSignalConnection from DCOPSignalConnection->sender
//    WARNING: Take care when sender and conn are the same client!
//    Remove DCOPSignalConnection from connections[DCOPSignalConnection->signal]

#endif