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;
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.0F;
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}
#define LOC
void Process(const ScanDTVTransportList &_transports, int sourceid=-1)
chan_info_map_t GetChannelList(transport_scan_items_it_t trans_info, ScannedChannelInfo *scan_info) const
void StopScanner(void)
Stops the ChannelScanSM event loop and the signal monitor, blocking until both exit.
virtual void Process(const ScanDTVTransportList &_transports)
void HandleEvent(const ScannerEvent *scanEvent) override
void MonitorProgress(bool lock, bool strength, bool snr, bool rotor) override
void InformUser(const QString &error) override
bool m_completeOnly
Only complete channels desired post scan?
ChannelScanSM * m_sigmonScanner
virtual void Teardown(void)
bool m_fullSearch
Extended search for old channels post scan?
bool m_channelNumbersOnly
Only channels with logical channel numbers desired post scan?
bool m_freeToAirOnly
Only fta channels desired post scan?
bool m_removeDuplicates
Remove duplicate transports and channels?
ScanMonitor * m_scanMonitor
bool m_addFullTS
Add MPTS "full transport stream" channels.
ServiceRequirements m_serviceRequirements
Services desired post scan.
static const Type kSetStatusSignalLock
Definition: scanmonitor.h:116
QString strValue() const
Definition: scanmonitor.h:94
static const Type kScanShutdown
Definition: scanmonitor.h:107
static const Type kSetStatusTitleText
Definition: scanmonitor.h:111
static const Type kSetStatusSignalToNoise
Definition: scanmonitor.h:114
static const Type kSetStatusText
Definition: scanmonitor.h:110
bool boolValue() const
Definition: scanmonitor.h:100
static const Type kAppendTextToLog
Definition: scanmonitor.h:109
static const Type kSetStatusRotorPosition
Definition: scanmonitor.h:113
static const Type kScanComplete
Definition: scanmonitor.h:106
static const Type kSetPercentComplete
Definition: scanmonitor.h:112
static const Type kSetStatusSignalStrength
Definition: scanmonitor.h:115
int intValue() const
Definition: scanmonitor.h:97
static const Type kScanErrored
Definition: scanmonitor.h:108
std::vector< ScanDTVTransport > ScanDTVTransportList
Definition: dtvmultiplex.h:143
static bool VERBOSE_LEVEL_CHECK(uint64_t mask, LogLevel_t level)
Definition: mythlogging.h:29
static bool VERBOSE_LEVEL_NONE()
Definition: mythlogging.h:28
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
def error(message)
Definition: smolt.py:409
void post_event(QObject *dest, QEvent::Type type, int val)
Percentage to set to after the first tune.
Definition: scanmonitor.cpp:68