• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • dcop
 

dcop

  • dcop
dcopsignals.cpp
1 /*
2 Copyright (c) 2000 Waldo Bastian <bastian@kde.org>
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 */
21 
22 #include <dcopserver.h>
23 #include <dcopsignals.h>
24 
25 template class TQPtrList<DCOPSignalConnection>;
26 
27 DCOPSignals::DCOPSignals()
28 {
29  connections.setAutoDelete(true);
30 }
31 
37 void
38 DCOPSignals::emitSignal( DCOPConnection *conn, const TQCString &_fun, const TQByteArray &data, bool excludeSelf)
39 {
40  TQCString senderObj;
41  TQCString fun = _fun;
42  int i = fun.find('#');
43  if (i > -1)
44  {
45  senderObj = fun.left(i);
46  fun = fun.mid(i+1);
47  }
48 
49  DCOPSignalConnectionList *list = connections.find(fun);
50  if (!list) return;
51  for(DCOPSignalConnection *current = list->first(); current; current = list->next())
52  {
53  bool doSend = false;
54  if (current->senderConn)
55  {
56  if (current->senderConn == conn)
57  doSend = true;
58  }
59  else if (!current->sender.isEmpty())
60  {
61  if ((conn && current->sender == conn->appId) || (current->sender == "DCOPServer"))
62  doSend = true;
63  }
64  else
65  {
66  doSend = true;
67  }
68 
69  if (!current->senderObj.isEmpty() &&
70  (current->senderObj != senderObj))
71  {
72  doSend = false;
73  }
74 
75  if (excludeSelf && (conn == current->recvConn))
76  doSend = false;
77  if (doSend)
78  {
79  the_server->sendMessage(current->recvConn, conn ? conn->appId : TQCString("DCOPServer"),
80  current->recvConn->appId, current->recvObj,
81  current->slot, data);
82  }
83  }
84 }
85 
96 bool
97 DCOPSignals::connectSignal( const TQCString &sender, const TQCString &senderObj,
98  const TQCString &signal,
99  DCOPConnection *conn, const TQCString &receiverObj,
100  const TQCString &slot, bool Volatile)
101 {
102  // TODO: Check if signal and slot match
103  TQCString signalArgs, slotArgs;
104  int i,j;
105  i = signal.find('(');
106  if (i < 0) return false;
107  signalArgs = signal.mid(i+1);
108  j = signalArgs.find(')');
109  if (j < 0) return false;
110  signalArgs.truncate(j);
111  i = slot.find('(');
112  if (i < 0) return false;
113  slotArgs = slot.mid(i+1);
114  j = slotArgs.find(')');
115  if (j < 0) return false;
116  slotArgs.truncate(j);
117 
118  if(signalArgs != slotArgs)
119  {
120  // Maybe the signal has more arguments than the slot...
121  if (signalArgs.length() <= slotArgs.length())
122  return false;
123  if ((slotArgs.length() > 0) && (signalArgs[slotArgs.length()] != ','))
124  return false;
125  if (signalArgs.left(slotArgs.length()) != slotArgs)
126  return false;
127  }
128 
129  DCOPConnection *senderConn = 0;
130  if (Volatile)
131  {
132  senderConn = the_server->findApp(sender);
133  if (!senderConn)
134  return false; // Sender does not exist.
135  }
136  DCOPSignalConnection *current = new DCOPSignalConnection;
137  current->sender = sender;
138  current->senderObj = senderObj;
139  current->senderConn = senderConn;
140  current->signal = signal;
141  current->recvConn = conn;
142  current->recvObj = receiverObj;
143  current->slot = slot;
144 
145  DCOPSignalConnectionList *list = connections.find(signal);
146  if (!list)
147  {
148  list = new DCOPSignalConnectionList;
149  connections.insert(signal, list);
150  }
151 
152  list->append( current );
153  conn->signalConnectionList()->append(current);
154  if (senderConn && senderConn != conn)
155  senderConn->signalConnectionList()->append(current);
156  return true;
157 }
158 
168 bool
169 DCOPSignals::disconnectSignal( const TQCString &sender, const TQCString &senderObj,
170  const TQCString &signal,
171  DCOPConnection *conn, const TQCString &receiverObj,
172  const TQCString &slot)
173 {
174  if (sender.isEmpty() && signal.isEmpty())
175  {
176  removeConnections(conn, receiverObj);
177  return true;
178  }
179 
180  DCOPSignalConnectionList *list = connections.find(signal);
181  if (!list)
182  return false; // Not found...
183 
184  DCOPSignalConnection *next = 0;
185  bool result = false;
186 
187  for(DCOPSignalConnection *current = list->first(); current; current = next)
188  {
189  next = list->next();
190 
191  if (current->recvConn != conn)
192  continue;
193 
194  if (current->senderConn)
195  {
196  if (current->senderConn->appId != sender)
197  continue;
198  }
199  else if (current->sender != sender)
200  continue;
201 
202  if (!senderObj.isEmpty() &&
203  (current->senderObj != senderObj))
204  continue;
205 
206  if (!receiverObj.isEmpty() &&
207  (current->recvObj != receiverObj))
208  continue;
209 
210  if (!slot.isEmpty() &&
211  (current->slot != slot))
212  continue;
213 
214  result = true;
215  list->removeRef(current);
216  conn->signalConnectionList()->removeRef(current);
217  if (current->senderConn)
218  current->senderConn->signalConnectionList()->removeRef(current);
219  delete current;
220  }
221  return result;
222 }
223 
230 void
231 DCOPSignals::removeConnections(DCOPConnection *conn, const TQCString &obj)
232 {
233  DCOPSignalConnectionList *list = conn->_signalConnectionList;
234  if (!list)
235  return; // Nothing to do...
236 
237  DCOPSignalConnection *next = 0;
238 
239  for(DCOPSignalConnection *current = list->first(); current; current = next)
240  {
241  next = list->next();
242 
243  if (!obj.isEmpty())
244  {
245  if ((current->senderConn == conn) && (current->senderObj != obj))
246  continue;
247 
248  if ((current->recvConn == conn) && (current->recvObj != obj))
249  continue;
250  }
251 
252  if (current->senderConn && (current->senderConn != conn))
253  current->senderConn->signalConnectionList()->removeRef(current);
254 
255  if (current->recvConn != conn)
256  current->recvConn->signalConnectionList()->removeRef(current);
257 
258  DCOPSignalConnectionList *signalList = connections.find(current->signal);
259  if (signalList)
260  {
261  signalList->removeRef(current);
262  if (signalList->isEmpty())
263  connections.remove(current->signal);
264  }
265  else
266  {
267  tqDebug("Error: Signal Connection was not in signalList!\n");
268  }
269  list->removeRef(current);
270  delete current;
271  }
272 }
273 
274 
TDEShortcut::remove
void remove(const KKeySequence &keySeq)
TDEStdAccel::next
const TDEShortcut & next()

dcop

Skip menu "dcop"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

dcop

Skip menu "dcop"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for dcop by doxygen 1.9.1
This website is maintained by Timothy Pearson.