dcopserver.h
00001 /* 00002 Copyright (c) 1999 Preston Brown <pbrown@kde.org> 00003 Copyright (c) 1999 Matthias Ettrich <ettrich@kde.org> 00004 00005 Permission is hereby granted, free of charge, to any person obtaining a copy 00006 of this software and associated documentation files (the "Software"), to deal 00007 in the Software without restriction, including without limitation the rights 00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 copies of the Software, and to permit persons to whom the Software is 00010 furnished to do so, subject to the following conditions: 00011 00012 The above copyright notice and this permission notice shall be included in 00013 all copies or substantial portions of the Software. 00014 00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 00019 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00020 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 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 // If you enable the following define DCOP will create 00056 // $HOME/.dcop.log file which will list all signals passing 00057 // through it. 00058 // #define DCOP_LOG 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 // Add the data from offset @p start in @p _data to the output 00080 // buffer and schedule it for later transmission. 00081 void waitForOutputReady(const TQByteArray &_data, int start); 00082 00083 // Called from DCOPServer::slotOutputReady() 00084 // Flush the output buffer. 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; // index on app id 00170 TQPtrDict<DCOPConnection> clients; // index on iceConn 00171 TQIntDict<DCOPConnection> fd_clients; // index on fd 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