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: dcopserver.h 423060 2005-06-07 10:49:14Z staniek $" 00024 00025 #include <qobject.h> 00026 00027 #include <qstring.h> 00028 #include <qsocketnotifier.h> 00029 #include <qptrlist.h> 00030 #include <qvaluelist.h> 00031 #include <qcstring.h> 00032 #include <qdict.h> 00033 #include <qptrdict.h> 00034 #include <qintdict.h> 00035 #include <qapplication.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 QTimer; 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 QTextStream; 00061 class QFile; 00062 #endif 00063 00064 typedef QValueList<QCString> QCStringList; 00065 00069 class DCOPConnection : public QSocketNotifier 00070 { 00071 public: 00072 DCOPConnection( IceConn conn ); 00073 ~DCOPConnection(); 00074 00075 DCOPSignalConnectionList *signalConnectionList(); 00076 00077 // Add the data from offset @p start in @p _data to the output 00078 // buffer and schedule it for later transmission. 00079 void waitForOutputReady(const QByteArray &_data, int start); 00080 00081 // Called from DCOPServer::slotOutputReady() 00082 // Flush the output buffer. 00083 void slotOutputReady(); 00084 00085 QCString appId; 00086 QCString plainAppId; 00087 IceConn iceConn; 00088 int notifyRegister; 00100 QPtrList <_IceConn> waitingOnReply; 00101 QPtrList <_IceConn> waitingForReply; 00102 QPtrList <_IceConn> waitingForDelayedReply; 00103 DCOPSignalConnectionList *_signalConnectionList; 00104 bool daemon; 00105 bool outputBlocked; 00106 QValueList <QByteArray> outputBuffer; 00107 unsigned long outputBufferStart; 00108 QSocketNotifier *outputBufferNotifier; 00109 }; 00110 00111 00115 class DCOPServer : public QObject 00116 { 00117 Q_OBJECT 00118 public: 00119 DCOPServer(bool _suicide); 00120 ~DCOPServer(); 00121 00122 void* watchConnection( IceConn iceConn ); 00123 void removeConnection( void* data ); 00124 void processMessage( IceConn iceConn, int opcode, unsigned long length, Bool swap); 00125 void ioError( IceConn iceConn ); 00126 00127 bool receive(const QCString &app, const QCString &obj, 00128 const QCString &fun, const QByteArray& data, 00129 QCString& replyType, QByteArray &replyData, IceConn iceConn); 00130 00131 DCOPConnection *findApp(const QCString &appId); 00132 DCOPConnection *findConn(IceConn iceConn) 00133 { return clients.find(iceConn); } 00134 00135 void sendMessage(DCOPConnection *conn, const QCString &sApp, 00136 const QCString &rApp, const QCString &rObj, 00137 const QCString &rFun, const QByteArray &data); 00138 00139 private slots: 00140 void newClient( int socket ); 00141 void processData( int socket ); 00142 void slotTerminate(); 00143 void slotSuicide(); 00144 void slotShutdown(); 00145 void slotExit(); 00146 void slotCleanDeadConnections(); 00147 void slotOutputReady(int socket ); 00148 00149 #ifdef Q_OS_WIN 00150 public: 00151 static BOOL WINAPI dcopServerConsoleProc(DWORD dwCtrlType); 00152 private: 00153 static DWORD WINAPI TerminatorThread(void * pParam); 00154 #endif 00155 private: 00156 void broadcastApplicationRegistration( DCOPConnection* conn, const QCString type, 00157 const QCString& data ); 00158 bool suicide; 00159 bool shutdown; 00160 int majorOpcode; 00161 int currentClientNumber; 00162 CARD32 serverKey; 00163 DCOPSignals *dcopSignals; 00164 QTimer *m_timer; 00165 QTimer *m_deadConnectionTimer; 00166 QPtrList<DCOPListener> listener; 00167 QAsciiDict<DCOPConnection> appIds; // index on app id 00168 QPtrDict<DCOPConnection> clients; // index on iceConn 00169 QIntDict<DCOPConnection> fd_clients; // index on fd 00170 QPtrList<_IceConn> deadConnections; 00171 00172 #ifdef Q_OS_WIN 00173 HANDLE m_evTerminate; 00174 HANDLE m_hTerminateThread; 00175 DWORD m_dwTerminateThreadId; 00176 #endif 00177 00178 #ifdef DCOP_LOG 00179 QTextStream *m_stream; 00180 QFile *m_logger; 00181 #endif 00182 }; 00183 00184 extern DCOPServer* the_server; 00185 00186 #endif