Fixing bug with reseting the state machine and adding a status checker for state...
authorEd Page <eopage@byu.net>
Wed, 17 Feb 2010 02:08:01 +0000 (20:08 -0600)
committerEd Page <eopage@byu.net>
Wed, 17 Feb 2010 02:08:01 +0000 (20:08 -0600)
src/channel/debug_prompt.py
src/gvoice/state_machine.py

index 9db5554..803bbcb 100644 (file)
@@ -112,6 +112,40 @@ class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd):
        def help_get_state(self):
                self._report_new_message("Print the current state the refreshing state machine is in")
 
        def help_get_state(self):
                self._report_new_message("Print the current state the refreshing state machine is in")
 
+       def do_get_polling(self, args):
+               if args:
+                       self._report_new_message("No arguments supported")
+                       return
+               self._report_new_message("\n".join((
+                       "Contacts:", repr(self._conn.session.addressbookStateMachine)
+               )))
+               self._report_new_message("\n".join((
+                       "Voicemail:", repr(self._conn.session.voicemailsStateMachine)
+               )))
+               self._report_new_message("\n".join((
+                       "Texts:", repr(self._conn.session.textsStateMachine)
+               )))
+
+       def help_get_polling(self):
+               self._report_new_message("Prints the frequency each of the state machines updates")
+
+       def do_get_state_status(self, args):
+               if args:
+                       self._report_new_message("No arguments supported")
+                       return
+               self._report_new_message("\n".join((
+                       "Contacts:", str(self._conn.session.addressbookStateMachine)
+               )))
+               self._report_new_message("\n".join((
+                       "Voicemail:", str(self._conn.session.voicemailsStateMachine)
+               )))
+               self._report_new_message("\n".join((
+                       "Texts:", str(self._conn.session.textsStateMachine)
+               )))
+
+       def help_get_state_status(self):
+               self._report_new_message("Prints the current setting for the state machines")
+
        def do_is_authed(self, args):
                if args:
                        self._report_new_message("No arguments supported")
        def do_is_authed(self, args):
                if args:
                        self._report_new_message("No arguments supported")
@@ -239,23 +273,6 @@ class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd):
        def help_version(self):
                self._report_new_message("Prints the version (hint: %s-%s)" % (constants.__version__, constants.__build__))
 
        def help_version(self):
                self._report_new_message("Prints the version (hint: %s-%s)" % (constants.__version__, constants.__build__))
 
-       def do_get_polling(self, args):
-               if args:
-                       self._report_new_message("No arguments supported")
-                       return
-               self._report_new_message("\n".join((
-                       "Contacts:", repr(self._conn.session.addressbookStateMachine)
-               )))
-               self._report_new_message("\n".join((
-                       "Voicemail:", repr(self._conn.session.voicemailsStateMachine)
-               )))
-               self._report_new_message("\n".join((
-                       "Texts:", repr(self._conn.session.textsStateMachine)
-               )))
-
-       def help_get_polling(self):
-               self._report_new_message("Prints the frequency each of the state machines updates")
-
        def do_grab_log(self, args):
                if args:
                        self._report_new_message("No arguments supported")
        def do_grab_log(self, args):
                if args:
                        self._report_new_message("No arguments supported")
index 1d784ab..0a04e07 100644 (file)
@@ -107,6 +107,11 @@ class NTimesStateStrategy(object):
                except IndexError:
                        return self._postTimeout
 
                except IndexError:
                        return self._postTimeout
 
+       def __str__(self):
+               return "NTimesStateStrategy(timeout=%r)" % (
+                       self.timeout,
+               )
+
        def __repr__(self):
                return "NTimesStateStrategy(timeouts=%r, postTimeout=%r)" % (
                        self._timeouts,
        def __repr__(self):
                return "NTimesStateStrategy(timeouts=%r, postTimeout=%r)" % (
                        self._timeouts,
@@ -149,6 +154,11 @@ class GeometricStateStrategy(object):
                        timeout = self._init + self._current
                return timeout
 
                        timeout = self._init + self._current
                return timeout
 
+       def __str__(self):
+               return "GeometricStateStrategy(timeout=%r)" % (
+                       self.timeout
+               )
+
        def __repr__(self):
                return "GeometricStateStrategy(init=%r, min=%r, max=%r)" % (
                        self._init, self._min, self._max
        def __repr__(self):
                return "GeometricStateStrategy(init=%r, min=%r, max=%r)" % (
                        self._init, self._min, self._max
@@ -224,6 +234,7 @@ class UpdateStateMachine(StateMachine):
                self._name = name
                self._updateItems = updateItems
                self._maxTime = maxTime
                self._name = name
                self._updateItems = updateItems
                self._maxTime = maxTime
+               self._isRunning = False
 
                self._state = self.STATE_ACTIVE
                self._onTimeout = gobject_utils.Timeout(self._on_timeout)
 
                self._state = self.STATE_ACTIVE
                self._onTimeout = gobject_utils.Timeout(self._on_timeout)
@@ -235,6 +246,13 @@ class UpdateStateMachine(StateMachine):
                        )
                )
 
                        )
                )
 
+       def __str__(self):
+               return """UpdateStateMachine(
+       name=%r,
+       strategie=%s,
+       isRunning=%r,
+)""" % (self._name, self._strategy, self._onTimeout.is_running())
+
        def __repr__(self):
                return """UpdateStateMachine(
        name=%r,
        def __repr__(self):
                return """UpdateStateMachine(
        name=%r,
@@ -249,10 +267,12 @@ class UpdateStateMachine(StateMachine):
                        strategy.initialize_state()
                if self._strategy.timeout != self.INFINITE_PERIOD:
                        self._onTimeout.start(seconds=0)
                        strategy.initialize_state()
                if self._strategy.timeout != self.INFINITE_PERIOD:
                        self._onTimeout.start(seconds=0)
+               self._isRunning = True
                _moduleLogger.info("%s Starting State Machine" % (self._name, ))
 
        def stop(self):
                _moduleLogger.info("%s Stopping State Machine" % (self._name, ))
                _moduleLogger.info("%s Starting State Machine" % (self._name, ))
 
        def stop(self):
                _moduleLogger.info("%s Stopping State Machine" % (self._name, ))
+               self._isRunning = False
                self._onTimeout.cancel()
 
        def close(self):
                self._onTimeout.cancel()
 
        def close(self):
@@ -292,7 +312,7 @@ class UpdateStateMachine(StateMachine):
                self._reset_timers()
 
        def _reset_timers(self, initialize=False):
                self._reset_timers()
 
        def _reset_timers(self, initialize=False):
-               if self._onTimeout.is_running():
+               if not self._isRunning:
                        return # not started yet
                _moduleLogger.info("%s Resetting State Machine" % (self._name, ))
                self._onTimeout.cancel()
                        return # not started yet
                _moduleLogger.info("%s Resetting State Machine" % (self._name, ))
                self._onTimeout.cancel()