00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <testdcop.h>
00027
00028 bool MyDCOPObject::process(const QCString &fun, const QByteArray &data,
00029 QCString& replyType, QByteArray &replyData)
00030 {
00031 qDebug("in MyDCOPObject::process, fun = %s", fun.data());
00032
00033
00034 if (fun == "aFunction(QString,int)") {
00035 QDataStream args(data, IO_ReadOnly);
00036 QString arg1;
00037 int arg2;
00038 args >> arg1 >> arg2;
00039 function(arg1, arg2);
00040 replyType = "void";
00041 return true;
00042 }
00043 if (fun == "canLaunchRockets(QRect)") {
00044 QDataStream args(data, IO_ReadOnly);
00045 QRect arg1;
00046 args >> arg1;
00047
00048 printf("Rect x = %d, y = %d, w = %d, h = %d\n", arg1.x(), arg1.y(), arg1.width(), arg1.height());
00049
00050 replyType = "QRect";
00051 QDataStream reply( replyData, IO_WriteOnly );
00052 QRect r(10,20,100,200);
00053 reply << r;
00054 return true;
00055 }
00056 if (fun == "isAliveSlot(int)") {
00057
00058 qDebug("isAliveSlot(int)");
00059 bool connectResult = kapp->dcopClient()->disconnectDCOPSignal("", objId(), "", objId(), "" );
00060 qDebug("disconnectDCOPSignal returns %s", connectResult ? "true" : "false");
00061 return true;
00062 }
00063
00064 return DCOPObject::process(fun, data, replyType, replyData);
00065 }
00066
00067 QCStringList MyDCOPObject::functions()
00068 {
00069 QCStringList result = DCOPObject::functions();
00070 result << "QRect canLaunchRockets(QRect)";
00071 return result;
00072 }
00073
00074 int main(int argc, char **argv)
00075 {
00076 KApplication app(argc, argv, "testdcop");
00077
00078 QCString replyType;
00079 QByteArray data, reply;
00080 DCOPClient *client; client = app.dcopClient();
00081
00082
00083
00084 client->registerAs( app.name(), false );
00085 qDebug("I registered as '%s'", client->appId().data() );
00086
00087 if ( client->isApplicationRegistered( app.name() ) )
00088 qDebug("indeed, we are registered!");
00089
00090 QDataStream dataStream( data, IO_WriteOnly );
00091 dataStream << (int) 43;
00092 client->emitDCOPSignal("alive(int,QCString)", data);
00093
00094 MyDCOPObject *obj1 = new MyDCOPObject("object1");
00095
00096 bool connectResult = client->connectDCOPSignal("", "alive(int , QCString)", "object1", "isAliveSlot(int)", false);
00097 qDebug("connectDCOPSignal returns %s", connectResult ? "true" : "false");
00098
00099 QDataStream ds(data, IO_WriteOnly);
00100 ds << QString("fourty-two") << 42;
00101 if (!client->call(app.name(), "object1", "aFunction(QString,int)", data, replyType, reply))
00102 qDebug("I couldn't call myself");
00103 else
00104 qDebug("return type was '%s'", replyType.data() );
00105
00106 client->send(app.name(), "object1", "aFunction(QString,int)", data );
00107
00108 int n = client->registeredApplications().count();
00109 qDebug("number of attached applications = %d", n );
00110
00111 QObject::connect( client, SIGNAL( applicationRegistered( const QCString&)),
00112 obj1, SLOT( registered( const QCString& )));
00113
00114 QObject::connect( client, SIGNAL( applicationRemoved( const QCString&)),
00115 obj1, SLOT( unregistered( const QCString& )));
00116
00117
00118 client->setNotifications( true );
00119
00120 QCString foundApp;
00121 QCString foundObj;
00122
00123
00124
00125
00126
00127
00128
00129
00130 bool boolResult = client->findObject( "konqueror*", "", "", data, foundApp, foundObj);
00131 qDebug("findObject: result = %s, %s, %s\n", boolResult ? "true" : "false",
00132 foundApp.data(), foundObj.data());
00133
00134
00135 boolResult = client->findObject( "", "ksycoca", "", data, foundApp, foundObj);
00136 qDebug("findObject: result = %s, %s, %s\n", boolResult ? "true" : "false",
00137 foundApp.data(), foundObj.data());
00138
00139 DCOPClient *client2 = new DCOPClient();
00140 client2->registerAs(app.name(), false);
00141 qDebug("I2 registered as '%s'", client2->appId().data() );
00142
00143 qDebug("Sending to object1");
00144 client2->send(app.name(), "object1", "aFunction(QString,int)", data );
00145
00146 qDebug("Calling object1");
00147 if (!client2->call(app.name(), "object1", "aFunction(QString,int)", data, replyType, reply))
00148 qDebug("I couldn't call myself");
00149 else
00150 qDebug("return type was '%s'", replyType.data() );
00151
00152 return app.exec();
00153
00154 client->detach();
00155 }
00156
00157 #include "testdcop.moc"