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 
34 
35 #include "channelscan_sm.h"
36 #include "channelimporter.h"
37 
38 #define LOC QString("ChScanCLI: ")
39 
41 {
42  if ((scanEvent->type() == ScannerEvent::kScanComplete) ||
43  (scanEvent->type() == ScannerEvent::kScanShutdown) ||
44  (scanEvent->type() == ScannerEvent::kScanErrored))
45  {
46  std::cout<<std::endl;
47 
48  if (scanEvent->type() == ScannerEvent::kScanShutdown)
49  std::cerr<<"HandleEvent(void) -- scan shutdown"<<std::endl;
50  else
51  std::cerr<<"HandleEvent(void) -- scan complete"<<std::endl;
52 
53  ScanDTVTransportList transports;
54  if (m_sigmonScanner)
55  {
58  }
59 
60  Teardown();
61 
62  if (scanEvent->type() == ScannerEvent::kScanErrored)
63  {
64  QString error = scanEvent->strValue();
66  }
67  else if (!transports.empty())
68  {
69  Process(transports);
70  }
71 
72  m_done = true;
73  QCoreApplication::exit(0);
74  }
75  else if (scanEvent->type() == ScannerEvent::kAppendTextToLog)
76  {
77  m_statusLastLog = scanEvent->strValue();
78  }
79  else if (scanEvent->type() == ScannerEvent::kSetStatusText)
80  {
81  m_statusText = scanEvent->strValue();
82  }
83  else if (scanEvent->type() == ScannerEvent::kSetPercentComplete)
84  {
85  m_statusComplete = scanEvent->intValue();
86  }
87  else if (scanEvent->type() == ScannerEvent::kSetStatusSignalLock)
88  {
89  m_statusLock = scanEvent->boolValue();
90  }
91  else if (scanEvent->type() == ScannerEvent::kSetStatusSignalToNoise)
92  {
93  m_statusSnr = scanEvent->intValue() / 65535.0;
94 }
95 #if 0 // THESE_ARE_CURRENTLY_IGNORED
96  else if (scanEvent->type() == ScannerEvent::kSetStatusTitleText)
97  {
98  ;
99  }
100  else if (scanEvent->type() == ScannerEvent::kSetStatusRotorPosition)
101  {
102  ;
103  }
104  else if (scanEvent->type() == ScannerEvent::kSetStatusSignalStrength)
105  {
106  ;
107  }
108 #endif
109 
110  //cout<<"HERE<"<<verboseMask<<">"<<endl;
111  QString msg;
112  if (VERBOSE_LEVEL_NONE() || VERBOSE_LEVEL_CHECK(VB_CHANSCAN, LOG_INFO))
113  {
114  msg = QString("%1% S/N %2 %3 : %4 (%5) %6")
115  .arg(m_statusComplete, 3)
116  .arg(m_statusSnr, 3, 'f', 1)
117  .arg((m_statusLock) ? "l" : "L",
118  qPrintable(m_statusText),
119  qPrintable(m_statusLastLog))
120  .arg("", 20);
121  }
122  //cout<<msg.toLatin1().constData()<<endl;
123 
124  if (VERBOSE_LEVEL_CHECK(VB_CHANSCAN, LOG_INFO))
125  {
126  static QString s_oldMsg;
127  if (msg != s_oldMsg)
128  {
129  LOG(VB_CHANSCAN, LOG_INFO, LOC + msg);
130  s_oldMsg = msg;
131  }
132  }
133  else if (VERBOSE_LEVEL_NONE())
134  {
135  if (msg.length() > 80)
136  msg = msg.left(77) + "...";
137  std::cout<<"\r"<<msg.toLatin1().constData()<<"\r";
138  std::cout<<std::flush;
139  }
140 }
141 
143 {
144  if (VERBOSE_LEVEL_NONE())
145  {
146  std::cerr<<"ERROR: "<<error.toLatin1().constData()<<std::endl;
147  }
148  else
149  {
150  LOG(VB_GENERAL, LOG_ERR, LOC + error);
151  }
153 }
154 
156 {
160  ci.Process(_transports, m_sourceid);
161 }
162 
163 /*
164  * The parameters are required by the parent class.
165  */
167  bool /*lock*/, bool /*strength*/, bool /*snr*/, bool /*rotor*/)
168 {
169  if (VERBOSE_LEVEL_NONE())
170  std::cout<<"\r0%"<<std::flush;
171 }
channelscanner_cli.h
channelimporter.h
ChannelScannerCLI::MonitorProgress
void MonitorProgress(bool lock, bool strength, bool snr, bool rotor) override
Definition: channelscanner_cli.cpp:166
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:40
ChannelImporter::Process
void Process(const ScanDTVTransportList &_transports, int sourceid=-1)
Definition: channelimporter.cpp:103
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
mythlogging.h
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:155
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:38
ChannelScannerCLI::InformUser
void InformUser(const QString &error) override
Definition: channelscanner_cli.cpp:142
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:65
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
hardwareprofile.smolt.error
def error(message)
Definition: smolt.py:409
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