[ANNOUNCE] VDR developer version 1.7.17

Message ID 4D987441.8090407@gmx.de
State New
Headers

Commit Message

Udo Richter April 3, 2011, 1:21 p.m. UTC
  Am 27.03.2011 16:45, schrieb Klaus Schmidinger:
> Can you please rewrite your patch so that it keeps the original 'd'
> variable? I liked the fact that the 'nextUpdate' variable was incremented
> in *one* place, and not in several places. Made the whole thing more
> transparent to me. Besides, I could then see what you have *actually*
> changed ;-)

Another example on how coding style is a matter of taste. One of the
first things I changed was the removing of the d variable that is IMHO
superfluous, doesn't have an unique meaning (file age in seconds and
time to next check), and no descriptive name. ;)

Anyway, I've rewritten it to match your original patch more closely.
Actually I'm surprised how similar they got again, I had some evolution
steps that were completely different.

Attached is the rewritten patch as updatemarks-4, and for your
convenience a diff between updatemarks-2 and updatemarks-4 that shows
the differences more closely.

Cheers,

Udo
  

Patch

diff -Naurp vdr-1.7.17-updatemarks-2/recording.c vdr-1.7.17-updatemarks-4/recording.c
--- vdr-1.7.17-updatemarks-2/recording.c	2011-04-03 14:59:24.000000000 +0200
+++ vdr-1.7.17-updatemarks-4/recording.c	2011-04-03 15:05:16.000000000 +0200
@@ -1272,6 +1272,7 @@  bool cMarks::Load(const char *RecordingF
   framesPerSecond = FramesPerSecond;
   nextUpdate = 0;
   lastFileTime = -1; // the first call to Load() must take place!
+  lastChange = 0;
   return Update();
 }
 
@@ -1280,16 +1281,9 @@  bool cMarks::Update(void)
   time_t t = time(NULL);
   if (t > nextUpdate) {
      time_t LastModified = LastModifiedTime(fileName);
-     int d;
-     if (LastModified > 0) // the file exists
-        d = t - LastModified;
-     else { // the file doesn't exist
-        if (lastFileTime <= 0) {
-           lastFileTime = t - 2; // -2 makes sure we don't miss an update within the very same second
-           LastModified = t; // make sure we run into the actual Load() below
-           }
-        d = t - lastFileTime;
-        }
+     if (LastModified != lastFileTime) // Change detected, or first run
+        lastChange = LastModified>0 ? LastModified : t;
+     int d = t - lastChange;
      if (d < 60)
         d = 1; // check frequently if the file has just been modified
      else if (d < 3600)
@@ -1297,8 +1291,10 @@  bool cMarks::Update(void)
      else
         d /= 360; // phase out checking for very old files
      nextUpdate = t + d;
-     if (LastModified > lastFileTime) {
+     if (LastModified != lastFileTime) { // Change detected, or first run
         lastFileTime = LastModified;
+        if (lastFileTime == t)
+           lastFileTime--; // Make sure we don't miss updates in the remaining second
         cMutexLock MutexLock(&MutexMarkFramesPerSecond);
         MarkFramesPerSecond = framesPerSecond;
         if (cConfig<cMark>::Load(fileName)) {
diff -Naurp vdr-1.7.17-updatemarks-2/recording.h vdr-1.7.17-updatemarks-4/recording.h
--- vdr-1.7.17-updatemarks-2/recording.h	2011-04-03 14:59:24.000000000 +0200
+++ vdr-1.7.17-updatemarks-4/recording.h	2011-04-03 14:57:20.000000000 +0200
@@ -194,6 +194,7 @@  private:
   double framesPerSecond;
   time_t nextUpdate;
   time_t lastFileTime;
+  time_t lastChange;
 public:
   bool Load(const char *RecordingFileName, double FramesPerSecond = DEFAULTFRAMESPERSECOND, bool IsPesRecording = false);
   bool Update(void);