HttpServer.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /***************************************************************************
  2. * Copyright (C) 2009, 2010 by Axel Jaeger <axeljaeger@googlemail.com> *
  3. * *
  4. * This file is part of Glowworm. *
  5. * *
  6. * Glowworm is free software: you can redistribute it and/or modify *
  7. * it under the terms of the GNU General Public License as published by *
  8. * the Free Software Foundation, version 3 of the License. *
  9. * *
  10. * Glowworm is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with Glowworm. If not, see <http://www.gnu.org/licenses/>. *
  17. ***************************************************************************/
  18. #ifndef HttpServer_H
  19. #define HttpServer_H
  20. #include <QObject>
  21. #include <QPointer>
  22. #include <QMap>
  23. class QTcpServer;
  24. class AbstractServlet;
  25. class FileServlet;
  26. class LogModel;
  27. class HttpServer : public QObject
  28. {
  29. Q_OBJECT
  30. Q_PROPERTY (bool enabled READ enabled WRITE setEnabled)
  31. Q_PROPERTY (int port READ port WRITE setPort)
  32. Q_PROPERTY (QString wwwRoot READ wwwRoot WRITE setWwwRoot)
  33. public:
  34. HttpServer(QObject* parent = 0);
  35. ~HttpServer();
  36. int port() const;
  37. bool enabled() const;
  38. QString wwwRoot() const;
  39. void addServlet(const QString & prefix, AbstractServlet* servlet);
  40. LogModel* logModel() const;
  41. public slots:
  42. void setEnabled(bool enable);
  43. void setPort(int port);
  44. void setWwwRoot(const QString & dir);
  45. signals:
  46. void selectedColor(unsigned char red, unsigned char green, unsigned char blue) const;
  47. private slots:
  48. void handleIncomingConnection();
  49. void handleRead();
  50. void handleDisconnect();
  51. private:
  52. QTcpServer* m_tcpServer;
  53. static QString statusMessage(int statusCode, const QString& contentType = QString("text/html"));
  54. int m_port;
  55. QString m_wwwRoot;
  56. QMap<QString, AbstractServlet*> m_servlets;
  57. QPointer<FileServlet> m_fileServlet;
  58. QPointer<LogModel> m_logModel;
  59. };
  60. #endif