Torc  0.1
torchttpservice.h
Go to the documentation of this file.
1 #ifndef TORCSERVICE_H
2 #define TORCSERVICE_H
3 
4 // Qt
5 #include <QMap>
6 #include <QMutex>
7 #include <QReadWriteLock>
8 #include <QMetaObject>
9 #include <QCoreApplication>
10 
11 // Torc
12 #include "torchttphandler.h"
13 #include "torchttprequest.h"
14 
15 #define TORC_SERVICE_VERSION QStringLiteral("version")
16 
17 class TorcHTTPServer;
18 class MethodParameters;
19 
21 {
22  Q_DECLARE_TR_FUNCTIONS(TorcHTTPService)
23 
24  public:
25  TorcHTTPService(QObject *Parent, const QString &Signature, const QString &Name,
26  const QMetaObject &MetaObject, const QString &Blacklist = QStringLiteral(""));
27  virtual ~TorcHTTPService();
28 
29  void ProcessHTTPRequest (const QString &PeerAddress, int PeerPort, const QString &LocalAddress, int LocalPort, TorcHTTPRequest &Request) override;
30  QVariantMap ProcessRequest (const QString &Method, const QVariant &Parameters, QObject *Connection, bool Authenticated) override;
31  QString GetMethod (int Index);
32  QVariant GetProperty (int Index);
33  QVariantMap GetServiceDetails (void);
34 
35  virtual QString GetUIName (void);
36  virtual QString GetPresentationURL (void);
37 
38  protected:
39  void HandleSubscriberDeleted (QObject* Subscriber);
40  // this is a generic lock around data that may be accessed fro multiple sockets/threads
41  // use with care to ensure maximum concurrency.
42  QReadWriteLock m_httpServiceLock;
43 
44  private:
45  QObject *m_parent;
46  QString m_version;
47  QMap<QString,MethodParameters*> m_methods;
48  QMap<int,int> m_properties;
49  QList<QObject*> m_subscribers;
50  QMutex m_subscriberLock;
51 
52  private:
53  Q_DISABLE_COPY(TorcHTTPService)
54 };
55 
56 Q_DECLARE_METATYPE(TorcHTTPService*)
57 #endif // TORCSERVICE_H
A class to encapsulate an incoming HTTP request.
Base HTTP response handler class.
virtual ~TorcHTTPService()
QString Signature(void) const
void ProcessHTTPRequest(const QString &PeerAddress, int PeerPort, const QString &LocalAddress, int LocalPort, TorcHTTPRequest &Request) override
virtual QString GetUIName(void)
virtual QString GetPresentationURL(void)
QString Name(void) const
void HandleSubscriberDeleted(QObject *Subscriber)
QReadWriteLock m_httpServiceLock
QVariantMap ProcessRequest(const QString &Method, const QVariant &Parameters, QObject *Connection, bool Authenticated) override
QVariant GetProperty(int Index)
Get the value of a given property.
QString GetMethod(int Index)
QVariantMap GetServiceDetails(void)
Return a QVariantMap describing the services methods and properties.
An HTTP server.
TorcHTTPService(QObject *Parent, const QString &Signature, const QString &Name, const QMetaObject &MetaObject, const QString &Blacklist=QStringLiteral(""))