MythTV  master
lcdserver.cpp
Go to the documentation of this file.
1 /*
2  lcdserver.cpp
3 
4  Methods for the core lcdserver object
5 */
6 
7 
8 /*
9  Command list
10 
11  SWITCH_TO_TIME
12  SWITCH_TO_MUSIC "Artist" "Album" "Track"
13  SWITCH_TO_VOLUME "AppName"
14  SWITCH_TO_CHANNEL "ChanNum" "Title" "SubTitle"
15  SWITCH_TO_NOTHING
16  SWITCH_TO_MENU AppName popup ["Text" Checked Selected Scroll Indent ...]
17  AppName is a string
18  Popup can be TRUE or FALSE
19  Text is a string
20  Checked can be CHECKED, UNCHECKED, NOTCHECKABLE
21  Selected can be TRUE or FALSE
22  Scroll can be TRUE or FALSE
23  Indent is an integer
24  ... repeat as required
25 
26  SWITCH_TO_GENERIC RowNo Align "Text" "Screen" Scrollable ...
27  RowNo is an integer
28  Align can be ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTERED
29  Scrollable can be TRUE or FALSE
30  ... repeat as required
31 
32  SET_VOLUME_LEVEL <level>
33  level is a float between 0.0 and 1.0
34 
35  SET_CHANNEL_PROGRESS <progress>
36  progress is a float between 0.0 and 1.0
37 
38  SET_MUSIC_PROGRESS "Time" <progress>
39  time is a string
40  progress is a float between 0.0 and 1.0
41 
42  SET_MUSIC_PLAYER_PROP <field> <val>
43  field is a string, currently SHUFFLE or REPEAT
44  val depends on field, currently integer
45 
46  SET_GENERIC_PROGRESS <busy> <progress>
47  busy is 0 for busy spinner, 0 for normal progess bar
48  progress is a float between 0.0 and 1.0
49 
50  UPDATE_LEDS
51 
52  STOP_ALL
53 
54  RESET
55 
56 */
57 
58 #include <cstdlib>
59 
60 #include <QCoreApplication>
61 #include <QDir>
62 #include <QList>
63 #include <QRegExp>
64 #include <QStringList>
65 #include <utility>
66 
67 #include "mythdate.h"
68 #include "mythcontext.h"
69 #include "lcddevice.h"
70 
71 #include "lcdserver.h"
72 
73 int debug_level = 0;
74 
75 #define LOC QString("LCDServer: ")
76 #define LOC_WARN QString("LCDServer, Warning: ")
77 #define LOC_ERR QString("LCDServer, Error: ")
78 
79 LCDServer::LCDServer(int port, QString message, int messageTime)
80  : m_lcd(new LCDProcClient(this)),
81  m_serverPool(new ServerPool()),
82  m_lastSocket(nullptr)
83 {
84  if (!m_lcd->SetupLCD())
85  {
86  delete m_lcd;
87  m_lcd = nullptr;
88  }
89 
90  connect(m_serverPool, SIGNAL(newConnection(QTcpSocket*)),
91  this, SLOT(newConnection(QTcpSocket*)));
92 
93  if (!m_serverPool->listen(port))
94  {
95  LOG(VB_GENERAL, LOG_ERR, "There is probably a copy of mythlcdserver "
96  "already running. You can verify this by running: \n"
97  "'ps ax | grep mythlcdserver'");
98  delete m_serverPool;
99  return;
100  }
101 
102  if (m_lcd)
103  m_lcd->setStartupMessage(std::move(message), messageTime);
104 }
105 
106 void LCDServer::newConnection(QTcpSocket *socket)
107 {
108  connect(socket, SIGNAL(readyRead()),
109  this, SLOT( readSocket()));
110  connect(socket, SIGNAL(disconnected()),
111  this, SLOT( endConnection()));
112 
113  if (debug_level > 0)
114  LOG(VB_NETWORK, LOG_INFO, "LCDServer: new connection");
115 
116  if (m_lcd)
117  m_lcd->switchToTime();
118 }
119 
121 {
122  auto *socket = dynamic_cast<QTcpSocket*>(sender());
123  if (socket)
124  {
125  socket->close();
126  socket->deleteLater();
127  if (debug_level > 0)
128  LOG(VB_NETWORK, LOG_INFO, "LCDServer: close connection");
129  }
130 
131  if (m_lastSocket == socket)
132  m_lastSocket = nullptr;
133 }
134 
136 {
137  auto *socket = dynamic_cast<QTcpSocket*>(sender());
138  if (socket)
139  {
140  m_lastSocket = socket;
141 
142  while(socket->canReadLine())
143  {
144  QString incoming_data = socket->readLine();
145  incoming_data = incoming_data.replace( QRegExp("\n"), "" );
146  incoming_data = incoming_data.replace( QRegExp("\r"), "" );
147  incoming_data = incoming_data.simplified();
148  QStringList tokens = parseCommand(incoming_data);
149  parseTokens(tokens, socket);
150  }
151  }
152 }
153 
154 QStringList LCDServer::parseCommand(QString &command)
155 {
156  QStringList tokens;
157  QString s = "";
158  QChar c;
159  bool bInString = false;
160 
161  for (int x = 0; x < command.length(); x++)
162  {
163  c = command[x];
164  if (!bInString && c == '"')
165  bInString = true;
166  else if (bInString && c == '"')
167  bInString = false;
168  else if (!bInString && c == ' ')
169  {
170  tokens.append(s);
171  s = "";
172  }
173  else
174  s = s + c;
175  }
176 
177  tokens.append(s);
178 
179  return tokens;
180 }
181 
182 void LCDServer::parseTokens(const QStringList &tokens, QTcpSocket *socket)
183 {
184  //
185  // parse commands coming in from the socket
186  //
187 
188  if (tokens[0] == "HALT" ||
189  tokens[0] == "QUIT" ||
190  tokens[0] == "SHUTDOWN")
191  {
192  shutDown();
193  }
194  else if (tokens[0] == "HELLO")
195  {
196  sendConnected(socket);
197  }
198  else if (tokens[0] == "SWITCH_TO_TIME")
199  {
200  switchToTime(socket);
201  }
202  else if (tokens[0] == "SWITCH_TO_MUSIC")
203  {
204  switchToMusic(tokens, socket);
205  }
206  else if (tokens[0] == "SWITCH_TO_VOLUME")
207  {
208  switchToVolume(tokens, socket);
209  }
210  else if (tokens[0] == "SWITCH_TO_GENERIC")
211  {
212  switchToGeneric(tokens, socket);
213  }
214  else if (tokens[0] == "SWITCH_TO_MENU")
215  {
216  switchToMenu(tokens, socket);
217  }
218  else if (tokens[0] == "SWITCH_TO_CHANNEL")
219  {
220  switchToChannel(tokens, socket);
221  }
222  else if (tokens[0] == "SWITCH_TO_NOTHING")
223  {
224  switchToNothing(socket);
225  }
226  else if (tokens[0] == "SET_VOLUME_LEVEL")
227  {
228  setVolumeLevel(tokens, socket);
229  }
230  else if (tokens[0] == "SET_GENERIC_PROGRESS")
231  {
232  setGenericProgress(tokens, socket);
233  }
234  else if (tokens[0] == "SET_MUSIC_PROGRESS")
235  {
236  setMusicProgress(tokens, socket);
237  }
238  else if (tokens[0] == "SET_MUSIC_PLAYER_PROP")
239  {
240  setMusicProp(tokens, socket);
241  }
242  else if (tokens[0] == "SET_CHANNEL_PROGRESS")
243  {
244  setChannelProgress(tokens, socket);
245  }
246  else if (tokens[0] == "UPDATE_LEDS")
247  {
248  updateLEDs(tokens, socket);
249  }
250  else if (tokens[0] == "STOP_ALL")
251  {
252  if (m_lcd)
253  m_lcd->stopAll();
254  }
255  else if (tokens[0] == "RESET")
256  {
257  // reset lcd & reload settings
258  if (m_lcd)
259  m_lcd->reset();
260  }
261  else
262  {
263  QString did_not_parse = tokens.join(" ");
264 
265  if (debug_level > 0)
266  LOG(VB_GENERAL, LOG_ERR, "LCDServer::failed to parse this: " +
267  did_not_parse);
268 
269  sendMessage(socket, "HUH?");
270  }
271 }
272 
274 {
275  if (debug_level > 0)
276  LOG(VB_GENERAL, LOG_INFO, "LCDServer:: shuting down");
277 
278  m_serverPool->disconnect();
279  m_serverPool->close();
280  delete m_serverPool;
281  m_serverPool = nullptr;
282 
283  exit(0);
284 }
285 
286 void LCDServer::sendMessage(QTcpSocket *where, const QString &what)
287 {
288  QString message = what;
289  message.append("\n");
290  QByteArray tmp = message.toUtf8();
291  where->write(tmp.constData(), tmp.length());
292 }
293 
294 void LCDServer::sendKeyPress(const QString& key_pressed)
295 {
296  if (debug_level > 0)
297  LOG(VB_GENERAL, LOG_INFO, "LCDServer:: send key press: " + key_pressed);
298 
299  // send key press to last client that sent us a message
300  if (m_lastSocket)
301  sendMessage(m_lastSocket, "KEY " + key_pressed);
302 }
303 
304 void LCDServer::sendConnected(QTcpSocket *socket)
305 {
306  QString sWidth, sHeight;
307  int nWidth = 0, nHeight = 0;
308 
309  if (m_lcd)
310  {
311  nWidth = m_lcd->getLCDWidth();
312  nHeight = m_lcd->getLCDHeight();
313  }
314 
315  sWidth = sWidth.setNum(nWidth);
316  sHeight = sHeight.setNum(nHeight);
317 
318  sendMessage(socket, "CONNECTED " + sWidth + " " + sHeight);
319 }
320 
321 void LCDServer::switchToTime(QTcpSocket *socket)
322 {
323  if (debug_level > 0)
324  LOG(VB_GENERAL, LOG_INFO, "LCDServer:: SWITCH_TO_TIME");
325 
326  if (m_lcd)
327  m_lcd->switchToTime();
328 
329  sendMessage(socket, "OK");
330 }
331 
332 void LCDServer::switchToMusic(const QStringList &tokens, QTcpSocket *socket)
333 {
334  if (debug_level > 0)
335  LOG(VB_GENERAL, LOG_INFO, "LCDServer: SWITCH_TO_MUSIC");
336 
337  QString flat = tokens.join(" ");
338 
339  if (tokens.count() != 4)
340  {
341  LOG(VB_GENERAL, LOG_ERR,
342  "LCDServer: bad SWITCH_TO_MUSIC command: " + flat);
343  sendMessage(socket, "HUH?");
344  return;
345  }
346 
347  if (m_lcd)
348  m_lcd->switchToMusic(tokens[1], tokens[2], tokens[3]);
349 
350  sendMessage(socket, "OK");
351 }
352 
353 void LCDServer::switchToGeneric(const QStringList &tokens, QTcpSocket *socket)
354 {
355  if (debug_level > 0)
356  LOG(VB_GENERAL, LOG_INFO, "LCDServer: SWITCH_TO_GENERIC");
357 
358  QString flat = tokens.join(" ");
359 
360  if ((tokens.count() - 1) % 5 != 0)
361  {
362  LOG(VB_GENERAL, LOG_ERR,
363  "LCDServer: bad no. of args SWITCH_TO_GENERIC command: " + flat);
364  sendMessage(socket, "HUH?");
365  return;
366  }
367 
368  QList<LCDTextItem> items;
369 
370  for (int x = 1; x < tokens.count(); x += 5)
371  {
372  bool bOK = false;
373  int row = tokens[x].toInt(&bOK);
374  if (!bOK)
375  {
376  LOG(VB_GENERAL, LOG_ERR,
377  "LCDServer: bad row no. in SWITCH_TO_GENERIC "
378  "command: " + tokens[x]);
379  sendMessage(socket, "HUH?");
380  return;
381  }
382 
383  TEXT_ALIGNMENT align = ALIGN_LEFT;
384  if (tokens[x + 1] == "ALIGN_LEFT")
385  align = ALIGN_LEFT;
386  else if (tokens[x + 1] == "ALIGN_RIGHT")
387  align = ALIGN_RIGHT;
388  else if (tokens[x + 1] == "ALIGN_CENTERED")
389  align = ALIGN_CENTERED;
390  else
391  {
392  LOG(VB_GENERAL, LOG_ERR,
393  "LCDServer: bad align in SWITCH_TO_GENERIC command: " +
394  tokens[x + 1]);
395  sendMessage(socket, "HUH?");
396  return;
397  }
398 
399  QString text = tokens[x + 2];
400  QString screen = tokens[x + 3];
401  bool scrollable = false;
402  if (tokens[x + 4] == "TRUE")
403  scrollable = true;
404  else if (tokens[x + 4] == "FALSE")
405  scrollable = false;
406  else
407  {
408  LOG(VB_GENERAL, LOG_ERR,
409  "LCDServer: bad scrollable bool in SWITCH_TO_GENERIC "
410  "command: " + tokens[x + 4]);
411  sendMessage(socket, "HUH?");
412  return;
413  }
414 
415  items.append(LCDTextItem(row, align, text, screen, scrollable));
416  }
417 
418  if (m_lcd)
419  m_lcd->switchToGeneric(&items);
420 
421  sendMessage(socket, "OK");
422 }
423 
424 void LCDServer::switchToChannel(const QStringList &tokens, QTcpSocket *socket)
425 {
426  if (debug_level > 0)
427  LOG(VB_GENERAL, LOG_INFO, "LCDServer: SWITCH_TO_CHANNEL");
428 
429  QString flat = tokens.join(" ");
430 
431  if (tokens.count() != 4)
432  {
433  LOG(VB_GENERAL, LOG_ERR,
434  "LCDServer: bad SWITCH_TO_CHANNEL command: " + flat);
435  sendMessage(socket, "HUH?");
436  return;
437  }
438 
439  if (m_lcd)
440  m_lcd->switchToChannel(tokens[1], tokens[2], tokens[3]);
441 
442  sendMessage(socket, "OK");
443 }
444 
445 void LCDServer::switchToVolume(const QStringList &tokens, QTcpSocket *socket)
446 {
447  if (debug_level > 0)
448  LOG(VB_GENERAL, LOG_INFO, "LCDServer: SWITCH_TO_VOLUME");
449 
450  QString flat = tokens.join(" ");
451 
452  if (tokens.count() != 2)
453  {
454  LOG(VB_GENERAL, LOG_ERR,
455  "LCDServer: bad SWITCH_TO_VOLUME command: " + flat);
456  sendMessage(socket, "HUH?");
457  return;
458  }
459 
460  if (m_lcd)
461  m_lcd->switchToVolume(tokens[1]);
462 
463  sendMessage(socket, "OK");
464 }
465 
466 void LCDServer::switchToNothing(QTcpSocket *socket)
467 {
468  if (debug_level > 0)
469  LOG(VB_GENERAL, LOG_INFO, "LCDServer: SWITCH_TO_NOTHING");
470 
471  if (m_lcd)
473 
474  sendMessage(socket, "OK");
475 }
476 
477 void LCDServer::switchToMenu(const QStringList &tokens, QTcpSocket *socket)
478 {
479  if (debug_level > 0)
480  LOG(VB_GENERAL, LOG_INFO,
481  QString("LCDServer: SWITCH_TO_MENU: %1").arg(tokens.count()));
482 
483  QString flat = tokens.join(" ");
484 
485  if ((tokens.count() - 3) % 5 != 0)
486  {
487  LOG(VB_GENERAL, LOG_ERR,
488  "LCDServer: bad no. of args SWITCH_TO_MENU command: " + flat);
489  sendMessage(socket, "HUH?");
490  return;
491  }
492 
493  QString appName = tokens[1];
494 
495  bool bPopup = false;
496  if (tokens[2] == "TRUE")
497  bPopup = true;
498  else if (tokens[2] == "FALSE")
499  bPopup = false;
500  else
501  {
502  LOG(VB_GENERAL, LOG_ERR,
503  "LCDServer: bad popup bool in SWITCH_TO_MENU command: " +
504  tokens[2]);
505  sendMessage(socket, "HUH?");
506  return;
507  }
508 
509  QList<LCDMenuItem> items;
510 
511  for (int x = 3; x < tokens.count(); x += 5)
512  {
513  QString text = tokens[x];
514 
515  CHECKED_STATE checked = CHECKED;
516  if (tokens[x + 1] == "CHECKED")
517  checked = CHECKED;
518  else if (tokens[x + 1] == "UNCHECKED")
519  checked = UNCHECKED;
520  else if (tokens[x + 1] == "NOTCHECKABLE")
521  checked = NOTCHECKABLE;
522  else
523  {
524  LOG(VB_GENERAL, LOG_ERR,
525  "LCDServer: bad checked state in SWITCH_TO_MENU command: " +
526  tokens[x + 1]);
527  sendMessage(socket, "HUH?");
528  return;
529  }
530 
531  bool selected = false;
532  if (tokens[x + 2] == "TRUE")
533  selected = true;
534  else if (tokens[x + 2] == "FALSE")
535  selected = false;
536  else
537  {
538  LOG(VB_GENERAL, LOG_ERR,
539  "LCDServer: bad selected state in SWITCH_TO_MENU command: " +
540  tokens[x + 2]);
541  sendMessage(socket, "HUH?");
542  return;
543  }
544 
545  bool scrollable = false;
546  if (tokens[x + 3] == "TRUE")
547  scrollable = true;
548  else if (tokens[x + 3] == "FALSE")
549  scrollable = false;
550  else
551  {
552  LOG(VB_GENERAL, LOG_ERR,
553  "LCDServer: bad scrollable bool in SWITCH_TO_MENU command: " +
554  tokens[x + 3]);
555  sendMessage(socket, "HUH?");
556  return;
557  }
558 
559  bool bOK = false;
560  int indent = tokens[x + 4].toInt(&bOK);
561  if (!bOK)
562  {
563  LOG(VB_GENERAL, LOG_ERR,
564  "LCDServer: bad indent in SWITCH_TO_MENU command: " +
565  tokens[x + 4]);
566  sendMessage(socket, "HUH?");
567  return;
568  }
569 
570  items.append(LCDMenuItem(selected, checked, text, indent, scrollable));
571  }
572 
573  if (m_lcd)
574  m_lcd->switchToMenu(&items, appName, bPopup);
575 
576  sendMessage(socket, "OK");
577 }
578 
579 void LCDServer::setChannelProgress(const QStringList &tokens, QTcpSocket *socket)
580 {
581  if (debug_level > 0)
582  LOG(VB_GENERAL, LOG_INFO, "LCDServer: SET_CHANNEL_PROGRESS");
583 
584  QString flat = tokens.join(" ");
585 
586  if (tokens.count() != 3)
587  {
588  LOG(VB_GENERAL, LOG_ERR,
589  "LCDServer: bad SET_CHANNEL_PROGRESS command: " + flat);
590  sendMessage(socket, "HUH?");
591  return;
592  }
593 
594  bool bOK = false;
595  float progress = tokens[2].toFloat(&bOK);
596  if (!bOK)
597  {
598  LOG(VB_GENERAL, LOG_ERR,
599  QString("LCDServer: bad float value in SET_CHANNEL_PROGRESS "
600  "command: %1").arg(tokens[2]));
601  sendMessage(socket, "HUH?");
602  return;
603  }
604 
605  if (m_lcd)
606  m_lcd->setChannelProgress(tokens[1], progress);
607 
608  sendMessage(socket, "OK");
609 }
610 
611 void LCDServer::setGenericProgress(const QStringList &tokens, QTcpSocket *socket)
612 {
613  if (debug_level > 0)
614  LOG(VB_GENERAL, LOG_INFO, "LCDServer: SET_GENERIC_PROGRESS");
615 
616  QString flat = tokens.join(" ");
617 
618  if (tokens.count() != 3)
619  {
620  LOG(VB_GENERAL, LOG_ERR,
621  "LCDServer: bad SET_GENERIC_PROGRESS command: " + flat);
622  sendMessage(socket, "HUH?");
623  return;
624  }
625 
626  bool bOK = false;
627  bool busy = tokens[1].toInt(&bOK) != 0;
628  if (!bOK)
629  {
630  LOG(VB_GENERAL, LOG_ERR,
631  QString("LCDServer: bad bool value in SET_GENERIC_PROGRESS "
632  "command: %1 %2").arg(tokens[1]).arg(tokens[2]));
633  sendMessage(socket, "HUH?");
634  return;
635  }
636  float progress = tokens[2].toFloat(&bOK);
637  if (!bOK)
638  {
639  LOG(VB_GENERAL, LOG_ERR,
640  QString("LCDServer: bad float value in SET_GENERIC_PROGRESS "
641  "command: %1").arg(tokens[2]));
642  sendMessage(socket, "HUH?");
643  return;
644  }
645 
646  if (m_lcd)
648 
649  sendMessage(socket, "OK");
650 }
651 
652 void LCDServer::setMusicProgress(const QStringList &tokens, QTcpSocket *socket)
653 {
654  if (debug_level > 0)
655  LOG(VB_GENERAL, LOG_INFO, "LCDServer: SET_MUSIC_PROGRESS");
656 
657  QString flat = tokens.join(" ");
658 
659  if (tokens.count() != 3)
660  {
661  LOG(VB_GENERAL, LOG_ERR,
662  "LCDServer: bad SET_MUSIC_PROGRESS command: " + flat);
663  sendMessage(socket, "HUH?");
664  return;
665  }
666 
667  bool bOK = false;
668  float progress = tokens[2].toFloat(&bOK);
669  if (!bOK)
670  {
671  LOG(VB_GENERAL, LOG_ERR,
672  "LCDServer: bad float value in SET_MUSIC_PROGRESS command: " +
673  tokens[2]);
674  sendMessage(socket, "HUH?");
675  return;
676  }
677 
678  if (m_lcd)
679  m_lcd->setMusicProgress(tokens[1], progress);
680 
681  sendMessage(socket, "OK");
682 }
683 
684 void LCDServer::setMusicProp(const QStringList &tokens, QTcpSocket *socket)
685 {
686  if (debug_level > 0)
687  LOG(VB_GENERAL, LOG_INFO, "LCDServer: SET_MUSIC_PROP");
688 
689  QString flat = tokens.join(" ");
690 
691  if (tokens.count() < 3)
692  {
693  LOG(VB_GENERAL, LOG_ERR,
694  "LCDServer: bad SET_MUSIC_PROP command: " + flat);
695  sendMessage(socket, "HUH?");
696  return;
697  }
698 
699  if (tokens[1] == "SHUFFLE")
700  {
701  if (tokens.count () != 3)
702  {
703  LOG(VB_GENERAL, LOG_ERR,
704  "LCDServer: missing argument for SET_MUSIC_PROP SHUFFLE "
705  "command: " + flat);
706  sendMessage(socket, "HUH?");
707  return;
708  }
709  bool bOk = false;
710  int state = tokens[2].toInt (&bOk);
711  if (!bOk)
712  {
713  LOG(VB_GENERAL, LOG_ERR,
714  "LCDServer: bad argument for SET_MUSIC_PROP SHUFFLE "
715  "command: " + tokens[2]);
716  sendMessage(socket, "HUH?");
717  return;
718  }
719  if (m_lcd)
720  m_lcd->setMusicShuffle (state);
721  }
722  else if (tokens[1] == "REPEAT")
723  {
724  if (tokens.count () != 3)
725  {
726  LOG(VB_GENERAL, LOG_ERR,
727  "LCDServer: missing argument for SET_MUSIC_PROP REPEAT "
728  "command: " + flat);
729  sendMessage(socket, "HUH?");
730  return;
731  }
732  bool bOk = false;
733  int state = tokens[2].toInt (&bOk);
734  if (!bOk)
735  {
736  LOG(VB_GENERAL, LOG_ERR,
737  "LCDServer: bad argument for SET_MUSIC_PROP REPEAT command: " +
738  tokens[2]);
739  sendMessage(socket, "HUH?");
740  return;
741  }
742  if (m_lcd)
743  m_lcd->setMusicRepeat (state);
744  }
745  else
746  {
747  LOG(VB_GENERAL, LOG_ERR,
748  "LCDServer: bad argument for SET_MUSIC_PROP command: " + tokens[1]);
749  sendMessage(socket, "HUH?");
750  return;
751  }
752 
753  sendMessage(socket, "OK");
754 }
755 
756 void LCDServer::setVolumeLevel(const QStringList &tokens, QTcpSocket *socket)
757 {
758  if (debug_level > 0)
759  LOG(VB_GENERAL, LOG_INFO, "LCDServer: SET_VOLUME_LEVEL");
760 
761  QString flat = tokens.join(" ");
762 
763  if (tokens.count() != 2)
764  {
765  LOG(VB_GENERAL, LOG_ERR,
766  "LCDServer: bad SET_VOLUME_LEVEL command: " + flat);
767  sendMessage(socket, "HUH?");
768  return;
769  }
770 
771  bool bOK = false;
772  float progress = tokens[1].toFloat(&bOK);
773  if (!bOK)
774  {
775  LOG(VB_GENERAL, LOG_ERR,
776  "LCDServer: bad float value in SET_VOLUME_LEVEL command: " +
777  tokens[1]);
778  sendMessage(socket, "HUH?");
779  return;
780  }
781 
782  if (m_lcd)
784 
785  sendMessage(socket, "OK");
786 }
787 
788 void LCDServer::updateLEDs(const QStringList &tokens, QTcpSocket *socket)
789 {
790  if (debug_level > 0)
791  LOG(VB_GENERAL, LOG_INFO, "LCDServer: UPDATE_LEDS");
792 
793  QString flat = tokens.join(" ");
794 
795  if (tokens.count() != 2)
796  {
797  LOG(VB_GENERAL, LOG_ERR, "LCDServer: bad UPDATE_LEDs command: " + flat);
798  sendMessage(socket, "HUH?");
799  return;
800  }
801 
802  bool bOK = false;
803  int mask = tokens[1].toInt(&bOK);
804  if (!bOK)
805  {
806  LOG(VB_GENERAL, LOG_ERR,
807  "LCDServer: bad mask in UPDATE_LEDS command: " + tokens[1]);
808  sendMessage(socket, "HUH?");
809  return;
810  }
811 
812  if (m_lcd)
813  m_lcd->updateLEDs(mask);
814 
815  sendMessage(socket, "OK");
816 }
static void sendMessage(QTcpSocket *where, const QString &what)
Definition: lcdserver.cpp:286
QTcpSocket * m_lastSocket
Definition: lcdserver.h:68
void switchToTime(QTcpSocket *socket)
Definition: lcdserver.cpp:321
bool listen(QList< QHostAddress > addrs, quint16 port, bool requireall=true, PoolServerType type=kTCPServer)
Definition: serverpool.cpp:380
void switchToChannel(const QStringList &tokens, QTcpSocket *socket)
Definition: lcdserver.cpp:424
CHECKED_STATE
Definition: lcddevice.h:13
void setMusicRepeat(int repeat)
void setChannelProgress(const QString &time, float value)
void switchToChannel(const QString &channum="", const QString &title="", const QString &subtitle="")
int getLCDWidth(void)
Definition: lcdprocclient.h:61
void switchToVolume(const QString &app_name)
LCDServer(int port, QString message, int messageTime)
Definition: lcdserver.cpp:79
void newConnection(QTcpSocket *socket)
Definition: lcdserver.cpp:106
int debug_level
Definition: lcdserver.cpp:73
static QStringList parseCommand(QString &command)
Definition: lcdserver.cpp:154
void setChannelProgress(const QStringList &tokens, QTcpSocket *socket)
Definition: lcdserver.cpp:579
static guint32 * tmp
Definition: goom_core.c:35
void setMusicProp(const QStringList &tokens, QTcpSocket *socket)
Definition: lcdserver.cpp:684
void readSocket()
Definition: lcdserver.cpp:135
void switchToMenu(QList< LCDMenuItem > *menuItems, const QString &app_name="", bool popMenu=true)
void switchToMusic(const QStringList &tokens, QTcpSocket *socket)
Definition: lcdserver.cpp:332
ServerPool * m_serverPool
Definition: lcdserver.h:67
void setStartupMessage(QString msg, uint messagetime)
void switchToNothing(QTcpSocket *socket)
Definition: lcdserver.cpp:466
void switchToMenu(const QStringList &tokens, QTcpSocket *socket)
Definition: lcdserver.cpp:477
void switchToGeneric(QList< LCDTextItem > *textItems)
void setGenericProgress(bool busy, float value)
static QString indent(uint level)
void setGenericProgress(const QStringList &tokens, QTcpSocket *socket)
Definition: lcdserver.cpp:611
void stopAll(void)
LCDProcClient * m_lcd
Definition: lcdserver.h:66
Manages a collection of sockets listening on different ports.
Definition: serverpool.h:59
void setMusicProgress(const QStringList &tokens, QTcpSocket *socket)
Definition: lcdserver.cpp:652
int getLCDHeight(void)
Definition: lcdprocclient.h:62
void updateLEDs(int mask)
void setMusicProgress(QString time, float value)
void reset(void)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
void switchToVolume(const QStringList &tokens, QTcpSocket *socket)
Definition: lcdserver.cpp:445
void switchToMusic(const QString &artist, const QString &album, const QString &track)
void close(void)
Definition: serverpool.cpp:359
void setVolumeLevel(float value)
void switchToGeneric(const QStringList &tokens, QTcpSocket *socket)
Definition: lcdserver.cpp:353
void setMusicShuffle(int shuffle)
void sendConnected(QTcpSocket *socket)
Definition: lcdserver.cpp:304
bool SetupLCD(void)
TEXT_ALIGNMENT
Definition: lcddevice.h:53
void endConnection(void)
Definition: lcdserver.cpp:120
void updateLEDs(const QStringList &tokens, QTcpSocket *socket)
Definition: lcdserver.cpp:788
void shutDown()
Definition: lcdserver.cpp:273
void setVolumeLevel(const QStringList &tokens, QTcpSocket *socket)
Definition: lcdserver.cpp:756
void parseTokens(const QStringList &tokens, QTcpSocket *socket)
Definition: lcdserver.cpp:182
void sendKeyPress(const QString &key_pressed)
Definition: lcdserver.cpp:294