Call-centric work
authorEd Page <eopage@byu.net>
Thu, 24 Dec 2009 15:36:32 +0000 (09:36 -0600)
committerEd Page <eopage@byu.net>
Thu, 24 Dec 2009 15:36:32 +0000 (09:36 -0600)
* Cleanup
* Putting a hack in for capabilities
* Call state stuff

src/aliasing.py
src/capabilities.py
src/channel/call.py
src/gvoice/backend.py
src/gvoice/conversations.py
src/gvoice/state_machine.py
src/handle.py
src/presence.py
src/simple_presence.py

index ed79708..bf73e06 100644 (file)
@@ -77,12 +77,11 @@ class AliasingMixin(telepathy.server.ConnectionInterfaceAliasing):
                """
                raise NotImplementedError("Abstract property called")
 
-       @property
-       def handle(self):
+       def handle(self, handleType, handleId):
                """
                @abstract
                """
-               raise NotImplementedError("Abstract property called")
+               raise NotImplementedError("Abstract function called")
 
        @gtk_toolbox.log_exception(_moduleLogger)
        def GetAliasFlags(self):
index 31227d4..c4a94cb 100644 (file)
@@ -24,27 +24,39 @@ class CapabilitiesMixin(telepathy.server.ConnectionInterfaceCapabilities):
                """
                raise NotImplementedError("Abstract property called")
 
-       @property
-       def handle(self):
+       def handle(self, handleType, handleId):
                """
                @abstract
                """
-               raise NotImplementedError("Abstract property called")
+               raise NotImplementedError("Abstract function called")
+
+       def GetSelfHandle(self):
+               """
+               @abstract
+               """
+               raise NotImplementedError("Abstract function called")
 
        @gtk_toolbox.log_exception(_moduleLogger)
-       def GetCapabilities(self, handles):
+       def GetCapabilities(self, handleIds):
                """
                @todo HACK Remove this once we are building against a fixed version of python-telepathy
                """
                ret = []
-               for handle in handles:
-                       if handle != 0 and (telepathy.HANDLE_TYPE_CONTACT, handle) not in self._handles:
+               for handleId in handleIds:
+                       h = self.handle(telepathy.HANDLE_TYPE_CONTACT, handleId)
+                       if handleId != 0 and (telepathy.HANDLE_TYPE_CONTACT, handleId) not in self._handles:
                                raise telepathy.errors.InvalidHandle
-                       elif handle in self._caps:
-                               theirs = self._caps[handle]
-                               for type in theirs:
-                                       ret.append([handle, type, theirs[0], theirs[1]])
-               _moduleLogger.info("GetCaps %r" % ret)
+                       elif h in self._caps:
+                               types = self._caps[h]
+                               for type in types:
+                                       for ctype, specs in types.iteritems():
+                                               ret.append([handleId, type, specs[0], specs[1]])
+                       else:
+                               # No caps, so just default to the connection's caps
+                               types = self._caps[self.GetSelfHandle()]
+                               for type in types:
+                                       for ctype, specs in types.iteritems():
+                                               ret.append([handleId, type, specs[0], specs[1]])
                return ret
 
        @gtk_toolbox.log_exception(_moduleLogger)
@@ -52,7 +64,7 @@ class CapabilitiesMixin(telepathy.server.ConnectionInterfaceCapabilities):
                """
                @todo HACK Remove this once we are building against a fixed version of python-telepathy
                """
-               my_caps = self._caps.setdefault(self._self_handle, {})
+               my_caps = self._caps.setdefault(self.GetSelfHandle(), {})
 
                changed = {}
                for ctype, spec_caps in add:
@@ -70,13 +82,12 @@ class CapabilitiesMixin(telepathy.server.ConnectionInterfaceCapabilities):
                                # channel type supports new capabilities
                                gen_new, spec_new = gen_old, spec_old | spec_caps
                        if spec_old != spec_new or gen_old != gen_new:
-                               caps.append((self._self_handle, ctype, gen_old, gen_new,
+                               caps.append((self.GetSelfHandle(), ctype, gen_old, gen_new,
                                                        spec_old, spec_new))
 
-               _moduleLogger.info("CapsChanged %r" % caps)
                self.CapabilitiesChanged(caps)
+               _moduleLogger.info("CapsChanged %r" % self._caps)
 
                # return all my capabilities
                ret = [(ctype, caps[1]) for ctype, caps in my_caps.iteritems()]
-               _moduleLogger.info("Adv %r" % ret)
                return ret
index 9de629e..24ec99f 100644 (file)
@@ -60,15 +60,13 @@ class CallChannel(
 
                @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)]
                """
-               for streamType in streamTypes:
-                       if streamType != telepathy.constants.MEDIA_STREAM_TYPE_AUDIO:
-                               raise telepathy.errors.NotImplemented("Audio is the only stream type supported")
-
                contact = self._conn.handle(telepathy.constants.HANDLE_TYPE_CONTACT, contactId)
                assert self._contactHandle == contact, "%r != %r" % (self._contactHandle, contact)
                contactId, contactNumber = handle.ContactHandle.from_handle_name(contact.name)
 
+               self.CallStateChanged(self._contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING)
                self._conn.session.backend.call(contactNumber)
+               self.CallStateChanged(self._contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED)
 
                streamId = 0
                streamState = telepathy.constants.MEDIA_STREAM_STATE_DISCONNECTED
@@ -84,4 +82,4 @@ class CallChannel(
                Get the current call states for all contacts involved in this call. 
                @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*}
                """
-               return {}
+               return {self._contactHandle: telepathy.constants.CHANNEL_CALL_STATE_FORWARDED}
index 251cfa5..a02ed76 100755 (executable)
@@ -437,6 +437,7 @@ class GVoiceBackend(object):
                @param callbacknumber should be a proper 10 digit number
                """
                self._callbackNumber = callbacknumber
+               _moduleLogger.info("Callback number changed: %r" % self._callbackNumber)
                return True
 
        def get_callback_number(self):
index 4541608..7435da8 100644 (file)
@@ -38,7 +38,8 @@ class Conversations(object):
                                mergedConversations.append_conversation(conversation)
                                isConversationUpdated = True
                        except RuntimeError, e:
-                               _moduleLogger.info("Skipping conversation for %r because '%s'" % (key, e))
+                               if False:
+                                       _moduleLogger.info("Skipping conversation for %r because '%s'" % (key, e))
                                isConversationUpdated = False
 
                        if isConversationUpdated:
index 6b0a58d..6080abd 100644 (file)
@@ -72,6 +72,7 @@ class StateMachine(object):
                        except Exception:
                                _moduleLogger.exception("Initial update failed for %r" % item)
                self._schedule_update()
+               return False # do not continue
 
        def stop(self):
                _moduleLogger.info("Stopping an already stopped state machine")
@@ -103,6 +104,7 @@ class StateMachine(object):
                self._currentPeriod = self._INITIAL_ACTIVE_PERIOD / 2 # We will double it later
 
        def _schedule_update(self):
+               assert self._timeoutId is None
                nextTimeout = self._calculate_step(self._state, self._currentPeriod)
                nextTimeout = int(nextTimeout)
                if nextTimeout != self._INFINITE_PERIOD:
@@ -117,6 +119,8 @@ class StateMachine(object):
                self._timeoutId = None
 
        def _reset_timers(self):
+               if self._timeoutId is None:
+                       return # not started yet
                self._stop_update()
                self._set_initial_period()
                self._schedule_update()
@@ -128,6 +132,7 @@ class StateMachine(object):
                                item.update(force=True)
                        except Exception:
                                _moduleLogger.exception("Update failed for %r" % item)
+               self._timeoutId = None
                self._schedule_update()
                return False # do not continue
 
index 55f36fb..33d5660 100644 (file)
@@ -121,8 +121,9 @@ def create_handle_factory():
                        cache[key] = handle
                        isNewHandle = True
                connection._handles[handle.get_type(), handle.get_id()] = handle
-               handleStatus = "Is New!" if isNewHandle else "From Cache"
-               _moduleLogger.info("Created Handle: %r (%s)" % (handle, handleStatus))
+               if False:
+                       handleStatus = "Is New!" if isNewHandle else "From Cache"
+                       _moduleLogger.info("Created Handle: %r (%s)" % (handle, handleStatus))
                return handle
 
        return create_handle
index f078e27..8c38252 100644 (file)
@@ -4,7 +4,6 @@ import telepathy
 
 import gtk_toolbox
 import simple_presence
-import gvoice.state_machine as state_machine
 
 
 _moduleLogger = logging.getLogger('presence')
index e5d5973..49941f8 100644 (file)
@@ -32,14 +32,13 @@ class TheOneRingPresence(object):
                """
                raise NotImplementedError()
 
-       @property
-       def handle(self):
+       def Disconnect(self):
                """
                @abstract
                """
-               raise NotImplementedError("Abstract property called")
+               raise NotImplementedError("Abstract function called")
 
-       def Disconnect(self):
+       def handle(self, handleType, handleId):
                """
                @abstract
                """