communicationmanager.cpp 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566
  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. #include "communicationmanager.h"
  21. // Protocol messages delimiters
  22. const char COM_MSG_SEPARATOR = ';';
  23. const char COM_MSG_ENDL = '\n';
  24. CommunicationManager::CommunicationManager(QObject *parent) :
  25. QTcpSocket(parent)
  26. {
  27. static bool instanciated = false;
  28. Q_ASSERT_X(instanciated == false, "CommunicationManager's' constructor",
  29. "Singleton pattern violated - "
  30. "CommunicationManager instanciated more than once");
  31. qDebug() << "CommunicationManager : initializing";
  32. // Init incoming messages
  33. initInMessageStrings();
  34. // Init outgoing messages
  35. initOutMessageStrings();
  36. // Init session data and communication states
  37. initializeSession();
  38. QObject::connect(this, SIGNAL(readyRead()), this,
  39. SLOT(messageReceived()));
  40. QObject::connect(this, SIGNAL(disconnected()), this,
  41. SLOT(clearDescriptions()));
  42. QObject::connect(this, SIGNAL(disconnected()), this,
  43. SLOT(initializeSession()));
  44. instanciated = true;
  45. }
  46. CommunicationManager::~CommunicationManager()
  47. {
  48. qDebug() << "CommunicationManager : terminating";
  49. delete _dataDescriptions;
  50. delete _paramDescriptions;
  51. delete _serverDevices;
  52. }
  53. void CommunicationManager::initializeSession()
  54. {
  55. _dataDescriptions = new QList<DataDescription*> ();
  56. _paramDescriptions = new QList<ParamDescription*> ();
  57. _serverDevices = new QList<starpu_top_device> ;
  58. _serverInfoMsgCount = 0;
  59. _state = COM_STATE_INIT;
  60. _initServerInfoCompleted = _initDataCompleted = _initParamsCompleted
  61. = _initDevCompleted = false;
  62. }
  63. /* -------------------------------------------------------------------------- */
  64. /* Receive messages */
  65. /* -------------------------------------------------------------------------- */
  66. void CommunicationManager::messageReceived()
  67. {
  68. while (canReadLine())
  69. {
  70. QByteArray message = readLine();
  71. QString messageString = QString(message).trimmed();
  72. switch (_state)
  73. {
  74. case COM_STATE_INIT:
  75. {
  76. if (_beginEndMessageStrings.contains(messageString))
  77. {
  78. parseInitMessage(messageString);
  79. }
  80. else
  81. {
  82. emit protocolError(
  83. "Unexpected message received in INIT ("
  84. + messageString
  85. + ")");
  86. }
  87. break;
  88. }
  89. case COM_STATE_INIT_SERVERINFO:
  90. parseInitServerInfoMessage(messageString);
  91. break;
  92. case COM_STATE_INIT_DATA:
  93. parseInitDataMessage(messageString);
  94. break;
  95. case COM_STATE_INIT_PARAMS:
  96. parseInitParamsMessage(messageString);
  97. break;
  98. case COM_STATE_INIT_DEV:
  99. parseInitDevMessage(messageString);
  100. break;
  101. case COM_STATE_READY:
  102. parseReadyMessage(messageString);
  103. break;
  104. case COM_STATE_LOOP:
  105. parseLoopMessage(messageString);
  106. break;
  107. }
  108. }
  109. }
  110. /* -------------------------------------------------------------------------- */
  111. /* Parse messages */
  112. /* -------------------------------------------------------------------------- */
  113. void CommunicationManager::parseInitMessage(QString messageString)
  114. {
  115. switch (_inMessageStrings.value(messageString))
  116. {
  117. case COM_MSG_IN_SERVERINFO_BEGIN:
  118. qDebug() << "CommunicationManager : SERVERINFO BEGIN received in INIT";
  119. _state = COM_STATE_INIT_SERVERINFO;
  120. break;
  121. case COM_MSG_IN_DATA_BEGIN:
  122. qDebug() << "CommunicationManager : DATA BEGIN received in INIT";
  123. _state = COM_STATE_INIT_DATA;
  124. break;
  125. case COM_MSG_IN_PARAMS_BEGIN:
  126. qDebug() << "CommunicationManager : PARAMS BEGIN received in INIT";
  127. _state = COM_STATE_INIT_PARAMS;
  128. break;
  129. case COM_MSG_IN_DEV_BEGIN:
  130. qDebug() << "CommunicationManager : DEV BEGIN received in INIT";
  131. _state = COM_STATE_INIT_DEV;
  132. break;
  133. default:
  134. ;
  135. }
  136. }
  137. void CommunicationManager::parseInitServerInfoMessage(QString messageString)
  138. {
  139. if (_beginEndMessageStrings.contains(messageString))
  140. {
  141. if (_inMessageStrings.value(messageString) == COM_MSG_IN_SERVERINFO_END)
  142. {
  143. qDebug()
  144. << "CommunicationManager : "
  145. "SERVERINFO END received in INIT SERVERINFO";
  146. _initServerInfoCompleted = true;
  147. emit protoConnected();
  148. if (isInitCompleted())
  149. {
  150. _state = COM_STATE_READY;
  151. }
  152. else
  153. {
  154. _state = COM_STATE_INIT;
  155. }
  156. }
  157. else
  158. {
  159. emit protocolError(
  160. "Bogus message received in INIT SERVERINFO ("
  161. + messageString + ")");
  162. }
  163. }
  164. else if (_serverInfoMsgCount == 0)
  165. { // First server info : Server ID
  166. qDebug()
  167. << "CommunicationManager : "
  168. "SERVERINFO received in INIT SERVERINFO ("
  169. << messageString + ")";
  170. _serverID = messageString;
  171. _serverInfoMsgCount++;
  172. }
  173. else if (_serverInfoMsgCount == 1)
  174. { // Second server info : Server timestamp
  175. qDebug()
  176. << "CommunicationManager : "
  177. "SERVERTIMESTAMP received in INIT SERVERINFO ("
  178. << messageString + ")";
  179. QString serverTimestampString = messageString;
  180. bool ok = false;
  181. qlonglong serverTimestamp = serverTimestampString.toLongLong(&ok);
  182. Q_ASSERT_X(ok == true,
  183. "CommunicationManager::parseInitServerInfoMessage()",
  184. "Bogus SERVERTIMESTAMP received in INIT SERVERINFO");
  185. emit(sessionTimeSynchronized(serverTimestamp));
  186. _serverTimestamp = serverTimestamp;
  187. _serverInfoMsgCount++;
  188. }
  189. }
  190. void CommunicationManager::parseInitDataMessage(QString messageString)
  191. {
  192. if (_beginEndMessageStrings.contains(messageString))
  193. {
  194. if (_inMessageStrings.value(messageString) == COM_MSG_IN_DATA_END)
  195. {
  196. qDebug() << "CommunicationManager : DATA END received in INIT DATA";
  197. _initDataCompleted = true;
  198. if (isInitCompleted())
  199. {
  200. _state = COM_STATE_READY;
  201. }
  202. else
  203. {
  204. _state = COM_STATE_INIT;
  205. }
  206. }
  207. else
  208. {
  209. emit protocolError(
  210. "Bogus message received in INIT DATA (" + messageString
  211. + ")");
  212. }
  213. }
  214. else
  215. {
  216. QStringList messageParts = messageString.split(COM_MSG_SEPARATOR);
  217. QString typeString = messageParts.at(0);
  218. QString idString = messageParts.at(1);
  219. bool ok = false;
  220. int id = idString.toInt(&ok); // Data ID
  221. Q_ASSERT_X(ok == true, "CommunicationManager::parseInitDataMessage()",
  222. "Bogus message received in INIT DATA");
  223. QString description = messageParts.at(2); // Data description
  224. DataType type;
  225. DataWidgetType widget; // Data widget
  226. double valMax = 0., valMin = 0.;
  227. bool active;
  228. Q_ASSERT_X(_typeMessageStrings.contains(typeString),
  229. "CommunicationManager::parseInitDataMessage()",
  230. "Bogus message received in INIT DATA");
  231. switch (_inMessageStrings.value(typeString))
  232. {
  233. case COM_MSG_IN_TYPE_BOOL:
  234. {
  235. Q_ASSERT_X(messageParts.count() == 4,
  236. "CommunicationManager::parseInitDataMessage()",
  237. "Bogus message received in INIT DATA");
  238. QString activeString = messageParts.at(3);
  239. Q_ASSERT_X(
  240. (activeString.compare("0") == 0)
  241. || (activeString.compare("1") == 0),
  242. "CommunicationManager::parseInitDataMessage()",
  243. "Bogus message received in INIT DATA");
  244. if (activeString.compare("1") == 0)
  245. {
  246. active = true;
  247. }
  248. else
  249. {
  250. active = false;
  251. }
  252. type = DATA_TYPE_BOOL;
  253. widget = DEFAULT_DATA_WIDGET_BOOL;
  254. break;
  255. }
  256. case COM_MSG_IN_TYPE_INT:
  257. {
  258. Q_ASSERT_X(messageParts.count() == 6,
  259. "CommunicationManager::parseInitDataMessage()",
  260. "Bogus message received in INIT DATA");
  261. QString activeString = messageParts.at(5);
  262. bool ok = false;
  263. int activeInt = activeString.toInt(&ok);
  264. Q_ASSERT_X(ok == true && (activeInt == 0 || activeInt == 1),
  265. "CommunicationManager::parseInitDataMessage()",
  266. "Bogus message received in INIT DATA");
  267. if (activeInt == 1)
  268. {
  269. active = true;
  270. }
  271. else
  272. {
  273. active = false;
  274. }
  275. QString valMinString = messageParts.at(3);
  276. valMin = valMinString.toDouble(&ok); // Data ID
  277. Q_ASSERT_X(ok == true,
  278. "CommunicationManager::parseInitDataMessage()",
  279. "Bogus message received in INIT DATA");
  280. QString valMaxString = messageParts.at(4);
  281. valMax = valMaxString.toDouble(&ok);
  282. Q_ASSERT_X(ok == true,
  283. "CommunicationManager::parseInitDataMessage()",
  284. "Bogus message received in INIT DATA");
  285. type = DATA_TYPE_INT;
  286. widget = DEFAULT_DATA_WIDGET_INT;
  287. break;
  288. }
  289. case COM_MSG_IN_TYPE_FLOAT:
  290. {
  291. Q_ASSERT_X(messageParts.count() == 6,
  292. "CommunicationManager::parseInitDataMessage()",
  293. "Bogus message received in INIT DATA");
  294. QString activeString = messageParts.at(5);
  295. bool ok = false;
  296. int activeInt = activeString.toInt(&ok);
  297. Q_ASSERT_X(ok == true && (activeInt == 0 || activeInt == 1),
  298. "CommunicationManager::parseInitDataMessage()",
  299. "Bogus message received in INIT DATA");
  300. if (activeInt == 1)
  301. {
  302. active = true;
  303. }
  304. else
  305. {
  306. active = false;
  307. }
  308. QString valMinString = messageParts.at(3);
  309. valMin = valMinString.toDouble(&ok);
  310. Q_ASSERT_X(ok == true,
  311. "CommunicationManager::parseInitDataMessage()",
  312. "Bogus message received in INIT DATA");
  313. QString valMaxString = messageParts.at(4);
  314. valMax = valMaxString.toDouble(&ok);
  315. Q_ASSERT_X(ok == true,
  316. "CommunicationManager::parseInitDataMessage()",
  317. "Bogus message received in INIT DATA");
  318. type = DATA_TYPE_FLOAT;
  319. widget = DEFAULT_DATA_WIDGET_FLOAT;
  320. break;
  321. }
  322. default:
  323. emit protocolError(
  324. "Bogus message received in INIT DATA (" + messageString
  325. + ")");
  326. return;
  327. }
  328. // Build the data description corresponding to this message
  329. if (active == false)
  330. {
  331. widget = DATA_WIDGET_NONE;
  332. }
  333. DataDescription *dataWidgetDescription = new DataDescription;
  334. dataWidgetDescription->id = id;
  335. dataWidgetDescription->descriptionString = description;
  336. dataWidgetDescription->type = type;
  337. dataWidgetDescription->widget = widget;
  338. dataWidgetDescription->valMin = valMin;
  339. dataWidgetDescription->valMax = valMax;
  340. _dataDescriptions->append(dataWidgetDescription);
  341. qDebug()
  342. << "CommunicationManager : "
  343. "DATA MSG successfully parsed in INIT DATA ("
  344. << messageString + ")";
  345. }
  346. }
  347. void CommunicationManager::parseInitParamsMessage(QString messageString)
  348. {
  349. if (_beginEndMessageStrings.contains(messageString))
  350. {
  351. if (_inMessageStrings.value(messageString) == COM_MSG_IN_PARAMS_END)
  352. {
  353. qDebug()
  354. << "CommunicationManager : "
  355. "PARAMS END received in INIT PARAMS";
  356. _initParamsCompleted = true;
  357. if (isInitCompleted())
  358. {
  359. _state = COM_STATE_READY;
  360. }
  361. else
  362. {
  363. _state = COM_STATE_INIT;
  364. }
  365. }
  366. else
  367. {
  368. emit protocolError(
  369. "Bogus message received in INIT PARAMS (" + messageString
  370. + ")");
  371. }
  372. }
  373. else
  374. {
  375. QStringList messageParts = messageString.split(COM_MSG_SEPARATOR);
  376. QString typeString = messageParts.at(0);
  377. QString idString = messageParts.at(1);
  378. bool ok = false;
  379. int id = idString.toInt(&ok); // Param ID
  380. Q_ASSERT_X(ok == true,
  381. "CommunicationManager::parseInitParamsMessage()",
  382. "Bogus message received in INIT PARAMS");
  383. QString description = messageParts.at(2); // Param description
  384. ParamType type;
  385. InteractiveWidgetType widget;
  386. bool valInitBool = false;
  387. int valInitInt = 0;
  388. double valInitDouble = 0.;
  389. int valInitEnum = 0;
  390. double valMax = 0., valMin = 0.;
  391. QStringList enumValues;
  392. Q_ASSERT_X(_typeMessageStrings.contains(typeString),
  393. "CommunicationManager::parseInitParamsMessage()",
  394. "Bogus message received in INIT PARAMS");
  395. switch (_inMessageStrings.value(typeString))
  396. {
  397. case COM_MSG_IN_TYPE_BOOL:
  398. {
  399. QString valInitString = messageParts.at(3);
  400. Q_ASSERT_X(
  401. messageParts.count() == 4
  402. && (valInitString.compare("0") == 0
  403. || valInitString.compare("1") == 1),
  404. "CommunicationManager::parseInitParamsMessage()",
  405. "Bogus message received in INIT PARAMS");
  406. if (valInitString.compare("0") == 0)
  407. {
  408. valInitBool = false;
  409. }
  410. else
  411. {
  412. valInitBool = true;
  413. }
  414. type = PARAM_TYPE_BOOL;
  415. widget = DEFAULT_INTERACTIVE_WIDGET_BOOL;
  416. break;
  417. }
  418. case COM_MSG_IN_TYPE_INT:
  419. {
  420. Q_ASSERT_X(messageParts.count() == 6,
  421. "CommunicationManager::parseInitParamsMessage()",
  422. "Bogus message received in INIT PARAMS");
  423. QString valInitString = messageParts.at(5);
  424. bool ok = false;
  425. valInitInt = valInitString.toInt(&ok);
  426. Q_ASSERT_X(ok == true,
  427. "CommunicationManager::parseInitParamsMessage()",
  428. "Bogus message received in INIT PARAMS");
  429. QString valMinString = messageParts.at(3);
  430. valMin = valMinString.toDouble(&ok);
  431. Q_ASSERT_X(ok == true,
  432. "CommunicationManager::parseInitParamsMessage()",
  433. "Bogus message received in INIT PARAMS");
  434. QString valMaxString = messageParts.at(4);
  435. valMax = valMaxString.toDouble(&ok);
  436. Q_ASSERT_X(ok == true,
  437. "CommunicationManager::parseInitParamsMessage()",
  438. "Bogus message received in INIT PARAMS");
  439. type = PARAM_TYPE_INT;
  440. widget = DEFAULT_INTERACTIVE_WIDGET_INT;
  441. break;
  442. }
  443. case COM_MSG_IN_TYPE_FLOAT:
  444. {
  445. Q_ASSERT_X(messageParts.count() == 6,
  446. "CommunicationManager::parseInitParamsMessage()",
  447. "Bogus message received in INIT PARAMS");
  448. QString valInitString = messageParts.at(5);
  449. bool ok = false;
  450. valInitDouble = valInitString.toDouble(&ok);
  451. Q_ASSERT_X(ok == true,
  452. "CommunicationManager::parseInitParamsMessage()",
  453. "Bogus message received in INIT PARAMS");
  454. QString valMinString = messageParts.at(3);
  455. valMin = valMinString.toDouble(&ok);
  456. Q_ASSERT_X(ok == true,
  457. "CommunicationManager::parseInitParamsMessage()",
  458. "Bogus message received in INIT PARAMS");
  459. QString valMaxString = messageParts.at(4);
  460. valMax = valMaxString.toDouble(&ok);
  461. Q_ASSERT_X(ok == true,
  462. "CommunicationManager::parseInitParamsMessage()",
  463. "Bogus message received in INIT PARAMS");
  464. type = PARAM_TYPE_FLOAT;
  465. widget = DEFAULT_INTERACTIVE_WIDGET_FLOAT;
  466. break;
  467. }
  468. case COM_MSG_IN_TYPE_ENUM:
  469. {
  470. Q_ASSERT_X(messageParts.count() > 4,
  471. "CommunicationManager::parseInitParamsMessage()",
  472. "Bogus message received in INIT PARAMS");
  473. QString valInitString = messageParts.at(messageParts.count()-1);
  474. bool ok = false;
  475. valInitEnum = valInitString.toInt(&ok);
  476. Q_ASSERT_X(ok == true,
  477. "CommunicationManager::parseInitParamsMessage()",
  478. "Bogus message received in INIT PARAMS");
  479. QStringList values;
  480. for (int i = 3; i < messageParts.count() - 1; i++)
  481. {
  482. values << messageParts.at(i);
  483. }
  484. valMin = 0.0;
  485. valMax = messageParts.count() - 3 - 1;
  486. enumValues = values;
  487. type = PARAM_TYPE_ENUM;
  488. widget = DEFAULT_INTERACTIVE_WIDGET_ENUM;
  489. break;
  490. }
  491. default:
  492. emit protocolError(
  493. "Bogus message received in INIT PARAMS (" + messageString
  494. + ")");
  495. return;
  496. }
  497. // Build the param description corresponding to this message
  498. ParamDescription *interactiveWidgetDescription = new ParamDescription;
  499. interactiveWidgetDescription->id = id;
  500. interactiveWidgetDescription->descriptionString = description;
  501. interactiveWidgetDescription->type = type;
  502. interactiveWidgetDescription->widget = widget;
  503. interactiveWidgetDescription->valInitBool = valInitBool;
  504. interactiveWidgetDescription->valInitInt = valInitInt;
  505. interactiveWidgetDescription->valInitDouble = valInitDouble;
  506. interactiveWidgetDescription->valInitEnum = valInitEnum;
  507. interactiveWidgetDescription->valMin = valMin;
  508. interactiveWidgetDescription->valMax = valMax;
  509. interactiveWidgetDescription->enumValues = enumValues;
  510. _paramDescriptions->append(interactiveWidgetDescription);
  511. qDebug()
  512. << "CommunicationManager : "
  513. "PARAMS MSG successfully parsed in INIT PARAMS ("
  514. << messageString + ")";
  515. }
  516. }
  517. void CommunicationManager::parseInitDevMessage(QString messageString)
  518. {
  519. if (_beginEndMessageStrings.contains(messageString))
  520. {
  521. if (_inMessageStrings.value(messageString) == COM_MSG_IN_DEV_END)
  522. {
  523. qDebug() << "CommunicationManager : DEV END received in INIT DEV";
  524. _initDevCompleted = true;
  525. if (isInitCompleted())
  526. {
  527. _state = COM_STATE_READY;
  528. }
  529. else
  530. {
  531. _state = COM_STATE_INIT;
  532. }
  533. }
  534. else
  535. {
  536. emit protocolError(
  537. "Bogus message received in INIT DEV (" + messageString
  538. + ")");
  539. }
  540. }
  541. else
  542. {
  543. QStringList messageParts = messageString.split(COM_MSG_SEPARATOR);
  544. Q_ASSERT_X(messageParts.count() == 3,
  545. "CommunicationManager::parseInitDevMessage()",
  546. "Bogus message received in INIT DEV");
  547. QString deviceIdString = messageParts.at(0);
  548. QString deviceTypeString = messageParts.at(1);
  549. QString deviceNameString = messageParts.at(2);
  550. bool ok = false;
  551. int deviceId = deviceIdString.toInt(&ok);
  552. Q_ASSERT_X(ok == true, "CommunicationManager::parseInitDevMessage()",
  553. "Bogus message received in INIT DEV");
  554. starpu_top_device_type deviceType;
  555. Q_ASSERT_X(
  556. deviceTypeString.compare(
  557. _inMessageStrings.key(COM_MSG_IN_DEV_CPU)) == 0
  558. || deviceTypeString.compare(
  559. _inMessageStrings.key(COM_MSG_IN_DEV_CUDA))
  560. == 0 || deviceTypeString.compare(
  561. _inMessageStrings.key(COM_MSG_IN_DEV_OPENCL)) == 0
  562. ,
  563. "CommunicationManager::parseInitDevMessage()",
  564. "Bogus message received in INIT DEV");
  565. if (deviceTypeString.compare(_inMessageStrings.key(COM_MSG_IN_DEV_CPU))
  566. == 0)
  567. {
  568. deviceType = SERVERDEVICE_CPU;
  569. }
  570. else if (deviceTypeString.compare(
  571. _inMessageStrings.key(COM_MSG_IN_DEV_CUDA)) == 0)
  572. {
  573. deviceType = SERVERDEVICE_CUDA;
  574. }
  575. else if (deviceTypeString.compare(
  576. _inMessageStrings.key(COM_MSG_IN_DEV_OPENCL)) == 0)
  577. {
  578. deviceType = SERVERDEVICE_OPENCL;
  579. }
  580. starpu_top_device device;
  581. device.id = deviceId;
  582. device.type = deviceType;
  583. device.name = deviceNameString;
  584. _serverDevices->append(device);
  585. qDebug()
  586. << "CommunicationManager : "
  587. "DEV MSG successfully parsed in INIT DEV ("
  588. << messageString + ")";
  589. }
  590. }
  591. void CommunicationManager::parseReadyMessage(QString messageString)
  592. {
  593. if (_inMessageStrings.value(messageString) == COM_MSG_IN_READY)
  594. {
  595. qDebug() << "CommunicationManager : READY received in READY ("
  596. << messageString + ")";
  597. emit serverInitCompleted(_serverID, _dataDescriptions,
  598. _paramDescriptions, _serverDevices);
  599. _state = COM_STATE_LOOP;
  600. }
  601. else
  602. {
  603. QStringList messageParts = messageString.split(COM_MSG_SEPARATOR);
  604. QString head = messageParts.at(0);
  605. Q_ASSERT_X(_widgetStatusChangeMessageStrings.contains(head),
  606. "CommunicationManager::parseReadyMessage()",
  607. "Bogus message received in READY");
  608. switch (_inMessageStrings.value(head))
  609. {
  610. case COM_MSG_IN_SET:
  611. parseParamNotificationMessage(messageString);
  612. break;
  613. default:
  614. ;
  615. }
  616. }
  617. }
  618. void CommunicationManager::parseLoopMessage(QString messageString)
  619. {
  620. QStringList messageParts = messageString.split(COM_MSG_SEPARATOR);
  621. QString head = messageParts.at(0);
  622. if (_widgetStatusChangeMessageStrings.contains(head))
  623. {
  624. switch (_inMessageStrings.value(head))
  625. {
  626. case COM_MSG_IN_SET:
  627. parseParamNotificationMessage(messageString);
  628. break;
  629. default:
  630. ;
  631. }
  632. }
  633. else if (_loopMessageStrings.contains(head))
  634. {
  635. switch (_inMessageStrings.value(head))
  636. {
  637. case COM_MSG_IN_PREV:
  638. parseTaskPrevMessage(messageString);
  639. break;
  640. case COM_MSG_IN_SHORT_PREV:
  641. parseTaskPrevMessage(messageString);
  642. break;
  643. case COM_MSG_IN_START:
  644. parseTaskStartMessage(messageString);
  645. break;
  646. case COM_MSG_IN_SHORT_START:
  647. parseTaskStartMessage(messageString);
  648. break;
  649. case COM_MSG_IN_END:
  650. parseTaskEndMessage(messageString);
  651. break;
  652. case COM_MSG_IN_SHORT_END:
  653. parseTaskEndMessage(messageString);
  654. break;
  655. case COM_MSG_IN_UPDATE:
  656. parseDataUpdateMessage(messageString);
  657. break;
  658. case COM_MSG_IN_SHORT_UPDATE:
  659. parseDataUpdateMessage(messageString);
  660. break;
  661. default:
  662. ;
  663. }
  664. }
  665. else if (_debugMessageStrings.contains(head))
  666. {
  667. switch (_inMessageStrings.value(head))
  668. {
  669. case COM_MSG_IN_DEBUG:
  670. parseDebugEnabledMessage(messageString);
  671. break;
  672. case COM_MSG_IN_DEBUG_MESSAGE:
  673. parseDebugMessageMessage(messageString);
  674. break;
  675. case COM_MSG_IN_DEBUG_LOCK:
  676. parseDebugLockMessage(messageString);
  677. break;
  678. default:
  679. ;
  680. }
  681. }
  682. else
  683. {
  684. emit protocolError(
  685. "Unexpected message received in LOOP (" + messageString + ")");
  686. }
  687. }
  688. void CommunicationManager::parseTaskPrevMessage(QString messageString)
  689. {
  690. QStringList messageParts = messageString.split(COM_MSG_SEPARATOR);
  691. if (messageParts.count() == 6)
  692. {
  693. QString taskIdString = messageParts.at(1);
  694. QString deviceIdString = messageParts.at(2);
  695. QString timestampString = messageParts.at(3);
  696. QString timestampStartString = messageParts.at(4);
  697. QString timestampEndString = messageParts.at(5);
  698. int taskId;
  699. int deviceId;
  700. qlonglong timestamp;
  701. qlonglong timestampStart;
  702. qlonglong timestampEnd;
  703. bool ok = false;
  704. taskId = taskIdString.toInt(&ok);
  705. if (ok == false)
  706. {
  707. emit protocolError(
  708. "Unexpected TASK PREV message received in LOOP ("
  709. + messageString + ")");
  710. return;
  711. }
  712. deviceId = deviceIdString.toInt(&ok);
  713. if (ok == false)
  714. {
  715. emit protocolError(
  716. "Unexpected TASK PREV message received in LOOP ("
  717. + messageString + ")");
  718. return;
  719. }
  720. timestamp = timestampString.toLongLong(&ok);
  721. if (ok == false)
  722. {
  723. emit protocolError(
  724. "Unexpected TASK PREV message received in LOOP ("
  725. + messageString + ")");
  726. return;
  727. }
  728. timestampStart = timestampStartString.toLongLong(&ok);
  729. if (ok == false)
  730. {
  731. emit protocolError(
  732. "Unexpected TASK PREV message received in LOOP ("
  733. + messageString + ")");
  734. return;
  735. }
  736. timestampEnd = timestampEndString.toLongLong(&ok);
  737. if (ok == false)
  738. {
  739. emit protocolError(
  740. "Unexpected TASK PREV message received in LOOP ("
  741. + messageString + ")");
  742. return;
  743. }
  744. emit notifyTaskPrevUpdate(taskId, deviceId, timestamp, timestampStart,
  745. timestampEnd);
  746. qDebug()
  747. << "CommunicationManager : "
  748. "TASK PREV message successfully parsed in LOOP ("
  749. << messageString + ")";
  750. }
  751. else
  752. {
  753. emit protocolError(
  754. "Unexpected TASK PREV message received in LOOP ("
  755. + messageString + ")");
  756. }
  757. }
  758. void CommunicationManager::parseTaskStartMessage(QString messageString)
  759. {
  760. QStringList messageParts = messageString.split(COM_MSG_SEPARATOR);
  761. if (messageParts.count() == 4)
  762. {
  763. QString taskIdString = messageParts.at(1);
  764. QString deviceIdString = messageParts.at(2);
  765. QString timestampString = messageParts.at(3);
  766. int taskId;
  767. int deviceId;
  768. qlonglong timestamp;
  769. bool ok = false;
  770. taskId = taskIdString.toInt(&ok);
  771. if (ok == false)
  772. {
  773. emit protocolError(
  774. "Bogus TASK START message received in LOOP ("
  775. + messageString + ")");
  776. return;
  777. }
  778. deviceId = deviceIdString.toInt(&ok);
  779. if (ok == false)
  780. {
  781. emit protocolError(
  782. "Bogus TASK START message received in LOOP ("
  783. + messageString + ")");
  784. return;
  785. }
  786. timestamp = timestampString.toLongLong(&ok);
  787. if (ok == false)
  788. {
  789. emit protocolError(
  790. "Bogus TASK START message received in LOOP ("
  791. + messageString + ")");
  792. return;
  793. }
  794. emit notifyTaskStartUpdate(taskId, deviceId, timestamp);
  795. qDebug()
  796. << "CommunicationManager : "
  797. "TASK START message succesfully parsed in LOOP ("
  798. << messageString + ")";
  799. }
  800. else
  801. {
  802. emit protocolError(
  803. "Bogus TASK START message received in LOOP (" + messageString
  804. + ")");
  805. }
  806. }
  807. void CommunicationManager::parseTaskEndMessage(QString messageString)
  808. {
  809. QStringList messageParts = messageString.split(COM_MSG_SEPARATOR);
  810. if (messageParts.count() == 3)
  811. {
  812. QString taskIdString = messageParts.at(1);
  813. QString timestampString = messageParts.at(2);
  814. int taskId;
  815. qlonglong timestamp;
  816. bool ok = false;
  817. taskId = taskIdString.toInt(&ok);
  818. if (ok == false)
  819. {
  820. emit protocolError(
  821. "Bogus TASK END message received in LOOP (" + messageString
  822. + ")");
  823. return;
  824. }
  825. timestamp = timestampString.toLongLong(&ok);
  826. if (ok == false)
  827. {
  828. emit protocolError(
  829. "Bogus TASK END message received in LOOP (" + messageString
  830. + ")");
  831. return;
  832. }
  833. emit notifyTaskEndUpdate(taskId, timestamp);
  834. qDebug()
  835. << "CommunicationManager : "
  836. "TASK END message successfully parsed in LOOP ("
  837. << messageString + ")";
  838. }
  839. else
  840. {
  841. emit protocolError(
  842. "Bogus TASK END message received in LOOP (" + messageString
  843. + ")");
  844. }
  845. }
  846. void CommunicationManager::parseDataUpdateMessage(QString messageString)
  847. {
  848. QStringList messageParts = messageString.split(COM_MSG_SEPARATOR);
  849. if (messageParts.count() == 4)
  850. {
  851. QString dataIdString = messageParts.at(1);
  852. QString timestampString = messageParts.at(3);
  853. QString dataValueString = messageParts.at(2);
  854. int dataId;
  855. qlonglong timestamp;
  856. bool ok = false;
  857. dataId = dataIdString.toInt(&ok);
  858. if (ok == false || (dataDescriptionFromId(dataId) == 0))
  859. {
  860. emit protocolError(
  861. "Bogus UPDATE message received in LOOP (" + messageString
  862. + ")");
  863. return;
  864. }
  865. timestamp = timestampString.toLongLong(&ok);
  866. if (ok == false)
  867. {
  868. emit protocolError(
  869. "Bogus UPDATE message received in LOOP (" + messageString
  870. + ")");
  871. return;
  872. }
  873. switch (dataDescriptionFromId(dataId)->type)
  874. {
  875. case DATA_TYPE_BOOL:
  876. {
  877. bool dataVal;
  878. if (dataValueString.compare("0") == 0)
  879. {
  880. dataVal = false;
  881. }
  882. else if (dataValueString.compare("1") == 0)
  883. {
  884. dataVal = true;
  885. }
  886. else
  887. {
  888. emit protocolError(
  889. "Bogus UPDATE message received in LOOP ("
  890. + messageString + ")");
  891. return;
  892. }
  893. emit notifyDataUpdate(dataId, dataVal, timestamp);
  894. break;
  895. }
  896. case DATA_TYPE_INT:
  897. {
  898. int dataVal = dataValueString.toInt(&ok);
  899. if (ok == false)
  900. {
  901. emit protocolError(
  902. "Bogus UPDATE message received in LOOP ("
  903. + messageString + ")");
  904. return;
  905. }
  906. emit notifyDataUpdate(dataId, dataVal, timestamp);
  907. break;
  908. }
  909. case DATA_TYPE_FLOAT:
  910. {
  911. double dataVal = dataValueString.toDouble(&ok);
  912. if (ok == false)
  913. {
  914. emit protocolError(
  915. "Bogus UPDATE message received in LOOP ("
  916. + messageString + ")");
  917. return;
  918. }
  919. emit notifyDataUpdate(dataId, dataVal, timestamp);
  920. break;
  921. }
  922. default:
  923. emit protocolError(
  924. "Bogus UPDATE message received in LOOP (" + messageString
  925. + ")");
  926. }
  927. qDebug()
  928. << "CommunicationManager : "
  929. "UPDATE message successfully parsed in LOOP ("
  930. << messageString + ")";
  931. }
  932. else
  933. {
  934. emit
  935. protocolError(
  936. "Bogus UPDATE message received in LOOP ("
  937. + messageString + ")");
  938. }
  939. }
  940. void CommunicationManager::parseParamNotificationMessage(QString messageString)
  941. {
  942. QStringList messageParts = messageString.split(COM_MSG_SEPARATOR);
  943. if (messageParts.count() != 4)
  944. {
  945. emit
  946. protocolError(
  947. "Bogus SET message received (" + messageString + ")");
  948. return;
  949. }
  950. QString paramIdString = messageParts.at(1);
  951. QString paramValueString = messageParts.at(2);
  952. QString timestampString = messageParts.at(3);
  953. int paramId;
  954. qlonglong timestamp;
  955. bool ok = false;
  956. paramId = paramIdString.toInt(&ok);
  957. if (ok == false || (paramDescriptionFromId(paramId) == 0))
  958. {
  959. emit
  960. protocolError(
  961. "Bogus SET message received (" + messageString + ")");
  962. return;
  963. }
  964. timestamp = timestampString.toLongLong(&ok);
  965. if (ok == false)
  966. {
  967. emit
  968. protocolError(
  969. "Bogus SET message received (" + messageString + ")");
  970. return;
  971. }
  972. switch (paramDescriptionFromId(paramId)->type)
  973. {
  974. case PARAM_TYPE_BOOL:
  975. {
  976. bool paramVal;
  977. if (paramValueString.compare("0") == 0)
  978. {
  979. paramVal = false;
  980. }
  981. else if (paramValueString.compare("1") == 0)
  982. {
  983. paramVal = true;
  984. }
  985. else
  986. {
  987. emit protocolError(
  988. "Bogus SET message received (" + messageString + ")");
  989. return;
  990. }
  991. emit notifyParamUpdate(paramId, paramVal, timestamp);
  992. break;
  993. }
  994. case PARAM_TYPE_INT:
  995. {
  996. int paramVal = paramValueString.toInt(&ok);
  997. if (ok == false)
  998. {
  999. emit protocolError(
  1000. "Bogus SET message received (" + messageString + ")");
  1001. return;
  1002. }
  1003. emit notifyParamUpdate(paramId, paramVal, timestamp);
  1004. break;
  1005. }
  1006. case PARAM_TYPE_FLOAT:
  1007. {
  1008. double paramVal = paramValueString.toDouble(&ok);
  1009. if (ok == false)
  1010. {
  1011. emit protocolError(
  1012. "Bogus SET message received (" + messageString + ")");
  1013. return;
  1014. }
  1015. emit notifyParamUpdate(paramId, paramVal, timestamp);
  1016. break;
  1017. }
  1018. case PARAM_TYPE_ENUM:
  1019. {
  1020. int paramVal = paramValueString.toInt(&ok);
  1021. if (ok == false)
  1022. {
  1023. emit protocolError(
  1024. "Bogus SET message received (" + messageString + ")");
  1025. return;
  1026. }
  1027. emit notifyParamUpdate(paramId, paramVal, timestamp);
  1028. break;
  1029. }
  1030. default:
  1031. emit
  1032. protocolError(
  1033. "Bogus SET message received (" + messageString + ")");
  1034. }
  1035. qDebug() << "CommunicationManager : SET successfully parsed in LOOP ("
  1036. << messageString + ")";
  1037. }
  1038. void CommunicationManager::parseDebugEnabledMessage(QString messageString)
  1039. {
  1040. QStringList messageParts = messageString.split(COM_MSG_SEPARATOR);
  1041. if (messageParts.count() != 2)
  1042. {
  1043. emit protocolError(
  1044. "Bogus DEBUG message received (" + messageString + ")");
  1045. return;
  1046. }
  1047. QString debugEnabledString = messageParts.at(1);
  1048. if (debugEnabledString.compare(_inMessageStrings.key(COM_MSG_IN_DEBUG_ON))
  1049. == 0)
  1050. {
  1051. qDebug() << "CommunicationManager : DEBUG ON received ("
  1052. << messageString + ")";
  1053. emit notifyDebugEnabled(true);
  1054. }
  1055. else if (debugEnabledString.compare(
  1056. _inMessageStrings.key(COM_MSG_IN_DEBUG_OFF)) == 0)
  1057. {
  1058. qDebug() << "CommunicationManager : DEBUG OFF received ("
  1059. << messageString + ")";
  1060. emit notifyDebugEnabled(false);
  1061. }
  1062. else
  1063. {
  1064. emit protocolError(
  1065. "Bogus DEBUG message received (" + messageString + ")");
  1066. }
  1067. }
  1068. void CommunicationManager::parseDebugMessageMessage(QString messageString)
  1069. {
  1070. QStringList messageParts = messageString.split(COM_MSG_SEPARATOR);
  1071. if (messageParts.count() != 2)
  1072. {
  1073. emit protocolError(
  1074. "Bogus DEBUG message received (" + messageString + ")");
  1075. return;
  1076. }
  1077. QString debugMessageString = messageParts.at(1);
  1078. emit notifyDebugMessage(debugMessageString);
  1079. qDebug() << "CommunicationManager : DEBUG MESSAGE received ("
  1080. << messageString + ")";
  1081. }
  1082. void CommunicationManager::parseDebugLockMessage(QString messageString)
  1083. {
  1084. QStringList messageParts = messageString.split(COM_MSG_SEPARATOR);
  1085. if (messageParts.count() != 2)
  1086. {
  1087. emit protocolError(
  1088. "Bogus DEBUG message received (" + messageString + ")");
  1089. return;
  1090. }
  1091. QString lockMessageString = messageParts.at(1);
  1092. emit notifyDebugLock(lockMessageString);
  1093. qDebug() << "CommunicationManager : DEBUG LOCK received (" << messageString
  1094. + ")";
  1095. }
  1096. /* -------------------------------------------------------------------------- */
  1097. /* Send messages */
  1098. /* -------------------------------------------------------------------------- */
  1099. void CommunicationManager::sendMessage(QString messageString)
  1100. {
  1101. messageString.append(COM_MSG_ENDL);
  1102. write(messageString.toAscii());
  1103. }
  1104. void CommunicationManager::sendGoMessage()
  1105. {
  1106. sendMessage( buildGoMessage());
  1107. }
  1108. void CommunicationManager::sendDataEnableMessage(int dataId)
  1109. {
  1110. sendMessage(buildDataEnableMessage(dataId));
  1111. }
  1112. void CommunicationManager::sendDataDisableMessage(int dataId)
  1113. {
  1114. sendMessage(buildDataDisableMessage(dataId));
  1115. }
  1116. void CommunicationManager::sendParamSetMessage(int paramId, bool paramValue)
  1117. {
  1118. sendMessage(buildParamSetMessage(paramId, paramValue));
  1119. }
  1120. void CommunicationManager::sendParamSetMessage(int paramId, int paramValue)
  1121. {
  1122. sendMessage(buildParamSetMessage(paramId, paramValue));
  1123. }
  1124. void CommunicationManager::sendParamSetMessage(int paramId, double paramValue)
  1125. {
  1126. sendMessage(buildParamSetMessage(paramId, paramValue));
  1127. }
  1128. void CommunicationManager::sendDebugEnabledMessage(bool enabled)
  1129. {
  1130. sendMessage(buildDebugEnabledMessage(enabled));
  1131. }
  1132. void CommunicationManager::sendStepMessage()
  1133. {
  1134. sendMessage( buildStepMessage());
  1135. }
  1136. /* -------------------------------------------------------------------------- */
  1137. /* Getters */
  1138. /* -------------------------------------------------------------------------- */
  1139. CommunicationState CommunicationManager::state() const
  1140. {
  1141. return _state;
  1142. }
  1143. bool CommunicationManager::isInitCompleted() const
  1144. {
  1145. return (_initServerInfoCompleted && _initDataCompleted
  1146. && _initParamsCompleted && _initDevCompleted);
  1147. }
  1148. /* -------------------------------------------------------------------------- */
  1149. /* Build messages */
  1150. /* -------------------------------------------------------------------------- */
  1151. QString CommunicationManager::buildGoMessage()
  1152. {
  1153. QString messageString = _outMessageStrings.value(COM_MSG_OUT_GO);
  1154. return messageString;
  1155. }
  1156. QString CommunicationManager::buildDataEnableMessage(int dataId)
  1157. {
  1158. QString head = _outMessageStrings.value(COM_MSG_OUT_ENABLE);
  1159. QString dataIdString = QString::number(dataId);
  1160. QString messageString = head.append(COM_MSG_SEPARATOR).append(dataIdString);
  1161. return messageString;
  1162. }
  1163. QString CommunicationManager::buildDataDisableMessage(int dataId)
  1164. {
  1165. QString head = _outMessageStrings.value(COM_MSG_OUT_DISABLE);
  1166. QString dataIdString = QString::number(dataId);
  1167. QString messageString = head.append(COM_MSG_SEPARATOR).append(dataIdString);
  1168. return messageString;
  1169. }
  1170. QString CommunicationManager::buildParamSetMessage(int paramId, bool paramValue)
  1171. {
  1172. QString head = _outMessageStrings.value(COM_MSG_OUT_SET);
  1173. QString paramIdString = QString::number(paramId);
  1174. QString paramValueString = QString::number(paramValue ? 1 : 0);
  1175. QString messageString =
  1176. head.append(COM_MSG_SEPARATOR).append(paramIdString).append(
  1177. COM_MSG_SEPARATOR) .append(paramValueString);
  1178. return messageString;
  1179. }
  1180. QString CommunicationManager::buildParamSetMessage(int paramId, int paramValue)
  1181. {
  1182. QString head = _outMessageStrings.value(COM_MSG_OUT_SET);
  1183. QString paramIdString = QString::number(paramId);
  1184. QString paramValueString = QString::number(paramValue);
  1185. QString messageString =
  1186. head.append(COM_MSG_SEPARATOR).append(paramIdString).append(
  1187. COM_MSG_SEPARATOR) .append(paramValueString);
  1188. return messageString;
  1189. }
  1190. QString CommunicationManager::buildParamSetMessage(int paramId,
  1191. double paramValue)
  1192. {
  1193. QString head = _outMessageStrings.value(COM_MSG_OUT_SET);
  1194. QString paramIdString = QString::number(paramId);
  1195. QString paramValueString = QString::number(paramValue);
  1196. QString messageString =
  1197. head.append(COM_MSG_SEPARATOR).append(paramIdString).append(
  1198. COM_MSG_SEPARATOR) .append(paramValueString);
  1199. return messageString;
  1200. }
  1201. QString CommunicationManager::buildDebugEnabledMessage(bool enabled)
  1202. {
  1203. QString head = _outMessageStrings.value(COM_MSG_OUT_DEBUG);
  1204. QString debugEnabledString = (enabled ? _outMessageStrings.value(
  1205. COM_MSG_OUT_DEBUG_ON) : _outMessageStrings.value(
  1206. COM_MSG_OUT_DEBUG_OFF));
  1207. QString messageString = head.append(COM_MSG_SEPARATOR).append(
  1208. debugEnabledString);
  1209. return messageString;
  1210. }
  1211. QString CommunicationManager::buildStepMessage()
  1212. {
  1213. QString messageString = _outMessageStrings.value(COM_MSG_OUT_DEBUG_STEP);
  1214. return messageString;
  1215. }
  1216. DataDescription *CommunicationManager::dataDescriptionFromId(int dataId) const
  1217. {
  1218. for (int i = 0; i < _dataDescriptions->count(); i++)
  1219. {
  1220. if (_dataDescriptions->at(i)->id == dataId)
  1221. return _dataDescriptions->at(i);
  1222. }
  1223. return 0;
  1224. }
  1225. ParamDescription
  1226. *CommunicationManager::paramDescriptionFromId(int paramId) const
  1227. {
  1228. for (int i = 0; i < _paramDescriptions->count(); i++)
  1229. {
  1230. if (_paramDescriptions->at(i)->id == paramId)
  1231. return _paramDescriptions->at(i);
  1232. }
  1233. return 0;
  1234. }
  1235. void CommunicationManager::clearDescriptions()
  1236. {
  1237. _dataDescriptions->clear();
  1238. _paramDescriptions->clear();
  1239. }
  1240. /* -------------------------------------------------------------------------- */
  1241. /* Init message strings */
  1242. /* -------------------------------------------------------------------------- */
  1243. void CommunicationManager::initInMessageStrings()
  1244. {
  1245. // Types
  1246. _inMessageStrings.insert("BOOL", COM_MSG_IN_TYPE_BOOL);
  1247. _inMessageStrings.insert("INT", COM_MSG_IN_TYPE_INT);
  1248. _inMessageStrings.insert("FLOAT", COM_MSG_IN_TYPE_FLOAT);
  1249. _inMessageStrings.insert("ENUM", COM_MSG_IN_TYPE_ENUM);
  1250. _typeMessageStrings.insert("BOOL");
  1251. _typeMessageStrings.insert("INT");
  1252. _typeMessageStrings.insert("FLOAT");
  1253. _typeMessageStrings.insert("ENUM");
  1254. // Init server ID
  1255. _inMessageStrings.insert("SERVERINFO", COM_MSG_IN_SERVERINFO_BEGIN);
  1256. _inMessageStrings.insert("/SERVERINFO", COM_MSG_IN_SERVERINFO_END);
  1257. _beginEndMessageStrings.insert("SERVERINFO");
  1258. _beginEndMessageStrings.insert("/SERVERINFO");
  1259. // Init data
  1260. _inMessageStrings.insert("DATA", COM_MSG_IN_DATA_BEGIN);
  1261. _inMessageStrings.insert("/DATA", COM_MSG_IN_DATA_END);
  1262. _beginEndMessageStrings.insert("DATA");
  1263. _beginEndMessageStrings.insert("/DATA");
  1264. // Init parameters
  1265. _inMessageStrings.insert("PARAMS", COM_MSG_IN_PARAMS_BEGIN);
  1266. _inMessageStrings.insert("/PARAMS", COM_MSG_IN_PARAMS_END);
  1267. _beginEndMessageStrings.insert("PARAMS");
  1268. _beginEndMessageStrings.insert("/PARAMS");
  1269. // Init devices
  1270. _inMessageStrings.insert("DEV", COM_MSG_IN_DEV_BEGIN);
  1271. _inMessageStrings.insert("/DEV", COM_MSG_IN_DEV_END);
  1272. _inMessageStrings.insert("CPU", COM_MSG_IN_DEV_CPU);
  1273. _inMessageStrings.insert("GPU", COM_MSG_IN_DEV_CUDA);
  1274. _inMessageStrings.insert("OPENCL", COM_MSG_IN_DEV_OPENCL);
  1275. _beginEndMessageStrings.insert("DEV");
  1276. _beginEndMessageStrings.insert("/DEV");
  1277. // Server ready
  1278. _inMessageStrings.insert("READY", COM_MSG_IN_READY);
  1279. // Widget status
  1280. _inMessageStrings.insert("SET", COM_MSG_IN_SET);
  1281. _widgetStatusChangeMessageStrings.insert("SET");
  1282. // Loop messages
  1283. // Complete versions
  1284. _inMessageStrings.insert("PREV", COM_MSG_IN_PREV);
  1285. _inMessageStrings.insert("START", COM_MSG_IN_START);
  1286. _inMessageStrings.insert("END", COM_MSG_IN_END);
  1287. _inMessageStrings.insert("UPDATE", COM_MSG_IN_UPDATE);
  1288. // Short versions
  1289. _inMessageStrings.insert("P", COM_MSG_IN_SHORT_PREV);
  1290. _inMessageStrings.insert("S", COM_MSG_IN_SHORT_START);
  1291. _inMessageStrings.insert("E", COM_MSG_IN_SHORT_END);
  1292. _inMessageStrings.insert("U", COM_MSG_IN_SHORT_UPDATE);
  1293. // Complete versions
  1294. _loopMessageStrings.insert("PREV");
  1295. _loopMessageStrings.insert("START");
  1296. _loopMessageStrings.insert("END");
  1297. _loopMessageStrings.insert("UPDATE");
  1298. // Short versions
  1299. _loopMessageStrings.insert("P");
  1300. _loopMessageStrings.insert("S");
  1301. _loopMessageStrings.insert("E");
  1302. _loopMessageStrings.insert("U");
  1303. // Debug messages
  1304. _inMessageStrings.insert("DEBUG", COM_MSG_IN_DEBUG);
  1305. _inMessageStrings.insert("ON", COM_MSG_IN_DEBUG_ON);
  1306. _inMessageStrings.insert("OFF", COM_MSG_IN_DEBUG_OFF);
  1307. _inMessageStrings.insert("MESSAGE", COM_MSG_IN_DEBUG_MESSAGE);
  1308. _inMessageStrings.insert("LOCK", COM_MSG_IN_DEBUG_LOCK);
  1309. _debugMessageStrings.insert("DEBUG");
  1310. _debugMessageStrings.insert("MESSAGE");
  1311. _debugMessageStrings.insert("LOCK");
  1312. }
  1313. void CommunicationManager::initOutMessageStrings()
  1314. {
  1315. // Launch session on server
  1316. _outMessageStrings.insert(COM_MSG_OUT_GO, "GO");
  1317. // Widget status change
  1318. _outMessageStrings.insert(COM_MSG_OUT_ENABLE, "ENABLE");
  1319. _outMessageStrings.insert(COM_MSG_OUT_DISABLE, "DISABLE");
  1320. _outMessageStrings.insert(COM_MSG_OUT_SET, "SET");
  1321. // Debug mode
  1322. _outMessageStrings.insert(COM_MSG_OUT_DEBUG, "DEBUG");
  1323. _outMessageStrings.insert(COM_MSG_OUT_DEBUG_ON, "ON");
  1324. _outMessageStrings.insert(COM_MSG_OUT_DEBUG_OFF, "OFF");
  1325. _outMessageStrings.insert(COM_MSG_OUT_DEBUG_STEP, "STEP");
  1326. }