blob: 7838357591161230d56d2b71a683b886f91889fa [file] [log] [blame]
Roger Meier86e89862012-02-10 19:53:20 +00001#ifndef _THRIFT_TASYNC_QTCP_SERVER_H_
2#define _THRIFT_TASYNC_QTCP_SERVER_H_
3
4#include <QObject>
5#include <QTcpServer>
6
7#include <boost/shared_ptr.hpp>
8
Roger Meier86e89862012-02-10 19:53:20 +00009namespace apache { namespace thrift { namespace protocol {
Roger Meier86e89862012-02-10 19:53:20 +000010class TProtocolFactory;
11}}} // apache::thrift::protocol
12
13namespace apache { namespace thrift { namespace async {
14
15class TAsyncProcessor;
16
Roger Meier19a99152012-02-11 19:09:30 +000017/**
18 * Server that uses Qt to listen for connections.
19 * Simply give it a QTcpServer that is listening, along with an async
20 * processor and a protocol factory, and then run the Qt event loop.
21 */
Roger Meier86e89862012-02-10 19:53:20 +000022class TQTcpServer : public QObject {
23 Q_OBJECT
24 public:
25 TQTcpServer(boost::shared_ptr<QTcpServer> server,
26 boost::shared_ptr<TAsyncProcessor> processor,
27 boost::shared_ptr<apache::thrift::protocol::TProtocolFactory> protocolFactory,
28 QT_PREPEND_NAMESPACE(QObject)* parent = NULL);
29 virtual ~TQTcpServer();
30
31 private Q_SLOTS:
32 void processIncoming();
33 void beginDecode();
34 void socketClosed();
35
36 private:
Roger Meier19a99152012-02-11 19:09:30 +000037 TQTcpServer(const TQTcpServer&);
38 TQTcpServer& operator=(const TQTcpServer&);
39
Roger Meier86e89862012-02-10 19:53:20 +000040 class ConnectionContext;
41
42 void finish(boost::shared_ptr<ConnectionContext> ctx, bool healthy);
43
44 boost::shared_ptr<QTcpServer> server_;
45 boost::shared_ptr<TAsyncProcessor> processor_;
46 boost::shared_ptr<apache::thrift::protocol::TProtocolFactory> pfact_;
47
48 std::map<QT_PREPEND_NAMESPACE(QTcpSocket)*, boost::shared_ptr<ConnectionContext> > ctxMap_;
49};
50
51}}} // apache::thrift::async
52
53#endif // #ifndef _THRIFT_TASYNC_QTCP_SERVER_H_