dcop
dcopserver.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef DCOPSERVER_H
00023 #define DCOPSERVER_H "$Id$"
00024
00025 #include <tqobject.h>
00026
00027 #include <tqstring.h>
00028 #include <tqsocketnotifier.h>
00029 #include <tqptrlist.h>
00030 #include <tqvaluelist.h>
00031 #include <tqcstring.h>
00032 #include <tqdict.h>
00033 #include <tqptrdict.h>
00034 #include <tqintdict.h>
00035 #include <tqapplication.h>
00036
00037 #define INT32 QINT32
00038 #ifdef Q_WS_X11
00039 #include <X11/Xlib.h>
00040 #include <X11/Xmd.h>
00041 #endif
00042 #include <KDE-ICE/ICElib.h>
00043 extern "C" {
00044 #include <KDE-ICE/ICEutil.h>
00045 #include <KDE-ICE/ICEmsg.h>
00046 #include <KDE-ICE/ICEproto.h>
00047 }
00048
00049 class DCOPConnection;
00050 class DCOPListener;
00051 class DCOPSignalConnectionList;
00052 class DCOPSignals;
00053 class TQTimer;
00054
00055
00056
00057
00058
00059 #ifdef DCOP_LOG
00060 class TQTextStream;
00061 class TQFile;
00062 #endif
00063
00064 #define NDEBUG
00065
00066 typedef TQValueList<TQCString> QCStringList;
00067
00071 class DCOPConnection : public TQSocketNotifier
00072 {
00073 public:
00074 DCOPConnection( IceConn conn );
00075 ~DCOPConnection();
00076
00077 DCOPSignalConnectionList *signalConnectionList();
00078
00079
00080
00081 void waitForOutputReady(const TQByteArray &_data, int start);
00082
00083
00084
00085 void slotOutputReady();
00086
00087 TQCString appId;
00088 TQCString plainAppId;
00089 IceConn iceConn;
00090 int notifyRegister;
00102 TQPtrList <_IceConn> waitingOnReply;
00103 TQPtrList <_IceConn> waitingForReply;
00104 TQPtrList <_IceConn> waitingForDelayedReply;
00105 DCOPSignalConnectionList *_signalConnectionList;
00106 bool daemon;
00107 bool outputBlocked;
00108 TQValueList <TQByteArray> outputBuffer;
00109 unsigned long outputBufferStart;
00110 TQSocketNotifier *outputBufferNotifier;
00111 };
00112
00113
00117 class DCOPServer : public TQObject
00118 {
00119 Q_OBJECT
00120 public:
00121 DCOPServer(bool _suicide);
00122 ~DCOPServer();
00123
00124 void* watchConnection( IceConn iceConn );
00125 void removeConnection( void* data );
00126 void processMessage( IceConn iceConn, int opcode, unsigned long length, Bool swap);
00127 void ioError( IceConn iceConn );
00128
00129 bool receive(const TQCString &app, const TQCString &obj,
00130 const TQCString &fun, const TQByteArray& data,
00131 TQCString& replyType, TQByteArray &replyData, IceConn iceConn);
00132
00133 DCOPConnection *findApp(const TQCString &appId);
00134 DCOPConnection *findConn(IceConn iceConn)
00135 { return clients.find(iceConn); }
00136
00137 void sendMessage(DCOPConnection *conn, const TQCString &sApp,
00138 const TQCString &rApp, const TQCString &rObj,
00139 const TQCString &rFun, const TQByteArray &data);
00140
00141 private slots:
00142 void newClient( int socket );
00143 void processData( int socket );
00144 void slotTerminate();
00145 void slotSuicide();
00146 void slotShutdown();
00147 void slotExit();
00148 void slotCleanDeadConnections();
00149 void slotOutputReady(int socket );
00150
00151 #ifdef Q_OS_WIN
00152 public:
00153 static BOOL WINAPI dcopServerConsoleProc(DWORD dwCtrlType);
00154 private:
00155 static DWORD WINAPI TerminatorThread(void * pParam);
00156 #endif
00157 private:
00158 void broadcastApplicationRegistration( DCOPConnection* conn, const TQCString type,
00159 const TQCString& data );
00160 bool suicide;
00161 bool shutdown;
00162 int majorOpcode;
00163 int currentClientNumber;
00164 CARD32 serverKey;
00165 DCOPSignals *dcopSignals;
00166 TQTimer *m_timer;
00167 TQTimer *m_deadConnectionTimer;
00168 TQPtrList<DCOPListener> listener;
00169 TQAsciiDict<DCOPConnection> appIds;
00170 TQPtrDict<DCOPConnection> clients;
00171 TQIntDict<DCOPConnection> fd_clients;
00172 TQPtrList<_IceConn> deadConnections;
00173
00174 #ifdef Q_OS_WIN
00175 HANDLE m_evTerminate;
00176 HANDLE m_hTerminateThread;
00177 DWORD m_dwTerminateThreadId;
00178 #endif
00179
00180 #ifdef DCOP_LOG
00181 TQTextStream *m_stream;
00182 TQFile *m_logger;
00183 #endif
00184 };
00185
00186 extern DCOPServer* the_server;
00187
00188 #endif