KDSOAP 1.2
|
00001 /**************************************************************************** 00002 ** Copyright (C) 2010-2012 Klaralvdalens Datakonsult AB. All rights reserved. 00003 ** 00004 ** This file is part of the KD Soap library. 00005 ** 00006 ** Licensees holding valid commercial KD Soap licenses may use this file in 00007 ** accordance with the KD Soap Commercial License Agreement provided with 00008 ** the Software. 00009 ** 00010 ** 00011 ** This file may be distributed and/or modified under the terms of the 00012 ** GNU General Public License version 2 and version 3 as published by the 00013 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included. 00014 ** 00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 ** 00018 ** Contact info@kdab.com if any conditions of this licensing are not 00019 ** clear to you. 00020 ** 00021 **********************************************************************/ 00022 #ifndef KDSOAPSERVERTHREAD_P_H 00023 #define KDSOAPSERVERTHREAD_P_H 00024 00025 #include <QThread> 00026 #include <QSemaphore> 00027 #include <QMutex> 00028 #include <QHash> 00029 class KDSoapServer; 00030 class KDSoapSocketList; 00031 00032 class KDSoapServerThreadImpl : public QObject 00033 { 00034 Q_OBJECT 00035 public: 00036 KDSoapServerThreadImpl(); 00037 ~KDSoapServerThreadImpl(); 00038 00039 public Q_SLOTS: 00040 void handleIncomingConnection(int socketDescriptor, KDSoapServer* server); 00041 void disconnectSocketsForServer(KDSoapServer* server, QSemaphore* semaphore); 00042 void quit(); 00043 00044 public: 00045 int socketCount(); 00046 int socketCountForServer(const KDSoapServer* server); 00047 int totalConnectionCountForServer(const KDSoapServer* server); 00048 void resetTotalConnectionCountForServer(const KDSoapServer* server); 00049 00050 void addIncomingConnection(); 00051 private: 00052 QMutex m_socketListMutex; 00053 KDSoapSocketList* socketListForServer(KDSoapServer* server); 00054 typedef QHash<KDSoapServer*, KDSoapSocketList*> SocketLists; 00055 SocketLists m_socketLists; 00056 00057 QAtomicInt m_incomingConnectionCount; 00058 }; 00059 00060 class KDSoapServerThread : public QThread 00061 { 00062 Q_OBJECT 00063 public: 00064 explicit KDSoapServerThread(QObject *parent = 0); 00065 ~KDSoapServerThread(); 00066 00067 void startThread(); 00068 void quitThread(); 00069 00070 int socketCount() const; 00071 int socketCountForServer(const KDSoapServer* server) const; 00072 int totalConnectionCountForServer(const KDSoapServer* server) const; 00073 void resetTotalConnectionCountForServer(const KDSoapServer* server); 00074 00075 void disconnectSocketsForServer(KDSoapServer* server, QSemaphore& semaphore); 00076 void handleIncomingConnection(int socketDescriptor, KDSoapServer* server); 00077 00078 protected: 00079 virtual void run(); 00080 00081 private: 00082 void start(); // use startThread instead 00083 void quit(); // use quitThread instead 00084 KDSoapServerThreadImpl* d; 00085 QSemaphore m_semaphore; 00086 }; 00087 00088 #endif // KDSOAPSERVERTHREAD_P_H