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

dcop

  • dcop
dcopobject.cpp
1/*****************************************************************
2
3Copyright (c) 1999,2000 Preston Brown <pbrown@kde.org>
4Copyright (c) 1999 Matthias Ettrich <ettrich@kde.org>
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23******************************************************************/
24
25#include <dcopobject.h>
26#include <dcopclient.h>
27
28TQMap<TQCString, DCOPObject *> *kde_dcopObjMap = 0;
29
30static inline TQMap<TQCString, DCOPObject *> *objMap()
31{
32 if (!kde_dcopObjMap)
33 kde_dcopObjMap = new TQMap<TQCString, DCOPObject *>;
34 return kde_dcopObjMap;
35}
36
37class DCOPObject::DCOPObjectPrivate
38{
39public:
40 DCOPObjectPrivate()
41 { m_signalConnections = 0; m_dcopClient = 0; }
42
43 unsigned int m_signalConnections;
44 DCOPClient *m_dcopClient;
45};
46
47DCOPObject::DCOPObject()
48{
49 d = new DCOPObjectPrivate;
50 ident.sprintf("%p", (void *)this );
51 objMap()->insert(ident, this );
52}
53
54DCOPObject::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 = currentObj->parent();
62 }
63 if ( ident[0] == '/' )
64 ident = ident.mid(1);
65
66 objMap()->insert(ident, this);
67}
68
69DCOPObject::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
78DCOPObject::~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
88DCOPClient *DCOPObject::callingDcopClient()
89{
90 return d->m_dcopClient;
91}
92
93void DCOPObject::setCallingDcopClient(DCOPClient *client)
94{
95 d->m_dcopClient = client;
96}
97
98bool 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
112TQCString DCOPObject::objId() const
113{
114 return ident;
115}
116
117bool DCOPObject::hasObject(const TQCString &_objId)
118{
119 if (objMap()->contains(_objId))
120 return true;
121 else
122 return false;
123}
124
125DCOPObject *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
135TQPtrList<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
146TQCString 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 = currentObj->parent();
159 }
160 if ( identity[0] == '/' )
161 identity = identity.mid(1);
162
163 return identity;
164}
165
166bool 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
183bool DCOPObject::processDynamic( const TQCString&, const TQByteArray&, TQCString&, TQByteArray& )
184{
185 return false;
186}
187QCStringList DCOPObject::interfacesDynamic()
188{
189 QCStringList result;
190 return result;
191}
192
193QCStringList DCOPObject::functionsDynamic()
194{
195 QCStringList result;
196 return result;
197}
198QCStringList DCOPObject::interfaces()
199{
200 QCStringList result = interfacesDynamic();
201 result << "DCOPObject";
202 return result;
203}
204
205QCStringList DCOPObject::functions()
206{
207 QCStringList result = functionsDynamic();
208 result.prepend("QCStringList functions()");
209 result.prepend("QCStringList interfaces()");
210 return result;
211}
212
213void 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
220bool 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
234bool 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
248TQPtrList<DCOPObjectProxy>* DCOPObjectProxy::proxies = 0;
249
250DCOPObjectProxy::DCOPObjectProxy()
251{
252 if ( !proxies )
253 proxies = new TQPtrList<DCOPObjectProxy>;
254 proxies->append( this );
255}
256
257DCOPObjectProxy::DCOPObjectProxy( DCOPClient*)
258{
259 if ( !proxies )
260 proxies = new TQPtrList<DCOPObjectProxy>;
261 proxies->append( this );
262}
263
264DCOPObjectProxy:: ~DCOPObjectProxy()
265{
266 if ( proxies )
267 proxies->removeRef( this );
268}
269
270bool 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
279void DCOPObject::virtual_hook( int, void* )
280{ /*BASE::virtual_hook( id, data );*/ }
281
282void DCOPObjectProxy::virtual_hook( int, void* )
283{ /*BASE::virtual_hook( id, data );*/ }
DCOPClient
Inter-process communication and remote procedure calls for KDE applications.
Definition: dcopclient.h:69
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:2179
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:2227
DCOPClient::mainClient
static DCOPClient * mainClient()
Returns the application's main dcop client.
Definition: dcopclient.cpp:599
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:2192
DCOPObjectProxy::DCOPObjectProxy
DCOPObjectProxy()
Creates a new proxy.
Definition: dcopobject.cpp:250
DCOPObjectProxy::~DCOPObjectProxy
virtual ~DCOPObjectProxy()
Destroy the proxy.
Definition: dcopobject.cpp:264
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
Provides an interface for receiving DCOP messages.
Definition: dcopobject.h:68
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::objectName
static TQCString objectName(TQObject *obj)
Creates an object id for the TQObject obj.
Definition: dcopobject.cpp:146
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::~DCOPObject
virtual ~DCOPObject()
Destroys the DCOPObject and removes it from the map of known objects.
Definition: dcopobject.cpp:78
DCOPObject::match
static TQPtrList< DCOPObject > match(const TQCString &partialId)
Tries to find an object using a partial object id.
Definition: dcopobject.cpp:135
DCOPObject::interfaces
virtual QCStringList interfaces()
Returns the names of the interfaces, specific ones last.
Definition: dcopobject.cpp:198
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
DCOPObject()
Creates a DCOPObject and calculates the object id using its physical memory address.
Definition: dcopobject.cpp:47
DCOPObject::objId
TQCString objId() const
Returns the object id of the DCOPObject.
Definition: dcopobject.cpp:112
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
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
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::functions
virtual QCStringList functions()
Returns the list of functions understood by the object.
Definition: dcopobject.cpp:205
DCOPObject::find
static DCOPObject * find(const TQCString &objId)
Try to find a dcop object with the given id.
Definition: dcopobject.cpp:125
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
DCOPObject::process
virtual bool process(const TQCString &fun, const TQByteArray &data, TQCString &replyType, TQByteArray &replyData)
Dispatches a message.
Definition: dcopobject.cpp:166
DCOPObject::callingDcopClient
DCOPClient * callingDcopClient()
Returns the DCOPClient responsible for making the call.
Definition: dcopobject.cpp:88
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

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.4
This website is maintained by Timothy Pearson.