RemoteComponent.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // Created by Tobias Hieta on 24/03/15.
  3. //
  4. #ifndef _KONVERGO_REMOTECOMPONENT_H_
  5. #define _KONVERGO_REMOTECOMPONENT_H_
  6. #include <QJsonObject>
  7. #include <QMutex>
  8. #include <QTimer>
  9. #include <QNetworkAccessManager>
  10. #include <QNetworkReply>
  11. #include "ComponentManager.h"
  12. #include "GDMManager.h"
  13. #include "server/HTTPServer.h"
  14. #include "qhttpserverresponse.hpp"
  15. #include "qhttpserver.hpp"
  16. #include "RemoteSubscriber.h"
  17. class RemoteComponent : public ComponentBase
  18. {
  19. Q_OBJECT
  20. DEFINE_SINGLETON(RemoteComponent);
  21. public:
  22. QNetworkAccessManager* getNetworkAccessManager();
  23. bool componentInitialize() override;
  24. const char* componentName() override { return "remote"; }
  25. bool componentExport() override { return true; }
  26. static QVariantMap ResourceInformation();
  27. static QVariantMap GDMInformation();
  28. static QVariantMap HeaderInformation();
  29. void handleResource(QHttpRequest* request, QHttpResponse* response);
  30. void handleCommand(QHttpRequest* request, QHttpResponse* response);
  31. static QVariantMap HeaderToMap(const qhttp::THeaderHash& hash);
  32. static QVariantMap QueryToMap(const QUrl& url);
  33. Q_INVOKABLE void commandResponse(const QVariantMap& responseArguments);
  34. Q_INVOKABLE QVariantMap resourceInfo() { return ResourceInformation(); }
  35. Q_INVOKABLE void timelineUpdate(quint64 commandID, const QString& timeline);
  36. void subscriberRemove(const QString& identifier);
  37. Q_SIGNALS:
  38. void commandReceived(const QVariantMap& commandInfo);
  39. private Q_SLOTS:
  40. void checkSubscribers();
  41. void timelineFinished(QNetworkReply* reply);
  42. void responseDone();
  43. private:
  44. explicit RemoteComponent(QObject* parent = nullptr);
  45. void handleSubscription(QHttpRequest * request, QHttpResponse * response, bool poll=false);
  46. void subscribeToWeb(bool subscribe);
  47. GDMManager* m_gdmManager;
  48. quint64 m_commandId;
  49. QMap<quint64, QHttpResponse*> m_responseMap;
  50. QMutex m_responseLock;
  51. QMutex m_subscriberLock;
  52. QMap<QString, RemoteSubscriber*> m_subscriberMap;
  53. QTimer m_subscriberTimer;
  54. QNetworkAccessManager* m_networkAccessManager;
  55. };
  56. #endif //_KONVERGO_REMOTECOMPONENT_H_