communicationmanager.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. = StarPU-Top for StarPU =
  3. Copyright (C) 2011
  4. William Braik
  5. Yann Courtois
  6. Jean-Marie Couteyen
  7. Anthony Roy
  8. This library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Lesser General Public
  10. License as published by the Free Software Foundation; either
  11. version 2.1 of the License, or (at your option) any later version.
  12. This library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Lesser General Public License for more details.
  16. You should have received a copy of the GNU Lesser General Public
  17. License along with this library; if not, write to the Free Software
  18. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef COMMUNICATIONMANAGER_H
  21. #define COMMUNICATIONMANAGER_H
  22. #include <QTcpSocket>
  23. #include "starpu_top_types.h"
  24. class CommunicationManager : public QTcpSocket
  25. { /* Receives protocol messages from server, parses them
  26. and notifies the GUI appropriately using signals.
  27. Sends protocol messages to server when the GUI notifies. */
  28. Q_OBJECT
  29. public:
  30. CommunicationManager(QObject *parent = 0);
  31. ~CommunicationManager();
  32. private:
  33. // Protocol message strings
  34. QHash<QString, CommunicationInMessageType> _inMessageStrings;
  35. QHash<CommunicationOutMessageType, QString> _outMessageStrings;
  36. QSet<QString> _typeMessageStrings;
  37. QSet<QString> _beginEndMessageStrings;
  38. QSet<QString> _widgetStatusChangeMessageStrings;
  39. QSet<QString> _debugMessageStrings;
  40. QSet<QString> _loopMessageStrings;
  41. // Metadata
  42. int _serverInfoMsgCount;
  43. QString _serverID;
  44. qlonglong _serverTimestamp;
  45. QList<DataDescription*> *_dataDescriptions;
  46. QList<ParamDescription*> *_paramDescriptions;
  47. QList<starpu_top_device> *_serverDevices;
  48. // Communication states
  49. CommunicationState _state;
  50. bool _initServerInfoCompleted;
  51. bool _initDataCompleted;
  52. bool _initParamsCompleted;
  53. bool _initDevCompleted;
  54. // Getters
  55. // Get communication states
  56. CommunicationState state() const;
  57. bool isInitCompleted() const;
  58. // Get session descriptions
  59. DataDescription *dataDescriptionFromId(int dataId) const;
  60. ParamDescription *paramDescriptionFromId(int paramId) const;
  61. // Init protocol message strings
  62. void initInMessageStrings();
  63. void initOutMessageStrings();
  64. private slots:
  65. // Initialize a new session
  66. void initializeSession();
  67. // Receive protocol messages
  68. void messageReceived();
  69. // Parse different protocol messages
  70. void parseInitMessage(QString messageString);
  71. void parseInitServerInfoMessage(QString messageString);
  72. void parseInitDataMessage(QString messageString);
  73. void parseInitParamsMessage(QString messageString);
  74. void parseInitDevMessage(QString messageString);
  75. void parseReadyMessage(QString messageString);
  76. void parseLoopMessage(QString messageString);
  77. void parseTaskPrevMessage(QString messageString);
  78. void parseTaskStartMessage(QString messageString);
  79. void parseTaskEndMessage(QString messageString);
  80. void parseDataUpdateMessage(QString messageString);
  81. void parseParamNotificationMessage(QString messageString);
  82. void parseDebugEnabledMessage(QString messageString);
  83. void parseDebugMessageMessage(QString messageString);
  84. void parseDebugLockMessage(QString messageString);
  85. public slots:
  86. // Build different protocol messages
  87. QString buildGoMessage();
  88. QString buildDataEnableMessage(int dataId);
  89. QString buildDataDisableMessage(int dataId);
  90. QString buildParamSetMessage(int paramId, bool paramValue);
  91. QString buildParamSetMessage(int paramId, int paramValue);
  92. QString buildParamSetMessage(int paramId, double paramValue);
  93. QString buildDebugEnabledMessage(bool enabled);
  94. QString buildStepMessage();
  95. // Send different protocol messages
  96. void sendMessage(QString messageString);
  97. void sendGoMessage();
  98. void sendDataEnableMessage(int dataId);
  99. void sendDataDisableMessage(int dataId);
  100. void sendParamSetMessage(int paramId, bool paramValue);
  101. void sendParamSetMessage(int paramId, int paramValue);
  102. void sendParamSetMessage(int paramId, double paramValue);
  103. void sendDebugEnabledMessage(bool enabled);
  104. void sendStepMessage();
  105. // Clear session descriptions
  106. void clearDescriptions();
  107. signals:
  108. // Reference time received from server
  109. void sessionTimeSynchronized(qlonglong serverTimestamp);
  110. // Send init session data to GUI
  111. void serverInitCompleted(QString serverID,
  112. QList<DataDescription*> *dataDescriptions,
  113. QList<ParamDescription*> *paramDescriptions,
  114. QList<starpu_top_device> *serverDevices);
  115. // Notify GUI with a protocol message
  116. // Protocol error
  117. void protocolError(QString errorMessage);
  118. // Debug protocol messages
  119. void notifyDebugEnabled(bool enabled);
  120. void notifyDebugMessage(QString debugMessage);
  121. void notifyDebugLock(QString lockMessage);
  122. // Data update protocol messages
  123. void notifyDataUpdate(int dataId, bool dataValue, qlonglong timestamp);
  124. void notifyDataUpdate(int dataId, int dataValue, qlonglong timestamp);
  125. void notifyDataUpdate(int dataId, double dataValue, qlonglong timestamp);
  126. // Parameter update protocol messages
  127. void notifyParamUpdate(int paramId, bool paramValue, qlonglong timestamp);
  128. void notifyParamUpdate(int paramId, int paramValue, qlonglong timestamp);
  129. void notifyParamUpdate(int paramId, double paramValue, qlonglong timestamp);
  130. // Task update protocol messages
  131. void notifyTaskPrevUpdate(int taskId, int deviceId, qlonglong timestamp,
  132. qlonglong timestampStart, qlonglong timestampEnd);
  133. void notifyTaskStartUpdate(int taskId, int deviceId, qlonglong timestamp);
  134. void notifyTaskEndUpdate(int taskId, qlonglong timestamp);
  135. void protoConnected();
  136. };
  137. #endif // COMMUNICATIONMANAGER_H