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