NorMIT-nav  22.09
An IGT application
cxSocket.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #ifndef CXSOCKET_H
13 #define CXSOCKET_H
14 
15 #include "cxResourceExport.h"
16 
17 #include <boost/shared_ptr.hpp>
18 #include <QObject>
19 #include <QAbstractSocket>
20 #include <QString>
21 #include "cxSocketConnection.h"
22 
23 QT_BEGIN_NAMESPACE
24 class QTcpSocket;
26 
27 namespace cx
28 {
29 
36 class SingleConnectionTcpServer : public QTcpServer
37 {
38  Q_OBJECT
39 public:
40  SingleConnectionTcpServer(QObject* parent);
41 // void setSocket(QPointer<Socket> socket);
42 signals:
43  void incoming(qintptr socketDescriptor);
44 protected:
45  void incomingConnection(qintptr socketDescriptor);
46 private:
47 // QPointer<Socket> mSocket;
48 };
49 
50 
51 class cxResource_EXPORT SocketConnector : public QObject
52 {
53  Q_OBJECT
54 public:
55  virtual ~SocketConnector() {}
56 // SocketConnector(SocketConnection::ConnectionInfo info, QSocket* socket);
57 
58  virtual void activate() = 0;
59  virtual void deactivate() = 0;
60  virtual CX_SOCKETCONNECTION_STATE getState() = 0;
61  virtual SocketConnection::ConnectionInfo getInfo() const = 0;
62 signals:
63  void stateChanged(CX_SOCKETCONNECTION_STATE);
64 };
65 
66 class cxResource_EXPORT SocketClientConnector : public SocketConnector
67 {
68 public:
70  virtual ~SocketClientConnector();
71 
72  virtual void activate();
73  virtual void deactivate();
74  virtual CX_SOCKETCONNECTION_STATE getState();
75  virtual SocketConnection::ConnectionInfo getInfo() const { return mInfo; }
76 
77 private:
78  void internalConnected();
79  void internalDisconnected();
80 
82  QTcpSocket* mSocket;
83 
84 };
85 
86 class cxResource_EXPORT SocketServerConnector : public SocketConnector
87 {
88  Q_OBJECT
89 public:
91  virtual ~SocketServerConnector();
92 
93  virtual void activate();
94  virtual void deactivate();
95  virtual CX_SOCKETCONNECTION_STATE getState();
96  virtual SocketConnection::ConnectionInfo getInfo() const { return mInfo; }
97 
98 private:
99  bool startListen();
100  void stopListen();
101  void incomingConnection(qintptr socketDescriptor);
102  QStringList getAllServerHostnames();
103 
105  QPointer<class SingleConnectionTcpServer> mServer;
106  QTcpSocket* mSocket;
107 };
108 
109 }
110 
111 #endif //CXSOCKET_H
cx::SocketConnector::~SocketConnector
virtual ~SocketConnector()
Definition: cxSocket.h:55
cx::SocketServerConnector
Definition: cxSocket.h:86
cx::SingleConnectionTcpServer::incoming
void incoming(qintptr socketDescriptor)
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::SocketClientConnector::getInfo
virtual SocketConnection::ConnectionInfo getInfo() const
Definition: cxSocket.h:75
cx::SocketConnection::ConnectionInfo
Definition: cxSocketConnection.h:60
cx::SingleConnectionTcpServer
Definition: cxSocket.h:36
cx::SocketConnector
Definition: cxSocket.h:51
cx::SingleConnectionTcpServer::incomingConnection
void incomingConnection(qintptr socketDescriptor)
Definition: cxSocket.cpp:34
QT_END_NAMESPACE
QT_END_NAMESPACE
Definition: cxHelpSearchWidget.h:19
cx::SocketServerConnector::getInfo
virtual SocketConnection::ConnectionInfo getInfo() const
Definition: cxSocket.h:96
cxSocketConnection.h
cx::SocketClientConnector
Definition: cxSocket.h:66
cx::CX_SOCKETCONNECTION_STATE
CX_SOCKETCONNECTION_STATE
Definition: cxSocketConnection.h:22
cx::SingleConnectionTcpServer::SingleConnectionTcpServer
SingleConnectionTcpServer(QObject *parent)
Definition: cxSocket.cpp:28