LocalJsonServer.h 898 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. //
  2. // Created by Tobias Hieta on 30/08/15.
  3. //
  4. #ifndef KONVERGO_LOCALJSONSEVER_H
  5. #define KONVERGO_LOCALJSONSEVER_H
  6. #include <QLocalServer>
  7. #include <QLocalSocket>
  8. #include <QJsonObject>
  9. #include <QJsonDocument>
  10. class LocalJsonServer : public QObject
  11. {
  12. Q_OBJECT
  13. public:
  14. explicit LocalJsonServer(const QString& serverName, QObject* parent = nullptr);
  15. bool listen();
  16. static bool sendMessage(const QVariantMap& message, QLocalSocket* socket);
  17. static QVariantList readFromSocket(QLocalSocket* socket);
  18. QString errorString() const { return m_server->errorString(); }
  19. Q_SIGNALS:
  20. void clientConnected(QLocalSocket* socket);
  21. void messageReceived(const QVariant& message);
  22. private Q_SLOTS:
  23. void serverClientConnected();
  24. void clientReadyRead();
  25. private:
  26. QString m_serverName;
  27. QLocalServer* m_server;
  28. QList<QLocalSocket*> m_clientSockets;
  29. };
  30. #endif //KONVERGO_LOCALJSONSEVER_H