CFEL - ASG Software Suite  2.5.0
CASS
tcpserver.h
Go to the documentation of this file.
1 // CASS TCP server
2 //
3 // Copyright (C) 2010 Jochen Küpper
4 // Copyright (C) 2011 - 2013 Lutz Foucar
5 
6 /**
7  * @file tcpserver.h the soap server implementation
8  *
9  * @author Jochen Kuepper
10  */
11 
12 #ifndef CASS_TCPSERVER_H
13 #define CASS_TCPSERVER_H
14 
15 #include <stdexcept>
16 #include <tr1/memory>
17 
18 #include <QtCore/QThread>
19 #include <QtCore/QMutex>
20 #include <QtCore/QRunnable>
21 
22 #include "cass_event.h"
23 #include "soapCASSsoapService.h"
24 
25 
26 namespace cass
27 {
28 
29 /** Handle a single SOAP request
30  *
31  * @author Jochen Küpper
32  */
33 class SoapHandler : public QRunnable
34 {
35 public:
36  /** constructor
37  *
38  * @param soap the soap instance to be used be handeld
39  */
40  SoapHandler(CASSsoapService *soap)
41  : _soap(soap)
42  {}
43 
44  /** destructor
45  *
46  * destroys the soap instance that was handelt by this
47  */
48  virtual ~SoapHandler() { delete _soap; }
49 
50  /** handle request and terminate*/
51  virtual void run();
52 
53 protected:
54  /** the service */
55  CASSsoapService *_soap;
56 };
57 
58 
59 
60 /** SOAP server
61  *
62  * @author Jochen Küpper
63  */
64 class SoapServer : public QThread
65 {
66  /** be friend with the soap instances */
67  friend class ::CASSsoapService;
68 
69 public:
70  /** a shared pointer of this class */
71  typedef std::tr1::shared_ptr<SoapServer> shared_pointer;
72 
73  /** create the instance if not it does not exist already
74  *
75  * @return the instance to this server
76  * @param port The port that the soap instance is running on. Default is 12321
77  */
78  static shared_pointer instance(size_t port=12321);
79 
80 protected:
81  /** perform thread-work
82  *
83  * Sets up and connects to the soap service then waits until the soap service
84  * get an information. Copies the soap instance and create an new handler to
85  * serve the soap request.
86  *
87  * The handler is put into a QThreadPool which will automatically destroy it
88  * once one is done serving.
89  */
90  virtual void run();
91 
92  /** return existing instance for our friends
93  *
94  * if it doesn't exist, throw exception
95  */
96  static shared_pointer instance()
97  {
98  QMutexLocker locker(&_mutex);
99  if(!_instance)
100  throw std::logic_error("SoapServer does not exist");
101  return _instance;
102  }
103 
104  /** the service */
105  CASSsoapService *_soap;
106 
107  /** maximum backlog of open requests */
108  static const size_t _backlog;
109 
110  /** server port */
111  const size_t _port;
112 
113 private:
114  /** Constructor
115  *
116  * sets up the initial values
117  *
118  * @param port The port that the soap will run on
119  * @param parent The Qt parent object that this class belong to
120  */
121  SoapServer(size_t port, QObject *parent=0);
122 
123  /** Disabled default constructor */
124  SoapServer();
125 
126  /** Disabled copy constructor */
127  SoapServer(const SoapServer&);
128 
129  /** Disabled assignment */
131 
132 public:
133  /** Destructor
134  *
135  * Check whether thread is still running. If so terminate it and wait until
136  * it finished. Then clean up SOAP by destroying and deleting the soap
137  * instance.
138  */
139  ~SoapServer();
140 
141 private:
142  /** pointer to the singleton instance */
143  static shared_pointer _instance;
144 
145  /** Singleton operation locker */
146  static QMutex _mutex;
147 };
148 
149 } //end namespace cass
150 #endif
SoapHandler(CASSsoapService *soap)
constructor
Definition: tcpserver.h:40
file contains declaration of the CASSEvent
~SoapServer()
Destructor.
Definition: tcpserver.cpp:69
CASSsoapService * _soap
the service
Definition: tcpserver.h:105
CASSsoapService * _soap
the service
Definition: tcpserver.h:55
virtual void run()
perform thread-work
Definition: tcpserver.cpp:78
static QMutex _mutex
Singleton operation locker.
Definition: tcpserver.h:146
SoapServer & operator=(const SoapServer &)
Disabled assignment.
static shared_pointer instance()
return existing instance for our friends
Definition: tcpserver.h:96
virtual ~SoapHandler()
destructor
Definition: tcpserver.h:48
std::tr1::shared_ptr< SoapServer > shared_pointer
a shared pointer of this class
Definition: tcpserver.h:71
static const size_t _backlog
maximum backlog of open requests
Definition: tcpserver.h:108
Handle a single SOAP request.
Definition: tcpserver.h:33
static shared_pointer _instance
pointer to the singleton instance
Definition: tcpserver.h:143
SoapServer()
Disabled default constructor.
virtual void run()
handle request and terminate
Definition: tcpserver.cpp:55
const size_t _port
server port
Definition: tcpserver.h:111
SOAP server.
Definition: tcpserver.h:64