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>
55 #ifndef QT_CLEAN_NAMESPACE
56 #define QT_CLEAN_NAMESPACE
58 #include <tqguardedptr.h>
59 #include <tqtextstream.h>
62 #include <tqapplication.h>
63 #include <tqsocketnotifier.h>
66 #include <tqucomextra_p.h>
68 #include <dcopglobal.h>
69 #include <dcopclient.h>
70 #include <dcopobject.h>
72 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
76 #include <KDE-ICE/ICElib.h>
77 #include <KDE-ICE/ICEutil.h>
78 #include <KDE-ICE/ICEmsg.h>
79 #include <KDE-ICE/ICEproto.h>
84 extern TQMap<TQCString, DCOPObject *> * kde_dcopObjMap;
89 typedef TQAsciiDict<DCOPClient> client_map_t;
90 static client_map_t *DCOPClient_CliMap = 0;
93 client_map_t *cliMap()
95 if (!DCOPClient_CliMap)
96 DCOPClient_CliMap =
new client_map_t;
97 return DCOPClient_CliMap;
102 return cliMap()->find(_appId.data());
106 void registerLocalClient(
const TQCString &_appId,
DCOPClient *client )
108 cliMap()->replace(_appId.data(), client);
112 void unregisterLocalClient(
const TQCString &_appId )
114 client_map_t *map = cliMap();
115 map->remove(_appId.data());
119 template class TQPtrList<DCOPObjectProxy>;
120 template class TQPtrList<DCOPClientTransaction>;
121 template class TQPtrList<_IceConn>;
123 struct DCOPClientMessage
130 class DCOPClient::ReplyStruct
133 enum ReplyStatus { Pending, Ok, Failed };
143 TQCString* replyType;
144 TQByteArray* replyData;
146 TQ_INT32 transactionId;
148 TQGuardedPtr<TQObject> replyObject;
152 class DCOPClientPrivate
160 int majorVersion, minorVersion;
162 static const char* serverAddr;
163 TQSocketNotifier *notifier;
164 bool non_blocking_call_lock;
168 bool accept_calls_override;
169 bool qt_bridge_enabled;
175 TQCString defaultObject;
176 TQPtrList<DCOPClientTransaction> *transactionList;
178 TQ_INT32 transactionId;
188 CARD32 currentKeySaved;
190 TQTimer postMessageTimer;
191 TQPtrList<DCOPClientMessage> messages;
193 TQPtrList<DCOPClient::ReplyStruct> pendingReplies;
194 TQPtrList<DCOPClient::ReplyStruct> asyncReplyQueue;
196 struct LocalTransactionResult
199 TQByteArray replyData;
202 TQIntDict<LocalTransactionResult> localTransActionList;
204 TQTimer eventLoopTimer;
207 class DCOPClientTransaction
217 #if defined(ICEAUTH_PATH)
219 #
if defined(Q_WS_WIN)
220 access(ICEAUTH_PATH, 0) == 0
222 access(ICEAUTH_PATH, X_OK) == 0
226 return TQCString(ICEAUTH_PATH);
229 #elif defined(Q_OS_WIN32)
233 ret = SearchPathA(NULL,
"iceauth.exe",NULL,
sizeof(szPath)/
sizeof(szPath[0]),szPath,&pszFilePart);
235 return TQCString(szPath);
238 TQCString path = ::getenv(
"PATH");
240 path =
"/bin:/usr/bin";
241 path +=
":/usr/bin/X11:/usr/X11/bin:/usr/X11R6/bin";
242 TQCString fPath = strtok(path.data(),
":\b");
243 while (!fPath.isNull())
246 if (access(fPath.data(), X_OK) == 0)
250 fPath = strtok(NULL,
":\b");
257 static TQCString dcopServerFile(
const TQCString &hostname,
bool old)
259 TQCString fName = ::getenv(
"DCOPAUTHORITY");
260 if (!old && !fName.isEmpty())
263 fName = TQFile::encodeName( TQDir::homeDirPath() );
267 fprintf(stderr,
"Aborting. $HOME is not set.\n");
271 TQCString disp = getenv(
"DISPLAY");
272 #elif defined(Q_WS_QWS)
273 TQCString disp = getenv(
"QWS_DISPLAY");
281 if((i = disp.findRev(
'.')) > disp.findRev(KPATH_SEPARATOR) && i >= 0)
286 while( (i = disp.find(KPATH_SEPARATOR)) >= 0)
290 fName +=
"/.DCOPserver_";
291 if (hostname.isEmpty())
295 if (getenv(
"XAUTHLOCALHOSTNAME"))
296 fName += getenv(
"XAUTHLOCALHOSTNAME");
297 else if (gethostname(hostName,
sizeof(hostName)))
299 fName +=
"localhost";
303 hostName[
sizeof(hostName)-1] =
'\0';
319 return ::dcopServerFile(hostname,
false);
326 return ::dcopServerFile(hostname,
true);
330 const char* DCOPClientPrivate::serverAddr = 0;
332 static void DCOPProcessInternal( DCOPClientPrivate *d,
int opcode, CARD32 key,
const TQByteArray& dataReceived,
bool canPost );
334 void DCOPClient::handleAsyncReply(ReplyStruct *replyStruct)
336 if (replyStruct->replyObject)
338 TQObject::connect(
this, TQT_SIGNAL(callBack(
int,
const TQCString&,
const TQByteArray &)),
339 replyStruct->replyObject, replyStruct->replySlot);
340 emit callBack(replyStruct->replyId, *(replyStruct->replyType), *(replyStruct->replyData));
341 TQObject::disconnect(
this, TQT_SIGNAL(callBack(
int,
const TQCString&,
const TQByteArray &)),
342 replyStruct->replyObject, replyStruct->replySlot);
350 static void DCOPProcessMessage(IceConn iceConn, IcePointer clientObject,
351 int opcode,
unsigned long length, Bool ,
352 IceReplyWaitInfo *replyWait,
356 DCOPClientPrivate *d =
static_cast<DCOPClientPrivate *
>(clientObject);
357 DCOPClient::ReplyStruct *replyStruct = replyWait ?
static_cast<DCOPClient::ReplyStruct*
>(replyWait->reply) : 0;
359 IceReadMessageHeader(iceConn,
sizeof(DCOPMsg), DCOPMsg, pMsg);
360 CARD32
key = pMsg->key;
364 TQByteArray dataReceived( length );
365 IceReadData(iceConn, length, dataReceived.data() );
370 case DCOPReplyFailed:
372 replyStruct->status = DCOPClient::ReplyStruct::Failed;
373 replyStruct->transactionId = 0;
374 *replyWaitRet = True;
377 tqWarning(
"Very strange! got a DCOPReplyFailed opcode, but we were not waiting for a reply!");
382 TQByteArray* b = replyStruct->replyData;
383 TQCString* t = replyStruct->replyType;
384 replyStruct->status = DCOPClient::ReplyStruct::Ok;
385 replyStruct->transactionId = 0;
387 TQCString calledApp, app;
388 TQDataStream ds( dataReceived, IO_ReadOnly );
389 ds >> calledApp >> app >> *t >> *b;
391 *replyWaitRet = True;
394 tqWarning(
"Very strange! got a DCOPReply opcode, but we were not waiting for a reply!");
399 TQCString calledApp, app;
401 TQDataStream ds( dataReceived, IO_ReadOnly );
402 ds >> calledApp >> app >> id;
403 replyStruct->transactionId = id;
404 replyStruct->calledApp = calledApp;
405 d->pendingReplies.append(replyStruct);
406 *replyWaitRet = True;
409 tqWarning(
"Very strange! got a DCOPReplyWait opcode, but we were not waiting for a reply!");
412 case DCOPReplyDelayed:
414 TQDataStream ds( dataReceived, IO_ReadOnly );
415 TQCString calledApp, app;
418 ds >> calledApp >> app >> id;
419 if (replyStruct && (
id == replyStruct->transactionId) && (calledApp == replyStruct->calledApp))
421 *replyWaitRet = True;
424 for(DCOPClient::ReplyStruct *rs = d->pendingReplies.first(); rs;
425 rs = d->pendingReplies.next())
427 if ((rs->transactionId ==
id) && (rs->calledApp == calledApp))
429 d->pendingReplies.remove();
430 TQByteArray* b = rs->replyData;
431 TQCString* t = rs->replyType;
434 rs->status = DCOPClient::ReplyStruct::Ok;
435 rs->transactionId = 0;
436 if (!rs->replySlot.isEmpty())
438 d->parent->handleAsyncReply(rs);
443 tqWarning(
"Very strange! got a DCOPReplyDelayed opcode, but we were not waiting for a reply!");
449 DCOPProcessInternal( d, opcode, key, dataReceived,
true );
453 void DCOPClient::processPostedMessagesInternal()
455 if ( d->messages.isEmpty() )
457 TQPtrListIterator<DCOPClientMessage> it (d->messages );
458 DCOPClientMessage* msg ;
459 while ( ( msg = it.current() ) ) {
461 if ( d->currentKey && msg->key != d->currentKey )
463 d->messages.removeRef( msg );
464 d->opcode = msg->opcode;
465 DCOPProcessInternal( d, msg->opcode, msg->key, msg->data,
false );
468 if ( !d->messages.isEmpty() )
469 d->postMessageTimer.start( 100,
true );
475 void DCOPProcessInternal( DCOPClientPrivate *d,
int opcode, CARD32 key,
const TQByteArray& dataReceived,
bool canPost )
477 if (!d->accept_calls && (opcode == DCOPSend))
480 IceConn iceConn = d->iceConn;
483 TQDataStream ds( dataReceived, IO_ReadOnly );
487 if (fromApp.isEmpty())
490 if (!d->accept_calls)
493 TQDataStream replyStream( reply, IO_WriteOnly );
495 replyStream << d->appId << fromApp;
496 IceGetHeader( iceConn, d->majorOpcode, DCOPReplyFailed,
497 sizeof(DCOPMsg), DCOPMsg, pMsg );
498 int datalen = reply.size();
500 pMsg->length += datalen;
501 IceSendData( iceConn, datalen, reply.data());
505 TQCString app, objId, fun;
507 ds >> app >> objId >> fun >> data;
508 d->senderId = fromApp;
514 if ( canPost && d->currentKey && key != d->currentKey ) {
515 DCOPClientMessage* msg =
new DCOPClientMessage;
516 msg->opcode = opcode;
518 msg->data = dataReceived;
519 d->messages.append( msg );
520 d->postMessageTimer.start( 0,
true );
528 TQByteArray replyData;
530 CARD32 oldCurrentKey = d->currentKey;
531 if ( opcode != DCOPSend )
534 if ( opcode == DCOPFind )
535 b = c->find(app, objId, fun, data, replyType, replyData );
537 b = c->receive( app, objId, fun, data, replyType, replyData );
540 if ( opcode == DCOPSend )
543 if ((d->currentKey == key) || (oldCurrentKey != 2))
544 d->currentKey = oldCurrentKey;
547 TQDataStream replyStream( reply, IO_WriteOnly );
552 replyStream << d->appId << fromApp << id;
554 IceGetHeader( iceConn, d->majorOpcode, DCOPReplyWait,
555 sizeof(DCOPMsg), DCOPMsg, pMsg );
557 pMsg->length += reply.size();
558 IceSendData( iceConn, reply.size(),
const_cast<char *
>(reply.data()));
565 replyStream << d->appId << fromApp;
566 IceGetHeader( iceConn, d->majorOpcode, DCOPReplyFailed,
567 sizeof(DCOPMsg), DCOPMsg, pMsg );
568 int datalen = reply.size();
570 pMsg->length += datalen;
571 IceSendData( iceConn, datalen, const_cast<char *>(reply.data()));
576 replyStream << d->appId << fromApp << replyType << replyData.size();
580 IceGetHeader( iceConn, d->majorOpcode,
DCOPReply,
581 sizeof(DCOPMsg), DCOPMsg, pMsg );
582 int datalen = reply.size() + replyData.size();
584 pMsg->length += datalen;
587 IceSendData( iceConn, reply.size(),
const_cast<char *
>(reply.data()));
588 IceSendData( iceConn, replyData.size(),
const_cast<char *
>(replyData.data()));
593 static IcePoVersionRec DCOPClientVersions[] = {
594 { DCOPVersionMajor, DCOPVersionMinor, DCOPProcessMessage }
602 return dcop_main_client;
607 dcop_main_client = client;
613 d =
new DCOPClientPrivate;
621 d->non_blocking_call_lock =
false;
622 d->registered =
false;
623 d->foreign_server =
true;
624 d->accept_calls =
true;
625 d->accept_calls_override =
false;
626 d->qt_bridge_enabled =
true;
627 d->transactionList = 0L;
628 d->transactionId = 0;
629 TQObject::connect( &d->postMessageTimer, TQT_SIGNAL( timeout() ),
this, TQT_SLOT( processPostedMessagesInternal() ) );
630 TQObject::connect( &d->eventLoopTimer, TQT_SIGNAL( timeout() ),
this, TQT_SLOT( eventLoopTimeout() ) );
638 #ifdef DCOPCLIENT_DEBUG
639 tqWarning(
"d->messages.count() = %d", d->messages.count());
640 TQPtrListIterator<DCOPClientMessage> it (d->messages );
641 DCOPClientMessage* msg ;
642 while ( ( msg = it.current() ) ) {
644 d->messages.removeRef( msg );
645 tqWarning(
"DROPPING UNHANDLED DCOP MESSAGE:");
646 tqWarning(
" opcode = %d key = %d", msg->opcode, msg->key);
647 TQDataStream ds( msg->data, IO_ReadOnly );
649 TQCString fromApp, app, objId, fun;
650 ds >> fromApp >> app >> objId >> fun;
651 tqWarning(
" from = %s", fromApp.data());
652 tqWarning(
" to = %s / %s / %s", app.data(), objId.data(), fun.data());
657 if (IceConnectionStatus(d->iceConn) == IceConnectAccepted)
661 unregisterLocalClient( d->appId );
664 delete d->transactionList;
665 d->messages.setAutoDelete(
true);
674 TQCString env =
"DCOPSERVER=" + addr;
675 putenv(strdup(env.data()));
676 delete [] DCOPClientPrivate::serverAddr;
677 DCOPClientPrivate::serverAddr = tqstrdup( addr.data() );
682 if (!attachInternal(
true ))
683 if (!attachInternal(
true ))
688 void DCOPClient::bindToApp()
695 d->notifier =
new TQSocketNotifier(
socket(),
696 TQSocketNotifier::Read, 0, 0);
697 TQObject::connect(d->notifier, TQT_SIGNAL(activated(
int)),
704 #ifdef Q_WS_WIN //TODO: remove (win32 ports sometimes do not create notifiers)
709 d->notifier->setEnabled(
false);
714 #ifdef Q_WS_WIN //TODO: remove
719 d->notifier->setEnabled(
true);
724 #if defined(Q_WS_WIN) || defined(Q_WS_MAC) //TODO: REMOVE
728 return !d->notifier->isEnabled();
731 #if defined(SO_PEERCRED) || defined(LOCAL_PEEREID)
732 #define USE_PEER_IS_US
734 static bool peerIsUs(
int sockfd)
737 #if defined(__OpenBSD__)
738 struct sockpeercred cred;
742 socklen_t siz =
sizeof(cred);
743 if (getsockopt(sockfd, SOL_SOCKET, SO_PEERCRED, &cred, &siz) != 0)
745 return (cred.uid == getuid());
746 #elif defined LOCAL_PEEREID
748 socklen_t siz =
sizeof(cred);
749 if (getsockopt(sockfd, 0, LOCAL_PEEREID, &cred, &siz) != 0 || siz !=
sizeof(cred))
751 return (cred.unp_euid == geteuid());
756 static bool isServerSocketOwnedByUser(
const char*server)
759 if (strncmp(server,
"tcp/", 4) != 0)
764 if (strncmp(server,
"local/", 6) != 0)
766 const char *path = strchr(server, KPATH_SEPARATOR);
771 struct stat stat_buf;
772 if (stat(path, &stat_buf) != 0)
775 return (stat_buf.st_uid == getuid());
781 bool DCOPClient::attachInternal(
bool registerAsAnonymous )
788 if ((d->majorOpcode = IceRegisterForProtocolSetup(const_cast<char *>(
"DCOP"),
789 const_cast<char *>(DCOPVendorString),
790 const_cast<char *>(DCOPReleaseString),
791 1, DCOPClientVersions,
793 const_cast<char **>(DCOPAuthNames),
794 DCOPClientAuthProcs, 0L)) < 0) {
795 emit
attachFailed(TQString::fromLatin1(
"Communications could not be established." ));
799 bool bClearServerAddr =
false;
801 if (!d->serverAddr) {
805 dcopSrv = ::getenv(
"DCOPSERVER");
806 if (dcopSrv.isEmpty()) {
808 TQFile f(TQFile::decodeName(fName));
809 if (!f.open(IO_ReadOnly)) {
810 emit
attachFailed(TQString::fromLatin1(
"Could not read network connection list.\n" )+TQFile::decodeName(fName));
813 int size = TQMIN( (qint64)1024, f.size() );
814 TQCString contents( size+1 );
815 if ( f.readBlock( contents.data(), size ) != size )
817 tqDebug(
"Error reading from %s, didn't read the expected %d bytes", fName.data(), size);
820 contents[size] =
'\0';
821 int pos = contents.find(
'\n');
824 tqDebug(
"Only one line in dcopserver file !: %s", contents.data());
829 if(contents[pos - 1] ==
'\r')
831 dcopSrv = contents.left( pos );
837 d->serverAddr = tqstrdup( const_cast<char *>(dcopSrv.data()) );
838 bClearServerAddr =
true;
841 if ((d->iceConn = IceOpenConnection(const_cast<char*>(d->serverAddr),
842 static_cast<IcePointer>(
this), False, d->majorOpcode,
843 sizeof(errBuf), errBuf)) == 0L) {
844 tqDebug(
"DCOPClient::attachInternal. Attach failed %s", errBuf);
846 if (bClearServerAddr) {
847 delete [] d->serverAddr;
853 fcntl(
socket(), F_SETFL, FD_CLOEXEC);
855 IceSetShutdownNegotiation(d->iceConn, False);
860 setupstat = IceProtocolSetup(d->iceConn, d->majorOpcode,
861 static_cast<IcePointer>(d),
863 &(d->majorVersion), &(d->minorVersion),
864 &(vendor), &(release), 1024, errBuf);
865 if (vendor) free(vendor);
866 if (release) free(release);
868 if (setupstat == IceProtocolSetupFailure ||
869 setupstat == IceProtocolSetupIOError) {
870 IceCloseConnection(d->iceConn);
872 if (bClearServerAddr) {
873 delete [] d->serverAddr;
878 }
else if (setupstat == IceProtocolAlreadyActive) {
879 if (bClearServerAddr) {
880 delete [] d->serverAddr;
884 emit
attachFailed(TQString::fromLatin1(
"internal error in IceOpenConnection" ));
889 if (IceConnectionStatus(d->iceConn) != IceConnectAccepted) {
890 if (bClearServerAddr) {
891 delete [] d->serverAddr;
894 emit
attachFailed(TQString::fromLatin1(
"DCOP server did not accept the connection." ));
898 #ifdef USE_PEER_IS_US
899 d->foreign_server = !peerIsUs(
socket());
901 d->foreign_server = !isServerSocketOwnedByUser(d->serverAddr);
903 if (!d->accept_calls_override)
904 d->accept_calls = !d->foreign_server;
908 if ( registerAsAnonymous )
920 IceProtocolShutdown(d->iceConn, d->majorOpcode);
921 status = IceCloseConnection(d->iceConn);
922 if (status != IceClosedNow)
929 unregisterLocalClient(d->appId);
933 d->registered =
false;
934 d->foreign_server =
true;
943 return (IceConnectionStatus(d->iceConn) == IceConnectAccepted);
959 d->accept_calls_override =
true;
964 return d->qt_bridge_enabled;
969 d->qt_bridge_enabled = b;
976 TQCString _appId =
appId;
980 pid.sprintf(
"-%d", getpid());
981 _appId = _appId + pid;
984 if( d->appId == _appId )
987 #if 0 // no need to detach, dcopserver can handle renaming
995 if (!attachInternal(
false ))
996 if (!attachInternal(
false ))
1001 TQCString replyType;
1002 TQByteArray data, replyData;
1003 TQDataStream arg( data, IO_WriteOnly );
1005 if (
call(
"DCOPServer",
"",
"registerAs(TQCString)", data, replyType, replyData ) ) {
1006 TQDataStream reply( replyData, IO_ReadOnly );
1011 d->registered = !result.isNull();
1014 registerLocalClient( d->appId,
this );
1021 return d->registered;
1034 return IceConnectionNumber(d->iceConn);
1038 static inline bool isIdentChar(
char x )
1040 return x ==
'_' || (x >=
'0' && x <=
'9') ||
1041 (x >=
'a' && x <=
'z') || (x >=
'A' && x <=
'Z');
1045 if ( fun.isEmpty() )
1047 TQCString result( fun.size() );
1048 char *from =
const_cast<TQCString&
>(fun).data();
1049 char *to = result.data();
1053 while ( *from && isspace(*from) )
1055 if ( last && isIdentChar( last ) && isIdentChar( *from ) )
1057 while ( *from && !isspace(*from) ) {
1064 if ( to > first && *(to-1) == 0x20 )
1067 result.resize( (
int)((
long)to - (
long)result.data()) + 1 );
1079 const TQCString &remFun,
const TQByteArray &data)
1081 if (remApp.isEmpty())
1085 if ( localClient ) {
1086 bool saveTransaction = d->transaction;
1087 TQ_INT32 saveTransactionId = d->transactionId;
1088 TQCString saveSenderId = d->senderId;
1091 TQCString replyType;
1092 TQByteArray replyData;
1093 (void) localClient->receive( remApp, remObjId, remFun, data, replyType, replyData );
1095 d->transaction = saveTransaction;
1096 d->transactionId = saveTransactionId;
1097 d->senderId = saveSenderId;
1112 TQDataStream ds(ba, IO_WriteOnly);
1115 IceGetHeader(d->iceConn, d->majorOpcode, DCOPSend,
1116 sizeof(DCOPMsg), DCOPMsg, pMsg);
1119 int datalen = ba.size() + data.size();
1120 pMsg->length += datalen;
1122 IceSendData( d->iceConn, ba.size(),
const_cast<char *
>(ba.data()) );
1123 IceSendData( d->iceConn, data.size(),
const_cast<char *
>(data.data()) );
1127 if (IceConnectionStatus(d->iceConn) == IceConnectAccepted)
1133 const TQCString &remFun,
const TQString &data)
1136 TQDataStream ds(ba, IO_WriteOnly);
1138 return send(remApp, remObjId, remFun, ba);
1142 const TQCString &remFun,
const TQByteArray &data,
1143 TQCString &foundApp, TQCString &foundObj,
1146 return findObject( remApp, remObj, remFun, data, foundApp, foundObj, useEventLoop, -1 );
1150 const TQCString &remFun,
const TQByteArray &data,
1151 TQCString &foundApp, TQCString &foundObj,
1152 bool useEventLoop,
int timeout)
1154 QCStringList appList;
1155 TQCString app = remApp;
1162 if (app[app.length()-1] ==
'*')
1167 int len = app.length()-1;
1169 for( QCStringList::ConstIterator it = apps.begin();
1173 if ( strncmp( (*it).data(), app.data(), len) == 0)
1174 appList.append(*it);
1179 appList.append(app);
1183 for(
int phase=1; phase <= 2; phase++)
1185 for( QCStringList::ConstIterator it = appList.begin();
1186 it != appList.end();
1189 TQCString remApp = *it;
1190 TQCString replyType;
1191 TQByteArray replyData;
1192 bool result =
false;
1195 if ( (phase == 1) && localClient ) {
1197 bool saveTransaction = d->transaction;
1198 TQ_INT32 saveTransactionId = d->transactionId;
1199 TQCString saveSenderId = d->senderId;
1202 result = localClient->find( remApp, remObj, remFun, data, replyType, replyData );
1208 TQApplication::eventLoop()->processEvents( TQEventLoop::WaitForMore);
1209 }
while( !localClient->isLocalTransactionFinished(
id, replyType, replyData));
1212 d->transaction = saveTransaction;
1213 d->transactionId = saveTransactionId;
1214 d->senderId = saveSenderId;
1216 else if ((phase == 2) && !localClient)
1219 result = callInternal(remApp, remObj, remFun, data,
1220 replyType, replyData, useEventLoop, timeout, DCOPFind);
1225 if (replyType ==
"DCOPRef")
1228 TQDataStream reply( replyData, IO_ReadOnly );
1231 if (ref.app() == remApp)
1234 foundApp = ref.
app();
1235 foundObj = ref.object();
1246 TQCString&, TQByteArray &)
1253 TQCString replyType;
1254 TQByteArray data, replyData;
1255 TQDataStream arg( data, IO_WriteOnly );
1258 if (
call(
"DCOPServer",
"",
"isApplicationRegistered(TQCString)", data, replyType, replyData ) ) {
1259 TQDataStream reply( replyData, IO_ReadOnly );
1267 TQCString replyType;
1268 TQByteArray data, replyData;
1269 QCStringList result;
1270 if (
call(
"DCOPServer",
"",
"registeredApplications()", data, replyType, replyData ) ) {
1271 TQDataStream reply( replyData, IO_ReadOnly );
1279 TQCString replyType;
1280 TQByteArray data, replyData;
1281 QCStringList result;
1284 if (
call( remApp,
"DCOPClient",
"objects()", data, replyType, replyData ) ) {
1285 TQDataStream reply( replyData, IO_ReadOnly );
1295 TQCString replyType;
1296 TQByteArray data, replyData;
1297 QCStringList result;
1300 if (
call( remApp, remObj,
"interfaces()", data, replyType, replyData ) && replyType ==
"QCStringList") {
1301 TQDataStream reply( replyData, IO_ReadOnly );
1311 TQCString replyType;
1312 TQByteArray data, replyData;
1313 QCStringList result;
1316 if (
call( remApp, remObj,
"functions()", data, replyType, replyData ) && replyType ==
"QCStringList") {
1317 TQDataStream reply( replyData, IO_ReadOnly );
1328 TQDataStream ds(data, IO_WriteOnly);
1329 ds << static_cast<TQ_INT8>(enabled);
1331 TQCString replyType;
1333 if (!
call(
"DCOPServer",
"",
"setNotifications( bool )", data, replyType, reply))
1334 tqWarning(
"I couldn't enable notifications at the dcopserver!");
1340 TQDataStream ds(data, IO_WriteOnly);
1341 ds << static_cast<TQ_INT8>( daemonMode );
1343 TQCString replyType;
1345 if (!
call(
"DCOPServer",
"",
"setDaemonMode(bool)", data, replyType, reply))
1346 tqWarning(
"I couldn't enable daemon mode at the dcopserver!");
1356 static void fillQtObjects( QCStringList& l, TQObject* o, TQCString path )
1358 if ( !path.isEmpty() )
1362 const TQObjectList list = o ? o->childrenListObject() : TQObject::objectTreesListObject();
1363 if ( !list.isEmpty() ) {
1364 TQObjectListIt it( list );
1366 while ( (obj=it.current()) ) {
1368 TQCString n = obj->name();
1369 if ( n ==
"unnamed" || n.isEmpty() )
1371 n.sprintf(
"%p", (
void *) obj);
1372 n = TQString(TQString(
"unnamed%1(%2, %3)").arg(++unnamed).arg(obj->className()).arg(TQString(n))).latin1();
1374 TQCString fn = path + n;
1376 if ( !obj->childrenListObject().isEmpty() )
1377 fillQtObjects( l, obj, fn );
1387 O (
const TQCString& str, TQObject* obj ):s(str), o(obj){}
1393 static void fillQtObjectsEx( TQValueList<O>& l, TQObject* o, TQCString path )
1395 if ( !path.isEmpty() )
1399 const TQObjectList list = o ? o->childrenListObject() : TQObject::objectTreesListObject();
1400 if ( !list.isEmpty() ) {
1401 TQObjectListIt it( list );
1403 while ( (obj=it.current()) ) {
1405 TQCString n = obj->name();
1406 if ( n ==
"unnamed" || n.isEmpty() )
1408 n.sprintf(
"%p", (
void *) obj);
1409 n = TQString(TQString(
"unnamed%1(%2, %3)").arg(++unnamed).arg(obj->className()).arg(TQString(n))).latin1();
1411 TQCString fn = path + n;
1412 l.append( O( fn, obj ) );
1413 if ( !obj->childrenListObject().isEmpty() )
1414 fillQtObjectsEx( l, obj, fn );
1420 static TQObject* findQtObject( TQCString
id )
1422 TQRegExp expr(
id );
1424 fillQtObjectsEx( l, 0,
"qt" );
1426 TQObject* firstContains = 0L;
1427 for ( TQValueList<O>::ConstIterator it = l.begin(); it != l.end(); ++it ) {
1428 if ( (*it).s ==
id )
1430 if ( !firstContains && (*it).s.contains( expr ) ) {
1431 firstContains = (*it).o;
1434 return firstContains;
1437 static QCStringList findQtObjects( TQCString
id )
1439 TQRegExp expr(
id );
1441 fillQtObjectsEx( l, 0,
"qt" );
1442 QCStringList result;
1443 for ( TQValueList<O>::ConstIterator it = l.begin(); it != l.end(); ++it ) {
1444 if ( (*it).s.contains( expr ) )
1450 static bool receiveQtObject(
const TQCString &objId,
const TQCString &fun,
const TQByteArray &data,
1451 TQCString& replyType, TQByteArray &replyData)
1453 if ( objId ==
"qt" ) {
1454 if ( fun ==
"interfaces()" ) {
1455 replyType =
"QCStringList";
1456 TQDataStream reply( replyData, IO_WriteOnly );
1462 }
else if ( fun ==
"functions()" ) {
1463 replyType =
"QCStringList";
1464 TQDataStream reply( replyData, IO_WriteOnly );
1466 l <<
"QCStringList functions()";
1467 l <<
"QCStringList interfaces()";
1468 l <<
"QCStringList objects()";
1469 l <<
"QCStringList find(TQCString)";
1472 }
else if ( fun ==
"objects()" ) {
1473 replyType =
"QCStringList";
1474 TQDataStream reply( replyData, IO_WriteOnly );
1476 fillQtObjects( l, 0,
"qt" );
1479 }
else if ( fun ==
"find(TQCString)" ) {
1480 TQDataStream ds( data, IO_ReadOnly );
1483 replyType =
"QCStringList";
1484 TQDataStream reply( replyData, IO_WriteOnly );
1485 reply << findQtObjects(
id ) ;
1488 }
else if ( objId.left(3) ==
"qt/" ) {
1489 TQObject* o = findQtObject( objId );
1492 if ( fun ==
"functions()" ) {
1493 replyType =
"QCStringList";
1494 TQDataStream reply( replyData, IO_WriteOnly );
1496 l <<
"QCStringList functions()";
1497 l <<
"QCStringList interfaces()";
1498 l <<
"QCStringList properties()";
1499 l <<
"bool setProperty(TQCString,TQVariant)";
1500 l <<
"TQVariant property(TQCString)";
1501 TQStrList lst = o->metaObject()->slotNames(
true );
1503 for ( TQPtrListIterator<char> it( lst ); it.current(); ++it ) {
1504 if ( o->metaObject()->slot( i++,
true )->tqt_mo_access != TQMetaData::Public )
1506 TQCString slot = it.current();
1507 if ( slot.contains(
"()" ) ) {
1508 slot.prepend(
"void ");
1514 }
else if ( fun ==
"interfaces()" ) {
1515 replyType =
"QCStringList";
1516 TQDataStream reply( replyData, IO_WriteOnly );
1518 TQMetaObject *meta = o->metaObject();
1520 l.prepend( meta->className() );
1521 meta = meta->superClass();
1525 }
else if ( fun ==
"properties()" ) {
1526 replyType =
"QCStringList";
1527 TQDataStream reply( replyData, IO_WriteOnly );
1529 TQStrList lst = o->metaObject()->propertyNames(
true );
1530 for ( TQPtrListIterator<char> it( lst ); it.current(); ++it ) {
1531 TQMetaObject *mo = o->metaObject();
1532 const TQMetaProperty* p = mo->property( mo->findProperty( it.current(), true ),
true );
1535 TQCString prop = p->type();
1538 if ( !p->writable() )
1539 prop +=
" readonly";
1544 }
else if ( fun ==
"property(TQCString)" ) {
1545 replyType =
"TQVariant";
1546 TQDataStream ds( data, IO_ReadOnly );
1549 TQVariant result = o->property( name );
1550 TQDataStream reply( replyData, IO_WriteOnly );
1553 }
else if ( fun ==
"setProperty(TQCString,TQVariant)" ) {
1554 TQDataStream ds( data, IO_ReadOnly );
1557 ds >> name >> value;
1559 TQDataStream reply( replyData, IO_WriteOnly );
1560 reply << (TQ_INT8) o->setProperty( name, value );
1563 int slot = o->metaObject()->findSlot( fun,
true );
1567 o->tqt_invoke( slot, uo );
1584 bool DCOPClient::receive(
const TQCString &,
const TQCString &objId,
1585 const TQCString &fun,
const TQByteArray &data,
1586 TQCString& replyType, TQByteArray &replyData)
1588 d->transaction =
false;
1589 if ( objId ==
"DCOPClient" ) {
1590 if ( fun ==
"objects()" ) {
1591 replyType =
"QCStringList";
1592 TQDataStream reply( replyData, IO_WriteOnly );
1594 if (d->qt_bridge_enabled)
1598 if ( kde_dcopObjMap ) {
1599 TQMap<TQCString, DCOPObject *>::ConstIterator it( kde_dcopObjMap->begin());
1600 for (; it != kde_dcopObjMap->end(); ++it) {
1601 if ( !it.key().isEmpty() ) {
1602 if ( it.key() == d->defaultObject )
1613 if ( objId.isEmpty() || objId ==
"DCOPClient" ) {
1614 if ( fun ==
"applicationRegistered(TQCString)" ) {
1615 TQDataStream ds( data, IO_ReadOnly );
1620 }
else if ( fun ==
"applicationRemoved(TQCString)" ) {
1621 TQDataStream ds( data, IO_ReadOnly );
1628 if (
process( fun, data, replyType, replyData ) )
1632 }
else if (d->qt_bridge_enabled &&
1633 (objId ==
"qt" || objId.left(3) ==
"qt/") ) {
1634 return receiveQtObject( objId, fun, data, replyType, replyData );
1637 if ( objId.isEmpty() || objId ==
"default" ) {
1640 objPtr->setCallingDcopClient(
this);
1641 if (objPtr->
process(fun, data, replyType, replyData))
1649 if (!objId.isEmpty() && ((objId.length()>0)?(objId[objId.length()-1] ==
'*'):0)) {
1652 TQPtrList<DCOPObject> matchList =
1655 objPtr != 0L; objPtr = matchList.next()) {
1656 objPtr->setCallingDcopClient(
this);
1657 if (!objPtr->
process(fun, data, replyType, replyData))
1662 if ( DCOPObjectProxy::proxies ) {
1663 for ( TQPtrListIterator<DCOPObjectProxy> it( *DCOPObjectProxy::proxies ); it.current(); ++it ) {
1665 if ( it.current()->process( objId, fun, data, replyType, replyData ) )
1673 objPtr->setCallingDcopClient(
this);
1674 if (!objPtr->
process(fun, data, replyType, replyData)) {
1686 static bool findResultOk(TQCString &replyType, TQByteArray &replyData)
1689 if (replyType !=
"bool")
return false;
1691 TQDataStream reply( replyData, IO_ReadOnly );
1694 if (!success)
return false;
1700 static bool findSuccess(
const TQCString &app,
const TQCString objId, TQCString &replyType, TQByteArray &replyData)
1703 replyType =
"DCOPRef";
1705 replyData = TQByteArray();
1706 TQDataStream final_reply( replyData, IO_WriteOnly );
1712 bool DCOPClient::find(
const TQCString &app,
const TQCString &objId,
1713 const TQCString &fun,
const TQByteArray &data,
1714 TQCString& replyType, TQByteArray &replyData)
1716 d->transaction =
false;
1717 if ( !app.isEmpty() && app != d->appId && app[app.length()-1] !=
'*') {
1718 tqWarning(
"WEIRD! we somehow received a DCOP message w/a different appId");
1722 if (objId.isEmpty() || objId[objId.length()-1] !=
'*')
1727 return findSuccess(app, objId, replyType, replyData);
1731 if (receive(app, objId, fun, data, replyType, replyData))
1733 if (findResultOk(replyType, replyData))
1734 return findSuccess(app, objId, replyType, replyData);
1740 TQPtrList<DCOPObject> matchList =
1743 objPtr != 0L; objPtr = matchList.next())
1746 replyData = TQByteArray();
1748 return findSuccess(app, objPtr->
objId(), replyType, replyData);
1749 objPtr->setCallingDcopClient(
this);
1750 if (objPtr->
process(fun, data, replyType, replyData))
1751 if (findResultOk(replyType, replyData))
1752 return findSuccess(app, objPtr->
objId(), replyType, replyData);
1760 const TQCString &remFun,
const TQByteArray &data,
1761 TQCString& replyType, TQByteArray &replyData,
1764 return call( remApp, remObjId, remFun, data, replyType, replyData, useEventLoop, -1,
false );
1768 const TQCString &remFun,
const TQByteArray &data,
1769 TQCString& replyType, TQByteArray &replyData,
1770 bool useEventLoop,
int timeout)
1772 return call( remApp, remObjId, remFun, data, replyType, replyData, useEventLoop, timeout,
false );
1776 const TQCString &remFun,
const TQByteArray &data,
1777 TQCString& replyType, TQByteArray &replyData,
1778 bool useEventLoop,
int timeout,
bool forceRemote)
1780 if (remApp.isEmpty())
1784 if ( localClient && !forceRemote ) {
1785 bool saveTransaction = d->transaction;
1786 TQ_INT32 saveTransactionId = d->transactionId;
1787 TQCString saveSenderId = d->senderId;
1790 bool b = localClient->receive( remApp, remObjId, remFun, data, replyType, replyData );
1796 TQApplication::eventLoop()->processEvents(TQEventLoop::WaitForMore);
1797 }
while( !localClient->isLocalTransactionFinished(
id, replyType, replyData));
1800 d->transaction = saveTransaction;
1801 d->transactionId = saveTransactionId;
1802 d->senderId = saveSenderId;
1806 return callInternal(remApp, remObjId, remFun, data,
1807 replyType, replyData, useEventLoop, timeout, DCOPCall);
1810 void DCOPClient::asyncReplyReady()
1812 while( d->asyncReplyQueue.count() )
1814 ReplyStruct *replyStruct = d->asyncReplyQueue.take(0);
1815 handleAsyncReply(replyStruct);
1820 const TQCString &remFun,
const TQByteArray &data,
1821 TQObject *callBackObj,
const char *callBackSlot)
1823 TQCString replyType;
1824 TQByteArray replyData;
1826 ReplyStruct *replyStruct =
new ReplyStruct;
1827 replyStruct->replyType =
new TQCString;
1828 replyStruct->replyData =
new TQByteArray;
1829 replyStruct->replyObject = callBackObj;
1830 replyStruct->replySlot = callBackSlot;
1831 replyStruct->replyId = ++d->transactionId;
1832 if (d->transactionId < 0)
1833 d->transactionId = 0;
1835 bool b = callInternal(remApp, remObjId, remFun, data,
1836 replyStruct,
false, -1, DCOPCall);
1839 delete replyStruct->replyType;
1840 delete replyStruct->replyData;
1845 if (replyStruct->transactionId == 0)
1848 TQTimer::singleShot(0,
this, TQT_SLOT(asyncReplyReady()));
1849 d->asyncReplyQueue.append(replyStruct);
1852 return replyStruct->replyId;
1855 bool DCOPClient::callInternal(
const TQCString &remApp,
const TQCString &remObjId,
1856 const TQCString &remFun,
const TQByteArray &data,
1857 TQCString& replyType, TQByteArray &replyData,
1858 bool useEventLoop,
int timeout,
int minor_opcode)
1860 ReplyStruct replyStruct;
1861 replyStruct.replyType = &replyType;
1862 replyStruct.replyData = &replyData;
1863 return callInternal(remApp, remObjId, remFun, data, &replyStruct, useEventLoop, timeout, minor_opcode);
1866 bool DCOPClient::callInternal(
const TQCString &remApp,
const TQCString &remObjId,
1867 const TQCString &remFun,
const TQByteArray &data,
1868 ReplyStruct *replyStruct,
1869 bool useEventLoop,
int timeout,
int minor_opcode)
1876 CARD32 oldCurrentKey = d->currentKey;
1877 if ( !d->currentKey )
1878 d->currentKey = d->key;
1881 TQDataStream ds(ba, IO_WriteOnly);
1884 IceGetHeader(d->iceConn, d->majorOpcode, minor_opcode,
1885 sizeof(DCOPMsg), DCOPMsg, pMsg);
1887 pMsg->key = d->currentKey;
1888 int datalen = ba.size() + data.size();
1889 pMsg->length += datalen;
1893 IceSendData(d->iceConn, ba.size(),
const_cast<char *
>(ba.data()));
1894 IceSendData(d->iceConn, data.size(),
const_cast<char *
>(data.data()));
1896 if (IceConnectionStatus(d->iceConn) != IceConnectAccepted)
1899 IceFlush (d->iceConn);
1901 IceReplyWaitInfo waitInfo;
1902 waitInfo.sequence_of_request = IceLastSentSequenceNumber(d->iceConn);
1903 waitInfo.major_opcode_of_request = d->majorOpcode;
1904 waitInfo.minor_opcode_of_request = minor_opcode;
1906 replyStruct->transactionId = -1;
1907 waitInfo.reply =
static_cast<IcePointer
>(replyStruct);
1909 Bool readyRet = False;
1910 IceProcessMessagesStatus s;
1912 timespec time_start;
1916 clock_gettime(CLOCK_MONOTONIC, &time_start);
1917 time_left = timeout;
1920 bool checkMessages =
true;
1922 ? d->notifier != NULL
1924 const int guiTimeout = 100;
1925 checkMessages =
false;
1927 int msecs = useEventLoop
1933 FD_SET(
socket(), &fds );
1934 tv.tv_sec = msecs / 1000;
1935 tv.tv_usec = (msecs % 1000) * 1000;
1936 if ( select(
socket() + 1, &fds, 0, 0, &tv ) <= 0 ) {
1937 if( useEventLoop && (timeout < 0 || time_left > guiTimeout)) {
1940 bool old_lock = d->non_blocking_call_lock;
1942 d->non_blocking_call_lock =
true;
1946 d->eventLoopTimer.start(time_left - guiTimeout,
true);
1947 tqApp->enter_loop();
1948 d->eventLoopTimer.stop();
1950 d->non_blocking_call_lock =
false;
1957 checkMessages =
true;
1963 if( replyStruct->transactionId != -1 )
1965 if (replyStruct->transactionId == 0)
1967 if (!replyStruct->replySlot.isEmpty())
1971 if( checkMessages ) {
1972 s = IceProcessMessages(d->iceConn, &waitInfo,
1974 if (s == IceProcessMessagesIOError) {
1976 d->currentKey = oldCurrentKey;
1981 if( replyStruct->transactionId != -1 )
1983 if (replyStruct->transactionId == 0)
1985 if (!replyStruct->replySlot.isEmpty())
1992 clock_gettime(CLOCK_MONOTONIC, &time_now);
1993 time_left = timeout -
1994 ((time_now.tv_sec - time_start.tv_sec) * 1000) -
1995 ((time_now.tv_nsec - time_start.tv_nsec) / 1000000);
2002 useEventLoop =
false;
2005 *(replyStruct->replyType) = TQCString();
2006 *(replyStruct->replyData) = TQByteArray();
2007 replyStruct->status = ReplyStruct::Failed;
2013 if ( d->non_blocking_call_lock ) {
2017 d->currentKey = oldCurrentKey;
2018 return replyStruct->status != ReplyStruct::Failed;
2021 void DCOPClient::eventLoopTimeout()
2032 timeout.tv_usec = 0;
2035 int result = select(fd+1, &fds, 0, 0, &timeout);
2039 if ( d->non_blocking_call_lock ) {
2047 d->notifier->deleteLater();
2049 tqWarning(
"received an error processing data from the DCOP server!");
2053 IceProcessMessagesStatus s = IceProcessMessages(d->iceConn, 0, 0);
2055 if (s == IceProcessMessagesIOError) {
2057 tqWarning(
"received an error processing data from the DCOP server!");
2064 d->defaultObject = objId;
2070 return d->defaultObject;
2074 DCOPClient::isLocalTransactionFinished(TQ_INT32
id, TQCString &replyType, TQByteArray &replyData)
2076 DCOPClientPrivate::LocalTransactionResult *result = d->localTransActionList.take(
id);
2080 replyType = result->replyType;
2081 replyData = result->replyData;
2087 DCOPClientTransaction *
2090 if (d->opcode == DCOPSend)
2092 if (!d->transactionList)
2093 d->transactionList =
new TQPtrList<DCOPClientTransaction>;
2095 d->transaction =
true;
2096 DCOPClientTransaction *trans =
new DCOPClientTransaction();
2097 trans->senderId = d->senderId;
2098 trans->id = ++d->transactionId;
2099 if (d->transactionId < 0)
2100 d->transactionId = 0;
2101 trans->key = d->currentKey;
2103 d->transactionList->append( trans );
2112 return d->transactionId;
2119 TQByteArray &replyData)
2127 if ( !d->transactionList) {
2128 tqWarning(
"Transaction unknown: No pending transactions!");
2132 if ( !d->transactionList->removeRef( trans ) ) {
2133 tqWarning(
"Transaction unknown: Not on list of pending transactions!");
2137 if (trans->senderId.isEmpty())
2140 DCOPClientPrivate::LocalTransactionResult *result =
new DCOPClientPrivate::LocalTransactionResult();
2141 result->replyType = replyType;
2142 result->replyData = replyData;
2144 d->localTransActionList.insert(trans->id, result);
2154 TQDataStream ds(ba, IO_WriteOnly);
2155 ds << d->appId << trans->senderId << trans->id << replyType << replyData;
2157 IceGetHeader(d->iceConn, d->majorOpcode, DCOPReplyDelayed,
2158 sizeof(DCOPMsg), DCOPMsg, pMsg);
2159 pMsg->key = trans->key;
2160 pMsg->length += ba.size();
2162 IceSendData( d->iceConn, ba.size(),
const_cast<char *
>(ba.data()) );
2182 const TQCString &signal,
2183 const TQCString &receiverObj,
const TQCString &slot,
bool Volatile)
2185 TQCString replyType;
2186 TQByteArray data, replyData;
2187 TQ_INT8 iVolatile = Volatile ? 1 : 0;
2189 TQDataStream args(data, IO_WriteOnly );
2192 if (!
call(
"DCOPServer", 0,
2193 "connectSignal(TQCString,TQCString,TQCString,TQCString,TQCString,bool)",
2194 data, replyType, replyData))
2199 if (replyType !=
"bool")
2202 TQDataStream reply(replyData, IO_ReadOnly );
2205 return (result != 0);
2210 const TQCString &receiverObj,
const TQCString &slot,
bool Volatile)
2217 const TQCString &signal,
2218 const TQCString &receiverObj,
const TQCString &slot)
2220 TQCString replyType;
2221 TQByteArray data, replyData;
2223 TQDataStream args(data, IO_WriteOnly );
2226 if (!
call(
"DCOPServer", 0,
2227 "disconnectSignal(TQCString,TQCString,TQCString,TQCString,TQCString)",
2228 data, replyType, replyData))
2233 if (replyType !=
"bool")
2236 TQDataStream reply(replyData, IO_ReadOnly );
2239 return (result != 0);
2244 const TQCString &receiverObj,
const TQCString &slot)
2250 DCOPClient::setPriorityCall(
bool b)
2254 if (d->currentKey == 2)
2256 d->currentKeySaved = d->currentKey;
2261 if (d->currentKey != 2)
2263 d->currentKey = d->currentKeySaved;
2264 if ( !d->messages.isEmpty() )
2265 d->postMessageTimer.start( 0,
true );
2272 DCOPClient::emergencyClose()
2274 TQPtrList<DCOPClient> list;
2275 client_map_t *map = DCOPClient_CliMap;
2277 TQAsciiDictIterator<DCOPClient> it(*map);
2278 while(it.current()) {
2279 list.removeRef(it.current());
2280 list.append(it.current());
2283 for(
DCOPClient *cl = list.first(); cl; cl = list.next())
2285 if (cl->d->iceConn) {
2286 IceProtocolShutdown(cl->d->iceConn, cl->d->majorOpcode);
2287 IceCloseConnection(cl->d->iceConn);
2288 cl->d->iceConn = 0L;
2294 DCOPClient::postMortemSender()
2296 if (!dcop_main_client)
2298 if (dcop_main_client->d->senderId.isEmpty())
2300 return dcop_main_client->d->senderId.data();
2304 DCOPClient::postMortemObject()
2306 if (!dcop_main_client)
2308 return dcop_main_client->d->objId.data();
2311 DCOPClient::postMortemFunction()
2313 if (!dcop_main_client)
2315 return dcop_main_client->d->function.data();
2318 void DCOPClient::virtual_hook(
int,
void* )
2321 #include <dcopclient.moc>
TQCString app() const
Name of the application in which the object resides.
static TQCString iceauthPath()
Return the path of iceauth or an empty string if not found.
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...
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 attachFailed(const TQString &msg)
Indicates that the process of establishing DCOP communications failed in some manner.
bool isApplicationRegistered(const TQCString &remApp)
Checks whether remApp is registered with the DCOP server.
static bool hasObject(const TQCString &objId)
Checks whether an object with the given id is known in this process.
bool acceptCalls() const
Returns whether the client handles incoming calls.
static DCOPClient * mainClient()
Returns the application's main dcop client.
int key(StdAccel) KDE_DEPRECATED
void setDefaultObject(const TQCString &objId)
Installs object objId as application-wide default object.
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 attach()
Attaches to the DCOP server.
void setAcceptCalls(bool b)
Specify whether the client should accept incoming calls.
DCOPClient()
Constructs a new DCOP client, but does not attach to any server.
void endTransaction(DCOPClientTransaction *t, TQCString &replyType, TQByteArray &replyData)
Sends the delayed reply of a function call.
bool send(const TQCString &remApp, const TQCString &remObj, const TQCString &remFun, const TQByteArray &data)
Sends a data block to the server.
A DCOPRef(erence) encapsulates a remote DCOP object as a triple
where type is optional...
void setQtBridgeEnabled(bool b)
Specify whether Qt objects of the application should be accessible via DCOP.
virtual ~DCOPClient()
Cleans up any open connections and dynamic data.
bool qtBridgeEnabled()
Returns whether the DCOP - Qt bridge is enabled.
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 isRegistered() const
Returns whether or not the client is registered at the server.
void processSocketData(int socknum)
Process data from the socket.
static TQPtrList< DCOPObject > match(const TQCString &partialId)
Tries to find an object using a partial object id.
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.
TQCString objId() const
Returns the object id of the DCOPObject.
static DCOPClient * findLocalClient(const TQCString &_appId)
Look for the given client only in this process.
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.
static void setMainClient(DCOPClient *mainClient)
Sets the application's main dcop client.
TQCString appId() const
Returns the current app id or a null string if the application hasn't yet been registered.
TQ_INT32 transactionId() const
Test whether the current function call is delayed.
void suspend()
Temporarily suspends processing of DCOP events.
bool detach()
Detaches from the DCOP server.
TQCString senderId() const
Returns the appId of the last application that talked to us.
QCStringList remoteInterfaces(const TQCString &remApp, const TQCString &remObj, bool *ok=0)
Retrieves the list of interfaces of the remote object remObj of application remApp.
static DCOPObject * find(const TQCString &objId)
Try to find a dcop object with the given id.
void setDaemonMode(bool daemonMode)
Tells the dcopserver to treat the client as daemon client, not as regular client. ...
TQCString defaultObject() const
Returns the current default object or an empty string if no object is installed as default object...
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.
bool isAttachedToForeignServer() const
Returns whether the client is attached to a server owned by another user.
QCStringList remoteFunctions(const TQCString &remApp, const TQCString &remObj, bool *ok=0)
Retrieves the list of functions of the remote object remObj of application remApp.
QCStringList remoteObjects(const TQCString &remApp, bool *ok=0)
Retrieves the list of objects of the remote application remApp.
void resume()
Resumes the processing of DCOP events.
void applicationRemoved(const TQCString &appId)
Indicates that the formerly registered application appId has been removed.
static TQCString dcopServerFile(const TQCString &hostname=0)
File with information how to reach the dcopserver.
bool isAttached() const
Returns whether or not the client is attached to the server.
void emitDCOPSignal(const TQCString &object, const TQCString &signal, const TQByteArray &data)
Emits signal as DCOP signal from object object with data as arguments.
bool isSuspended() const
Returns whether DCOP events are being processed.
Provides an interface for receiving DCOP messages.
int socket() const
Returns the socket fd that is used for communication with the server.
void blockUserInput(bool block)
Indicates that user input shall be blocked or released, depending on the argument.
TQString name(StdAccel id)
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.
Represents the return value of a DCOPRef:call() or DCOPRef:send() invocation.
static TQCString dcopServerFileOld(const TQCString &hostname=0) KDE_DEPRECATED
static TQCString normalizeFunctionSignature(const TQCString &fun)
Normalizes the function signature fun.