25 #include <tqvariant.h>
28 #include "../kdatastream.h"
29 #include "../dcopclient.h"
30 #include "../dcopref.h"
35 #include "marshall.cpp"
38 static bool bAppIdOnly = 0;
39 static bool bLaunchApp = 0;
41 bool findObject(
const char* app,
const char* obj,
const char* func, QCStringList args )
44 int left = f.find(
'(' );
45 int right = f.find(
')' );
49 tqWarning(
"parentheses do not match" );
53 if ( !f.isEmpty() && (left < 0) )
60 TQStringList intTypes;
61 intTypes <<
"int" <<
"unsigned" <<
"long" <<
"bool" ;
64 if ( left >0 && left + 1 < right - 1) {
65 types = TQStringList::split(
',', f.mid( left + 1, right - left - 1) );
66 for ( TQStringList::Iterator it = types.begin(); it != types.end(); ++it ) {
67 TQString lt = (*it).simplifyWhiteSpace();
79 TQStringList partl = TQStringList::split(
' ' , lt);
89 while (s < (
int)partl.count() && intTypes.contains(partl[s]))
94 if (s<(
int)partl.count()-1)
96 tqWarning(
"The argument `%s' seems syntactically wrong.",
99 if (s==(
int)partl.count()-1)
101 partl.remove(partl.at(s));
104 lt = partl.join(
" ");
105 lt = lt.simplifyWhiteSpace();
110 TQString fc = f.left( left );
113 for ( TQStringList::Iterator it = types.begin(); it != types.end(); ++it ) {
123 if ( types.count() != args.count() ) {
124 tqWarning(
"arguments do not match" );
129 TQDataStream arg(data, IO_WriteOnly);
132 for ( TQStringList::Iterator it = types.begin(); it != types.end(); ++it ) {
133 marshall(arg, args, i, *it);
135 if ( (uint) i != args.count() ) {
136 tqWarning(
"arguments do not match" );
142 if ( dcop->
findObject( app, obj, f.latin1(), data, foundApp, foundObj) )
145 puts(foundApp.data());
147 printf(
"DCOPRef(%s,%s)\n", qStringToC(foundApp), qStringToC(foundObj));
153 bool launchApp(TQString app)
155 int l = app.length();
156 if (l && (app[l-1] ==
'*'))
158 if (l && (app[l-1] ==
'-'))
160 if (!l)
return false;
164 TQByteArray data, replyData;
166 TQDataStream arg(data, IO_WriteOnly);
169 if ( !dcop->
call(
"tdelauncher",
"tdelauncher",
"start_service_by_desktop_name(TQString,TQStringList)",
170 data, replyType, replyData) ) {
171 tqWarning(
"call to tdelauncher failed.");
174 TQDataStream reply(replyData, IO_ReadOnly);
176 if ( replyType !=
"serviceResult" )
178 tqWarning(
"unexpected result '%s' from tdelauncher.", replyType.data());
184 reply >> result >> dcopName >> error;
187 tqWarning(
"Error starting '%s': %s", app.local8Bit().data(), error.local8Bit().data());
195 fprintf( stderr,
"[dcopfind] Usage: dcopfind [-l] [-a] application [object [function [arg1] [arg2] [arg3] ... ] ] ] \n" );
200 # define main kdemain
203 int main(
int argc,
char** argv )
207 while ((argi < argc) && (argv[argi][0] ==
'-'))
209 switch ( argv[argi][1] ) {
233 if ((argc > argi) && (strncmp(argv[argi],
"DCOPRef(", 8)) == 0)
235 char *delim = strchr(argv[argi],
',');
238 fprintf(stderr,
"Error: '%s' is not a valid DCOP reference.\n", argv[argi]);
242 app = argv[argi++] + 8;
244 delim[strlen(delim)-1] = 0;
252 objid = argv[argi++];
255 function = argv[argi++];
268 for(
int i = 0; i < argc; i++ )
269 params.append( args[ i ] );
270 bool ok = findObject( app, objid,
function, params );
278 ok = findObject( app, objid,
function, params );
Inter-process communication and remote procedure calls for KDE applications.
bool attach()
Attaches to the DCOP 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.