]> git.neil.brown.name Git - plato.git/commitdiff
gsmd: allow repeat= arg to be a function.
authorNeilBrown <neilb@suse.de>
Sun, 30 Dec 2012 20:37:56 +0000 (07:37 +1100)
committerNeilBrown <neilb@suse.de>
Sun, 30 Dec 2012 20:39:45 +0000 (07:39 +1100)
This allows commands to be repeated differently, or not at all,
depending on arbitrary aspects of state.
'data' support will use this.

gsm/gsmd.py

index 893d6ce0352cc6518ee7308a167022a834c1f1d0..f71e8c6683895fd3da4269ff95a5c510e5192662 100644 (file)
@@ -831,11 +831,18 @@ class GsmD(AtChannel):
         n = len(cs)
         now = int(time.time()*1000)
         for i in range(n):
-            if self.lastrun[i] == 0 or (cs[i].repeat and
-                                        self.lastrun[i] + cs[i].repeat <= now):
+            if self.lastrun[i] == 0:
                 return (i, 0)
-            if cs[i].repeat:
-                delay = (self.lastrun[i] + cs[i].repeat) - now;
+            repeat = cs[i].repeat
+            if repeat == None:
+                repeat = 0
+            elif type(repeat) != int:
+                repeat = repeat(self)
+
+            if repeat and self.lastrun[i] + repeat <= now):
+                return (i, 0)
+            if repeat:
+                delay = (self.lastrun[i] + repeat) - now;
                 if delay < mindelay:
                     mindelay = delay
         return (0, mindelay)