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

dcop

  • dcop
dcopobject.cpp
1 /*****************************************************************
2 
3 Copyright (c) 1999,2000 Preston Brown <pbrown@kde.org>
4 Copyright (c) 1999 Matthias Ettrich <ettrich@kde.org>
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 
23 ******************************************************************/
24 
25 #include <dcopobject.h>
26 #include <dcopclient.h>
27 
28 TQMap<TQCString, DCOPObject *> *kde_dcopObjMap = 0;
29 
30 static inline TQMap<TQCString, DCOPObject *> *objMap()
31 {
32  if (!kde_dcopObjMap)
33  kde_dcopObjMap = new TQMap<TQCString, DCOPObject *>;
34  return kde_dcopObjMap;
35 }
36 
37 class DCOPObject::DCOPObjectPrivate
38 {
39 public:
40  DCOPObjectPrivate()
41  { m_signalConnections = 0; m_dcopClient = 0; }
42 
43  unsigned int m_signalConnections;
44  DCOPClient *m_dcopClient;
45 };
46 
47 DCOPObject::DCOPObject()
48 {
49  d = new DCOPObjectPrivate;
50  ident.sprintf("%p", (void *)this );
51  objMap()->insert(ident, this );
52 }
53 
54 DCOPObject::DCOPObject(TQObject *obj)
55 {
56  d = new DCOPObjectPrivate;
57  TQObject *currentObj = obj;
58  while (currentObj != 0L) {
59  ident.prepend( currentObj->name() );
60  ident.prepend("/");
61  currentObj = TQT_TQOBJECT(currentObj->parent());
62  }
63  if ( ident[0] == '/' )
64  ident = ident.mid(1);
65 
66  objMap()->insert(ident, this);
67 }
68 
69 DCOPObject::DCOPObject(const TQCString &_objId)
70  : ident(_objId)
71 {
72  d = new DCOPObjectPrivate;
73  if ( ident.isEmpty() )
74  ident.sprintf("%p", (void *)this );
75  objMap()->insert(ident, this);
76 }
77 
78 DCOPObject::~DCOPObject()
79 {
80  DCOPClient *client = DCOPClient::mainClient();
81  if ( d->m_signalConnections > 0 && client )
82  client->disconnectDCOPSignal( 0, 0, 0, objId(), 0 );
83 
84  objMap()->remove(ident);
85  delete d;
86 }
87 
88 DCOPClient *DCOPObject::callingDcopClient()
89 {
90  return d->m_dcopClient;
91 }
92 
93 void DCOPObject::setCallingDcopClient(DCOPClient *client)
94 {
95  d->m_dcopClient = client;
96 }
97 
98 bool DCOPObject::setObjId(const TQCString &objId)
99 {
100  if (objMap()->find(objId)!=objMap()->end()) return false;
101 
102  DCOPClient *client = DCOPClient::mainClient();
103  if ( d->m_signalConnections > 0 && client )
104  client->disconnectDCOPSignal( 0, 0, 0, ident, 0 );
105 
106  objMap()->remove(ident);
107  ident=objId;
108  objMap()->insert(ident,this);
109  return true;
110 }
111 
112 TQCString DCOPObject::objId() const
113 {
114  return ident;
115 }
116 
117 bool DCOPObject::hasObject(const TQCString &_objId)
118 {
119  if (objMap()->contains(_objId))
120  return true;
121  else
122  return false;
123 }
124 
125 DCOPObject *DCOPObject::find(const TQCString &_objId)
126 {
127  TQMap<TQCString, DCOPObject *>::ConstIterator it;
128  it = objMap()->find(_objId);
129  if (it != objMap()->end())
130  return *it;
131  else
132  return 0L;
133 }
134 
135 TQPtrList<DCOPObject> DCOPObject::match(const TQCString &partialId)
136 {
137  TQPtrList<DCOPObject> mlist;
138  TQMap<TQCString, DCOPObject *>::ConstIterator it(objMap()->begin());
139  for (; it != objMap()->end(); ++it)
140  if (it.key().left(partialId.length()) == partialId) // found it?
141  mlist.append(it.data());
142  return mlist;
143 }
144 
145 
146 TQCString DCOPObject::objectName( TQObject* obj )
147 {
148  if ( obj == 0 )
149  return TQCString();
150 
151  TQCString identity;
152 
153  TQObject *currentObj = obj;
154  while (currentObj != 0 )
155  {
156  identity.prepend( currentObj->name() );
157  identity.prepend("/");
158  currentObj = TQT_TQOBJECT(currentObj->parent());
159  }
160  if ( identity[0] == '/' )
161  identity = identity.mid(1);
162 
163  return identity;
164 }
165 
166 bool DCOPObject::process(const TQCString &fun, const TQByteArray &data,
167  TQCString& replyType, TQByteArray &replyData)
168 {
169  if ( fun == "interfaces()" ) {
170  replyType = "QCStringList";
171  TQDataStream reply( replyData, IO_WriteOnly );
172  reply << interfaces();
173  return true;
174  } else if ( fun == "functions()" ) {
175  replyType = "QCStringList";
176  TQDataStream reply( replyData, IO_WriteOnly );
177  reply << functions();
178  return true;
179  }
180  return processDynamic( fun, data, replyType, replyData );
181 }
182 
183 bool DCOPObject::processDynamic( const TQCString&, const TQByteArray&, TQCString&, TQByteArray& )
184 {
185  return false;
186 }
187 QCStringList DCOPObject::interfacesDynamic()
188 {
189  QCStringList result;
190  return result;
191 }
192 
193 QCStringList DCOPObject::functionsDynamic()
194 {
195  QCStringList result;
196  return result;
197 }
198 QCStringList DCOPObject::interfaces()
199 {
200  QCStringList result = interfacesDynamic();
201  result << "DCOPObject";
202  return result;
203 }
204 
205 QCStringList DCOPObject::functions()
206 {
207  QCStringList result = functionsDynamic();
208  result.prepend("QCStringList functions()");
209  result.prepend("QCStringList interfaces()");
210  return result;
211 }
212 
213 void DCOPObject::emitDCOPSignal( const TQCString &signal, const TQByteArray &data)
214 {
215  DCOPClient *client = DCOPClient::mainClient();
216  if ( client )
217  client->emitDCOPSignal( objId(), signal, data );
218 }
219 
220 bool DCOPObject::connectDCOPSignal( const TQCString &sender, const TQCString &senderObj,
221  const TQCString &signal,
222  const TQCString &slot,
223  bool Volatile)
224 {
225  DCOPClient *client = DCOPClient::mainClient();
226 
227  if ( !client )
228  return false;
229 
230  d->m_signalConnections++;
231  return client->connectDCOPSignal( sender, senderObj, signal, objId(), slot, Volatile );
232 }
233 
234 bool DCOPObject::disconnectDCOPSignal( const TQCString &sender, const TQCString &senderObj,
235  const TQCString &signal,
236  const TQCString &slot)
237 {
238  DCOPClient *client = DCOPClient::mainClient();
239 
240  if ( !client )
241  return false;
242 
243  d->m_signalConnections--;
244  return client->disconnectDCOPSignal( sender, senderObj, signal, objId(), slot );
245 }
246 
247 
248 TQPtrList<DCOPObjectProxy>* DCOPObjectProxy::proxies = 0;
249 
250 DCOPObjectProxy::DCOPObjectProxy()
251 {
252  if ( !proxies )
253  proxies = new TQPtrList<DCOPObjectProxy>;
254  proxies->append( this );
255 }
256 
257 DCOPObjectProxy::DCOPObjectProxy( DCOPClient*)
258 {
259  if ( !proxies )
260  proxies = new TQPtrList<DCOPObjectProxy>;
261  proxies->append( this );
262 }
263 
264 DCOPObjectProxy:: ~DCOPObjectProxy()
265 {
266  if ( proxies )
267  proxies->removeRef( this );
268 }
269 
270 bool DCOPObjectProxy::process( const TQCString& /*obj*/,
271  const TQCString& /*fun*/,
272  const TQByteArray& /*data*/,
273  TQCString& /*replyType*/,
274  TQByteArray &/*replyData*/ )
275 {
276  return false;
277 }
278 
279 void DCOPObject::virtual_hook( int, void* )
280 { /*BASE::virtual_hook( id, data );*/ }
281 
282 void DCOPObjectProxy::virtual_hook( int, void* )
283 { /*BASE::virtual_hook( id, data );*/ }
DCOPClient::connectDCOPSignal
bool connectDCOPSignal(const TQCString &sender, const TQCString &senderObj, const TQCString &signal, const TQCString &receiverObj, const TQCString &slot, bool Volatile)
Connects to a DCOP signal.
Definition: dcopclient.cpp:2180
DCOPObjectProxy::DCOPObjectProxy
DCOPObjectProxy()
Creates a new proxy.
Definition: dcopobject.cpp:250
DCOPObject::hasObject
static bool hasObject(const TQCString &objId)
Checks whether an object with the given id is known in this process.
Definition: dcopobject.cpp:117
DCOPObject::~DCOPObject
virtual ~DCOPObject()
Destroys the DCOPObject and removes it from the map of known objects.
Definition: dcopobject.cpp:78
DCOPClient::mainClient
static DCOPClient * mainClient()
Returns the application's main dcop client.
Definition: dcopclient.cpp:599
DCOPObject::emitDCOPSignal
void emitDCOPSignal(const TQCString &signal, const TQByteArray &data)
Emit signal as DCOP signal from this object with data as arguments.
Definition: dcopobject.cpp:213
DCOPObjectProxy::~DCOPObjectProxy
virtual ~DCOPObjectProxy()
Destroy the proxy.
Definition: dcopobject.cpp:264
DCOPClient::disconnectDCOPSignal
bool disconnectDCOPSignal(const TQCString &sender, const TQCString &senderObj, const TQCString &signal, const TQCString &receiverObj, const TQCString &slot)
Disconnects a DCOP signal.
Definition: dcopclient.cpp:2215
DCOPObject::process
virtual bool process(const TQCString &fun, const TQByteArray &data, TQCString &replyType, TQByteArray &replyData)
Dispatches a message.
Definition: dcopobject.cpp:166
DCOPClient
Inter-process communication and remote procedure calls for KDE applications.
Definition: dcopclient.h:68
DCOPObject::objectName
static TQCString objectName(TQObject *obj)
Creates an object id for the TQObject obj.
Definition: dcopobject.cpp:146
DCOPObject::functions
virtual QCStringList functions()
Returns the list of functions understood by the object.
Definition: dcopobject.cpp:205
DCOPObject::match
static TQPtrList< DCOPObject > match(const TQCString &partialId)
Tries to find an object using a partial object id.
Definition: dcopobject.cpp:135
DCOPObject::objId
TQCString objId() const
Returns the object id of the DCOPObject.
Definition: dcopobject.cpp:112
DCOPObject::connectDCOPSignal
bool connectDCOPSignal(const TQCString &sender, const TQCString &senderObj, const TQCString &signal, const TQCString &slot, bool Volatile)
Connects to a DCOP signal.
Definition: dcopobject.cpp:220
DCOPObject::disconnectDCOPSignal
bool disconnectDCOPSignal(const TQCString &sender, const TQCString &senderObj, const TQCString &signal, const TQCString &slot)
Disconnects a DCOP signal.
Definition: dcopobject.cpp:234
DCOPObject::find
static DCOPObject * find(const TQCString &objId)
Try to find a dcop object with the given id.
Definition: dcopobject.cpp:125
DCOPObject::interfacesDynamic
virtual QCStringList interfacesDynamic()
This function is of interest when you used an IDL compiler to generate the implementation for interfa...
Definition: dcopobject.cpp:187
DCOPObjectProxy::process
virtual bool process(const TQCString &obj, const TQCString &fun, const TQByteArray &data, TQCString &replyType, TQByteArray &replyData)
Reimplement this method to dispatch method calls.
Definition: dcopobject.cpp:270
DCOPObject::interfaces
virtual QCStringList interfaces()
Returns the names of the interfaces, specific ones last.
Definition: dcopobject.cpp:198
DCOPObject::processDynamic
virtual bool processDynamic(const TQCString &fun, const TQByteArray &data, TQCString &replyType, TQByteArray &replyData)
This function is of interest when you used an IDL compiler to generate the implementation for process...
Definition: dcopobject.cpp:183
DCOPObject::setObjId
bool setObjId(const TQCString &objId)
Renames a dcop object, if no other with the same name exists Use with care, all dcop signals are disc...
Definition: dcopobject.cpp:98
DCOPClient::emitDCOPSignal
void emitDCOPSignal(const TQCString &object, const TQCString &signal, const TQByteArray &data)
Emits signal as DCOP signal from object object with data as arguments.
Definition: dcopclient.cpp:2167
DCOPObject
Provides an interface for receiving DCOP messages.
Definition: dcopobject.h:67
DCOPObject::DCOPObject
DCOPObject()
Creates a DCOPObject and calculates the object id using its physical memory address.
Definition: dcopobject.cpp:47
DCOPObject::callingDcopClient
DCOPClient * callingDcopClient()
Returns the DCOPClient responsible for making the call.
Definition: dcopobject.cpp:88
DCOPObject::functionsDynamic
virtual QCStringList functionsDynamic()
This function is of interest when you used an IDL compiler to generate the implementation for functio...
Definition: dcopobject.cpp:193

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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for dcop by doxygen 1.8.8
This website is maintained by Timothy Pearson.