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 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()") {
74 tqDebug(
"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 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, TQT_SLOT(slotTimeout()));
120 void 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, 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 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() );
165 void 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());
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 tqWarning(
"#1 Calling countDown");
194 int result = client->
callAsync(appId,
"object1",
"countDown()", data, &
obj, TQT_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, TQT_SLOT(slotCallBack(
int,
const TQCString&,
const TQByteArray&)));
198 tqDebug(
"#2 countDown() call id = %d", result);
207 tqDebug(
"I registered as '%s'", client->
appId().data() );
210 tqDebug(
"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 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 );
235 tqDebug(
"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 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());
271 client2->registerAs(app.name(),
false);
272 tqDebug(
"I2 registered as '%s'", client2->appId().data() );
274 tqDebug(
"Sending to object1");
275 client2->send(app.name(),
"object1",
"aFunction(TQString,int)", data );
277 tqDebug(
"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() );
283 tqDebug(
"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" 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.
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.
$TQTDIR/bin/moc testdcop.cpp -o testdcop.moc g++ -o testdcop testdcop.cpp -I$TQTDIR/include -L$TQTDIR...
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.
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.