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 using namespace std;
31 
32 // MythTv headers
33 #include "channelscanner_cli.h"
34 #include "channelscan_sm.h"
35 #include "channelimporter.h"
36 
37 #define LOC QString("ChScanCLI: ")
38 
39 ChannelScannerCLI::ChannelScannerCLI(bool doScanSaveOnly, bool promptsOk) :
40  done(false), onlysavescan(doScanSaveOnly), interactive(promptsOk),
41  status_lock(false), status_complete(0), status_snr(0),
42  status_text(""), status_last_log("")
43 {
44 }
45 
47 {
48 }
49 
51 {
52  if ((scanEvent->type() == ScannerEvent::ScanComplete) ||
53  (scanEvent->type() == ScannerEvent::ScanShutdown) ||
54  (scanEvent->type() == ScannerEvent::ScanErrored))
55  {
56  cout<<endl;
57 
58  if (scanEvent->type() == ScannerEvent::ScanShutdown)
59  cerr<<"HandleEvent(void) -- scan shutdown"<<endl;
60  else
61  cerr<<"HandleEvent(void) -- scan complete"<<endl;
62 
63  ScanDTVTransportList transports;
64  if (sigmonScanner)
65  {
67  transports = sigmonScanner->GetChannelList(addFullTS);
68  }
69 
70  Teardown();
71 
72  if (scanEvent->type() == ScannerEvent::ScanErrored)
73  {
74  QString error = scanEvent->strValue();
76  }
77  else if (!transports.empty())
78  Process(transports);
79 
80  done = true;
81  QCoreApplication::exit(0);
82  }
83  else if (scanEvent->type() == ScannerEvent::AppendTextToLog)
84  status_last_log = scanEvent->strValue();
85  else if (scanEvent->type() == ScannerEvent::SetStatusText)
86  status_text = scanEvent->strValue();
87  else if (scanEvent->type() == ScannerEvent::SetPercentComplete)
88  status_complete = scanEvent->intValue();
89  else if (scanEvent->type() == ScannerEvent::SetStatusSignalLock)
90  status_lock = scanEvent->intValue();
91  else if (scanEvent->type() == ScannerEvent::SetStatusSignalToNoise)
92  status_snr = scanEvent->intValue() / 65535.0;
93 #if THESE_ARE_CURRENTLY_IGNORED
94  else if (scanEvent->type() == ScannerEvent::SetStatusTitleText)
95  ;
96  else if (scanEvent->type() == ScannerEvent::SetStatusRotorPosition)
97  ;
98  else if (scanEvent->type() == ScannerEvent::SetStatusSignalStrength)
99  ;
100 #endif
101 
102  //cout<<"HERE<"<<verboseMask<<">"<<endl;
103  QString msg;
104  if (VERBOSE_LEVEL_NONE || VERBOSE_LEVEL_CHECK(VB_CHANSCAN, LOG_INFO))
105  {
106  msg.sprintf("%3i%% S/N %3.1f %s : %s (%s) %20s",
107  status_complete, static_cast<double>(status_snr),
108  (status_lock) ? "l" : "L",
109  status_text.toLatin1().constData(),
110  status_last_log.toLatin1().constData(), "");
111  }
112  //cout<<msg.toLatin1().constData()<<endl;
113 
114  if (VERBOSE_LEVEL_CHECK(VB_CHANSCAN, LOG_INFO))
115  {
116  static QString old_msg;
117  if (msg != old_msg)
118  {
119  LOG(VB_CHANSCAN, LOG_INFO, LOC + msg);
120  old_msg = msg;
121  }
122  }
123  else if (VERBOSE_LEVEL_NONE)
124  {
125  if (msg.length() > 80)
126  msg = msg.left(77) + "...";
127  cout<<"\r"<<msg.toLatin1().constData()<<"\r";
128  cout<<flush;
129  }
130 }
131 
133 {
134  if (VERBOSE_LEVEL_NONE)
135  {
136  cerr<<"ERROR: "<<error.toLatin1().constData()<<endl;
137  }
138  else
139  {
140  LOG(VB_GENERAL, LOG_ERR, LOC + error);
141  }
143 }
144 
146 {
149  ci.Process(_transports, m_sourceid);
150 }
151 
152 /*
153  * The parameters are required by the parent class.
154  */
156  bool /*lock*/, bool /*strength*/, bool /*snr*/, bool /*rotor*/)
157 {
158  if (VERBOSE_LEVEL_NONE)
159  cout<<"\r0%"<<flush;
160 }
ChannelScannerCLI(bool doScanSaveOnly, bool promptsOk)
static Type SetStatusText
Definition: scanmonitor.h:109
static Type SetStatusSignalStrength
Definition: scanmonitor.h:114
void HandleEvent(const ScannerEvent *scanEvent) override
virtual void Process(const ScanDTVTransportList &)
static void error(const char *str,...)
Definition: vbi.c:41
virtual void Teardown(void)
static Type SetStatusTitleText
Definition: scanmonitor.h:110
vector< ScanDTVTransport > ScanDTVTransportList
Definition: dtvmultiplex.h:132
#define LOC
ScanMonitor * scanMonitor
static Type AppendTextToLog
Definition: scanmonitor.h:108
static Type SetPercentComplete
Definition: scanmonitor.h:111
static Type ScanComplete
Definition: scanmonitor.h:105
static Type ScanShutdown
Definition: scanmonitor.h:106
chan_info_map_t GetChannelList(transport_scan_items_it_t trans_info, ScannedChannelInfo *scan_info) const
#define VERBOSE_LEVEL_NONE
Definition: mythlogging.h:22
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
#define VERBOSE_LEVEL_CHECK(_MASK_, _LEVEL_)
Definition: mythlogging.h:24
QString strValue() const
Definition: scanmonitor.h:95
ChannelScanSM * sigmonScanner
static Type SetStatusRotorPosition
Definition: scanmonitor.h:112
bool freeToAirOnly
Only fta channels desired post scan?
static Type ScanErrored
Definition: scanmonitor.h:107
static Type SetStatusSignalToNoise
Definition: scanmonitor.h:113
void InformUser(const QString &error) override
int intValue() const
Definition: scanmonitor.h:98
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
bool addFullTS
Add MPTS "full transport stream" channels.
static Type SetStatusSignalLock
Definition: scanmonitor.h:115
void StopScanner(void)
Stops the ChannelScanSM event loop and the signal monitor, blocking until both exit.
void post_event(QObject *dest, QEvent::Type type, int val)
Definition: scanmonitor.cpp:68
ServiceRequirements serviceRequirements
Services desired post scan.
void MonitorProgress(bool lock, bool strength, bool snr, bool rotor) override
void Process(const ScanDTVTransportList &, int sourceid=-1)