ServerQueryThread.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. GNU General Public License version 3 notice
  3. Copyright (C) 2012 Mihawk <luiz@netdome.biz>. All rights reserved.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see < http://www.gnu.org/licenses/ >.
  14. */
  15. #ifndef SERVERQUERYTHREAD_H
  16. #define SERVERQUERYTHREAD_H
  17. #include <QRunnable>
  18. #include "ServerQuery.h"
  19. class QReadWriteLock;
  20. class ServerQueryThread : public QRunnable
  21. {
  22. public:
  23. ServerQueryThread();
  24. virtual ~ServerQueryThread();
  25. void setAddress(const QHostAddress& serverAddress, quint16 serverPort);
  26. bool startQueryThread();
  27. void stopQueryThread();
  28. quint8 playerCount() const;
  29. bool isRunning() const;
  30. const QHostAddress& serverAddress() const;
  31. quint16 serverPort() const;
  32. protected:
  33. void run();
  34. private:
  35. QReadWriteLock* myStopMutex; /* For reading thread state and for stopping the thread */
  36. QReadWriteLock* myServerInfoMutex; /* For retrieving server information regarding the player count */
  37. bool myStopThreadFlag;
  38. bool myThreadRunningFlag;
  39. QHostAddress myServerAddress;
  40. quint16 myServerPort;
  41. quint8 myServerPlayerCount;
  42. };
  43. #endif // SERVERQUERYTHREAD_H