MythTV  master
channelscanner_cli.cpp
Go to the documentation of this file.
1 /* -*- Mode: c++ -*-
2  * vim: set expandtab tabstop=4 shiftwidth=4:
3  *
4  * Original Project
5  * MythTV http://www.mythtv.org
6  *
7  * Copyright (c) 2008 Daniel Kristjansson
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
23  *
24  */
25 
26 // Qt headers
27 #include <QCoreApplication>
28 #include <iostream>
29 
30 // MythTv headers
31 #include "channelscanner_cli.h"
32 #include "channelscan_sm.h"
33 #include "channelimporter.h"
34 
35 #define LOC QString("ChScanCLI: ")
36 
38 {
39  if ((scanEvent->type() == ScannerEvent::kScanComplete) ||
40  (scanEvent->type() == ScannerEvent::kScanShutdown) ||
41  (scanEvent->type() == ScannerEvent::kScanErrored))
42  {
43  std::cout<<std::endl;
44 
45  if (scanEvent->type() == ScannerEvent::kScanShutdown)
46  std::cerr<<"HandleEvent(void) -- scan shutdown"<<std::endl;
47  else
48  std::cerr<<"HandleEvent(void) -- scan complete"<<std::endl;
49 
50  ScanDTVTransportList transports;
51  if (m_sigmonScanner)
52  {
55  }
56 
57  Teardown();
58 
59  if (scanEvent->type() == ScannerEvent::kScanErrored)
60  {
61  QString error = scanEvent->strValue();
63  }
64  else if (!transports.empty())
65  Process(transports);
66 
67  m_done = true;
68  QCoreApplication::exit(0);
69  }
70  else if (scanEvent->type() == ScannerEvent::kAppendTextToLog)
71  m_statusLastLog = scanEvent->strValue();
72  else if (scanEvent->type() == ScannerEvent::kSetStatusText)
73  m_statusText = scanEvent->strValue();
74  else if (scanEvent->type() == ScannerEvent::kSetPercentComplete)
75  m_statusComplete = scanEvent->intValue();
76  else if (scanEvent->type() == ScannerEvent::kSetStatusSignalLock)
77  m_statusLock = scanEvent->boolValue();
78  else if (scanEvent->type() == ScannerEvent::kSetStatusSignalToNoise)
79  m_statusSnr = scanEvent->intValue() / 65535.0;
80 #if 0 // THESE_ARE_CURRENTLY_IGNORED
81  else if (scanEvent->type() == ScannerEvent::SetStatusTitleText)
82  ;
83  else if (scanEvent->type() == ScannerEvent::SetStatusRotorPosition)
84  ;
85  else if (scanEvent->type() == ScannerEvent::SetStatusSignalStrength)
86  ;
87 #endif
88 
89  //cout<<"HERE<"<<verboseMask<<">"<<endl;
90  QString msg;
91  if (VERBOSE_LEVEL_NONE() || VERBOSE_LEVEL_CHECK(VB_CHANSCAN, LOG_INFO))
92  {
93  msg = QString("%1% S/N %2 %3 : %4 (%5) %6")
94  .arg(m_statusComplete, 3)
95  .arg(m_statusSnr, 3, 'f', 1)
96  .arg((m_statusLock) ? "l" : "L",
97  qPrintable(m_statusText),
98  qPrintable(m_statusLastLog))
99  .arg("", 20);
100  }
101  //cout<<msg.toLatin1().constData()<<endl;
102 
103  if (VERBOSE_LEVEL_CHECK(VB_CHANSCAN, LOG_INFO))
104  {
105  static QString s_oldMsg;
106  if (msg != s_oldMsg)
107  {
108  LOG(VB_CHANSCAN, LOG_INFO, LOC + msg);
109  s_oldMsg = msg;
110  }
111  }
112  else if (VERBOSE_LEVEL_NONE())
113  {
114  if (msg.length() > 80)
115  msg = msg.left(77) + "...";
116  std::cout<<"\r"<<msg.toLatin1().constData()<<"\r";
117  std::cout<<std::flush;
118  }
119 }
120 
122 {
123  if (VERBOSE_LEVEL_NONE())
124  {
125  std::cerr<<"ERROR: "<<error.toLatin1().constData()<<std::endl;
126  }
127  else
128  {
129  LOG(VB_GENERAL, LOG_ERR, LOC + error);
130  }
132 }
133 
135 {
139  ci.Process(_transports, m_sourceid);
140 }
141 
142 /*
143  * The parameters are required by the parent class.
144  */
146  bool /*lock*/, bool /*strength*/, bool /*snr*/, bool /*rotor*/)
147 {
148  if (VERBOSE_LEVEL_NONE())
149  std::cout<<"\r0%"<<std::flush;
150 }
channelscanner_cli.h
error
static void error(const char *str,...)
Definition: vbi.cpp:36
channelimporter.h
ChannelScannerCLI::MonitorProgress
void MonitorProgress(bool lock, bool strength, bool snr, bool rotor) override
Definition: channelscanner_cli.cpp:145
channelscan_sm.h
VERBOSE_LEVEL_CHECK
static bool VERBOSE_LEVEL_CHECK(uint64_t mask, LogLevel_t level)
Definition: mythlogging.h:29
ScannerEvent::kAppendTextToLog
static const Type kAppendTextToLog
Definition: scanmonitor.h:109
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
ChannelScanner::m_removeDuplicates
bool m_removeDuplicates
Remove duplicate transports and channels?
Definition: channelscanner.h:163
ChannelScannerCLI::HandleEvent
void HandleEvent(const ScannerEvent *scanEvent) override
Definition: channelscanner_cli.cpp:37
ChannelImporter::Process
void Process(const ScanDTVTransportList &_transports, int sourceid=-1)
Definition: channelimporter.cpp:76
ChannelScanSM::StopScanner
void StopScanner(void)
Stops the ChannelScanSM event loop and the signal monitor, blocking until both exit.
Definition: channelscan_sm.cpp:2273
ScannerEvent::kSetStatusText
static const Type kSetStatusText
Definition: scanmonitor.h:110
ScannerEvent::boolValue
bool boolValue() const
Definition: scanmonitor.h:100
ScannerEvent::kScanShutdown
static const Type kScanShutdown
Definition: scanmonitor.h:107
ChannelScannerCLI::m_statusSnr
float m_statusSnr
Definition: channelscanner_cli.h:62
ScannerEvent::kScanComplete
static const Type kScanComplete
Definition: scanmonitor.h:106
ChannelScanner::m_freeToAirOnly
bool m_freeToAirOnly
Only fta channels desired post scan?
Definition: channelscanner.h:151
ChannelScannerCLI::m_statusText
QString m_statusText
Definition: channelscanner_cli.h:63
ChannelScannerCLI::m_onlysavescan
bool m_onlysavescan
Definition: channelscanner_cli.h:58
ChannelScanner::m_sigmonScanner
ChannelScanSM * m_sigmonScanner
Definition: channelscanner.h:131
ChannelScanner::m_sourceid
int m_sourceid
Definition: channelscanner.h:168
ScannerEvent::intValue
int intValue() const
Definition: scanmonitor.h:97
ChannelScannerCLI::Process
virtual void Process(const ScanDTVTransportList &_transports)
Definition: channelscanner_cli.cpp:134
ScannerEvent::kSetStatusSignalToNoise
static const Type kSetStatusSignalToNoise
Definition: scanmonitor.h:114
LOC
#define LOC
Definition: channelscanner_cli.cpp:35
ChannelScannerCLI::InformUser
void InformUser(const QString &error) override
Definition: channelscanner_cli.cpp:121
ChannelScanner::m_fullSearch
bool m_fullSearch
Extended search for old channels post scan?
Definition: channelscanner.h:160
ChannelScanner::Teardown
virtual void Teardown(void)
Definition: channelscanner.cpp:63
ScannerEvent::kSetStatusSignalLock
static const Type kSetStatusSignalLock
Definition: scanmonitor.h:116
ScanDTVTransportList
std::vector< ScanDTVTransport > ScanDTVTransportList
Definition: dtvmultiplex.h:143
ChannelScanner::m_channelNumbersOnly
bool m_channelNumbersOnly
Only channels with logical channel numbers desired post scan?
Definition: channelscanner.h:154
ScannerEvent
Definition: scanmonitor.h:86
ChannelScanner::m_addFullTS
bool m_addFullTS
Add MPTS "full transport stream" channels.
Definition: channelscanner.h:166
ChannelScanner::m_serviceRequirements
ServiceRequirements m_serviceRequirements
Services desired post scan.
Definition: channelscanner.h:171
ScannerEvent::strValue
QString strValue() const
Definition: scanmonitor.h:94
ChannelScannerCLI::m_done
bool m_done
Definition: channelscanner_cli.h:57
ChannelScanner::m_scanMonitor
ScanMonitor * m_scanMonitor
Definition: channelscanner.h:127
ChannelScannerCLI::m_interactive
bool m_interactive
Definition: channelscanner_cli.h:59
ChannelScannerCLI::m_statusLock
bool m_statusLock
Definition: channelscanner_cli.h:60
ChannelImporter
Definition: channelimporter.h:71
ScannerEvent::kSetPercentComplete
static const Type kSetPercentComplete
Definition: scanmonitor.h:112
ScannerEvent::kScanErrored
static const Type kScanErrored
Definition: scanmonitor.h:108
VERBOSE_LEVEL_NONE
static bool VERBOSE_LEVEL_NONE()
Definition: mythlogging.h:28
ChannelScannerCLI::m_statusComplete
uint m_statusComplete
Definition: channelscanner_cli.h:61
ChannelScanSM::GetChannelList
chan_info_map_t GetChannelList(transport_scan_items_it_t trans_info, ScannedChannelInfo *scan_info) const
Definition: channelscan_sm.cpp:1359
ChannelScannerCLI::m_statusLastLog
QString m_statusLastLog
Definition: channelscanner_cli.h:64
post_event
void post_event(QObject *dest, QEvent::Type type, int val)
Percentage to set to after the first tune.
Definition: scanmonitor.cpp:68
ChannelScanner::m_completeOnly
bool m_completeOnly
Only complete channels desired post scan?
Definition: channelscanner.h:157