From 3c7e014dcc43614f9d35642dd25887612b799aad Mon Sep 17 00:00:00 2001 From: kamel5 Date: Sun, 16 May 2021 13:19:42 +0200 Subject: [PATCH] Fix a device is currently recording The token indicating whether a device is currently recording was not updated correctly --- coreengine/viewelementscommon.c | 67 +++++++++++++++++++-------------- coreengine/viewelementscommon.h | 4 +- 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/coreengine/viewelementscommon.c b/coreengine/viewelementscommon.c index 2df678a..f12bb03 100644 --- a/coreengine/viewelementscommon.c +++ b/coreengine/viewelementscommon.c @@ -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; iNumProvidedSystems()) { @@ -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; } /****************************************************************** diff --git a/coreengine/viewelementscommon.h b/coreengine/viewelementscommon.h index e0b2870..629a9cc 100644 --- a/coreengine/viewelementscommon.h +++ b/coreengine/viewelementscommon.h @@ -51,7 +51,6 @@ public: class cVeDevices : public cViewElement { private: bool light; - time_t lastRefresh; vector 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 \ No newline at end of file +#endif //__VIEWELEMENTSCOMMON_H