31DCOPClientTransaction *countDownAction = 0;
32int countDownCount = 0;
34DCOPClientTransaction *countDownAction2 = 0;
35int countDownCount2 = 0;
38bool MyDCOPObject::process(
const TQCString &fun,
const TQByteArray &data,
39 TQCString& replyType, TQByteArray &replyData)
41 tqDebug(
"in MyDCOPObject::process, fun = %s", fun.data());
44 if (fun ==
"aFunction(TQString,int)") {
45 TQDataStream args(data, IO_ReadOnly);
53 if (fun ==
"canLaunchRockets(TQRect)") {
54 TQDataStream args(data, IO_ReadOnly);
58 printf(
"Rect x = %d, y = %d, w = %d, h = %d\n", arg1.x(), arg1.y(), arg1.width(), arg1.height());
61 TQDataStream reply( replyData, IO_WriteOnly );
62 TQRect r(10,20,100,200);
66 if (fun ==
"isAliveSlot(int)") {
68 tqDebug(
"isAliveSlot(int)");
70 tqDebug(
"disconnectDCOPSignal returns %s", connectResult ?
"true" :
"false");
73 if (fun ==
"countDown()") {
74tqDebug(
"countDown() countDownAction = %p", countDownAction);
77 replyType =
"TQString";
78 TQDataStream reply( replyData, IO_WriteOnly );
79 reply << TQString(
"Hey");
83 if (countDownAction == 0)
87 TQTimer::singleShot(1000,
this, TQ_SLOT(slotTimeout()));
93 TQTimer::singleShot(1000,
this, TQ_SLOT(slotTimeout2()));
101void MyDCOPObject::slotTimeout()
103 tqDebug(
"MyDCOPObject::slotTimeout() %d", countDownCount);
105 if (countDownCount == 0)
107 TQCString replyType =
"TQString";
108 TQByteArray replyData;
109 TQDataStream reply( replyData, IO_WriteOnly );
110 reply << TQString(
"Hello World");
116 TQTimer::singleShot(1000,
this, TQ_SLOT(slotTimeout()));
120void MyDCOPObject::slotTimeout2()
122 tqDebug(
"MyDCOPObject::slotTimeout2() %d", countDownCount2);
124 if (countDownCount2 == 0)
126 TQCString replyType =
"TQString";
127 TQByteArray replyData;
128 TQDataStream reply( replyData, IO_WriteOnly );
129 reply << TQString(
"Hello World");
131 countDownAction2 = 0;
135 TQTimer::singleShot(1000,
this, TQ_SLOT(slotTimeout2()));
142 result <<
"TQRect canLaunchRockets(TQRect)";
146TestObject::TestObject(
const TQCString& app)
149 TQTimer::singleShot(2500,
this, TQ_SLOT(slotTimeout()));
152void TestObject::slotTimeout()
155 TQByteArray data, reply;
156 tqWarning(
"#3 Calling countDown");
158 if (!client->
call(m_app,
"object1",
"countDown()", data, replyType, reply))
159 tqDebug(
"#3 I couldn't call countDown");
161 tqDebug(
"#3 countDown() return type was '%s'", replyType.data() );
165void TestObject::slotCallBack(
int callId,
const TQCString &replyType,
const TQByteArray &replyData)
167 tqWarning(
"Call Back! callId = %d", callId);
168 tqWarning(
"Type = %s", replyType.data());
170 TQDataStream args(replyData, IO_ReadOnly);
174 tqWarning(
"Value = %s", arg1.latin1());
181int main(
int argc,
char **argv)
183 TQApplication app(argc, argv,
"testdcop");
186 TQByteArray data, reply;
191 TQCString appId = argv[1];
193 tqWarning(
"#1 Calling countDown");
194 int result = client->callAsync(appId,
"object1",
"countDown()", data, &obj, TQ_SLOT(slotCallBack(
int,
const TQCString&,
const TQByteArray&)));
195 tqDebug(
"#1 countDown() call id = %d", result);
196 tqWarning(
"#2 Calling countDown");
197 result = client->callAsync(appId,
"object1",
"countDown()", data, &obj, TQ_SLOT(slotCallBack(
int,
const TQCString&,
const TQByteArray&)));
198 tqDebug(
"#2 countDown() call id = %d", result);
206 client->registerAs( app.name(),
false );
207 tqDebug(
"I registered as '%s'", client->appId().data() );
209 if ( client->isApplicationRegistered( app.name() ) )
210 tqDebug(
"indeed, we are registered!");
212 TQDataStream dataStream( data, IO_WriteOnly );
213 dataStream << (int) 43;
214 client->emitDCOPSignal(
"alive(int,TQCString)", data);
216 MyDCOPObject *obj1 =
new MyDCOPObject(
"object1");
218 bool connectResult = client->connectDCOPSignal(
"",
"alive(int , TQCString)",
"object1",
"isAliveSlot(int)",
false);
219 tqDebug(
"connectDCOPSignal returns %s", connectResult ?
"true" :
"false");
221 TQDataStream ds(data, IO_WriteOnly);
222 ds << TQString(
"fourty-two") << 42;
223 if (!client->call(app.name(),
"object1",
"aFunction(TQString,int)", data, replyType, reply)) {
224 tqDebug(
"I couldn't call myself");
228 tqDebug(
"return type was '%s'", replyType.data() );
229 assert( replyType ==
"void" );
232 client->send(app.name(),
"object1",
"aFunction(TQString,int)", data );
234 int n = client->registeredApplications().count();
235 tqDebug(
"number of attached applications = %d", n );
237 TQObject::connect( client, TQ_SIGNAL( applicationRegistered(
const TQCString&)),
238 obj1, TQ_SLOT( registered(
const TQCString& )));
240 TQObject::connect( client, TQ_SIGNAL( applicationRemoved(
const TQCString&)),
241 obj1, TQ_SLOT( unregistered(
const TQCString& )));
244 client->setNotifications(
true );
256 bool boolResult = client->findObject(
"konqueror*",
"",
"", data, foundApp, foundObj);
257 tqDebug(
"findObject: result = %s, %s, %s\n", boolResult ?
"true" :
"false",
258 foundApp.data(), foundObj.data());
261 boolResult = client->findObject(
"",
"tdesycoca",
"", data, foundApp, foundObj);
262 tqDebug(
"findObject: result = %s, %s, %s\n", boolResult ?
"true" :
"false",
263 foundApp.data(), foundObj.data());
266 boolResult = client->findObject(
"testdcop",
"tdesycoca",
"", data, foundApp, foundObj);
267 tqDebug(
"findObject: result = %s, %s, %s\n", boolResult ?
"true" :
"false",
268 foundApp.data(), foundObj.data());
272 tqDebug(
"I2 registered as '%s'", client2->
appId().data() );
274tqDebug(
"Sending to object1");
275 client2->
send(app.name(),
"object1",
"aFunction(TQString,int)", data );
277tqDebug(
"Calling object1");
278 if (!client2->
call(app.name(),
"object1",
"aFunction(TQString,int)", data, replyType, reply))
279 tqDebug(
"I couldn't call myself");
281 tqDebug(
"return type was '%s'", replyType.data() );
283tqDebug(
"Calling countDown() in object1");
284 if (!client2->
call(app.name(),
"object1",
"countDown()", data, replyType, reply))
285 tqDebug(
"I couldn't call myself");
287 tqDebug(
"return type was '%s'", replyType.data() );
290 boolResult = client2->
findObject(
"testdcop",
"object1",
"", data, foundApp, foundObj);
291 tqDebug(
"findObject: result = %s, %s, %s\n", boolResult ?
"true" :
"false",
292 foundApp.data(), foundObj.data());
298#include "testdcop.moc"
Inter-process communication and remote procedure calls for KDE applications.
void endTransaction(DCOPClientTransaction *t, TQCString &replyType, TQByteArray &replyData)
Sends the delayed reply of a function call.
TQCString appId() const
Returns the current app id or a null string if the application hasn't yet been registered.
DCOPClientTransaction * beginTransaction()
Delays the reply of the current function call until endTransaction() is called.
bool disconnectDCOPSignal(const TQCString &sender, const TQCString &senderObj, const TQCString &signal, const TQCString &receiverObj, const TQCString &slot)
Disconnects a DCOP signal.
bool send(const TQCString &remApp, const TQCString &remObj, const TQCString &remFun, const TQByteArray &data)
Sends a data block to the server.
bool call(const TQCString &remApp, const TQCString &remObj, const TQCString &remFun, const TQByteArray &data, TQCString &replyType, TQByteArray &replyData, bool useEventLoop, int timeout, bool forceRemote)
Performs a synchronous send and receive.
bool findObject(const TQCString &remApp, const TQCString &remObj, const TQCString &remFun, const TQByteArray &data, TQCString &foundApp, TQCString &foundObj, bool useEventLoop, int timeout)
Searches for an object which matches a criteria.
TQCString registerAs(const TQCString &appId, bool addPID=true)
Registers at the DCOP server.
TQCString objId() const
Returns the object id of the DCOPObject.
virtual QCStringList functions()
Returns the list of functions understood by the object.
virtual bool process(const TQCString &fun, const TQByteArray &data, TQCString &replyType, TQByteArray &replyData)
Dispatches a message.
$TQTDIR/bin/moc testdcop.cpp -o testdcop.moc g++ -o testdcop testdcop.cpp -I$TQTDIR/include -L$TQTDIR...