From eb1bc0727b3773d8ea7aa7b690aaf4abdde62b6d Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 12 Oct 2010 21:27:55 -0500 Subject: [PATCH] Adding quit, update_now. Fixing reset_state_machine --- src/channel/debug_prompt.py | 49 +++++++++++++++++++++++++++++++++++++++---- src/connection_manager.py | 10 ++++++++- src/gvoice/state_machine.py | 19 +++++++++++++++-- support/builddeb.py | 3 +++ 4 files changed, 74 insertions(+), 7 deletions(-) diff --git a/src/channel/debug_prompt.py b/src/channel/debug_prompt.py index 85b1794..fca8a9b 100644 --- a/src/channel/debug_prompt.py +++ b/src/channel/debug_prompt.py @@ -77,6 +77,19 @@ class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd): self.__nextRecievedId += 1 + def do_quit(self, args): + if args: + self._report_new_message("No arguments supported") + return + + try: + self._conn.manager.quit_now() + except Exception, e: + self._report_new_message(str(e)) + + def help_quit(self): + self._report_new_message("Shutdown the connection manager immediately, forcing it to be relaunched on reconnect") + def do_reset_state_machine(self, args): try: args = args.strip().lower() @@ -84,13 +97,13 @@ class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd): args = "all" if args == "all": for machine in self._conn.session.stateMachine._machines: - machine.reset_timers() + machine.reset_timers(True) elif args == "contacts": - self._conn.session.addressbookStateMachine.reset_timers() + self._conn.session.addressbookStateMachine.reset_timers(True) elif args == "voicemail": - self._conn.session.voicemailsStateMachine.reset_timers() + self._conn.session.voicemailsStateMachine.reset_timers(True) elif args == "texts": - self._conn.session.textsStateMachine.reset_timers() + self._conn.session.textsStateMachine.reset_timers(True) else: self._report_new_message('Unknown machine "%s"' % (args, )) except Exception, e: @@ -105,6 +118,34 @@ class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd): "reset_state_machine texts" """) + def do_update_now(self, args): + try: + args = args.strip().lower() + if not args: + args = "all" + if args == "all": + for machine in self._conn.session.stateMachine._machines: + machine.update_now() + elif args == "contacts": + self._conn.session.addressbookStateMachine.update_now() + elif args == "voicemail": + self._conn.session.voicemailsStateMachine.update_now() + elif args == "texts": + self._conn.session.textsStateMachine.update_now() + else: + self._report_new_message('Unknown machine "%s"' % (args, )) + except Exception, e: + self._report_new_message(str(e)) + + def help_update_now(self): + self._report_new_message("""Updates all the state machines now skipping there initialization time. +"update_now" - for all +"update_now all" +"update_now contacts" +"update_now voicemail" +"update_now texts" +""") + def do_get_state(self, args): if args: self._report_new_message("No arguments supported") diff --git a/src/connection_manager.py b/src/connection_manager.py index b9a8e37..6d074e9 100644 --- a/src/connection_manager.py +++ b/src/connection_manager.py @@ -22,6 +22,7 @@ class TheOneRingConnectionManager(tp.ConnectionManager): # self._protos is from super self._protos[constants._telepathy_protocol_name_] = connection.TheOneRingConnection self._on_shutdown = shutdown_func + self._quitImmediately = False _moduleLogger.info("Connection manager created") @misc_utils.log_exception(_moduleLogger) @@ -62,7 +63,10 @@ class TheOneRingConnectionManager(tp.ConnectionManager): return result def disconnect_completed(self): - gobject_utils.timeout_add_seconds(self.IDLE_TIMEOUT, self._shutdown) + if self._quitImmediately: + self._shutdown() + else: + gobject_utils.timeout_add_seconds(self.IDLE_TIMEOUT, self._shutdown) def quit(self): """ @@ -72,6 +76,10 @@ class TheOneRingConnectionManager(tp.ConnectionManager): conn.Disconnect() _moduleLogger.info("Connection manager quitting") + def quit_now(self): + self._quitImmediately = True + self.quit() + @misc_utils.log_exception(_moduleLogger) def _shutdown(self): if ( diff --git a/src/gvoice/state_machine.py b/src/gvoice/state_machine.py index 6d184d0..c4a2382 100644 --- a/src/gvoice/state_machine.py +++ b/src/gvoice/state_machine.py @@ -293,8 +293,23 @@ class UpdateStateMachine(StateMachine): def state(self): return self._state - def reset_timers(self): - self._reset_timers() + def reset_timers(self, initialize=False): + self._reset_timers(initialize) + + def update_now(self): + if not self._isActive: + return # not started yet + _moduleLogger.info("%s Forcing immediate update of state machine" % (self._name, )) + self._onTimeout.cancel() + self._strategy.initialize_state() + self._strategy.increment_state() + nextTimeout = self._strategy.timeout + if nextTimeout != self.INFINITE_PERIOD and nextTimeout < self._maxTime: + nextTimeout = 0 + self._onTimeout.start(seconds=nextTimeout) + _moduleLogger.info("%s Marked for update" % (self._name, )) + else: + _moduleLogger.info("%s Disabled, skipping update (timeout is %s seconds)" % (self._name, nextTimeout, )) @property def request_reset_timers(self): diff --git a/support/builddeb.py b/support/builddeb.py index 67f1203..535a17a 100755 --- a/support/builddeb.py +++ b/support/builddeb.py @@ -34,6 +34,9 @@ __build__ = constants.__build__ __changelog__ = """ * Shaving 300ms off of startup time * Making the alias code a bit more robust, taken from a fix for an issue that breaks dialcentral +* Adding a quit command to the debug prompt +* Adding a update_now command to the debug prompt +* Fixing a bug with reset_timers debug prompt """.strip() -- 1.7.9.5