This repository has been archived by the owner on Dec 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
recordingscache.c
133 lines (114 loc) · 3.28 KB
/
recordingscache.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* vdr-plugin-vnsi - KODI server plugin for VDR
*
* Copyright (C) 2011 Alexander Pipelka
* Copyright (C) 2015 Team KODI
*
* http://kodi.tv
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KODI; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "recordingscache.h"
#include "config.h"
#include "vnsiclient.h"
#include "hash.h"
cRecordingsCache::cRecordingsCache() {
}
cRecordingsCache::~cRecordingsCache() {
}
cRecordingsCache& cRecordingsCache::GetInstance() {
static cRecordingsCache singleton;
return singleton;
}
uint32_t cRecordingsCache::Register(const cRecording* recording, bool deleted) {
cString filename = recording->FileName();
uint32_t uid = CreateStringHash(filename);
m_mutex.Lock();
if(m_recordings.find(uid) == m_recordings.end())
{
DEBUGLOG("%s - uid: %08x '%s'", __FUNCTION__, uid, (const char*)filename);
m_recordings[uid].filename = filename;
m_recordings[uid].isDeleted = deleted;
}
m_mutex.Unlock();
return uid;
}
const cRecording* cRecordingsCache::Lookup(uint32_t uid) {
DEBUGLOG("%s - lookup uid: %08x", __FUNCTION__, uid);
if(m_recordings.find(uid) == m_recordings.end()) {
DEBUGLOG("%s - not found !", __FUNCTION__);
return NULL;
}
m_mutex.Lock();
cString filename = m_recordings[uid].filename;
DEBUGLOG("%s - filename: %s", __FUNCTION__, (const char*)filename);
const cRecording* r;
if (!m_recordings[uid].isDeleted)
{
#if VDRVERSNUM >= 20301
LOCK_RECORDINGS_READ;
r = Recordings->GetByName(filename);
#else
r = Recordings.GetByName(filename);
#endif
}
else
{
#if VDRVERSNUM >= 20301
LOCK_DELETEDRECORDINGS_READ;
r = DeletedRecordings->GetByName(filename);
#else
r = DeletedRecordings.GetByName(filename);
#endif
}
DEBUGLOG("%s - recording %s", __FUNCTION__, (r == NULL) ? "not found !" : "found");
m_mutex.Unlock();
return r;
}
cRecording* cRecordingsCache::LookupWrite(uint32_t uid)
{
DEBUGLOG("%s - lookup uid: %08x", __FUNCTION__, uid);
if(m_recordings.find(uid) == m_recordings.end())
{
DEBUGLOG("%s - not found !", __FUNCTION__);
return NULL;
}
m_mutex.Lock();
cString filename = m_recordings[uid].filename;
DEBUGLOG("%s - filename: %s", __FUNCTION__, (const char*)filename);
cRecording* r;
if (!m_recordings[uid].isDeleted)
{
#if VDRVERSNUM >= 20301
LOCK_RECORDINGS_WRITE;
r = Recordings->GetByName(filename);
#else
r = Recordings.GetByName(filename);
#endif
}
else
{
#if VDRVERSNUM >= 20301
LOCK_DELETEDRECORDINGS_WRITE;
r = DeletedRecordings->GetByName(filename);
#else
r = DeletedRecordings.GetByName(filename);
#endif
}
DEBUGLOG("%s - recording %s", __FUNCTION__, (r == NULL) ? "not found !" : "found");
m_mutex.Unlock();
return r;
}