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  {
66  Process(transports);
67  }
68 
69  m_done = true;
70  QCoreApplication::exit(0);
71  }
72  else if (scanEvent->type() == ScannerEvent::kAppendTextToLog)
73  {
74  m_statusLastLog = scanEvent->strValue();
75  }
76  else if (scanEvent->type() == ScannerEvent::kSetStatusText)
77  {
78  m_statusText = scanEvent->strValue();
79  }
80  else if (scanEvent->type() == ScannerEvent::kSetPercentComplete)
81  {
82  m_statusComplete = scanEvent->intValue();
83  }
84  else if (scanEvent->type() == ScannerEvent::kSetStatusSignalLock)
85  {
86  m_statusLock = scanEvent->boolValue();
87  }
88  else if (scanEvent->type() == ScannerEvent::kSetStatusSignalToNoise)
89  {
90  m_statusSnr = scanEvent->intValue() / 65535.0;
91 }
92 #if 0 // THESE_ARE_CURRENTLY_IGNORED
93  else if (scanEvent->type() == ScannerEvent::kSetStatusTitleText)
94  {
95  ;
96  }
97  else if (scanEvent->type() == ScannerEvent::kSetStatusRotorPosition)
98  {
99  ;
100  }
101  else if (scanEvent->type() == ScannerEvent::kSetStatusSignalStrength)
102  {
103  ;
104  }
105 #endif
106 
107  //cout<<"HERE<"<<verboseMask<<">"<<endl;
108  QString msg;
109  if (VERBOSE_LEVEL_NONE() || VERBOSE_LEVEL_CHECK(VB_CHANSCAN, LOG_INFO))
110  {
111  msg = QString("%1% S/N %2 %3 : %4 (%5) %6")
112  .arg(m_statusComplete, 3)
113  .arg(m_statusSnr, 3, 'f', 1)
114  .arg((m_statusLock) ? "l" : "L",
115  qPrintable(m_statusText),
116  qPrintable(m_statusLastLog))
117  .arg("", 20);
118  }
119  //cout<<msg.toLatin1().constData()<<endl;
120 
121  if (VERBOSE_LEVEL_CHECK(VB_CHANSCAN, LOG_INFO))
122  {
123  static QString s_oldMsg;
124  if (msg != s_oldMsg)
125  {
126  LOG(VB_CHANSCAN, LOG_INFO, LOC + msg);
127  s_oldMsg = msg;
128  }
129  }
130  else if (VERBOSE_LEVEL_NONE())
131  {
132  if (msg.length() > 80)
133  msg = msg.left(77) + "...";
134  std::cout<<"\r"<<msg.toLatin1().constData()<<"\r";
135  std::cout<<std::flush;
136  }
137 }
138 
140 {
141  if (VERBOSE_LEVEL_NONE())
142  {
143  std::cerr<<"ERROR: "<<error.toLatin1().constData()<<std::endl;
144  }
145  else
146  {
147  LOG(VB_GENERAL, LOG_ERR, LOC + error);
148  }
150 }
151 
153 {
157  ci.Process(_transports, m_sourceid);
158 }
159 
160 /*
161  * The parameters are required by the parent class.
162  */
164  bool /*lock*/, bool /*strength*/, bool /*snr*/, bool /*rotor*/)
165 {
166  if (VERBOSE_LEVEL_NONE())
167  std::cout<<"\r0%"<<std::flush;
168 }
channelscanner_cli.h
error
static void error(const char *str,...)
Definition: vbi.cpp:37
channelimporter.h
ChannelScannerCLI::MonitorProgress
void MonitorProgress(bool lock, bool strength, bool snr, bool rotor) override
Definition: channelscanner_cli.cpp:163
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:164
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:101
ChannelScanSM::StopScanner
void StopScanner(void)
Stops the ChannelScanSM event loop and the signal monitor, blocking until both exit.
Definition: channelscan_sm.cpp:2291
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:152
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:132
ChannelScanner::m_sourceid
int m_sourceid
Definition: channelscanner.h:169
ScannerEvent::intValue
int intValue() const
Definition: scanmonitor.h:97
ChannelScannerCLI::Process
virtual void Process(const ScanDTVTransportList &_transports)
Definition: channelscanner_cli.cpp:152
ScannerEvent::kSetStatusRotorPosition
static const Type kSetStatusRotorPosition
Definition: scanmonitor.h:113
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:139
ChannelScanner::m_fullSearch
bool m_fullSearch
Extended search for old channels post scan?
Definition: channelscanner.h:161
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
ScannerEvent::kSetStatusSignalStrength
static const Type kSetStatusSignalStrength
Definition: scanmonitor.h:115
ChannelScanner::m_channelNumbersOnly
bool m_channelNumbersOnly
Only channels with logical channel numbers desired post scan?
Definition: channelscanner.h:155
ScannerEvent
Definition: scanmonitor.h:86
ChannelScanner::m_addFullTS
bool m_addFullTS
Add MPTS "full transport stream" channels.
Definition: channelscanner.h:167
ChannelScanner::m_serviceRequirements
ServiceRequirements m_serviceRequirements
Services desired post scan.
Definition: channelscanner.h:172
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:128
ChannelScannerCLI::m_interactive
bool m_interactive
Definition: channelscanner_cli.h:59
ChannelScannerCLI::m_statusLock
bool m_statusLock
Definition: channelscanner_cli.h:60
ScannerEvent::kSetStatusTitleText
static const Type kSetStatusTitleText
Definition: scanmonitor.h:111
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:1374
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:158