MythTV master
scaninfo.cpp
Go to the documentation of this file.
1// C++ headers
2#include <cstdint>
3#include <utility>
4
5// Qt headers
6#include <QString>
7
8// MythTV headers
10#include "libmythbase/mythdb.h"
13#include "scaninfo.h"
14
15ScanInfo::ScanInfo(uint scanid, uint cardid, uint sourceid,
16 bool processed, QDateTime scandate) :
17 m_scanid(scanid), m_cardid(cardid), m_sourceid(sourceid),
18 m_processed(processed), m_scandate(std::move(scandate))
19{
20}
21
23{
24 LOG(VB_CHANSCAN, LOG_INFO, QString("SaveScan() scan.size(): %1")
25 .arg(scan.size()));
26
27 uint scanid = 0;
28 if (scan.empty() || scan[0].m_channels.empty())
29 return scanid;
30
31 uint sourceid = scan[0].m_channels[0].m_sourceId;
32 uint cardid = scan[0].m_cardid;
33
34 // Delete saved scans when there are too many or when they are too old
35 const std::vector<ScanInfo> list = LoadScanList(sourceid);
36 for (uint i = 0; i < list.size(); i++)
37 {
38 if (((i + 10) < (list.size())) ||
39 (list[i].m_scandate < MythDate::current().addMonths(-6)))
40 {
41 LOG(VB_CHANSCAN, LOG_INFO, "SaveScan() " +
42 QString("Delete saved scan id:%1 date:%2")
43 .arg(list[i].m_scanid).arg(list[i].m_scandate.toString()));
44 ScanInfo::DeleteScan(list[i].m_scanid);
45 }
46 }
47
49 query.prepare(
50 "INSERT INTO channelscan ( cardid, sourceid, scandate) "
51 "VALUES (:CARDID, :SOURCEID, :SCANDATE) ");
52 query.bindValue(":CARDID", cardid);
53 query.bindValue(":SOURCEID", sourceid);
54 query.bindValue(":SCANDATE", MythDate::current());
55
56 if (!query.exec())
57 {
58 MythDB::DBError("SaveScan 1", query);
59 return scanid;
60 }
61
62 query.prepare("SELECT MAX(scanid) FROM channelscan");
63 if (!query.exec())
64 MythDB::DBError("SaveScan 2", query);
65 else if (query.next())
66 scanid = query.value(0).toUInt();
67
68 if (!scanid)
69 return scanid;
70
71 for (const auto & si : scan)
72 si.SaveScan(scanid);
73
74 return scanid;
75}
76
78{
82 query.prepare(
83 "SELECT frequency, inversion, symbolrate, " // 0, 1, 2
84 " fec, polarity, " // 3, 4
85 " hp_code_rate, lp_code_rate, modulation, " // 5, 6, 7
86 " transmission_mode, guard_interval, hierarchy, " // 8, 9, 10
87 " modulation, bandwidth, sistandard, " // 11, 12, 13
88 " tuner_type, transportid, mod_sys, " // 14, 15, 16
89 " rolloff, signal_strength " // 17, 18
90 "FROM channelscan_dtv_multiplex "
91 "WHERE scanid = :SCANID");
92 query.bindValue(":SCANID", scanid);
93 if (!query.exec())
94 {
95 MythDB::DBError("LoadScan 1", query);
96 return list;
97 }
98
99 while (query.next())
100 {
103 (DTVTunerType) query.value(14).toUInt(),
104 query.value(0).toString(), query.value(1).toString(), // frequency inversion
105 query.value(2).toString(), query.value(3).toString(), // symbolrate fec
106 query.value(4).toString(), query.value(5).toString(), // polarity hp_code_rate
107 query.value(6).toString(), query.value(7).toString(), // lp_code_rate modulation
108 query.value(8).toString(), query.value(9).toString(), // transmission_mode guard_interval
109 query.value(10).toString(), query.value(11).toString(), // hierarchy modulation
110 query.value(12).toString(), query.value(16).toString(), // bandwidth mod_sys
111 query.value(17).toString(), query.value(18).toString()); // roloff signal_strength
112
113 mux.m_sistandard = query.value(13).toString(); // sistandard
114
115 query2.prepare(
116 "SELECT "
117 " mplex_id, source_id, channel_id, " // 0, 1, 2
118 " callsign, service_name, chan_num, " // 3, 4, 5
119 " service_id, atsc_major_channel, atsc_minor_channel, " // 6, 7, 8
120 " use_on_air_guide, hidden, hidden_in_guide, " // 9, 10, 11
121 " freqid, icon, tvformat, " // 12, 13, 14
122 " xmltvid, pat_tsid, vct_tsid, " // 15, 16, 17
123 " vct_chan_tsid, sdt_tsid, orig_netid, " // 18, 19, 20
124 " netid, si_standard, in_channels_conf, " // 21, 22, 23
125 " in_pat, in_pmt, in_vct, " // 24, 25, 26
126 " in_nit, in_sdt, is_encrypted, " // 27, 28, 29
127 " is_data_service, is_audio_service, is_opencable, " // 30, 31, 32
128 " could_be_opencable, decryption_status, default_authority, " // 33, 34, 35
129 " service_type, logical_channel, simulcast_channel " // 36, 37, 38
130 "FROM channelscan_channel "
131 "WHERE transportid = :TRANSPORTID");
132 query2.bindValue(":TRANSPORTID", query.value(15).toUInt());
133
134 if (!query2.exec())
135 {
136 MythDB::DBError("LoadScan 2", query2);
137 continue;
138 }
139
140 while (query2.next())
141 {
142 QString si_standard = query2.value(22).toString();
143 si_standard = (si_standard.isEmpty()) ?
144 query.value(13).toString() : si_standard;
145
147 query2.value(0).toUInt(), // mplex_id
148 query2.value(1).toUInt(), // source_id
149 query2.value(2).toUInt(), // channel_id
150 query2.value(3).toString(), // callsign
151 query2.value(4).toString(), // service_name
152 query2.value(5).toString(), // chan_num
153 query2.value(6).toUInt(), // service_id
154
155 query2.value(7).toUInt(), // atsc_major_channel
156 query2.value(8).toUInt(), // atsc_minor_channel
157 query2.value(9).toBool(), // use_on_air_guide
158 query2.value(10).toBool(), // hidden
159 query2.value(11).toBool(), // hidden_in_guide
160
161 query2.value(12).toString(), // freqid
162 query2.value(13).toString(), // icon
163 query2.value(14).toString(), // tvformat
164 query2.value(15).toString(), // xmltvid
165
166 query2.value(16).toUInt(), // pat_tsid
167 query2.value(17).toUInt(), // vct_tsid
168 query2.value(18).toUInt(), // vct_chan_tsid
169 query2.value(19).toUInt(), // sdt_tsid
170
171 query2.value(20).toUInt(), // orig_netid
172 query2.value(21).toUInt(), // netid
173
174 si_standard,
175
176 query2.value(23).toBool(), // in_channels_conf
177 query2.value(24).toBool(), // in_pat
178 query2.value(25).toBool(), // in_pmt
179 query2.value(26).toBool(), // in_vct
180 query2.value(27).toBool(), // in_nit
181 query2.value(28).toBool(), // in_sdt
182
183 query2.value(29).toBool(), // is_encrypted
184 query2.value(30).toBool(), // is_data_service
185 query2.value(31).toBool(), // is_audio_service
186 query2.value(32).toBool(), // is_opencable
187 query2.value(33).toBool(), // could_be_opencable
188 query2.value(34).toInt(), // decryption_status
189 query2.value(35).toString(), // default_authority
190 query2.value(36).toUInt(), // service_type
191 query2.value(37).toUInt(), // logical_channel
192 query2.value(38).toUInt()); // simulcast_channel
193 mux.m_channels.push_back(chan);
194 }
195
196 list.push_back(mux);
197 }
198
199 return list;
200}
201
203{
205 query.prepare(
206 "UPDATE channelscan "
207 "SET processed = 1 "
208 "WHERE scanid = :SCANID");
209 query.bindValue(":SCANID", scanid);
210
211 if (!query.exec())
212 {
213 MythDB::DBError("MarkProcessed", query);
214 return false;
215 }
216
217 return true;
218}
219
221{
223 query.prepare(
224 "DELETE FROM channelscan_channel "
225 "WHERE scanid = :SCANID");
226 query.bindValue(":SCANID", scanid);
227
228 if (!query.exec())
229 {
230 MythDB::DBError("DeleteScan", query);
231 return false;
232 }
233
234 query.prepare(
235 "DELETE FROM channelscan_dtv_multiplex "
236 "WHERE scanid = :SCANID");
237 query.bindValue(":SCANID", scanid);
238
239 if (!query.exec())
240 {
241 MythDB::DBError("DeleteScan", query);
242 return false;
243 }
244
245 query.prepare(
246 "DELETE FROM channelscan "
247 "WHERE scanid = :SCANID");
248 query.bindValue(":SCANID", scanid);
249
250 if (!query.exec())
251 {
252 MythDB::DBError("DeleteScan", query);
253 return false;
254 }
255
256 return true;
257}
258
260{
261 std::vector<ScanInfo> scans = LoadScanList(sourceid);
262 for (auto &scan : scans)
263 {
264 DeleteScan(scan.m_scanid);
265 }
266}
267
268std::vector<ScanInfo> LoadScanList(void)
269{
270 std::vector<ScanInfo> list;
271
273 query.prepare(
274 "SELECT scanid, cardid, sourceid, processed, scandate "
275 "FROM channelscan "
276 "ORDER BY scanid, sourceid, cardid, scandate");
277
278 if (!query.exec())
279 {
280 MythDB::DBError("LoadScanList", query);
281 return list;
282 }
283
284 while (query.next())
285 {
286 list.emplace_back(query.value(0).toUInt(),
287 query.value(1).toUInt(),
288 query.value(2).toUInt(),
289 (bool) query.value(3).toUInt(),
290 MythDate::as_utc(query.value(4).toDateTime()));
291 }
292
293 return list;
294}
295
296std::vector<ScanInfo> LoadScanList(uint sourceid)
297{
298 std::vector<ScanInfo> list;
299
301 query.prepare(
302 "SELECT scanid, cardid, sourceid, processed, scandate "
303 "FROM channelscan "
304 "WHERE sourceid = :SOURCEID "
305 "ORDER BY scanid, sourceid, cardid, scandate");
306 query.bindValue(":SOURCEID", sourceid);
307
308 if (!query.exec())
309 {
310 MythDB::DBError("LoadScanList", query);
311 return list;
312 }
313
314 while (query.next())
315 {
316 list.emplace_back(query.value(0).toUInt(),
317 query.value(1).toUInt(),
318 query.value(2).toUInt(),
319 (bool) query.value(3).toUInt(),
320 MythDate::as_utc(query.value(4).toDateTime()));
321 }
322
323 return list;
324}
QString m_sistandard
Definition: dtvmultiplex.h:111
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:128
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:837
QVariant value(int i) const
Definition: mythdbcon.h:204
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:618
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:888
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:812
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:550
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:226
bool ParseTuningParams(DTVTunerType type, const QString &frequency, const QString &inversion, const QString &symbolrate, const QString &fec, const QString &polarity, const QString &hp_code_rate, const QString &lp_code_rate, const QString &ofdm_modulation, const QString &trans_mode, const QString &guard_interval, const QString &hierarchy, const QString &modulation, const QString &bandwidth, const QString &mod_sys, const QString &rolloff, const QString &signal_strength)
ChannelInsertInfoList m_channels
Definition: dtvmultiplex.h:138
static bool DeleteScan(uint scanid)
Definition: scaninfo.cpp:220
ScanInfo()=default
static void DeleteScansFromSource(uint sourceid)
Definition: scaninfo.cpp:259
static bool MarkProcessed(uint scanid)
Definition: scaninfo.cpp:202
std::vector< ScanDTVTransport > ScanDTVTransportList
Definition: dtvmultiplex.h:143
unsigned int uint
Definition: freesurround.h:24
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
QDateTime as_utc(const QDateTime &old_dt)
Returns copy of QDateTime with TimeSpec set to UTC.
Definition: mythdate.cpp:28
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
def scan(profile, smoonURL, gate)
Definition: scan.py:54
STL namespace.
uint SaveScan(const ScanDTVTransportList &scan)
Definition: scaninfo.cpp:22
std::vector< ScanInfo > LoadScanList(void)
Definition: scaninfo.cpp:268
ScanDTVTransportList LoadScan(uint scanid)
Definition: scaninfo.cpp:77