31 DCOPClientTransaction *countDownAction = 0;
32 int countDownCount = 0;
34 DCOPClientTransaction *countDownAction2 = 0;
35 int countDownCount2 = 0;
38 bool MyDCOPObject::process(
const TQCString &fun,
const TQByteArray &data,
39 TQCString& replyType, TQByteArray &replyData)
41 qDebug(
"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 qDebug(
"isAliveSlot(int)");
70 qDebug(
"disconnectDCOPSignal returns %s", connectResult ?
"true" :
"false");
73 if (fun ==
"countDown()") {
74 qDebug(
"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, TQT_SLOT(slotTimeout()));
93 TQTimer::singleShot(1000,
this, TQT_SLOT(slotTimeout2()));
101 void MyDCOPObject::slotTimeout()
103 qDebug(
"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, TQT_SLOT(slotTimeout()));
120 void MyDCOPObject::slotTimeout2()
122 qDebug(
"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, TQT_SLOT(slotTimeout2()));
139 QCStringList MyDCOPObject::functions()
142 result <<
"TQRect canLaunchRockets(TQRect)";
146 TestObject::TestObject(
const TQCString& app)
149 TQTimer::singleShot(2500,
this, TQT_SLOT(slotTimeout()));
152 void TestObject::slotTimeout()
155 TQByteArray data, reply;
156 qWarning(
"#3 Calling countDown");
158 if (!client->
call(m_app,
"object1",
"countDown()", data, replyType, reply))
159 qDebug(
"#3 I couldn't call countDown");
161 qDebug(
"#3 countDown() return type was '%s'", replyType.data() );
165 void TestObject::slotCallBack(
int callId,
const TQCString &replyType,
const TQByteArray &replyData)
167 qWarning(
"Call Back! callId = %d", callId);
168 qWarning(
"Type = %s", replyType.data());
170 TQDataStream args(replyData, IO_ReadOnly);
174 qWarning(
"Value = %s", arg1.latin1());
178 # define main kdemain 181 int main(
int argc,
char **argv)
183 TQApplication
app(argc, argv,
"testdcop");
186 TQByteArray data, reply;
191 TQCString appId = argv[1];
193 qWarning(
"#1 Calling countDown");
194 int result = client->
callAsync(appId,
"object1",
"countDown()", data, &
obj, TQT_SLOT(slotCallBack(
int,
const TQCString&,
const TQByteArray&)));
195 qDebug(
"#1 countDown() call id = %d", result);
196 qWarning(
"#2 Calling countDown");
197 result = client->
callAsync(appId,
"object1",
"countDown()", data, &
obj, TQT_SLOT(slotCallBack(
int,
const TQCString&,
const TQByteArray&)));
198 qDebug(
"#2 countDown() call id = %d", result);
207 qDebug(
"I registered as '%s'", client->
appId().data() );
210 qDebug(
"indeed, we are registered!");
212 TQDataStream dataStream( data, IO_WriteOnly );
213 dataStream << (int) 43;
216 MyDCOPObject *obj1 =
new MyDCOPObject(
"object1");
218 bool connectResult = client->
connectDCOPSignal(
"",
"alive(int , TQCString)",
"object1",
"isAliveSlot(int)",
false);
219 qDebug(
"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 qDebug(
"I couldn't call myself");
228 qDebug(
"return type was '%s'", replyType.data() );
229 assert( replyType ==
"void" );
232 client->
send(app.name(),
"object1",
"aFunction(TQString,int)", data );
235 qDebug(
"number of attached applications = %d", n );
237 TQObject::connect( client, TQT_SIGNAL( applicationRegistered(
const TQCString&)),
238 obj1, TQT_SLOT( registered(
const TQCString& )));
240 TQObject::connect( client, TQT_SIGNAL( applicationRemoved(
const TQCString&)),
241 obj1, TQT_SLOT( unregistered(
const TQCString& )));
256 bool boolResult = client->
findObject(
"konqueror*",
"",
"", data, foundApp, foundObj);
257 qDebug(
"findObject: result = %s, %s, %s\n", boolResult ?
"true" :
"false",
258 foundApp.data(), foundObj.data());
261 boolResult = client->
findObject(
"",
"ksycoca",
"", data, foundApp, foundObj);
262 qDebug(
"findObject: result = %s, %s, %s\n", boolResult ?
"true" :
"false",
263 foundApp.data(), foundObj.data());
266 boolResult = client->
findObject(
"testdcop",
"ksycoca",
"", data, foundApp, foundObj);
267 qDebug(
"findObject: result = %s, %s, %s\n", boolResult ?
"true" :
"false",
268 foundApp.data(), foundObj.data());
271 client2->registerAs(app.name(),
false);
272 qDebug(
"I2 registered as '%s'", client2->appId().data() );
274 qDebug(
"Sending to object1");
275 client2->send(app.name(),
"object1",
"aFunction(TQString,int)", data );
277 qDebug(
"Calling object1");
278 if (!client2->call(app.name(),
"object1",
"aFunction(TQString,int)", data, replyType, reply))
279 qDebug(
"I couldn't call myself");
281 qDebug(
"return type was '%s'", replyType.data() );
283 qDebug(
"Calling countDown() in object1");
284 if (!client2->call(app.name(),
"object1",
"countDown()", data, replyType, reply))
285 qDebug(
"I couldn't call myself");
287 qDebug(
"return type was '%s'", replyType.data() );
290 boolResult = client2->findObject(
"testdcop",
"object1",
"", data, foundApp, foundObj);
291 qDebug(
"findObject: result = %s, %s, %s\n", boolResult ?
"true" :
"false",
292 foundApp.data(), foundObj.data());
298 #include "testdcop.moc" bool connectDCOPSignal(const TQCString &sender, const TQCString &senderObj, const TQCString &signal, const TQCString &receiverObj, const TQCString &slot, bool Volatile)
Connects to a DCOP signal.
bool isApplicationRegistered(const TQCString &remApp)
Checks whether remApp is registered with the DCOP server.
int callAsync(const TQCString &remApp, const TQCString &remObj, const TQCString &remFun, const TQByteArray &data, TQObject *callBackObj, const char *callBackSlot)
Performs a asynchronous send with receive callback.
void endTransaction(DCOPClientTransaction *t, TQCString &replyType, TQByteArray &replyData)
Sends the delayed reply of a function call.
TQCString app() const
Return the application id.
bool send(const TQCString &remApp, const TQCString &remObj, const TQCString &remFun, const TQByteArray &data)
Sends a data block to the server.
bool disconnectDCOPSignal(const TQCString &sender, const TQCString &senderObj, const TQCString &signal, const TQCString &receiverObj, const TQCString &slot)
Disconnects a DCOP signal.
virtual bool process(const TQCString &fun, const TQByteArray &data, TQCString &replyType, TQByteArray &replyData)
Dispatches a message.
Inter-process communication and remote procedure calls for KDE applications.
DCOPClientTransaction * beginTransaction()
Delays the reply of the current function call until endTransaction() is called.
bool call(const TQCString &remApp, const TQCString &remObj, const TQCString &remFun, const TQByteArray &data, TQCString &replyType, TQByteArray &replyData, bool useEventLoop, int timeout)
Performs a synchronous send and receive.
virtual QCStringList functions()
Returns the list of functions understood by the object.
TQCString obj() const
Return the object id.
TQCString appId() const
Returns the current app id or a null string if the application hasn't yet been registered.
TQCString registerAs(const TQCString &appId, bool addPID=true)
Registers at the DCOP server.
QCStringList registeredApplications()
Retrieves the list of all currently registered applications from dcopserver.
bool detach()
Detaches from the DCOP server.
$QTDIR/bin/moc testdcop.cpp -o testdcop.moc g++ -o testdcop testdcop.cpp -I$QTDIR/include -L$QTDIR/li...
void setNotifications(bool enabled)
Enables / disables the applicationRegistered() / applicationRemoved() signals.
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.
void emitDCOPSignal(const TQCString &object, const TQCString &signal, const TQByteArray &data)
Emits signal as DCOP signal from object object with data as arguments.