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" 39 ProtoMonitor::ProtoMonitor(
const std::string& server,
unsigned port)
45 ProtoMonitor::ProtoMonitor(
const std::string& server,
unsigned port,
bool frontend)
47 , m_frontend(frontend)
51 bool ProtoMonitor::Open()
55 if (!OpenConnection(PROTO_MONITOR_RCVBUF))
58 if (m_protoVersion >= 88)
71 void ProtoMonitor::Close()
78 bool ProtoMonitor::IsOpen()
82 return ProtoMonitor::Open();
83 return ProtoBase::IsOpen();
86 bool ProtoMonitor::Announce75()
88 OS::CLockGuard lock(*m_mutex);
90 std::string cmd(
"ANN Monitor ");
91 cmd.append(m_socket->GetMyHostName()).append(
" 0");
92 if (!SendCommand(cmd.c_str()))
96 if (!
ReadField(field) || !IsMessageOK(field))
105 bool ProtoMonitor::Announce88()
107 OS::CLockGuard lock(*m_mutex);
109 std::string cmd((m_frontend ?
"ANN Frontend " :
"ANN Monitor "));
110 cmd.append(m_socket->GetMyHostName()).append(
" 0");
111 if (!SendCommand(cmd.c_str()))
115 if (!
ReadField(field) || !IsMessageOK(field))
124 ProtoRecorderPtr ProtoMonitor::GetRecorderFromNum75(
int rnum)
128 ProtoRecorderPtr recorder;
129 std::string hostname;
132 OS::CLockGuard lock(*m_mutex);
135 std::string cmd(
"GET_RECORDER_FROM_NUM");
136 cmd.append(PROTO_STR_SEPARATOR);
137 int32_to_string((int32_t)rnum, buf);
140 if (!SendCommand(cmd.c_str()))
143 if (!
ReadField(hostname) || hostname ==
"nohost")
145 if (!
ReadField(field) || string_to_uint16(field.c_str(), &port))
148 DBG(DBG_DEBUG,
"%s: open recorder %d (%s:%u)\n", __FUNCTION__, (
int)rnum, hostname.c_str(), (unsigned)port);
152 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
157 bool ProtoMonitor::QueryFreeSpaceSummary75(int64_t *total, int64_t *used)
161 OS::CLockGuard lock(*m_mutex);
164 std::string cmd(
"QUERY_FREE_SPACE_SUMMARY");
166 if (!SendCommand(cmd.c_str()))
169 if (!
ReadField(field) || string_to_int64(field.c_str(), total))
171 if (!
ReadField(field) || string_to_int64(field.c_str(), used))
176 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
181 std::string ProtoMonitor::GetSetting75(
const std::string& hostname,
const std::string& setting)
185 OS::CLockGuard lock(*m_mutex);
188 std::string cmd(
"QUERY_SETTING ");
189 cmd.append(hostname).append(
" ").append(setting);
191 if (!SendCommand(cmd.c_str()))
199 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
205 bool ProtoMonitor::SetSetting75(
const std::string& hostname,
const std::string& setting,
const std::string& value)
209 OS::CLockGuard lock(*m_mutex);
212 std::string cmd(
"SET_SETTING ");
213 cmd.append(hostname).append(
" ").append(setting).append(
" ").append(value);
215 if (!SendCommand(cmd.c_str()))
218 if (!
ReadField(field) || !IsMessageOK(field))
223 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
228 bool ProtoMonitor::QueryGenpixmap75(
const Program& program)
232 OS::CLockGuard lock(*m_mutex);
235 std::string cmd(
"QUERY_GENPIXMAP2");
236 cmd.append(PROTO_STR_SEPARATOR).append(
"do_not_care").append(PROTO_STR_SEPARATOR);
237 MakeProgramInfo(program, field);
240 if (!SendCommand(cmd.c_str()))
243 if (!
ReadField(field) || !IsMessageOK(field))
248 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
253 bool ProtoMonitor::DeleteRecording75(
const Program& program,
bool force,
bool forget)
258 OS::CLockGuard lock(*m_mutex);
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(
" ");
267 cmd.append(
"FORCE ");
269 cmd.append(
"NO_FORCE ");
271 cmd.append(
"FORGET");
273 cmd.append(
"NO_FORGET");
275 if (!SendCommand(cmd.c_str()))
280 DBG(DBG_DEBUG,
"%s: succeeded (%s)\n", __FUNCTION__, program.fileName.c_str());
283 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
288 bool ProtoMonitor::UndeleteRecording75(
const Program& program)
292 OS::CLockGuard lock(*m_mutex);
295 std::string cmd(
"UNDELETE_RECORDING");
296 cmd.append(PROTO_STR_SEPARATOR);
297 MakeProgramInfo(program, field);
300 if (!SendCommand(cmd.c_str()))
305 DBG(DBG_DEBUG,
"%s: succeeded (%s)\n", __FUNCTION__, program.fileName.c_str());
308 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
313 bool ProtoMonitor::StopRecording75(
const Program& program)
318 OS::CLockGuard lock(*m_mutex);
321 std::string cmd(
"STOP_RECORDING");
322 cmd.append(PROTO_STR_SEPARATOR);
323 MakeProgramInfo(program, field);
326 if (!SendCommand(cmd.c_str()))
329 if (!
ReadField(field) || string_to_int32(field.c_str(), &num) || num < 0)
331 DBG(DBG_DEBUG,
"%s: succeeded (%s)\n", __FUNCTION__, program.fileName.c_str());
334 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
339 bool ProtoMonitor::CancelNextRecording75(
int rnum,
bool cancel)
344 OS::CLockGuard lock(*m_mutex);
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"));
353 if (!SendCommand(cmd.c_str()))
356 if (!
ReadField(field) || !IsMessageOK(field))
358 DBG(DBG_DEBUG,
"%s: succeeded\n", __FUNCTION__);
361 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
366 StorageGroupFilePtr ProtoMonitor::QuerySGFile75(
const std::string& hostname,
const std::string& sgname,
const std::string& filename)
370 StorageGroupFilePtr sgfile;
372 OS::CLockGuard lock(*m_mutex);
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);
381 if (!SendCommand(cmd.c_str()))
387 if (!
ReadField(field) || string_to_int64(field.c_str(), &tmpi))
389 sgfile->lastModified = (time_t)tmpi;
390 if (!
ReadField(field) || string_to_int64(field.c_str(), &(sgfile->size)))
392 sgfile->hostName = hostname;
393 sgfile->storageGroup = sgname;
395 DBG(DBG_DEBUG,
"%s: succeeded (%s)\n", __FUNCTION__, sgfile->fileName.c_str());
398 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
404 MarkListPtr ProtoMonitor::GetCutList75(
const Program& program)
409 MarkListPtr list(
new MarkList);
411 OS::CLockGuard lock(*m_mutex);
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);
420 if (!SendCommand(cmd.c_str()))
423 if (!
ReadField(field) || string_to_int32(field.c_str(), &nb))
430 MarkPtr mark = MarkPtr(
new Mark());
431 if (!
ReadField(field) || string_to_int8(field.c_str(), (int8_t*)&(mark->markType)))
433 if (!
ReadField(field) || string_to_int64(field.c_str(), &(mark->markValue)))
435 list->push_back(mark);
439 DBG(DBG_DEBUG,
"%s: succeeded (%s)\n", __FUNCTION__, program.fileName.c_str());
442 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
447 MarkListPtr ProtoMonitor::GetCommBreakList75(
const Program& program)
452 MarkListPtr list(
new MarkList);
454 OS::CLockGuard lock(*m_mutex);
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);
463 if (!SendCommand(cmd.c_str()))
466 if (!
ReadField(field) || string_to_int32(field.c_str(), &nb))
473 MarkPtr mark = MarkPtr(
new Mark());
474 if (!
ReadField(field) || string_to_int8(field.c_str(), (int8_t*)&(mark->markType)))
476 if (!
ReadField(field) || string_to_int64(field.c_str(), &(mark->markValue)))
478 list->push_back(mark);
482 DBG(DBG_DEBUG,
"%s: succeeded (%s)\n", __FUNCTION__, program.fileName.c_str());
485 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
490 bool ProtoMonitor::BlockShutdown75()
494 OS::CLockGuard lock(*m_mutex);
497 std::string cmd(
"BLOCK_SHUTDOWN");
499 if (!SendCommand(cmd.c_str()))
502 if (!
ReadField(field) || !IsMessageOK(field))
504 DBG(DBG_DEBUG,
"%s: succeeded\n", __FUNCTION__);
507 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
512 bool ProtoMonitor::AllowShutdown75()
516 OS::CLockGuard lock(*m_mutex);
519 std::string cmd(
"ALLOW_SHUTDOWN");
521 if (!SendCommand(cmd.c_str()))
524 if (!
ReadField(field) || !IsMessageOK(field))
526 DBG(DBG_DEBUG,
"%s: succeeded\n", __FUNCTION__);
529 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
534 std::vector<int> ProtoMonitor::GetFreeCardIdList75()
537 std::vector<int> ids;
540 OS::CLockGuard lock(*m_mutex);
543 std::string cmd(
"GET_FREE_RECORDER_LIST");
545 if (!SendCommand(cmd.c_str()))
548 while (m_msgConsumed < m_msgLength)
550 if (!
ReadField(field) || string_to_int32(field.c_str(), &rnum))
552 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
560 DBG(DBG_DEBUG,
"%s: succeeded (%u)\n", __FUNCTION__, (
unsigned)ids.size());
564 CardInputListPtr ProtoMonitor::GetFreeInputs75()
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)
570 bool succeeded =
false;
574 OS::CLockGuard lock(*m_mutex);
577 std::string cmd(
"QUERY_RECORDER ");
578 int32_to_string((int32_t)(*cardIt), buf);
580 cmd.append(PROTO_STR_SEPARATOR);
581 cmd.append(
"GET_FREE_INPUTS");
583 if (!SendCommand(cmd.c_str()))
586 while (m_msgConsumed < m_msgLength)
591 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
593 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
595 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->cardId)))
597 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
599 if (!
ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
601 list->push_back(input);
611 CardInputListPtr ProtoMonitor::GetFreeInputs79()
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)
617 bool succeeded =
false;
621 OS::CLockGuard lock(*m_mutex);
624 std::string cmd(
"QUERY_RECORDER ");
625 int32_to_string((int32_t)(*cardIt), buf);
627 cmd.append(PROTO_STR_SEPARATOR);
628 cmd.append(
"GET_FREE_INPUTS");
630 if (!SendCommand(cmd.c_str()))
633 while (m_msgConsumed < m_msgLength)
638 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
640 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
642 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->cardId)))
644 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
646 if (!
ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
656 list->push_back(input);
666 CardInputListPtr ProtoMonitor::GetFreeInputs81()
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)
672 bool succeeded =
false;
676 OS::CLockGuard lock(*m_mutex);
679 std::string cmd(
"QUERY_RECORDER ");
680 int32_to_string((int32_t)(*cardIt), buf);
682 cmd.append(PROTO_STR_SEPARATOR);
683 cmd.append(
"GET_FREE_INPUTS");
685 if (!SendCommand(cmd.c_str()))
688 while (m_msgConsumed < m_msgLength)
693 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
695 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
697 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->cardId)))
699 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
701 if (!
ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
713 list->push_back(input);
723 CardInputListPtr ProtoMonitor::GetFreeInputs87(
int rnum)
725 CardInputListPtr list = CardInputListPtr(
new CardInputList());
729 OS::CLockGuard lock(*m_mutex);
732 std::string cmd(
"GET_FREE_INPUT_INFO ");
733 int32_to_string((int32_t)rnum, buf);
736 if (!SendCommand(cmd.c_str()))
739 while (m_msgConsumed < m_msgLength)
744 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
746 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
748 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->cardId)))
750 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
752 if (!
ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
764 list->push_back(input);
770 CardInputListPtr ProtoMonitor::GetFreeInputs89(
int rnum)
772 CardInputListPtr list = CardInputListPtr(
new CardInputList());
776 OS::CLockGuard lock(*m_mutex);
779 std::string cmd(
"GET_FREE_INPUT_INFO ");
780 int32_to_string((int32_t)rnum, buf);
783 if (!SendCommand(cmd.c_str()))
786 while (m_msgConsumed < m_msgLength)
791 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
793 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
795 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->cardId)))
797 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
799 if (!
ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
813 list->push_back(input);
819 CardInputListPtr ProtoMonitor::GetFreeInputs90(
int rnum)
821 CardInputListPtr list = CardInputListPtr(
new CardInputList());
825 OS::CLockGuard lock(*m_mutex);
828 std::string cmd(
"GET_FREE_INPUT_INFO ");
829 int32_to_string((int32_t)rnum, buf);
832 if (!SendCommand(cmd.c_str()))
835 while (m_msgConsumed < m_msgLength)
840 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
842 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
844 input->cardId = input->inputId;
847 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
849 if (!
ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
863 list->push_back(input);
869 CardInputListPtr ProtoMonitor::GetFreeInputs91(
int rnum)
871 CardInputListPtr list = CardInputListPtr(
new CardInputList());
875 OS::CLockGuard lock(*m_mutex);
878 std::string cmd(
"GET_FREE_INPUT_INFO ");
879 int32_to_string((int32_t)rnum, buf);
882 if (!SendCommand(cmd.c_str()))
885 while (m_msgConsumed < m_msgLength)
890 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
892 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
894 input->cardId = input->inputId;
895 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
897 if (!
ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
909 list->push_back(input);
bool m_hang
Connection hang: while true allow retry.
bool ReadField(std::string &field)
This is the main namespace that encloses all public classes.
bool m_tainted
Connection has hung since last reset.