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

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