Fix a device is currently recording

The token indicating whether a device is currently recording was not
updated correctly
This commit is contained in:
kamel5 2021-05-16 13:19:42 +02:00
parent b977e3582a
commit 3c7e014dcc
2 changed files with 41 additions and 30 deletions

View File

@ -160,12 +160,12 @@ bool cVeMessage::Parse(bool forced) {
* cVeDevices
******************************************************************/
cVeDevices::cVeDevices(void) {
lastRefresh = 0;
initial = true;
devicesIndex = -1;
lastSignalStrength = NULL;
lastSignalQuality = NULL;
recDevices = NULL;
lastRecDevices = NULL;
}
cVeDevices::~cVeDevices(void) {
@ -176,6 +176,8 @@ cVeDevices::~cVeDevices(void) {
lastSignalQuality = NULL;
delete[] recDevices;
recDevices = NULL;
delete[] lastRecDevices;
lastRecDevices = NULL;
mutexDevices.Unlock();
}
@ -193,11 +195,13 @@ void cVeDevices::Init(void) {
lastSignalStrength = new int[numDevices];
lastSignalQuality = new int[numDevices];
recDevices = new bool[numDevices];
lastRecDevices = new bool[numDevices];
mutexDevices.Lock();
for (int i=0; i<numDevices; i++) {
lastSignalStrength[i] = 0;
lastSignalQuality[i] = 0;
recDevices[i] = false;
lastRecDevices[i] = false;
}
mutexDevices.Unlock();
}
@ -205,7 +209,6 @@ void cVeDevices::Init(void) {
void cVeDevices::Close(void) {
devices.clear();
initial = true;
lastRefresh = 0;
numDevices = 0;
mutexDevices.Lock();
delete[] lastSignalStrength;
@ -214,6 +217,8 @@ void cVeDevices::Close(void) {
lastSignalQuality = NULL;
delete[] recDevices;
recDevices = NULL;
delete[] lastRecDevices;
lastRecDevices = NULL;
mutexDevices.Unlock();
cViewElement::Close();
}
@ -243,17 +248,17 @@ void cVeDevices::SetTokenContainer(void) {
bool cVeDevices::Parse(bool forced) {
if (!cViewElement::Parse(forced))
return false;
bool changed = false;
if (initial) {
Init();
initial = false;
changed = true;
} else {
//in light modus content is static
if (light)
return false;
//check if drawing is necessary
if (cTimeMs::Now() - lastRefresh < 500)
return false;
bool changed = false;
for (int i = 0; i < numDevices; i++) {
const cDevice *device = cDevice::GetDevice(devices[i]);
if (!device || !device->NumProvidedSystems()) {
@ -272,22 +277,15 @@ bool cVeDevices::Parse(bool forced) {
if ((signalStrength != lastSigStr) || (signalQuality != lastSigQual)) {
changed = true;
break;
}
}
if (!changed) {
return false;
}
}
}
//check device which currently displays live tv
int deviceLiveTV = -1;
cDevice *primaryDevice = cDevice::PrimaryDevice();
if (primaryDevice) {
if (!primaryDevice->Replaying() || primaryDevice->Transferring())
deviceLiveTV = cDevice::ActualDevice()->DeviceNumber();
else
deviceLiveTV = primaryDevice->DeviceNumber();
// reset recording devices
for (int i = 0; i < numDevices; i++) {
recDevices[i] = false;
}
// check currently recording devices
// BLOCK for LOCK_TIMERS_READ scope !!
{
@ -305,8 +303,7 @@ bool cVeDevices::Parse(bool forced) {
const cDevice *recDevice = RecordControl->Device();
if (recDevice) {
mutexDevices.Lock();
if (recDevices)
{
if (recDevices) {
int d = recDevice->DeviceNumber();
for (int i = 0; i < numDevices; i++) {
if (devices[i] == d) {
@ -319,6 +316,27 @@ bool cVeDevices::Parse(bool forced) {
}
}
}
} // LOCK_TIMERS_READ
for (int i = 0; i < numDevices; i++) {
if (recDevices[i] != lastRecDevices[i]) {
lastRecDevices[i] = recDevices[i];
changed = true;
}
}
if (!changed) {
return false;
}
//check device which currently displays live tv
int deviceLiveTV = -1;
cDevice *primaryDevice = cDevice::PrimaryDevice();
if (primaryDevice) {
if (!primaryDevice->Replaying() || primaryDevice->Transferring())
deviceLiveTV = cDevice::ActualDevice()->DeviceNumber();
else
deviceLiveTV = primaryDevice->DeviceNumber();
}
//create loop container
@ -356,13 +374,7 @@ bool cVeDevices::Parse(bool forced) {
tokenContainer->AddLoopToken(devicesIndex, i, (int)eDevicesLT::signalstrength, *cString::sprintf("%d", signalStrength));
tokenContainer->AddLoopToken(devicesIndex, i, (int)eDevicesLT::signalquality, *cString::sprintf("%d", signalQuality));
tokenContainer->AddLoopToken(devicesIndex, i, (int)eDevicesLT::livetv, devices[i] == deviceLiveTV ? "1" : "0");
bool isRecording = false;
mutexDevices.Lock();
if (recDevices && recDevices[i])
isRecording = true;
mutexDevices.Unlock();
tokenContainer->AddLoopToken(devicesIndex, i, (int)eDevicesLT::recording, isRecording ? "1" : "0");
tokenContainer->AddLoopToken(devicesIndex, i, (int)eDevicesLT::recording, (recDevices && recDevices[i]) ? "1" : "0");
const cChannel *channel = device->GetCurrentlyTunedTransponder();
const cSource *source = (channel) ? Sources.Get(channel->Source()) : NULL;
@ -388,7 +400,6 @@ bool cVeDevices::Parse(bool forced) {
}
SetDirty();
lastRefresh = cTimeMs::Now();
return true;
}
/******************************************************************

View File

@ -51,7 +51,6 @@ public:
class cVeDevices : public cViewElement {
private:
bool light;
time_t lastRefresh;
vector<int> devices;
bool initial;
int devicesIndex;
@ -60,6 +59,7 @@ private:
int* lastSignalStrength;
int* lastSignalQuality;
bool* recDevices;
bool* lastRecDevices;
void Init(void);
public:
cVeDevices(void);
@ -107,4 +107,4 @@ public:
void Set(int current, int total, bool mute);
bool Parse(bool forced = false);
};
#endif //__VIEWELEMENTSCOMMON_H
#endif //__VIEWELEMENTSCOMMON_H