communicationmanager.cpp 48 KB

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