MythTV
master
mythtv
libs
libmythtv
programinfoupdater.cpp
Go to the documentation of this file.
1
#include <thread>
2
3
// MythTV headers
4
#include "
libmythbase/mthreadpool.h
"
5
#include "
libmythbase/mythcorecontext.h
"
6
7
#include "
programinfoupdater.h
"
8
9
void
ProgramInfoUpdater::insert
(
10
uint
recordedid,
PIAction
action
, uint64_t filesize)
11
{
12
if
(recordedid == 0)
13
return
;
14
QMutexLocker locker(&
m_lock
);
15
if
(
kPIUpdate
==
action
||
kPIUpdateFileSize
==
action
)
16
{
17
QHash<uint,PIKeyData>::iterator it =
m_needsUpdate
.find(recordedid);
18
// If there is no action in the set we can insert
19
// If it is the same type of action we can overwrite,
20
// If it the new action is a full update we can overwrite
21
if
(it ==
m_needsUpdate
.end())
22
m_needsUpdate
.insert(recordedid,
PIKeyData
(
action
, filesize));
23
else
if
(((*it).m_action ==
action
) || (
kPIUpdate
==
action
))
24
(*it) =
PIKeyData
(
action
, filesize);
25
}
26
else
27
{
28
m_needsAddDelete
.emplace_back(recordedid,
action
);
29
}
30
31
// Start a new run() if one isn't already running..
32
// The lock prevents anything from getting stuck on a queue.
33
if
(!
m_isRunning
)
34
{
35
m_isRunning
=
true
;
36
MThreadPool::globalInstance
()->
start
(
this
,
"ProgramInfoUpdater"
);
37
}
38
else
39
{
40
m_moreWork
.wakeAll();
41
}
42
}
43
44
void
ProgramInfoUpdater::run
(
void
)
45
{
46
bool
workDone =
true
;
47
48
while
( workDone )
49
{
50
workDone =
false
;
51
52
// we don't need instant updates allow a few to queue up
53
// if they come in quick succession, this allows multiple
54
// updates to be consolidated into one update...
55
std::this_thread::sleep_for(200ms);
56
57
m_lock
.lock();
58
59
// send adds and deletes in the order they were queued
60
for
(
auto
& pi :
m_needsAddDelete
)
61
{
62
if
(
kPIAdd
!= pi.m_action &&
kPIDelete
!= pi.m_action)
63
continue
;
64
65
QString
type
= (
kPIAdd
== pi.m_action) ?
"ADD"
:
"DELETE"
;
66
QString msg = QString(
"RECORDING_LIST_CHANGE %1 %2"
)
67
.arg(
type
).arg(pi.m_recordedid);
68
69
workDone =
true
;
70
gCoreContext
->
SendMessage
(msg);
71
}
72
m_needsAddDelete
.clear();
73
74
// Send updates in any old order, we just need
75
// one per updated ProgramInfo.
76
// NOLINTNEXTLINE(modernize-loop-convert)
77
for
(
auto
itu =
m_needsUpdate
.begin(); itu !=
m_needsUpdate
.end(); ++itu)
78
{
79
QString msg;
80
81
if
(
kPIUpdateFileSize
== (*itu).m_action)
82
{
83
msg = QString(
"UPDATE_FILE_SIZE %1 %2"
)
84
.arg(itu.key())
85
.arg((*itu).m_filesize);
86
}
87
else
88
{
89
msg = QString(
"MASTER_UPDATE_REC_INFO %1"
)
90
.arg(itu.key());
91
}
92
93
workDone =
true
;
94
gCoreContext
->
SendMessage
(msg);
95
}
96
m_needsUpdate
.clear();
97
98
if
( workDone )
99
m_moreWork
.wait(&
m_lock
, 1000);
100
101
m_lock
.unlock();
102
}
103
104
m_isRunning
=
false
;
105
}
106
107
/*
108
* vim:ts=4:sw=4:ai:et:si:sts=4
109
*/
MThreadPool::globalInstance
static MThreadPool * globalInstance(void)
Definition:
mthreadpool.cpp:298
MThreadPool::start
void start(QRunnable *runnable, const QString &debugName, int priority=0)
Definition:
mthreadpool.cpp:333
MythCoreContext::SendMessage
void SendMessage(const QString &message)
Definition:
mythcorecontext.cpp:1552
PIKeyData
Definition:
programinfoupdater.h:41
ProgramInfoUpdater::m_isRunning
bool m_isRunning
Definition:
programinfoupdater.h:60
ProgramInfoUpdater::m_needsUpdate
QHash< uint, PIKeyData > m_needsUpdate
Definition:
programinfoupdater.h:62
ProgramInfoUpdater::run
void run(void) override
Definition:
programinfoupdater.cpp:44
ProgramInfoUpdater::m_lock
QMutex m_lock
Definition:
programinfoupdater.h:58
ProgramInfoUpdater::insert
void insert(uint recordedid, PIAction action, uint64_t filesize=0ULL)
Definition:
programinfoupdater.cpp:9
ProgramInfoUpdater::m_needsAddDelete
std::vector< PIKeyAction > m_needsAddDelete
Definition:
programinfoupdater.h:61
ProgramInfoUpdater::m_moreWork
QWaitCondition m_moreWork
Definition:
programinfoupdater.h:59
uint
unsigned int uint
Definition:
compat.h:60
mthreadpool.h
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition:
mythcorecontext.cpp:60
mythcorecontext.h
build_compdb.action
action
Definition:
build_compdb.py:9
hardwareprofile.getLink.type
type
Definition:
getLink.py:56
programinfoupdater.h
PIAction
PIAction
Definition:
programinfoupdater.h:18
kPIUpdateFileSize
@ kPIUpdateFileSize
Definition:
programinfoupdater.h:22
kPIUpdate
@ kPIUpdate
Definition:
programinfoupdater.h:21
kPIAdd
@ kPIAdd
Definition:
programinfoupdater.h:19
kPIDelete
@ kPIDelete
Definition:
programinfoupdater.h:20
Generated on Tue Jul 28 2026 03:18:38 for MythTV by
1.9.4