26 #include <tqobjectlist.h>
27 #include <tqmetaobject.h>
28 #include <tqvariant.h>
30 #include <tqintdict.h>
31 #include <tqeventloop.h>
40 #include <sys/types.h>
43 #include <sys/socket.h>
54 #include <tqguardedptr.h>
55 #include <tqtextstream.h>
58 #include <tqapplication.h>
59 #include <tqsocketnotifier.h>
62 #include <tqucomextra_p.h>
64 #include <dcopglobal.h>
65 #include <dcopclient.h>
66 #include <dcopobject.h>
68 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
72 #include <KDE-ICE/ICElib.h>
73 #include <KDE-ICE/ICEutil.h>
74 #include <KDE-ICE/ICEmsg.h>
75 #include <KDE-ICE/ICEproto.h>
80 extern TQMap<TQCString, DCOPObject *> * kde_dcopObjMap;
85 typedef TQAsciiDict<DCOPClient> client_map_t;
86 static client_map_t *DCOPClient_CliMap = 0;
89 client_map_t *cliMap()
91 if (!DCOPClient_CliMap)
92 DCOPClient_CliMap =
new client_map_t;
93 return DCOPClient_CliMap;
98 return cliMap()->find(_appId.data());
102 void registerLocalClient(
const TQCString &_appId,
DCOPClient *client )
104 cliMap()->replace(_appId.data(), client);
108 void unregisterLocalClient(
const TQCString &_appId )
110 client_map_t *map = cliMap();
111 map->remove(_appId.data());
115 template class TQPtrList<DCOPObjectProxy>;
116 template class TQPtrList<DCOPClientTransaction>;
117 template class TQPtrList<_IceConn>;
119 struct DCOPClientMessage
126 class DCOPClient::ReplyStruct
129 enum ReplyStatus { Pending, Ok, Failed };
139 TQCString* replyType;
140 TQByteArray* replyData;
142 TQ_INT32 transactionId;
144 TQGuardedPtr<TQObject> replyObject;
148 class DCOPClientPrivate
156 int majorVersion, minorVersion;
158 static const char* serverAddr;
159 TQSocketNotifier *notifier;
160 bool non_blocking_call_lock;
164 bool accept_calls_override;
165 bool qt_bridge_enabled;
171 TQCString defaultObject;
172 TQPtrList<DCOPClientTransaction> *transactionList;
174 TQ_INT32 transactionId;
184 CARD32 currentKeySaved;
186 TQTimer postMessageTimer;
187 TQPtrList<DCOPClientMessage> messages;
189 TQPtrList<DCOPClient::ReplyStruct> pendingReplies;
190 TQPtrList<DCOPClient::ReplyStruct> asyncReplyQueue;
192 struct LocalTransactionResult
195 TQByteArray replyData;
198 TQIntDict<LocalTransactionResult> localTransActionList;
200 TQTimer eventLoopTimer;
203 class DCOPClientTransaction
213 #if defined(ICEAUTH_PATH)
215 #
if defined(Q_WS_WIN)
216 access(ICEAUTH_PATH, 0) == 0
218 access(ICEAUTH_PATH, X_OK) == 0
222 return TQCString(ICEAUTH_PATH);
225 #elif defined(Q_OS_WIN32)
229 ret = SearchPathA(NULL,
"iceauth.exe",NULL,
sizeof(szPath)/
sizeof(szPath[0]),szPath,&pszFilePart);
231 return TQCString(szPath);
234 TQCString path = ::getenv(
"PATH");
236 path =
"/bin:/usr/bin";
237 path +=
":/usr/bin/X11:/usr/X11/bin:/usr/X11R6/bin";
238 TQCString fPath = strtok(path.data(),
":\b");
239 while (!fPath.isNull())
242 if (access(fPath.data(), X_OK) == 0)
246 fPath = strtok(NULL,
":\b");
253 static TQCString dcopServerFile(
const TQCString &hostname,
bool old)
255 TQCString fName = ::getenv(
"DCOPAUTHORITY");
256 if (!old && !fName.isEmpty())
259 fName = TQFile::encodeName( TQDir::homeDirPath() );
263 fprintf(stderr,
"Aborting. $HOME is not set.\n");
267 TQCString disp = getenv(
"DISPLAY");
268 #elif defined(Q_WS_QWS)
269 TQCString disp = getenv(
"QWS_DISPLAY");
277 if((i = disp.findRev(
'.')) > disp.findRev(KPATH_SEPARATOR) && i >= 0)
282 while( (i = disp.find(KPATH_SEPARATOR)) >= 0)
286 fName +=
"/.DCOPserver_";
287 if (hostname.isEmpty())
291 if (getenv(
"XAUTHLOCALHOSTNAME"))
292 fName += getenv(
"XAUTHLOCALHOSTNAME");
293 else if (gethostname(hostName,
sizeof(hostName)))
295 fName +=
"localhost";
299 hostName[
sizeof(hostName)-1] =
'\0';
315 return ::dcopServerFile(hostname,
false);
322 return ::dcopServerFile(hostname,
true);
326 const char* DCOPClientPrivate::serverAddr = 0;
328 static void DCOPProcessInternal( DCOPClientPrivate *d,
int opcode, CARD32 key,
const TQByteArray& dataReceived,
bool canPost );
330 void DCOPClient::handleAsyncReply(ReplyStruct *replyStruct)
332 if (replyStruct->replyObject)
334 TQObject::connect(
this, TQT_SIGNAL(callBack(
int,
const TQCString&,
const TQByteArray &)),
335 replyStruct->replyObject, replyStruct->replySlot);
336 emit callBack(replyStruct->replyId, *(replyStruct->replyType), *(replyStruct->replyData));
337 TQObject::disconnect(
this, TQT_SIGNAL(callBack(
int,
const TQCString&,
const TQByteArray &)),
338 replyStruct->replyObject, replyStruct->replySlot);
346 static void DCOPProcessMessage(IceConn iceConn, IcePointer clientObject,
347 int opcode,
unsigned long length, Bool ,
348 IceReplyWaitInfo *replyWait,
352 DCOPClientPrivate *d =
static_cast<DCOPClientPrivate *
>(clientObject);
353 DCOPClient::ReplyStruct *replyStruct = replyWait ?
static_cast<DCOPClient::ReplyStruct*
>(replyWait->reply) : 0;
355 IceReadMessageHeader(iceConn,
sizeof(DCOPMsg), DCOPMsg, pMsg);
356 CARD32
key = pMsg->key;
360 TQByteArray dataReceived( length );
361 IceReadData(iceConn, length, dataReceived.data() );
366 case DCOPReplyFailed:
368 replyStruct->status = DCOPClient::ReplyStruct::Failed;
369 replyStruct->transactionId = 0;
370 *replyWaitRet = True;
373 tqWarning(
"Very strange! got a DCOPReplyFailed opcode, but we were not waiting for a reply!");
378 TQByteArray* b = replyStruct->replyData;
379 TQCString* t = replyStruct->replyType;
380 replyStruct->status = DCOPClient::ReplyStruct::Ok;
381 replyStruct->transactionId = 0;
383 TQCString calledApp, app;
384 TQDataStream ds( dataReceived, IO_ReadOnly );
385 ds >> calledApp >> app >> *t >> *b;
387 *replyWaitRet = True;
390 tqWarning(
"Very strange! got a DCOPReply opcode, but we were not waiting for a reply!");
395 TQCString calledApp, app;
397 TQDataStream ds( dataReceived, IO_ReadOnly );
398 ds >> calledApp >> app >> id;
399 replyStruct->transactionId = id;
400 replyStruct->calledApp = calledApp;
401 d->pendingReplies.append(replyStruct);
402 *replyWaitRet = True;
405 tqWarning(
"Very strange! got a DCOPReplyWait opcode, but we were not waiting for a reply!");
408 case DCOPReplyDelayed:
410 TQDataStream ds( dataReceived, IO_ReadOnly );
411 TQCString calledApp, app;
414 ds >> calledApp >> app >> id;
415 if (replyStruct && (
id == replyStruct->transactionId) && (calledApp == replyStruct->calledApp))
417 *replyWaitRet = True;
420 for(DCOPClient::ReplyStruct *rs = d->pendingReplies.first(); rs;
421 rs = d->pendingReplies.next())
423 if ((rs->transactionId ==
id) && (rs->calledApp == calledApp))
425 d->pendingReplies.remove();
426 TQByteArray* b = rs->replyData;
427 TQCString* t = rs->replyType;
430 rs->status = DCOPClient::ReplyStruct::Ok;
431 rs->transactionId = 0;
432 if (!rs->replySlot.isEmpty())
434 d->parent->handleAsyncReply(rs);
439 tqWarning(
"Very strange! got a DCOPReplyDelayed opcode, but we were not waiting for a reply!");
445 DCOPProcessInternal( d, opcode, key, dataReceived,
true );
449 void DCOPClient::processPostedMessagesInternal()
451 if ( d->messages.isEmpty() )
453 TQPtrListIterator<DCOPClientMessage> it (d->messages );
454 DCOPClientMessage* msg ;
455 while ( ( msg = it.current() ) ) {
457 if ( d->currentKey && msg->key != d->currentKey )
459 d->messages.removeRef( msg );
460 d->opcode = msg->opcode;
461 DCOPProcessInternal( d, msg->opcode, msg->key, msg->data,
false );
464 if ( !d->messages.isEmpty() )
465 d->postMessageTimer.start( 100,
true );
471 void DCOPProcessInternal( DCOPClientPrivate *d,
int opcode, CARD32 key,
const TQByteArray& dataReceived,
bool canPost )
473 if (!d->accept_calls && (opcode == DCOPSend))
476 IceConn iceConn = d->iceConn;
479 TQDataStream ds( dataReceived, IO_ReadOnly );
483 if (fromApp.isEmpty())
486 if (!d->accept_calls)
489 TQDataStream replyStream( reply, IO_WriteOnly );
491 replyStream << d->appId << fromApp;
492 IceGetHeader( iceConn, d->majorOpcode, DCOPReplyFailed,
493 sizeof(DCOPMsg), DCOPMsg, pMsg );
494 int datalen = reply.size();
496 pMsg->length += datalen;
497 IceSendData( iceConn, datalen, reply.data());
501 TQCString app, objId, fun;
503 ds >> app >> objId >> fun >> data;
504 d->senderId = fromApp;
510 if ( canPost && d->currentKey && key != d->currentKey ) {
511 DCOPClientMessage* msg =
new DCOPClientMessage;
512 msg->opcode = opcode;
514 msg->data = dataReceived;
515 d->messages.append( msg );
516 d->postMessageTimer.start( 0,
true );
524 TQByteArray replyData;
526 CARD32 oldCurrentKey = d->currentKey;
527 if ( opcode != DCOPSend )
530 if ( opcode == DCOPFind )
531 b = c->find(app, objId, fun, data, replyType, replyData );
533 b = c->receive( app, objId, fun, data, replyType, replyData );
536 if ( opcode == DCOPSend )
539 if ((d->currentKey == key) || (oldCurrentKey != 2))
540 d->currentKey = oldCurrentKey;
543 TQDataStream replyStream( reply, IO_WriteOnly );
548 replyStream << d->appId << fromApp << id;
550 IceGetHeader( iceConn, d->majorOpcode, DCOPReplyWait,
551 sizeof(DCOPMsg), DCOPMsg, pMsg );
553 pMsg->length += reply.size();
554 IceSendData( iceConn, reply.size(),
const_cast<char *
>(reply.data()));
561 replyStream << d->appId << fromApp;
562 IceGetHeader( iceConn, d->majorOpcode, DCOPReplyFailed,
563 sizeof(DCOPMsg), DCOPMsg, pMsg );
564 int datalen = reply.size();
566 pMsg->length += datalen;
567 IceSendData( iceConn, datalen,
const_cast<char *
>(reply.data()));
572 replyStream << d->appId << fromApp << replyType << replyData.size();
576 IceGetHeader( iceConn, d->majorOpcode,
DCOPReply,
577 sizeof(DCOPMsg), DCOPMsg, pMsg );
578 int datalen = reply.size() + replyData.size();
580 pMsg->length += datalen;
583 IceSendData( iceConn, reply.size(),
const_cast<char *
>(reply.data()));
584 IceSendData( iceConn, replyData.size(),
const_cast<char *
>(replyData.data()));
589 static IcePoVersionRec DCOPClientVersions[] = {
590 { DCOPVersionMajor, DCOPVersionMinor, DCOPProcessMessage }
598 return dcop_main_client;
603 dcop_main_client = client;
609 d =
new DCOPClientPrivate;
617 d->non_blocking_call_lock =
false;
618 d->registered =
false;
619 d->foreign_server =
true;
620 d->accept_calls =
true;
621 d->accept_calls_override =
false;
622 d->qt_bridge_enabled =
true;
623 d->transactionList = 0L;
624 d->transactionId = 0;
625 TQObject::connect( &d->postMessageTimer, TQT_SIGNAL( timeout() ),
this, TQT_SLOT( processPostedMessagesInternal() ) );
626 TQObject::connect( &d->eventLoopTimer, TQT_SIGNAL( timeout() ),
this, TQT_SLOT( eventLoopTimeout() ) );
634 #ifdef DCOPCLIENT_DEBUG
635 tqWarning(
"d->messages.count() = %d", d->messages.count());
636 TQPtrListIterator<DCOPClientMessage> it (d->messages );
637 DCOPClientMessage* msg ;
638 while ( ( msg = it.current() ) ) {
640 d->messages.removeRef( msg );
641 tqWarning(
"DROPPING UNHANDLED DCOP MESSAGE:");
642 tqWarning(
" opcode = %d key = %d", msg->opcode, msg->key);
643 TQDataStream ds( msg->data, IO_ReadOnly );
645 TQCString fromApp, app, objId, fun;
646 ds >> fromApp >> app >> objId >> fun;
647 tqWarning(
" from = %s", fromApp.data());
648 tqWarning(
" to = %s / %s / %s", app.data(), objId.data(), fun.data());
653 if (IceConnectionStatus(d->iceConn) == IceConnectAccepted)
657 unregisterLocalClient( d->appId );
660 delete d->transactionList;
661 d->messages.setAutoDelete(
true);
670 TQCString env =
"DCOPSERVER=" + addr;
671 putenv(strdup(env.data()));
672 delete [] DCOPClientPrivate::serverAddr;
673 DCOPClientPrivate::serverAddr = tqstrdup( addr.data() );
678 if (!attachInternal(
true ))
679 if (!attachInternal(
true ))
684 void DCOPClient::bindToApp()
691 d->notifier =
new TQSocketNotifier(
socket(),
692 TQSocketNotifier::Read, 0, 0);
693 TQObject::connect(d->notifier, TQT_SIGNAL(activated(
int)),
705 d->notifier->setEnabled(
false);
715 d->notifier->setEnabled(
true);
720 #if defined(Q_WS_WIN) || defined(Q_WS_MAC)
724 return !d->notifier->isEnabled();
727 #if defined(SO_PEERCRED) || defined(LOCAL_PEEREID)
728 #define USE_PEER_IS_US
730 static bool peerIsUs(
int sockfd)
733 #if defined(__OpenBSD__)
734 struct sockpeercred cred;
738 socklen_t siz =
sizeof(cred);
739 if (getsockopt(sockfd, SOL_SOCKET, SO_PEERCRED, &cred, &siz) != 0)
741 return (cred.uid == getuid());
742 #elif defined LOCAL_PEEREID
744 socklen_t siz =
sizeof(cred);
745 if (getsockopt(sockfd, 0, LOCAL_PEEREID, &cred, &siz) != 0 || siz !=
sizeof(cred))
747 return (cred.unp_euid == geteuid());
752 static bool isServerSocketOwnedByUser(
const char*server)
755 if (strncmp(server,
"tcp/", 4) != 0)
760 if (strncmp(server,
"local/", 6) != 0)
762 const char *path = strchr(server, KPATH_SEPARATOR);
767 struct stat stat_buf;
768 if (stat(path, &stat_buf) != 0)
771 return (stat_buf.st_uid == getuid());
777 bool DCOPClient::attachInternal(
bool registerAsAnonymous )
784 if ((d->majorOpcode = IceRegisterForProtocolSetup(
const_cast<char *
>(
"DCOP"),
785 const_cast<char *
>(DCOPVendorString),
786 const_cast<char *
>(DCOPReleaseString),
787 1, DCOPClientVersions,
789 const_cast<char **
>(DCOPAuthNames),
790 DCOPClientAuthProcs, 0L)) < 0) {
791 emit
attachFailed(TQString::fromLatin1(
"Communications could not be established." ));
795 bool bClearServerAddr =
false;
797 if (!d->serverAddr) {
801 dcopSrv = ::getenv(
"DCOPSERVER");
802 if (dcopSrv.isEmpty()) {
804 TQFile f(TQFile::decodeName(fName));
805 if (!f.open(IO_ReadOnly)) {
806 emit
attachFailed(TQString::fromLatin1(
"Could not read network connection list.\n" )+TQFile::decodeName(fName));
809 int size = TQMIN( (qint64)1024, f.size() );
810 TQCString contents( size+1 );
811 if ( f.readBlock( contents.data(), size ) != size )
813 tqDebug(
"Error reading from %s, didn't read the expected %d bytes", fName.data(), size);
816 contents[size] =
'\0';
817 int pos = contents.find(
'\n');
820 tqDebug(
"Only one line in dcopserver file !: %s", contents.data());
825 if(contents[pos - 1] ==
'\r')
827 dcopSrv = contents.left( pos );
833 d->serverAddr = tqstrdup(
const_cast<char *
>(dcopSrv.data()) );
834 bClearServerAddr =
true;
837 if ((d->iceConn = IceOpenConnection(
const_cast<char*
>(d->serverAddr),
838 static_cast<IcePointer
>(
this), False, d->majorOpcode,
839 sizeof(errBuf), errBuf)) == 0L) {
840 tqDebug(
"DCOPClient::attachInternal. Attach failed %s", errBuf);
842 if (bClearServerAddr) {
843 delete [] d->serverAddr;
849 fcntl(
socket(), F_SETFL, FD_CLOEXEC);
851 IceSetShutdownNegotiation(d->iceConn, False);
856 setupstat = IceProtocolSetup(d->iceConn, d->majorOpcode,
857 static_cast<IcePointer
>(d),
859 &(d->majorVersion), &(d->minorVersion),
860 &(vendor), &(release), 1024, errBuf);
861 if (vendor) free(vendor);
862 if (release) free(release);
864 if (setupstat == IceProtocolSetupFailure ||
865 setupstat == IceProtocolSetupIOError) {
866 IceCloseConnection(d->iceConn);
868 if (bClearServerAddr) {
869 delete [] d->serverAddr;
874 }
else if (setupstat == IceProtocolAlreadyActive) {
875 if (bClearServerAddr) {
876 delete [] d->serverAddr;
880 emit
attachFailed(TQString::fromLatin1(
"internal error in IceOpenConnection" ));
885 if (IceConnectionStatus(d->iceConn) != IceConnectAccepted) {
886 if (bClearServerAddr) {
887 delete [] d->serverAddr;
890 emit
attachFailed(TQString::fromLatin1(
"DCOP server did not accept the connection." ));
894 #ifdef USE_PEER_IS_US
895 d->foreign_server = !peerIsUs(
socket());
897 d->foreign_server = !isServerSocketOwnedByUser(d->serverAddr);
899 if (!d->accept_calls_override)
900 d->accept_calls = !d->foreign_server;
904 if ( registerAsAnonymous )
916 IceProtocolShutdown(d->iceConn, d->majorOpcode);
917 status = IceCloseConnection(d->iceConn);
918 if (status != IceClosedNow)
925 unregisterLocalClient(d->appId);
929 d->registered =
false;
930 d->foreign_server =
true;
939 return (IceConnectionStatus(d->iceConn) == IceConnectAccepted);
955 d->accept_calls_override =
true;
960 return d->qt_bridge_enabled;
965 d->qt_bridge_enabled = b;
972 TQCString _appId =
appId;
976 pid.sprintf(
"-%d", getpid());
977 _appId = _appId + pid;
980 if( d->appId == _appId )
991 if (!attachInternal(
false ))
992 if (!attachInternal(
false ))
998 TQByteArray data, replyData;
999 TQDataStream arg( data, IO_WriteOnly );
1001 if (
call(
"DCOPServer",
"",
"registerAs(TQCString)", data, replyType, replyData ) ) {
1002 TQDataStream reply( replyData, IO_ReadOnly );
1007 d->registered = !result.isNull();
1010 registerLocalClient( d->appId,
this );
1017 return d->registered;
1030 return IceConnectionNumber(d->iceConn);
1034 static inline bool isIdentChar(
char x )
1036 return x ==
'_' || (x >=
'0' && x <=
'9') ||
1037 (x >=
'a' && x <=
'z') || (x >=
'A' && x <=
'Z');
1041 if ( fun.isEmpty() )
1043 TQCString result( fun.size() );
1044 char *from =
const_cast<TQCString&
>(fun).data();
1045 char *to = result.data();
1049 while ( *from && isspace(*from) )
1051 if ( last && isIdentChar( last ) && isIdentChar( *from ) )
1053 while ( *from && !isspace(*from) ) {
1060 if ( to > first && *(to-1) == 0x20 )
1063 result.resize( (
int)((long)to - (
long)result.data()) + 1 );
1075 const TQCString &remFun,
const TQByteArray &data)
1077 if (remApp.isEmpty())
1081 if ( localClient ) {
1082 bool saveTransaction = d->transaction;
1083 TQ_INT32 saveTransactionId = d->transactionId;
1084 TQCString saveSenderId = d->senderId;
1087 TQCString replyType;
1088 TQByteArray replyData;
1089 (void) localClient->receive( remApp, remObjId, remFun, data, replyType, replyData );
1091 d->transaction = saveTransaction;
1092 d->transactionId = saveTransactionId;
1093 d->senderId = saveSenderId;
1108 TQDataStream ds(ba, IO_WriteOnly);
1111 IceGetHeader(d->iceConn, d->majorOpcode, DCOPSend,
1112 sizeof(DCOPMsg), DCOPMsg, pMsg);
1115 int datalen = ba.size() + data.size();
1116 pMsg->length += datalen;
1118 IceSendData( d->iceConn, ba.size(),
const_cast<char *
>(ba.data()) );
1119 IceSendData( d->iceConn, data.size(),
const_cast<char *
>(data.data()) );
1123 if (IceConnectionStatus(d->iceConn) == IceConnectAccepted)
1129 const TQCString &remFun,
const TQString &data)
1132 TQDataStream ds(ba, IO_WriteOnly);
1134 return send(remApp, remObjId, remFun, ba);
1138 const TQCString &remFun,
const TQByteArray &data,
1139 TQCString &foundApp, TQCString &foundObj,
1142 return findObject( remApp, remObj, remFun, data, foundApp, foundObj, useEventLoop, -1 );
1146 const TQCString &remFun,
const TQByteArray &data,
1147 TQCString &foundApp, TQCString &foundObj,
1148 bool useEventLoop,
int timeout)
1150 QCStringList appList;
1151 TQCString app = remApp;
1158 if (app[app.length()-1] ==
'*')
1163 int len = app.length()-1;
1165 for( QCStringList::ConstIterator it = apps.begin();
1169 if ( strncmp( (*it).data(), app.data(), len) == 0)
1170 appList.append(*it);
1175 appList.append(app);
1179 for(
int phase=1; phase <= 2; phase++)
1181 for( QCStringList::ConstIterator it = appList.begin();
1182 it != appList.end();
1185 TQCString remApp = *it;
1186 TQCString replyType;
1187 TQByteArray replyData;
1188 bool result =
false;
1191 if ( (phase == 1) && localClient ) {
1193 bool saveTransaction = d->transaction;
1194 TQ_INT32 saveTransactionId = d->transactionId;
1195 TQCString saveSenderId = d->senderId;
1198 result = localClient->find( remApp, remObj, remFun, data, replyType, replyData );
1204 TQApplication::eventLoop()->processEvents( TQEventLoop::WaitForMore);
1205 }
while( !localClient->isLocalTransactionFinished(
id, replyType, replyData));
1208 d->transaction = saveTransaction;
1209 d->transactionId = saveTransactionId;
1210 d->senderId = saveSenderId;
1212 else if ((phase == 2) && !localClient)
1215 result = callInternal(remApp, remObj, remFun, data,
1216 replyType, replyData, useEventLoop, timeout, DCOPFind);
1221 if (replyType ==
"DCOPRef")
1224 TQDataStream reply( replyData, IO_ReadOnly );
1227 if (ref.
app() == remApp)
1230 foundApp = ref.
app();
1242 TQCString&, TQByteArray &)
1249 TQCString replyType;
1250 TQByteArray data, replyData;
1251 TQDataStream arg( data, IO_WriteOnly );
1254 if (
call(
"DCOPServer",
"",
"isApplicationRegistered(TQCString)", data, replyType, replyData ) ) {
1255 TQDataStream reply( replyData, IO_ReadOnly );
1263 TQCString replyType;
1264 TQByteArray data, replyData;
1265 QCStringList result;
1266 if (
call(
"DCOPServer",
"",
"registeredApplications()", data, replyType, replyData ) ) {
1267 TQDataStream reply( replyData, IO_ReadOnly );
1275 TQCString replyType;
1276 TQByteArray data, replyData;
1277 QCStringList result;
1280 if (
call( remApp,
"DCOPClient",
"objects()", data, replyType, replyData ) ) {
1281 TQDataStream reply( replyData, IO_ReadOnly );
1291 TQCString replyType;
1292 TQByteArray data, replyData;
1293 QCStringList result;
1296 if (
call( remApp, remObj,
"interfaces()", data, replyType, replyData ) && replyType ==
"QCStringList") {
1297 TQDataStream reply( replyData, IO_ReadOnly );
1307 TQCString replyType;
1308 TQByteArray data, replyData;
1309 QCStringList result;
1312 if (
call( remApp, remObj,
"functions()", data, replyType, replyData ) && replyType ==
"QCStringList") {
1313 TQDataStream reply( replyData, IO_ReadOnly );
1324 TQDataStream ds(data, IO_WriteOnly);
1325 ds << static_cast<TQ_INT8>(enabled);
1327 TQCString replyType;
1329 if (!
call(
"DCOPServer",
"",
"setNotifications( bool )", data, replyType, reply))
1330 tqWarning(
"I couldn't enable notifications at the dcopserver!");
1336 TQDataStream ds(data, IO_WriteOnly);
1337 ds << static_cast<TQ_INT8>( daemonMode );
1339 TQCString replyType;
1341 if (!
call(
"DCOPServer",
"",
"setDaemonMode(bool)", data, replyType, reply))
1342 tqWarning(
"I couldn't enable daemon mode at the dcopserver!");
1352 static void fillQtObjects( QCStringList& l, TQObject* o, TQCString path )
1354 if ( !path.isEmpty() )
1358 const TQObjectList list = o ? o->childrenListObject() : TQObject::objectTreesListObject();
1359 if ( !list.isEmpty() ) {
1360 TQObjectListIt it( list );
1362 while ( (obj=it.current()) ) {
1364 TQCString n = obj->name();
1365 if ( n ==
"unnamed" || n.isEmpty() )
1367 n.sprintf(
"%p", (
void *) obj);
1368 n = TQString(TQString(
"unnamed%1(%2, %3)").arg(++unnamed).arg(obj->className()).arg(TQString(n))).latin1();
1370 TQCString fn = path + n;
1372 if ( !obj->childrenListObject().isEmpty() )
1373 fillQtObjects( l, obj, fn );
1383 O (
const TQCString& str, TQObject* obj ):s(str), o(obj){}
1389 static void fillQtObjectsEx( TQValueList<O>& l, TQObject* o, TQCString path )
1391 if ( !path.isEmpty() )
1395 const TQObjectList list = o ? o->childrenListObject() : TQObject::objectTreesListObject();
1396 if ( !list.isEmpty() ) {
1397 TQObjectListIt it( list );
1399 while ( (obj=it.current()) ) {
1401 TQCString n = obj->name();
1402 if ( n ==
"unnamed" || n.isEmpty() )
1404 n.sprintf(
"%p", (
void *) obj);
1405 n = TQString(TQString(
"unnamed%1(%2, %3)").arg(++unnamed).arg(obj->className()).arg(TQString(n))).latin1();
1407 TQCString fn = path + n;
1408 l.append( O( fn, obj ) );
1409 if ( !obj->childrenListObject().isEmpty() )
1410 fillQtObjectsEx( l, obj, fn );
1416 static TQObject* findQtObject( TQCString
id )
1418 TQRegExp expr(
id );
1420 fillQtObjectsEx( l, 0,
"qt" );
1422 TQObject* firstContains = 0L;
1423 for ( TQValueList<O>::ConstIterator it = l.begin(); it != l.end(); ++it ) {
1424 if ( (*it).s ==
id )
1426 if ( !firstContains && (*it).s.contains( expr ) ) {
1427 firstContains = (*it).o;
1430 return firstContains;
1433 static QCStringList findQtObjects( TQCString
id )
1435 TQRegExp expr(
id );
1437 fillQtObjectsEx( l, 0,
"qt" );
1438 QCStringList result;
1439 for ( TQValueList<O>::ConstIterator it = l.begin(); it != l.end(); ++it ) {
1440 if ( (*it).s.contains( expr ) )
1446 static bool receiveQtObject(
const TQCString &objId,
const TQCString &fun,
const TQByteArray &data,
1447 TQCString& replyType, TQByteArray &replyData)
1449 if ( objId ==
"qt" ) {
1450 if ( fun ==
"interfaces()" ) {
1451 replyType =
"QCStringList";
1452 TQDataStream reply( replyData, IO_WriteOnly );
1458 }
else if ( fun ==
"functions()" ) {
1459 replyType =
"QCStringList";
1460 TQDataStream reply( replyData, IO_WriteOnly );
1462 l <<
"QCStringList functions()";
1463 l <<
"QCStringList interfaces()";
1464 l <<
"QCStringList objects()";
1465 l <<
"QCStringList find(TQCString)";
1468 }
else if ( fun ==
"objects()" ) {
1469 replyType =
"QCStringList";
1470 TQDataStream reply( replyData, IO_WriteOnly );
1472 fillQtObjects( l, 0,
"qt" );
1475 }
else if ( fun ==
"find(TQCString)" ) {
1476 TQDataStream ds( data, IO_ReadOnly );
1479 replyType =
"QCStringList";
1480 TQDataStream reply( replyData, IO_WriteOnly );
1481 reply << findQtObjects(
id ) ;
1484 }
else if ( objId.left(3) ==
"qt/" ) {
1485 TQObject* o = findQtObject( objId );
1488 if ( fun ==
"functions()" ) {
1489 replyType =
"QCStringList";
1490 TQDataStream reply( replyData, IO_WriteOnly );
1492 l <<
"QCStringList functions()";
1493 l <<
"QCStringList interfaces()";
1494 l <<
"QCStringList properties()";
1495 l <<
"bool setProperty(TQCString,TQVariant)";
1496 l <<
"TQVariant property(TQCString)";
1497 TQStrList lst = o->metaObject()->slotNames(
true );
1499 for ( TQPtrListIterator<char> it( lst ); it.current(); ++it ) {
1500 if ( o->metaObject()->slot( i++,
true )->tqt_mo_access != TQMetaData::Public )
1502 TQCString slot = it.current();
1503 if ( slot.contains(
"()" ) ) {
1504 slot.prepend(
"void ");
1510 }
else if ( fun ==
"interfaces()" ) {
1511 replyType =
"QCStringList";
1512 TQDataStream reply( replyData, IO_WriteOnly );
1514 TQMetaObject *meta = o->metaObject();
1516 l.prepend( meta->className() );
1517 meta = meta->superClass();
1521 }
else if ( fun ==
"properties()" ) {
1522 replyType =
"QCStringList";
1523 TQDataStream reply( replyData, IO_WriteOnly );
1525 TQStrList lst = o->metaObject()->propertyNames(
true );
1526 for ( TQPtrListIterator<char> it( lst ); it.current(); ++it ) {
1527 TQMetaObject *mo = o->metaObject();
1528 const TQMetaProperty* p = mo->property( mo->findProperty( it.current(),
true ),
true );
1531 TQCString prop = p->type();
1534 if ( !p->writable() )
1535 prop +=
" readonly";
1540 }
else if ( fun ==
"property(TQCString)" ) {
1541 replyType =
"TQVariant";
1542 TQDataStream ds( data, IO_ReadOnly );
1545 TQVariant result = o->property( name );
1546 TQDataStream reply( replyData, IO_WriteOnly );
1549 }
else if ( fun ==
"setProperty(TQCString,TQVariant)" ) {
1550 TQDataStream ds( data, IO_ReadOnly );
1553 ds >>
name >> value;
1555 TQDataStream reply( replyData, IO_WriteOnly );
1556 reply << (TQ_INT8) o->setProperty( name, value );
1559 int slot = o->metaObject()->findSlot( fun,
true );
1563 o->tqt_invoke( slot, uo );
1580 bool DCOPClient::receive(
const TQCString &,
const TQCString &objId,
1581 const TQCString &fun,
const TQByteArray &data,
1582 TQCString& replyType, TQByteArray &replyData)
1584 d->transaction =
false;
1585 if ( objId ==
"DCOPClient" ) {
1586 if ( fun ==
"objects()" ) {
1587 replyType =
"QCStringList";
1588 TQDataStream reply( replyData, IO_WriteOnly );
1590 if (d->qt_bridge_enabled)
1594 if ( kde_dcopObjMap ) {
1595 TQMap<TQCString, DCOPObject *>::ConstIterator it( kde_dcopObjMap->begin());
1596 for (; it != kde_dcopObjMap->end(); ++it) {
1597 if ( !it.key().isEmpty() ) {
1598 if ( it.key() == d->defaultObject )
1609 if ( objId.isEmpty() || objId ==
"DCOPClient" ) {
1610 if ( fun ==
"applicationRegistered(TQCString)" ) {
1611 TQDataStream ds( data, IO_ReadOnly );
1616 }
else if ( fun ==
"applicationRemoved(TQCString)" ) {
1617 TQDataStream ds( data, IO_ReadOnly );
1624 if (
process( fun, data, replyType, replyData ) )
1628 }
else if (d->qt_bridge_enabled &&
1629 (objId ==
"qt" || objId.left(3) ==
"qt/") ) {
1630 return receiveQtObject( objId, fun, data, replyType, replyData );
1633 if ( objId.isEmpty() || objId ==
"default" ) {
1636 objPtr->setCallingDcopClient(
this);
1637 if (objPtr->
process(fun, data, replyType, replyData))
1645 if (!objId.isEmpty() && ((objId.length()>0)?(objId[objId.length()-1] ==
'*'):0)) {
1648 TQPtrList<DCOPObject> matchList =
1651 objPtr != 0L; objPtr = matchList.next()) {
1652 objPtr->setCallingDcopClient(
this);
1653 if (!objPtr->
process(fun, data, replyType, replyData))
1658 if ( DCOPObjectProxy::proxies ) {
1659 for ( TQPtrListIterator<DCOPObjectProxy> it( *DCOPObjectProxy::proxies ); it.current(); ++it ) {
1661 if ( it.current()->process( objId, fun, data, replyType, replyData ) )
1669 objPtr->setCallingDcopClient(
this);
1670 if (!objPtr->
process(fun, data, replyType, replyData)) {
1682 static bool findResultOk(TQCString &replyType, TQByteArray &replyData)
1685 if (replyType !=
"bool")
return false;
1687 TQDataStream reply( replyData, IO_ReadOnly );
1690 if (!success)
return false;
1696 static bool findSuccess(
const TQCString &app,
const TQCString objId, TQCString &replyType, TQByteArray &replyData)
1699 replyType =
"DCOPRef";
1701 replyData = TQByteArray();
1702 TQDataStream final_reply( replyData, IO_WriteOnly );
1708 bool DCOPClient::find(
const TQCString &app,
const TQCString &objId,
1709 const TQCString &fun,
const TQByteArray &data,
1710 TQCString& replyType, TQByteArray &replyData)
1712 d->transaction =
false;
1713 if ( !app.isEmpty() && app != d->appId && app[app.length()-1] !=
'*') {
1714 tqWarning(
"WEIRD! we somehow received a DCOP message w/a different appId");
1718 if (objId.isEmpty() || objId[objId.length()-1] !=
'*')
1723 return findSuccess(app, objId, replyType, replyData);
1727 if (receive(app, objId, fun, data, replyType, replyData))
1729 if (findResultOk(replyType, replyData))
1730 return findSuccess(app, objId, replyType, replyData);
1736 TQPtrList<DCOPObject> matchList =
1739 objPtr != 0L; objPtr = matchList.next())
1742 replyData = TQByteArray();
1744 return findSuccess(app, objPtr->
objId(), replyType, replyData);
1745 objPtr->setCallingDcopClient(
this);
1746 if (objPtr->
process(fun, data, replyType, replyData))
1747 if (findResultOk(replyType, replyData))
1748 return findSuccess(app, objPtr->
objId(), replyType, replyData);
1756 const TQCString &remFun,
const TQByteArray &data,
1757 TQCString& replyType, TQByteArray &replyData,
1760 return call( remApp, remObjId, remFun, data, replyType, replyData, useEventLoop, -1,
false );
1764 const TQCString &remFun,
const TQByteArray &data,
1765 TQCString& replyType, TQByteArray &replyData,
1766 bool useEventLoop,
int timeout)
1768 return call( remApp, remObjId, remFun, data, replyType, replyData, useEventLoop, timeout,
false );
1772 const TQCString &remFun,
const TQByteArray &data,
1773 TQCString& replyType, TQByteArray &replyData,
1774 bool useEventLoop,
int timeout,
bool forceRemote)
1776 if (remApp.isEmpty())
1780 if ( localClient && !forceRemote ) {
1781 bool saveTransaction = d->transaction;
1782 TQ_INT32 saveTransactionId = d->transactionId;
1783 TQCString saveSenderId = d->senderId;
1786 bool b = localClient->receive( remApp, remObjId, remFun, data, replyType, replyData );
1792 TQApplication::eventLoop()->processEvents(TQEventLoop::WaitForMore);
1793 }
while( !localClient->isLocalTransactionFinished(
id, replyType, replyData));
1796 d->transaction = saveTransaction;
1797 d->transactionId = saveTransactionId;
1798 d->senderId = saveSenderId;
1802 return callInternal(remApp, remObjId, remFun, data,
1803 replyType, replyData, useEventLoop, timeout, DCOPCall);
1806 void DCOPClient::asyncReplyReady()
1808 while( d->asyncReplyQueue.count() )
1810 ReplyStruct *replyStruct = d->asyncReplyQueue.take(0);
1811 handleAsyncReply(replyStruct);
1816 const TQCString &remFun,
const TQByteArray &data,
1817 TQObject *callBackObj,
const char *callBackSlot)
1819 TQCString replyType;
1820 TQByteArray replyData;
1822 ReplyStruct *replyStruct =
new ReplyStruct;
1823 replyStruct->replyType =
new TQCString;
1824 replyStruct->replyData =
new TQByteArray;
1825 replyStruct->replyObject = callBackObj;
1826 replyStruct->replySlot = callBackSlot;
1827 replyStruct->replyId = ++d->transactionId;
1828 if (d->transactionId < 0)
1829 d->transactionId = 0;
1831 bool b = callInternal(remApp, remObjId, remFun, data,
1832 replyStruct,
false, -1, DCOPCall);
1835 delete replyStruct->replyType;
1836 delete replyStruct->replyData;
1841 if (replyStruct->transactionId == 0)
1844 TQTimer::singleShot(0,
this, TQT_SLOT(asyncReplyReady()));
1845 d->asyncReplyQueue.append(replyStruct);
1848 return replyStruct->replyId;
1851 bool DCOPClient::callInternal(
const TQCString &remApp,
const TQCString &remObjId,
1852 const TQCString &remFun,
const TQByteArray &data,
1853 TQCString& replyType, TQByteArray &replyData,
1854 bool useEventLoop,
int timeout,
int minor_opcode)
1856 ReplyStruct replyStruct;
1857 replyStruct.replyType = &replyType;
1858 replyStruct.replyData = &replyData;
1859 return callInternal(remApp, remObjId, remFun, data, &replyStruct, useEventLoop, timeout, minor_opcode);
1862 bool DCOPClient::callInternal(
const TQCString &remApp,
const TQCString &remObjId,
1863 const TQCString &remFun,
const TQByteArray &data,
1864 ReplyStruct *replyStruct,
1865 bool useEventLoop,
int timeout,
int minor_opcode)
1872 CARD32 oldCurrentKey = d->currentKey;
1873 if ( !d->currentKey )
1874 d->currentKey = d->key;
1877 TQDataStream ds(ba, IO_WriteOnly);
1880 IceGetHeader(d->iceConn, d->majorOpcode, minor_opcode,
1881 sizeof(DCOPMsg), DCOPMsg, pMsg);
1883 pMsg->key = d->currentKey;
1884 int datalen = ba.size() + data.size();
1885 pMsg->length += datalen;
1889 IceSendData(d->iceConn, ba.size(),
const_cast<char *
>(ba.data()));
1890 IceSendData(d->iceConn, data.size(),
const_cast<char *
>(data.data()));
1892 if (IceConnectionStatus(d->iceConn) != IceConnectAccepted)
1895 IceFlush (d->iceConn);
1897 IceReplyWaitInfo waitInfo;
1898 waitInfo.sequence_of_request = IceLastSentSequenceNumber(d->iceConn);
1899 waitInfo.major_opcode_of_request = d->majorOpcode;
1900 waitInfo.minor_opcode_of_request = minor_opcode;
1902 replyStruct->transactionId = -1;
1903 waitInfo.reply =
static_cast<IcePointer
>(replyStruct);
1905 Bool readyRet = False;
1906 IceProcessMessagesStatus s;
1912 gettimeofday( &time_start, NULL );
1913 time_left = timeout;
1916 bool checkMessages =
true;
1918 ? d->notifier != NULL
1920 const int guiTimeout = 100;
1921 checkMessages =
false;
1923 int msecs = useEventLoop
1929 FD_SET(
socket(), &fds );
1930 tv.tv_sec = msecs / 1000;
1931 tv.tv_usec = (msecs % 1000) * 1000;
1932 if ( select(
socket() + 1, &fds, 0, 0, &tv ) <= 0 ) {
1933 if( useEventLoop && (timeout < 0 || time_left > guiTimeout)) {
1936 bool old_lock = d->non_blocking_call_lock;
1938 d->non_blocking_call_lock =
true;
1942 d->eventLoopTimer.start(time_left - guiTimeout,
true);
1943 tqApp->enter_loop();
1944 d->eventLoopTimer.stop();
1946 d->non_blocking_call_lock =
false;
1953 checkMessages =
true;
1959 if( replyStruct->transactionId != -1 )
1961 if (replyStruct->transactionId == 0)
1963 if (!replyStruct->replySlot.isEmpty())
1967 if( checkMessages ) {
1968 s = IceProcessMessages(d->iceConn, &waitInfo,
1970 if (s == IceProcessMessagesIOError) {
1972 d->currentKey = oldCurrentKey;
1977 if( replyStruct->transactionId != -1 )
1979 if (replyStruct->transactionId == 0)
1981 if (!replyStruct->replySlot.isEmpty())
1988 gettimeofday( &time_now, NULL );
1989 time_left = timeout -
1990 ((time_now.tv_sec - time_start.tv_sec) * 1000) -
1991 ((time_now.tv_usec - time_start.tv_usec) / 1000);
1998 useEventLoop =
false;
2001 *(replyStruct->replyType) = TQCString();
2002 *(replyStruct->replyData) = TQByteArray();
2003 replyStruct->status = ReplyStruct::Failed;
2009 if ( d->non_blocking_call_lock ) {
2013 d->currentKey = oldCurrentKey;
2014 return replyStruct->status != ReplyStruct::Failed;
2017 void DCOPClient::eventLoopTimeout()
2028 timeout.tv_usec = 0;
2031 int result = select(fd+1, &fds, 0, 0, &timeout);
2035 if ( d->non_blocking_call_lock ) {
2043 d->notifier->deleteLater();
2045 tqWarning(
"received an error processing data from the DCOP server!");
2049 IceProcessMessagesStatus s = IceProcessMessages(d->iceConn, 0, 0);
2051 if (s == IceProcessMessagesIOError) {
2053 tqWarning(
"received an error processing data from the DCOP server!");
2060 d->defaultObject = objId;
2066 return d->defaultObject;
2070 DCOPClient::isLocalTransactionFinished(TQ_INT32
id, TQCString &replyType, TQByteArray &replyData)
2072 DCOPClientPrivate::LocalTransactionResult *result = d->localTransActionList.take(
id);
2076 replyType = result->replyType;
2077 replyData = result->replyData;
2083 DCOPClientTransaction *
2086 if (d->opcode == DCOPSend)
2088 if (!d->transactionList)
2089 d->transactionList =
new TQPtrList<DCOPClientTransaction>;
2091 d->transaction =
true;
2092 DCOPClientTransaction *trans =
new DCOPClientTransaction();
2093 trans->senderId = d->senderId;
2094 trans->id = ++d->transactionId;
2095 if (d->transactionId < 0)
2096 d->transactionId = 0;
2097 trans->key = d->currentKey;
2099 d->transactionList->append( trans );
2108 return d->transactionId;
2115 TQByteArray &replyData)
2123 if ( !d->transactionList) {
2124 tqWarning(
"Transaction unknown: No pending transactions!");
2128 if ( !d->transactionList->removeRef( trans ) ) {
2129 tqWarning(
"Transaction unknown: Not on list of pending transactions!");
2133 if (trans->senderId.isEmpty())
2136 DCOPClientPrivate::LocalTransactionResult *result =
new DCOPClientPrivate::LocalTransactionResult();
2137 result->replyType = replyType;
2138 result->replyData = replyData;
2140 d->localTransActionList.insert(trans->id, result);
2150 TQDataStream ds(ba, IO_WriteOnly);
2151 ds << d->appId << trans->senderId << trans->id << replyType << replyData;
2153 IceGetHeader(d->iceConn, d->majorOpcode, DCOPReplyDelayed,
2154 sizeof(DCOPMsg), DCOPMsg, pMsg);
2155 pMsg->key = trans->key;
2156 pMsg->length += ba.size();
2158 IceSendData( d->iceConn, ba.size(),
const_cast<char *
>(ba.data()) );
2178 const TQCString &signal,
2179 const TQCString &receiverObj,
const TQCString &slot,
bool Volatile)
2181 TQCString replyType;
2182 TQByteArray data, replyData;
2183 TQ_INT8 iVolatile = Volatile ? 1 : 0;
2185 TQDataStream args(data, IO_WriteOnly );
2188 if (!
call(
"DCOPServer", 0,
2189 "connectSignal(TQCString,TQCString,TQCString,TQCString,TQCString,bool)",
2190 data, replyType, replyData))
2195 if (replyType !=
"bool")
2198 TQDataStream reply(replyData, IO_ReadOnly );
2201 return (result != 0);
2206 const TQCString &receiverObj,
const TQCString &slot,
bool Volatile)
2213 const TQCString &signal,
2214 const TQCString &receiverObj,
const TQCString &slot)
2216 TQCString replyType;
2217 TQByteArray data, replyData;
2219 TQDataStream args(data, IO_WriteOnly );
2222 if (!
call(
"DCOPServer", 0,
2223 "disconnectSignal(TQCString,TQCString,TQCString,TQCString,TQCString)",
2224 data, replyType, replyData))
2229 if (replyType !=
"bool")
2232 TQDataStream reply(replyData, IO_ReadOnly );
2235 return (result != 0);
2240 const TQCString &receiverObj,
const TQCString &slot)
2246 DCOPClient::setPriorityCall(
bool b)
2250 if (d->currentKey == 2)
2252 d->currentKeySaved = d->currentKey;
2257 if (d->currentKey != 2)
2259 d->currentKey = d->currentKeySaved;
2260 if ( !d->messages.isEmpty() )
2261 d->postMessageTimer.start( 0,
true );
2268 DCOPClient::emergencyClose()
2270 TQPtrList<DCOPClient> list;
2271 client_map_t *map = DCOPClient_CliMap;
2273 TQAsciiDictIterator<DCOPClient> it(*map);
2274 while(it.current()) {
2275 list.removeRef(it.current());
2276 list.append(it.current());
2279 for(
DCOPClient *cl = list.first(); cl; cl = list.next())
2281 if (cl->d->iceConn) {
2282 IceProtocolShutdown(cl->d->iceConn, cl->d->majorOpcode);
2283 IceCloseConnection(cl->d->iceConn);
2284 cl->d->iceConn = 0L;
2290 DCOPClient::postMortemSender()
2292 if (!dcop_main_client)
2294 if (dcop_main_client->d->senderId.isEmpty())
2296 return dcop_main_client->d->senderId.data();
2300 DCOPClient::postMortemObject()
2302 if (!dcop_main_client)
2304 return dcop_main_client->d->objId.data();
2307 DCOPClient::postMortemFunction()
2309 if (!dcop_main_client)
2311 return dcop_main_client->d->function.data();
2314 void DCOPClient::virtual_hook(
int,
void* )
2317 #include <dcopclient.moc>
Inter-process communication and remote procedure calls for KDE applications.
void setDaemonMode(bool daemonMode)
Tells the dcopserver to treat the client as daemon client, not as regular client.
QCStringList remoteFunctions(const TQCString &remApp, const TQCString &remObj, bool *ok=0)
Retrieves the list of functions of the remote object remObj of application remApp.
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.
bool detach()
Detaches from the DCOP server.
void setQtBridgeEnabled(bool b)
Specify whether Qt objects of the application should be accessible via DCOP.
DCOPClientTransaction * beginTransaction()
Delays the reply of the current function call until endTransaction() is called.
bool isApplicationRegistered(const TQCString &remApp)
Checks whether remApp is registered with the DCOP server.
void emitDCOPSignal(const TQCString &object, const TQCString &signal, const TQByteArray &data)
Emits signal as DCOP signal from object object with data as arguments.
QCStringList registeredApplications()
Retrieves the list of all currently registered applications from dcopserver.
bool disconnectDCOPSignal(const TQCString &sender, const TQCString &senderObj, const TQCString &signal, const TQCString &receiverObj, const TQCString &slot)
Disconnects a DCOP signal.
QCStringList remoteInterfaces(const TQCString &remApp, const TQCString &remObj, bool *ok=0)
Retrieves the list of interfaces of the remote object remObj of application remApp.
TQ_INT32 transactionId() const
Test whether the current function call is delayed.
bool attach()
Attaches to the DCOP server.
bool send(const TQCString &remApp, const TQCString &remObj, const TQCString &remFun, const TQByteArray &data)
Sends a data block to the server.
bool isRegistered() const
Returns whether or not the client is registered at the server.
void resume()
Resumes the processing of DCOP events.
bool isAttachedToForeignServer() const
Returns whether the client is attached to a server owned by another user.
TQCString senderId() const
Returns the appId of the last application that talked to us.
static DCOPClient * findLocalClient(const TQCString &_appId)
Look for the given client only in this process.
bool qtBridgeEnabled()
Returns whether the DCOP - Qt bridge is enabled.
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.
bool isAttached() const
Returns whether or not the client is attached to the server.
bool acceptCalls() const
Returns whether the client handles incoming calls.
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.
int socket() const
Returns the socket fd that is used for communication with the server.
void setNotifications(bool enabled)
Enables / disables the applicationRegistered() / applicationRemoved() signals.
static void setMainClient(DCOPClient *mainClient)
Sets the application's main dcop client.
void blockUserInput(bool block)
Indicates that user input shall be blocked or released, depending on the argument.
static void setServerAddress(const TQCString &addr)
Sets the address of a server to use upon attaching.
void applicationRegistered(const TQCString &appId)
Indicates that the application appId has been registered with the server we are attached to.
static DCOPClient * mainClient()
Returns the application's main dcop client.
void applicationRemoved(const TQCString &appId)
Indicates that the formerly registered application appId has been removed.
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.
static TQCString dcopServerFileOld(const TQCString &hostname=0) KDE_DEPRECATED
TQCString defaultObject() const
Returns the current default object or an empty string if no object is installed as default object.
DCOPClient()
Constructs a new DCOP client, but does not attach to any server.
void attachFailed(const TQString &msg)
Indicates that the process of establishing DCOP communications failed in some manner.
QCStringList remoteObjects(const TQCString &remApp, bool *ok=0)
Retrieves the list of objects of the remote application remApp.
virtual bool process(const TQCString &fun, const TQByteArray &data, TQCString &replyType, TQByteArray &replyData)
Reimplement this function to handle app-wide function calls unassociated w/an object.
bool connectDCOPSignal(const TQCString &sender, const TQCString &senderObj, const TQCString &signal, const TQCString &receiverObj, const TQCString &slot, bool Volatile)
Connects to a DCOP signal.
void suspend()
Temporarily suspends processing of DCOP events.
virtual ~DCOPClient()
Cleans up any open connections and dynamic data.
TQCString registerAs(const TQCString &appId, bool addPID=true)
Registers at the DCOP server.
void processSocketData(int socknum)
Process data from the socket.
bool isSuspended() const
Returns whether DCOP events are being processed.
static TQCString dcopServerFile(const TQCString &hostname=0)
File with information how to reach the dcopserver.
static TQCString normalizeFunctionSignature(const TQCString &fun)
Normalizes the function signature fun.
void setAcceptCalls(bool b)
Specify whether the client should accept incoming calls.
void setDefaultObject(const TQCString &objId)
Installs object objId as application-wide default object.
static TQCString iceauthPath()
Return the path of iceauth or an empty string if not found.
Provides an interface for receiving DCOP messages.
static TQPtrList< DCOPObject > match(const TQCString &partialId)
Tries to find an object using a partial object id.
static bool hasObject(const TQCString &objId)
Checks whether an object with the given id is known in this process.
TQCString objId() const
Returns the object id of the DCOPObject.
static DCOPObject * find(const TQCString &objId)
Try to find a dcop object with the given id.
virtual bool process(const TQCString &fun, const TQByteArray &data, TQCString &replyType, TQByteArray &replyData)
Dispatches a message.
A DCOPRef(erence) encapsulates a remote DCOP object as a triple <app,obj,type> where type is optional...
TQCString app() const
Name of the application in which the object resides.
Represents the return value of a DCOPRef:call() or DCOPRef:send() invocation.
TQString name(StdAccel id)