super(SendText, self)._on_done()
+class Block(Action):
+
+ def __init__(self):
+ super(Block, self).__init__()
+
+ def queue_action(self):
+ print "Blocking"
+
+ def _on_done(self):
+ #super(SendText, self)._on_done()
+ pass
+
+
class Disconnect(Action):
def __init__(self, connAction):
lastAction.append_action(sendtext)
lastAction = sendtext
+ if True:
+ bl = Block()
+ lastAction.append_action(bl)
+ lastAction = bl
dis = Disconnect(con)
lastAction.append_action(dis)
@coroutines.func_sink
@coroutines.expand_positional
@gobject_utils.async
+ @gtk_toolbox.log_exception(_moduleLogger)
def _on_contacts_refreshed(self, addressbook, added, removed, changed):
self._process_refresh(addressbook, added, removed)
@coroutines.func_sink
@coroutines.expand_positional
@gobject_utils.async
+ @gtk_toolbox.log_exception(_moduleLogger)
def _on_conversations_updated(self, conversationIds):
if self._contactKey not in conversationIds:
return
+ _moduleLogger.info("Incoming messages from %r for existing conversation" % (self._contactKey, ))
conversation = self._conn.session.conversations.get_conversation(self._contactKey)
self._report_conversation(conversation)
def _report_conversation(self, conversation):
- # @bug Check if messages sent need to be filtered out
+ # @bug? Check if messages sent need to be filtered out
completeMessageHistory = conversation["messageParts"]
messages = self._filter_seen_messages(completeMessageHistory)
self._lastMessageTimestamp = messages[-1][0]
self._callbackNumber = parameters['forward'].encode('utf-8')
self._channelManager = channel_manager.ChannelManager(self)
- cookieFilePath = "%s/cookies.txt" % constants._data_path_
+ cookieFilePath = None
self._session = gvoice.session.Session(cookieFilePath)
self.set_self_handle(handle.create_handle(self, 'connection'))
telepathy.CONNECTION_STATUS_REASON_REQUESTED
)
try:
+ self.session.conversations.updateSignalHandler.register_sink(
+ self._on_conversations_updated
+ )
self.session.login(*self._credentials)
self.session.backend.set_callback_number(self._callbackNumber)
except gvoice.backend.NetworkError, e:
"""
_moduleLogger.info("Disconnecting")
try:
+ self.session.conversations.updateSignalHandler.unregister_sink(
+ self._on_conversations_updated
+ )
self._channelManager.close()
self.session.logout()
_moduleLogger.info("Disconnected")
@coroutines.func_sink
@coroutines.expand_positional
@gobject_utils.async
+ @gtk_toolbox.log_exception(_moduleLogger)
def _on_conversations_updated(self, conversationIds):
# @todo get conversations update running
# @todo test conversatiuons
+ _moduleLogger.info("Incoming messages from: %r" % (conversationIds, ))
channelManager = self._channelManager
for contactId, phoneNumber in conversationIds:
h = self._create_contact_handle(contactId, phoneNumber)
self._conversations = {}
self.updateSignalHandler = coroutines.CoTee()
- self.update()
def update(self, force=False):
if not force and self._conversations:
import backend
import addressbook
import conversations
+import state_machine
_moduleLogger = logging.getLogger("gvoice.session")
class Session(object):
- def __init__(self, cookiePath):
- self._cookiePath = cookiePath
+ def __init__(self, cookiePath = None):
self._username = None
self._password = None
- self._backend = None
- self._addressbook = None
- self._conversations = None
+
+ self._backend = backend.GVoiceBackend(cookiePath)
+ self._addressbook = addressbook.Addressbook(self._backend)
+ self._conversations = conversations.Conversations(self._backend)
+ self._stateMachine = state_machine.StateMachine([self.addressbook], [self.conversations])
+
+ self._conversations.updateSignalHandler.register_sink(
+ self._stateMachine.request_reset_timers
+ )
def login(self, username, password):
self._username = username
self._password = password
- self._backend = backend.GVoiceBackend(self._cookiePath)
if not self._backend.is_authed():
self._backend.login(self._username, self._password)
+ self._stateMachine.start()
+
def logout(self):
+ self._loggedIn = False
+ self._stateMachine.stop()
+ self._backend.logout()
+
self._username = None
self._password = None
- self._backend = None
- self._addressbook = None
- self._conversations = None
def is_logged_in(self):
- if self._backend is None:
- _moduleLogger.info("No Backend")
+ if self._username is None and self._password is None:
+ _moduleLogger.info("Hasn't even attempted to login yet")
return False
elif self._backend.is_authed():
return True
"""
Delay initialized addressbook
"""
- if self._addressbook is None:
- _moduleLogger.info("Initializing addressbook")
- self._addressbook = addressbook.Addressbook(self.backend)
return self._addressbook
@property
"""
Delay initialized addressbook
"""
- if self._conversations is None:
- _moduleLogger.info("Initializing conversations")
- self._conversations = conversations.Conversations(self.backend)
return self._conversations
#!/usr/bin/env python
+"""
+@todo Look into switching from POLL_TIME = min(F * 2^n, MAX) to POLL_TIME = min(CONST + F * 2^n, MAX)
+@todo Look into supporting more states that have a different F and MAX
+"""
+
import Queue
import threading
import logging
import util.algorithms as algorithms
import util.coroutines as coroutines
+
_moduleLogger = logging.getLogger("gvoice.state_machine")
self.reset_timers()
def _run(self):
+ logging.basicConfig(level=logging.DEBUG)
+ _moduleLogger.info("Starting State Machine")
for item in self._initItems:
try:
item.update()
actions = list(algorithms.itr_available(self._actions, initiallyBlock = True))
if self._ACTION_STOP in actions:
+ _moduleLogger.info("Requested to stop")
self._stop_update()
break
elif self._ACTION_RESET in actions:
+ _moduleLogger.info("Reseting timers")
self._reset_timers()
elif self._ACTION_UPDATE in actions:
+ _moduleLogger.info("Update")
for item in self._updateItems:
try:
item.update(force=True)
conversings.updateSignalHandler.register_sink(callback)
assert len(callbackData) == 0, "%r" % callbackData
+ conversings.update()
+ assert len(callbackData) == 1, "%r" % callbackData
+ del callbackData[:]
+
cons = list(conversings.get_conversations())
assert len(cons) == 1
assert cons[0] == ("con1", "5555551224"), cons
conversings.updateSignalHandler.register_sink(callback)
assert len(callbackData) == 0, "%r" % callbackData
+ conversings.update()
+ assert len(callbackData) == 1, "%r" % callbackData
+ del callbackData[:]
+
cons = list(conversings.get_conversations())
assert len(cons) == 1
assert cons[0] == ("con1", "5555551224"), cons
conversings.updateSignalHandler.register_sink(callback)
assert len(callbackData) == 0, "%r" % callbackData
+ conversings.update()
+ assert len(callbackData) == 1, "%r" % callbackData
+ del callbackData[:]
+
cons = list(conversings.get_conversations())
assert len(cons) == 1
assert cons[0] == ("con1", "5555551224"), cons