KD SOAP
 All Classes Functions Enumerations Enumerator Pages
KDSoapServerThread_p.h
1 /****************************************************************************
2 ** Copyright (C) 2010-2013 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Soap library.
5 **
6 ** Licensees holding valid commercial KD Soap licenses may use this file in
7 ** accordance with the KD Soap Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU Lesser General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.LGPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 #ifndef KDSOAPSERVERTHREAD_P_H
23 #define KDSOAPSERVERTHREAD_P_H
24 
25 #include <QThread>
26 #include <QSemaphore>
27 #include <QMutex>
28 #include <QHash>
29 class KDSoapServer;
30 class KDSoapSocketList;
31 
32 class KDSoapServerThreadImpl : public QObject
33 {
34  Q_OBJECT
35 public:
36  KDSoapServerThreadImpl();
37  ~KDSoapServerThreadImpl();
38 
39 public Q_SLOTS:
40  void handleIncomingConnection(int socketDescriptor, KDSoapServer* server);
41  void disconnectSocketsForServer(KDSoapServer* server, QSemaphore* semaphore);
42  void quit();
43 
44 public:
45  int socketCount();
46  int socketCountForServer(const KDSoapServer* server);
47  int totalConnectionCountForServer(const KDSoapServer* server);
48  void resetTotalConnectionCountForServer(const KDSoapServer* server);
49 
50  void addIncomingConnection();
51 private:
52  QMutex m_socketListMutex;
53  KDSoapSocketList* socketListForServer(KDSoapServer* server);
54  typedef QHash<KDSoapServer*, KDSoapSocketList*> SocketLists;
55  SocketLists m_socketLists;
56 
57  QAtomicInt m_incomingConnectionCount;
58 };
59 
60 class KDSoapServerThread : public QThread
61 {
62  Q_OBJECT
63 public:
64  explicit KDSoapServerThread(QObject *parent = 0);
65  ~KDSoapServerThread();
66 
67  void startThread();
68  void quitThread();
69 
70  int socketCount() const;
71  int socketCountForServer(const KDSoapServer* server) const;
72  int totalConnectionCountForServer(const KDSoapServer* server) const;
73  void resetTotalConnectionCountForServer(const KDSoapServer* server);
74 
75  void disconnectSocketsForServer(KDSoapServer* server, QSemaphore& semaphore);
76  void handleIncomingConnection(int socketDescriptor, KDSoapServer* server);
77 
78 protected:
79  virtual void run();
80 
81 private:
82  void start(); // use startThread instead
83  void quit(); // use quitThread instead
84  KDSoapServerThreadImpl* d;
85  QSemaphore m_semaphore;
86 };
87 
88 #endif // KDSOAPSERVERTHREAD_P_H

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-soap/