CPPMyth
Library to interoperate with MythTV server
mythprotomonitor.cpp
1 /*
2  * Copyright (C) 2014 Jean-Luc Barriere
3  *
4  * This Program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2, or (at your option)
7  * any later version.
8  *
9  * This Program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; see the file COPYING. If not, write to
16  * the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
17  * MA 02110-1301 USA
18  * http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21 
22 #include "mythprotomonitor.h"
23 #include "mythprotorecorder.h"
24 #include "../private/debug.h"
25 #include "../private/socket.h"
26 #include "../private/os/threads/mutex.h"
27 #include "../private/builtin.h"
28 
29 #include <limits>
30 #include <cstdio>
31 
32 using namespace Myth;
33 
38 
39 ProtoMonitor::ProtoMonitor(const std::string& server, unsigned port)
40 : ProtoBase(server, port)
41 , m_frontend(false)
42 {
43 }
44 
45 ProtoMonitor::ProtoMonitor(const std::string& server, unsigned port, bool frontend)
46 : ProtoBase(server, port)
47 , m_frontend(frontend)
48 {
49 }
50 
51 bool ProtoMonitor::Open()
52 {
53  bool ok = false;
54 
55  if (!OpenConnection(PROTO_MONITOR_RCVBUF))
56  return false;
57 
58  if (m_protoVersion >= 88)
59  ok = Announce88();
60  else
61  ok = Announce75();
62 
63  if (ok)
64  {
65  return true;
66  }
67  Close();
68  return false;
69 }
70 
71 void ProtoMonitor::Close()
72 {
73  ProtoBase::Close();
74  // Clean hanging and disable retry
75  m_tainted = m_hang = false;
76 }
77 
78 bool ProtoMonitor::IsOpen()
79 {
80  // Try reconnect
81  if (m_hang)
82  return ProtoMonitor::Open();
83  return ProtoBase::IsOpen();
84 }
85 
86 bool ProtoMonitor::Announce75()
87 {
88  OS::CLockGuard lock(*m_mutex);
89 
90  std::string cmd("ANN Monitor ");
91  cmd.append(m_socket->GetMyHostName()).append(" 0");
92  if (!SendCommand(cmd.c_str()))
93  return false;
94 
95  std::string field;
96  if (!ReadField(field) || !IsMessageOK(field))
97  goto out;
98  return true;
99 
100 out:
101  FlushMessage();
102  return false;
103 }
104 
105 bool ProtoMonitor::Announce88()
106 {
107  OS::CLockGuard lock(*m_mutex);
108 
109  std::string cmd((m_frontend ? "ANN Frontend " : "ANN Monitor "));
110  cmd.append(m_socket->GetMyHostName()).append(" 0");
111  if (!SendCommand(cmd.c_str()))
112  return false;
113 
114  std::string field;
115  if (!ReadField(field) || !IsMessageOK(field))
116  goto out;
117  return true;
118 
119 out:
120  FlushMessage();
121  return false;
122 }
123 
124 ProtoRecorderPtr ProtoMonitor::GetRecorderFromNum75(int rnum)
125 {
126  char buf[32];
127  std::string field;
128  ProtoRecorderPtr recorder;
129  std::string hostname;
130  uint16_t port;
131 
132  OS::CLockGuard lock(*m_mutex);
133  if (!IsOpen())
134  return recorder;
135  std::string cmd("GET_RECORDER_FROM_NUM");
136  cmd.append(PROTO_STR_SEPARATOR);
137  int32_to_string((int32_t)rnum, buf);
138  cmd.append(buf);
139 
140  if (!SendCommand(cmd.c_str()))
141  return recorder;
142 
143  if (!ReadField(hostname) || hostname == "nohost")
144  goto out;
145  if (!ReadField(field) || string_to_uint16(field.c_str(), &port))
146  goto out;
147  FlushMessage();
148  DBG(DBG_DEBUG, "%s: open recorder %d (%s:%u)\n", __FUNCTION__, (int)rnum, hostname.c_str(), (unsigned)port);
149  recorder.reset(new ProtoRecorder(rnum, hostname, port));
150  return recorder;
151 out:
152  DBG(DBG_ERROR, "%s: failed\n", __FUNCTION__);
153  FlushMessage();
154  return recorder;
155 }
156 
157 bool ProtoMonitor::QueryFreeSpaceSummary75(int64_t *total, int64_t *used)
158 {
159  std::string field;
160 
161  OS::CLockGuard lock(*m_mutex);
162  if (!IsOpen())
163  return false;
164  std::string cmd("QUERY_FREE_SPACE_SUMMARY");
165 
166  if (!SendCommand(cmd.c_str()))
167  return false;
168 
169  if (!ReadField(field) || string_to_int64(field.c_str(), total))
170  goto out;
171  if (!ReadField(field) || string_to_int64(field.c_str(), used))
172  goto out;
173  FlushMessage();
174  return true;
175 out:
176  DBG(DBG_ERROR, "%s: failed\n", __FUNCTION__);
177  FlushMessage();
178  return false;
179 }
180 
181 std::string ProtoMonitor::GetSetting75(const std::string& hostname, const std::string& setting)
182 {
183  std::string field;
184 
185  OS::CLockGuard lock(*m_mutex);
186  if (!IsOpen())
187  return field;
188  std::string cmd("QUERY_SETTING ");
189  cmd.append(hostname).append(" ").append(setting);
190 
191  if (!SendCommand(cmd.c_str()))
192  return field;
193 
194  if (!ReadField(field))
195  goto out;
196  FlushMessage();
197  return field;
198 out:
199  DBG(DBG_ERROR, "%s: failed\n", __FUNCTION__);
200  FlushMessage();
201  field.clear();
202  return field;
203 }
204 
205 bool ProtoMonitor::SetSetting75(const std::string& hostname, const std::string& setting, const std::string& value)
206 {
207  std::string field;
208 
209  OS::CLockGuard lock(*m_mutex);
210  if (!IsOpen())
211  return false;
212  std::string cmd("SET_SETTING ");
213  cmd.append(hostname).append(" ").append(setting).append(" ").append(value);
214 
215  if (!SendCommand(cmd.c_str()))
216  return false;
217 
218  if (!ReadField(field) || !IsMessageOK(field))
219  goto out;
220  FlushMessage();
221  return true;
222 out:
223  DBG(DBG_ERROR, "%s: failed\n", __FUNCTION__);
224  FlushMessage();
225  return false;
226 }
227 
228 bool ProtoMonitor::QueryGenpixmap75(const Program& program)
229 {
230  std::string field;
231 
232  OS::CLockGuard lock(*m_mutex);
233  if (!IsOpen())
234  return false;
235  std::string cmd("QUERY_GENPIXMAP2");
236  cmd.append(PROTO_STR_SEPARATOR).append("do_not_care").append(PROTO_STR_SEPARATOR);
237  MakeProgramInfo(program, field);
238  cmd.append(field);
239 
240  if (!SendCommand(cmd.c_str()))
241  return false;
242 
243  if (!ReadField(field) || !IsMessageOK(field))
244  goto out;
245  FlushMessage();
246  return true;
247 out:
248  DBG(DBG_ERROR, "%s: failed\n", __FUNCTION__);
249  FlushMessage();
250  return false;
251 }
252 
253 bool ProtoMonitor::DeleteRecording75(const Program& program, bool force, bool forget)
254 {
255  char buf[32];
256  std::string field;
257 
258  OS::CLockGuard lock(*m_mutex);
259  if (!IsOpen())
260  return false;
261  std::string cmd("DELETE_RECORDING ");
262  uint32_to_string(program.channel.chanId, buf);
263  cmd.append(buf).append(" ");
264  time_to_iso8601utc(program.recording.startTs, buf);
265  cmd.append(buf).append(" ");
266  if (force)
267  cmd.append("FORCE ");
268  else
269  cmd.append("NO_FORCE ");
270  if (forget)
271  cmd.append("FORGET");
272  else
273  cmd.append("NO_FORGET");
274 
275  if (!SendCommand(cmd.c_str()))
276  return false;
277 
278  if (!ReadField(field))
279  goto out;
280  DBG(DBG_DEBUG, "%s: succeeded (%s)\n", __FUNCTION__, program.fileName.c_str());
281  return true;
282  out:
283  DBG(DBG_ERROR, "%s: failed\n", __FUNCTION__);
284  FlushMessage();
285  return false;
286 }
287 
288 bool ProtoMonitor::UndeleteRecording75(const Program& program)
289 {
290  std::string field;
291 
292  OS::CLockGuard lock(*m_mutex);
293  if (!IsOpen())
294  return false;
295  std::string cmd("UNDELETE_RECORDING");
296  cmd.append(PROTO_STR_SEPARATOR);
297  MakeProgramInfo(program, field);
298  cmd.append(field);
299 
300  if (!SendCommand(cmd.c_str()))
301  return false;
302 
303  if (!ReadField(field) || field != "0")
304  goto out;
305  DBG(DBG_DEBUG, "%s: succeeded (%s)\n", __FUNCTION__, program.fileName.c_str());
306  return true;
307  out:
308  DBG(DBG_ERROR, "%s: failed\n", __FUNCTION__);
309  FlushMessage();
310  return false;
311 }
312 
313 bool ProtoMonitor::StopRecording75(const Program& program)
314 {
315  std::string field;
316  int32_t num;
317 
318  OS::CLockGuard lock(*m_mutex);
319  if (!IsOpen())
320  return false;
321  std::string cmd("STOP_RECORDING");
322  cmd.append(PROTO_STR_SEPARATOR);
323  MakeProgramInfo(program, field);
324  cmd.append(field);
325 
326  if (!SendCommand(cmd.c_str()))
327  return false;
328 
329  if (!ReadField(field) || string_to_int32(field.c_str(), &num) || num < 0)
330  goto out;
331  DBG(DBG_DEBUG, "%s: succeeded (%s)\n", __FUNCTION__, program.fileName.c_str());
332  return true;
333  out:
334  DBG(DBG_ERROR, "%s: failed\n", __FUNCTION__);
335  FlushMessage();
336  return false;
337 }
338 
339 bool ProtoMonitor::CancelNextRecording75(int rnum, bool cancel)
340 {
341  char buf[32];
342  std::string field;
343 
344  OS::CLockGuard lock(*m_mutex);
345  if (!IsOpen())
346  return false;
347  std::string cmd("QUERY_RECORDER ");
348  int32_to_string(rnum, buf);
349  cmd.append(buf).append(PROTO_STR_SEPARATOR);
350  cmd.append("CANCEL_NEXT_RECORDING").append(PROTO_STR_SEPARATOR);
351  cmd.append((cancel ? "1" : "0"));
352 
353  if (!SendCommand(cmd.c_str()))
354  return false;
355 
356  if (!ReadField(field) || !IsMessageOK(field))
357  goto out;
358  DBG(DBG_DEBUG, "%s: succeeded\n", __FUNCTION__);
359  return true;
360  out:
361  DBG(DBG_ERROR, "%s: failed\n", __FUNCTION__);
362  FlushMessage();
363  return false;
364 }
365 
366 StorageGroupFilePtr ProtoMonitor::QuerySGFile75(const std::string& hostname, const std::string& sgname, const std::string& filename)
367 {
368  std::string field;
369  int64_t tmpi;
370  StorageGroupFilePtr sgfile;
371 
372  OS::CLockGuard lock(*m_mutex);
373  if (!IsOpen())
374  return sgfile;
375  std::string cmd("QUERY_SG_FILEQUERY");
376  cmd.append(PROTO_STR_SEPARATOR);
377  cmd.append(hostname).append(PROTO_STR_SEPARATOR);
378  cmd.append(sgname).append(PROTO_STR_SEPARATOR);
379  cmd.append(filename);
380 
381  if (!SendCommand(cmd.c_str()))
382  return sgfile;
383  sgfile.reset(new StorageGroupFile());
384 
385  if (!ReadField(sgfile->fileName))
386  goto out;
387  if (!ReadField(field) || string_to_int64(field.c_str(), &tmpi))
388  goto out;
389  sgfile->lastModified = (time_t)tmpi;
390  if (!ReadField(field) || string_to_int64(field.c_str(), &(sgfile->size)))
391  goto out;
392  sgfile->hostName = hostname;
393  sgfile->storageGroup = sgname;
394 
395  DBG(DBG_DEBUG, "%s: succeeded (%s)\n", __FUNCTION__, sgfile->fileName.c_str());
396  return sgfile;
397  out:
398  DBG(DBG_ERROR, "%s: failed\n", __FUNCTION__);
399  FlushMessage();
400  sgfile.reset();
401  return sgfile;
402 }
403 
404 MarkListPtr ProtoMonitor::GetCutList75(const Program& program)
405 {
406  char buf[32];
407  std::string field;
408  int32_t nb;
409  MarkListPtr list(new MarkList);
410 
411  OS::CLockGuard lock(*m_mutex);
412  if (!IsOpen())
413  return list;
414  std::string cmd("QUERY_CUTLIST ");
415  uint32_to_string(program.channel.chanId, buf);
416  cmd.append(buf).append(" ");
417  int64_to_string(program.recording.startTs, buf);
418  cmd.append(buf);
419 
420  if (!SendCommand(cmd.c_str()))
421  return list;
422 
423  if (!ReadField(field) || string_to_int32(field.c_str(), &nb))
424  goto out;
425  if (nb > 0)
426  {
427  list->reserve(nb);
428  do
429  {
430  MarkPtr mark = MarkPtr(new Mark());
431  if (!ReadField(field) || string_to_int8(field.c_str(), (int8_t*)&(mark->markType)))
432  break;
433  if (!ReadField(field) || string_to_int64(field.c_str(), &(mark->markValue)))
434  break;
435  list->push_back(mark);
436  }
437  while (--nb > 0);
438  }
439  DBG(DBG_DEBUG, "%s: succeeded (%s)\n", __FUNCTION__, program.fileName.c_str());
440  return list;
441  out:
442  DBG(DBG_ERROR, "%s: failed\n", __FUNCTION__);
443  FlushMessage();
444  return list;
445 }
446 
447 MarkListPtr ProtoMonitor::GetCommBreakList75(const Program& program)
448 {
449  char buf[32];
450  std::string field;
451  int32_t nb;
452  MarkListPtr list(new MarkList);
453 
454  OS::CLockGuard lock(*m_mutex);
455  if (!IsOpen())
456  return list;
457  std::string cmd("QUERY_COMMBREAK ");
458  uint32_to_string(program.channel.chanId, buf);
459  cmd.append(buf).append(" ");
460  int64_to_string(program.recording.startTs, buf);
461  cmd.append(buf);
462 
463  if (!SendCommand(cmd.c_str()))
464  return list;
465 
466  if (!ReadField(field) || string_to_int32(field.c_str(), &nb))
467  goto out;
468  if (nb > 0)
469  {
470  list->reserve(nb);
471  do
472  {
473  MarkPtr mark = MarkPtr(new Mark());
474  if (!ReadField(field) || string_to_int8(field.c_str(), (int8_t*)&(mark->markType)))
475  break;
476  if (!ReadField(field) || string_to_int64(field.c_str(), &(mark->markValue)))
477  break;
478  list->push_back(mark);
479  }
480  while (--nb > 0);
481  }
482  DBG(DBG_DEBUG, "%s: succeeded (%s)\n", __FUNCTION__, program.fileName.c_str());
483  return list;
484  out:
485  DBG(DBG_ERROR, "%s: failed\n", __FUNCTION__);
486  FlushMessage();
487  return list;
488 }
489 
490 bool ProtoMonitor::BlockShutdown75()
491 {
492  std::string field;
493 
494  OS::CLockGuard lock(*m_mutex);
495  if (!IsOpen())
496  return false;
497  std::string cmd("BLOCK_SHUTDOWN");
498 
499  if (!SendCommand(cmd.c_str()))
500  return false;
501 
502  if (!ReadField(field) || !IsMessageOK(field))
503  goto out;
504  DBG(DBG_DEBUG, "%s: succeeded\n", __FUNCTION__);
505  return true;
506  out:
507  DBG(DBG_ERROR, "%s: failed\n", __FUNCTION__);
508  FlushMessage();
509  return false;
510 }
511 
512 bool ProtoMonitor::AllowShutdown75()
513 {
514  std::string field;
515 
516  OS::CLockGuard lock(*m_mutex);
517  if (!IsOpen())
518  return false;
519  std::string cmd("ALLOW_SHUTDOWN");
520 
521  if (!SendCommand(cmd.c_str()))
522  return false;
523 
524  if (!ReadField(field) || !IsMessageOK(field))
525  goto out;
526  DBG(DBG_DEBUG, "%s: succeeded\n", __FUNCTION__);
527  return true;
528  out:
529  DBG(DBG_ERROR, "%s: failed\n", __FUNCTION__);
530  FlushMessage();
531  return false;
532 }
533 
534 std::vector<int> ProtoMonitor::GetFreeCardIdList75()
535 {
536  std::string field;
537  std::vector<int> ids;
538  int32_t rnum;
539 
540  OS::CLockGuard lock(*m_mutex);
541  if (!IsOpen())
542  return ids;
543  std::string cmd("GET_FREE_RECORDER_LIST");
544 
545  if (!SendCommand(cmd.c_str()))
546  return ids;
547 
548  while (m_msgConsumed < m_msgLength)
549  {
550  if (!ReadField(field) || string_to_int32(field.c_str(), &rnum))
551  {
552  DBG(DBG_ERROR, "%s: failed\n", __FUNCTION__);
553  FlushMessage();
554  ids.clear();
555  return ids;
556  }
557  if (rnum > 0)
558  ids.push_back(rnum);
559  }
560  DBG(DBG_DEBUG, "%s: succeeded (%u)\n", __FUNCTION__, (unsigned)ids.size());
561  return ids;
562 }
563 
564 CardInputListPtr ProtoMonitor::GetFreeInputs75()
565 {
566  CardInputListPtr list = CardInputListPtr(new CardInputList());
567  std::vector<int> cardList = GetFreeCardIdList75();
568  for (std::vector<int>::const_iterator cardIt = cardList.begin(); cardIt != cardList.end(); ++cardIt)
569  {
570  bool succeeded = false;
571  char buf[32];
572  std::string field;
573 
574  OS::CLockGuard lock(*m_mutex);
575  if (!IsOpen())
576  break;
577  std::string cmd("QUERY_RECORDER ");
578  int32_to_string((int32_t)(*cardIt), buf);
579  cmd.append(buf);
580  cmd.append(PROTO_STR_SEPARATOR);
581  cmd.append("GET_FREE_INPUTS");
582 
583  if (!SendCommand(cmd.c_str()))
584  break;
585 
586  while (m_msgConsumed < m_msgLength)
587  {
588  CardInputPtr input(new CardInput());
589  if (!ReadField(input->inputName))
590  break;
591  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
592  break;
593  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
594  break;
595  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->cardId)))
596  break;
597  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
598  break;
599  if (!ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
600  break;
601  list->push_back(input);
602  succeeded = true;
603  }
604  FlushMessage();
605  if (!succeeded)
606  break;
607  }
608  return list;
609 }
610 
611 CardInputListPtr ProtoMonitor::GetFreeInputs79()
612 {
613  CardInputListPtr list = CardInputListPtr(new CardInputList());
614  std::vector<int> cardList = GetFreeCardIdList75();
615  for (std::vector<int>::const_iterator cardIt = cardList.begin(); cardIt != cardList.end(); ++cardIt)
616  {
617  bool succeeded = false;
618  char buf[32];
619  std::string field;
620 
621  OS::CLockGuard lock(*m_mutex);
622  if (!IsOpen())
623  break;
624  std::string cmd("QUERY_RECORDER ");
625  int32_to_string((int32_t)(*cardIt), buf);
626  cmd.append(buf);
627  cmd.append(PROTO_STR_SEPARATOR);
628  cmd.append("GET_FREE_INPUTS");
629 
630  if (!SendCommand(cmd.c_str()))
631  break;
632 
633  while (m_msgConsumed < m_msgLength)
634  {
635  CardInputPtr input(new CardInput());
636  if (!ReadField(input->inputName))
637  break;
638  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
639  break;
640  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
641  break;
642  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->cardId)))
643  break;
644  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
645  break;
646  if (!ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
647  break;
648  if (!ReadField(field)) // displayName
649  break;
650  if (!ReadField(field)) // recPriority
651  break;
652  if (!ReadField(field)) // schedOrder
653  break;
654  if (!ReadField(field)) // quickTune
655  break;
656  list->push_back(input);
657  succeeded = true;
658  }
659  FlushMessage();
660  if (!succeeded)
661  break;
662  }
663  return list;
664 }
665 
666 CardInputListPtr ProtoMonitor::GetFreeInputs81()
667 {
668  CardInputListPtr list = CardInputListPtr(new CardInputList());
669  std::vector<int> cardList = GetFreeCardIdList75();
670  for (std::vector<int>::const_iterator cardIt = cardList.begin(); cardIt != cardList.end(); ++cardIt)
671  {
672  bool succeeded = false;
673  char buf[32];
674  std::string field;
675 
676  OS::CLockGuard lock(*m_mutex);
677  if (!IsOpen())
678  break;
679  std::string cmd("QUERY_RECORDER ");
680  int32_to_string((int32_t)(*cardIt), buf);
681  cmd.append(buf);
682  cmd.append(PROTO_STR_SEPARATOR);
683  cmd.append("GET_FREE_INPUTS");
684 
685  if (!SendCommand(cmd.c_str()))
686  break;
687 
688  while (m_msgConsumed < m_msgLength)
689  {
690  CardInputPtr input(new CardInput());
691  if (!ReadField(input->inputName))
692  break;
693  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
694  break;
695  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
696  break;
697  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->cardId)))
698  break;
699  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
700  break;
701  if (!ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
702  break;
703  if (!ReadField(field)) // displayName
704  break;
705  if (!ReadField(field)) // recPriority
706  break;
707  if (!ReadField(field)) // schedOrder
708  break;
709  if (!ReadField(field)) // quickTune
710  break;
711  if (!ReadField(field)) // chanid
712  break;
713  list->push_back(input);
714  succeeded = true;
715  }
716  FlushMessage();
717  if (!succeeded)
718  break;
719  }
720  return list;
721 }
722 
723 CardInputListPtr ProtoMonitor::GetFreeInputs87(int rnum)
724 {
725  CardInputListPtr list = CardInputListPtr(new CardInputList());
726  char buf[32];
727  std::string field;
728 
729  OS::CLockGuard lock(*m_mutex);
730  if (!IsOpen())
731  return list;
732  std::string cmd("GET_FREE_INPUT_INFO ");
733  int32_to_string((int32_t)rnum, buf);
734  cmd.append(buf);
735 
736  if (!SendCommand(cmd.c_str()))
737  return list;
738 
739  while (m_msgConsumed < m_msgLength)
740  {
741  CardInputPtr input(new CardInput());
742  if (!ReadField(input->inputName))
743  break;
744  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
745  break;
746  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
747  break;
748  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->cardId))) // obsolete: same as inputId
749  break;
750  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
751  break;
752  if (!ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
753  break;
754  if (!ReadField(field)) // displayName
755  break;
756  if (!ReadField(field)) // recPriority
757  break;
758  if (!ReadField(field)) // schedOrder
759  break;
760  if (!ReadField(field)) // quickTune
761  break;
762  if (!ReadField(field)) // chanid
763  break;
764  list->push_back(input);
765  }
766  FlushMessage();
767  return list;
768 }
769 
770 CardInputListPtr ProtoMonitor::GetFreeInputs89(int rnum)
771 {
772  CardInputListPtr list = CardInputListPtr(new CardInputList());
773  char buf[32];
774  std::string field;
775 
776  OS::CLockGuard lock(*m_mutex);
777  if (!IsOpen())
778  return list;
779  std::string cmd("GET_FREE_INPUT_INFO ");
780  int32_to_string((int32_t)rnum, buf);
781  cmd.append(buf);
782 
783  if (!SendCommand(cmd.c_str()))
784  return list;
785 
786  while (m_msgConsumed < m_msgLength)
787  {
788  CardInputPtr input(new CardInput());
789  if (!ReadField(input->inputName))
790  break;
791  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
792  break;
793  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
794  break;
795  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->cardId))) // obsolete: same as inputId
796  break;
797  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
798  break;
799  if (!ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
800  break;
801  if (!ReadField(field)) // displayName
802  break;
803  if (!ReadField(field)) // recPriority
804  break;
805  if (!ReadField(field)) // schedOrder
806  break;
807  if (!ReadField(field)) // quickTune
808  break;
809  if (!ReadField(field)) // chanid
810  break;
811  if (!ReadField(field)) // reclimit
812  break;
813  list->push_back(input);
814  }
815  FlushMessage();
816  return list;
817 }
818 
819 CardInputListPtr ProtoMonitor::GetFreeInputs90(int rnum)
820 {
821  CardInputListPtr list = CardInputListPtr(new CardInputList());
822  char buf[32];
823  std::string field;
824 
825  OS::CLockGuard lock(*m_mutex);
826  if (!IsOpen())
827  return list;
828  std::string cmd("GET_FREE_INPUT_INFO ");
829  int32_to_string((int32_t)rnum, buf);
830  cmd.append(buf);
831 
832  if (!SendCommand(cmd.c_str()))
833  return list;
834 
835  while (m_msgConsumed < m_msgLength)
836  {
837  CardInputPtr input(new CardInput());
838  if (!ReadField(input->inputName))
839  break;
840  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
841  break;
842  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
843  break;
844  input->cardId = input->inputId; // @FIXME: since protocol 90
845  if (!ReadField(field)) // reccount
846  break;
847  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
848  break;
849  if (!ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
850  break;
851  if (!ReadField(field)) // displayName
852  break;
853  if (!ReadField(field)) // recPriority
854  break;
855  if (!ReadField(field)) // schedOrder
856  break;
857  if (!ReadField(field)) // quickTune
858  break;
859  if (!ReadField(field)) // chanid
860  break;
861  if (!ReadField(field)) // reclimit
862  break;
863  list->push_back(input);
864  }
865  FlushMessage();
866  return list;
867 }
868 
869 CardInputListPtr ProtoMonitor::GetFreeInputs91(int rnum)
870 {
871  CardInputListPtr list = CardInputListPtr(new CardInputList());
872  char buf[32];
873  std::string field;
874 
875  OS::CLockGuard lock(*m_mutex);
876  if (!IsOpen())
877  return list;
878  std::string cmd("GET_FREE_INPUT_INFO ");
879  int32_to_string((int32_t)rnum, buf);
880  cmd.append(buf);
881 
882  if (!SendCommand(cmd.c_str()))
883  return list;
884 
885  while (m_msgConsumed < m_msgLength)
886  {
887  CardInputPtr input(new CardInput());
888  if (!ReadField(input->inputName))
889  break;
890  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
891  break;
892  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
893  break;
894  input->cardId = input->inputId; // @FIXME: since protocol 90
895  if (!ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
896  break;
897  if (!ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
898  break;
899  if (!ReadField(field)) // displayName
900  break;
901  if (!ReadField(field)) // recPriority
902  break;
903  if (!ReadField(field)) // schedOrder
904  break;
905  if (!ReadField(field)) // quickTune
906  break;
907  if (!ReadField(field)) // chanid
908  break;
909  list->push_back(input);
910  }
911  FlushMessage();
912  return list;
913 }
bool m_hang
Connection hang: while true allow retry.
Definition: mythprotobase.h:76
bool ReadField(std::string &field)
This is the main namespace that encloses all public classes.
Definition: mythcontrol.h:29
bool m_tainted
Connection has hung since last reset.
Definition: mythprotobase.h:77