LocalJsonClient.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // Created by Tobias Hieta on 30/08/15.
  3. //
  4. #include "Paths.h"
  5. #include "LocalJsonClient.h"
  6. #include "LocalJsonServer.h"
  7. /////////////////////////////////////////////////////////////////////////////////////////
  8. LocalJsonClient::LocalJsonClient(const QString serverPath, QObject* parent) : QLocalSocket(parent)
  9. {
  10. m_serverPath = Paths::socketName(serverPath);
  11. connect(this, &QLocalSocket::readyRead, this, &LocalJsonClient::readyRead);
  12. }
  13. /////////////////////////////////////////////////////////////////////////////////////////
  14. void LocalJsonClient::connectToServer()
  15. {
  16. QLocalSocket::connectToServer(m_serverPath, QIODevice::ReadWrite);
  17. }
  18. /////////////////////////////////////////////////////////////////////////////////////////
  19. bool LocalJsonClient::sendMessage(const QVariantMap& message)
  20. {
  21. return LocalJsonServer::sendMessage(message, this);
  22. }
  23. /////////////////////////////////////////////////////////////////////////////////////////
  24. void LocalJsonClient::readyRead()
  25. {
  26. QVariantList list = LocalJsonServer::readFromSocket(this);
  27. for(const QVariant& msg : list)
  28. emit messageReceived(msg.toMap());
  29. }