Lessons learned from looking at telepathy-python to better understand what it was...
authorEd Page <eopage@byu.net>
Sat, 3 Oct 2009 23:08:25 +0000 (18:08 -0500)
committerEd Page <eopage@byu.net>
Sat, 3 Oct 2009 23:08:25 +0000 (18:08 -0500)
src/channel/call.py
src/channel/contact_list.py
src/channel/text.py
src/connection.py
src/connection_manager.py
src/handle.py

index 21613b7..29b56b1 100644 (file)
@@ -1,4 +1,3 @@
-import weakref
 import logging
 
 import telepathy
 import logging
 
 import telepathy
@@ -13,16 +12,11 @@ class CallChannel(
        ):
 
        def __init__(self, connection):
        ):
 
        def __init__(self, connection):
-               self._recv_id = 0
-               self._connRef = weakref.ref(connection)
-
-               telepathy.server.ChannelTypeText.__init__(self, connection, None)
+               h = None
+               telepathy.server.ChannelTypeStreamedMedia.__init__(self, connection, h)
                telepathy.server.ChannelInterfaceGroup.__init__(self)
                telepathy.server.ChannelInterfaceChatState.__init__(self)
 
                telepathy.server.ChannelInterfaceGroup.__init__(self)
                telepathy.server.ChannelInterfaceChatState.__init__(self)
 
-               self.GroupFlagsChanged(telepathy.CHANNEL_GROUP_FLAG_CAN_ADD, 0)
-               self.__add_initial_participants()
-
        def ListStreams(self):
                """
                For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
        def ListStreams(self):
                """
                For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
index 7f538db..b51a050 100644 (file)
@@ -1,4 +1,3 @@
-import weakref
 import logging
 
 import telepathy
 import logging
 
 import telepathy
@@ -21,7 +20,6 @@ class AbstractListChannel(
                telepathy.server.ChannelTypeContactList.__init__(self, connection, h)
                telepathy.server.ChannelInterfaceGroup.__init__(self)
 
                telepathy.server.ChannelTypeContactList.__init__(self, connection, h)
                telepathy.server.ChannelInterfaceGroup.__init__(self)
 
-               self._conn_ref = weakref.ref(connection)
                self._session = connection.session
 
 
                self._session = connection.session
 
 
@@ -47,7 +45,7 @@ class AllContactsListChannel(AbstractListChannel):
                @todo This currently does not handle people with multiple phone
                        numbers, yay that'll be annoying to resolve
                """
                @todo This currently does not handle people with multiple phone
                        numbers, yay that'll be annoying to resolve
                """
-               connection = self._conn_ref()
+               connection = self._conn
                handlesAdded = [
                        handle.create_handle(connection, "contact", contactId)
                        for contactId in added
                handlesAdded = [
                        handle.create_handle(connection, "contact", contactId)
                        for contactId in added
index e882bfd..51d1a91 100644 (file)
@@ -1,8 +1,13 @@
 import time
 import time
-import weakref
+import logger
 
 import telepathy
 
 
 import telepathy
 
+import handle
+
+
+_moduleLogger = logger.getLogger("channel.text")
+
 
 class TextChannel(telepathy.server.ChannelTypeText):
        """
 
 class TextChannel(telepathy.server.ChannelTypeText):
        """
@@ -10,22 +15,37 @@ class TextChannel(telepathy.server.ChannelTypeText):
        """
 
        def __init__(self, connection):
        """
 
        def __init__(self, connection):
-               self._recv_id = 0
-               self._connRef = weakref.ref(connection)
-
-               telepathy.server.ChannelTypeText.__init__(self, connection, None)
+               h = None
+               telepathy.server.ChannelTypeText.__init__(self, connection, h)
+               self._nextRecievedId = 0
 
 
-               self.GroupFlagsChanged(telepathy.CHANNEL_GROUP_FLAG_CAN_ADD, 0)
-               self.__add_initial_participants()
+               handles = []
+               # @todo Populate participants
+               self.MembersChanged('', handles, [], [], [],
+                               0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
 
        def Send(self, messageType, text):
 
        def Send(self, messageType, text):
-               if messageType == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
-                       pass
-               else:
+               if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
                        raise telepathy.NotImplemented("Unhandled message type")
                        raise telepathy.NotImplemented("Unhandled message type")
+               # @todo implement sending message
                self.Sent(int(time.time()), messageType, text)
 
        def Close(self):
                self.Sent(int(time.time()), messageType, text)
 
        def Close(self):
-               self._conversation.leave()
                telepathy.server.ChannelTypeText.Close(self)
                self.remove_from_connection()
                telepathy.server.ChannelTypeText.Close(self)
                self.remove_from_connection()
+
+       def _on_message_received(self, sender, message):
+               """
+               @todo Attatch this to receiving a message
+               """
+               currentReceivedId = self._nextRecievedId
+
+               timestamp = int(time.time())
+               h = handle.create_handle(self._conn, "contact", sender.account)
+               type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
+               message = message.content
+
+               _moduleLogger.info("Received message from User %r" % h)
+               self.Received(id, timestamp, h, type, 0, message)
+
+               self._nextRecievedId += 1
index 591f7b7..a772bb5 100644 (file)
@@ -129,6 +129,7 @@ class TheOneRingConnection(telepathy.server.Connection):
                @returns DBus object path for the channel created or retrieved
                """
                self.check_connected()
                @returns DBus object path for the channel created or retrieved
                """
                self.check_connected()
+               self.check_handle(handleType, handleId)
 
                channel = None
                channelManager = self._channelManager
 
                channel = None
                channelManager = self._channelManager
@@ -152,6 +153,7 @@ class TheOneRingConnection(telepathy.server.Connection):
        def RequestHandles(self, handleType, names, sender):
                """
                For org.freedesktop.telepathy.Connection
        def RequestHandles(self, handleType, names, sender):
                """
                For org.freedesktop.telepathy.Connection
+               Overiding telepathy.server.Connecton to allow custom handles
                """
                self.check_connected()
                self.check_handle_type(handleType)
                """
                self.check_connected()
                self.check_handle_type(handleType)
index 50f15f7..f169789 100644 (file)
@@ -15,6 +15,7 @@ class TheOneRingConnectionManager(telepathy.server.ConnectionManager):
        def __init__(self, shutdown_func=None):
                telepathy.server.ConnectionManager.__init__(self, constants._telepathy_implementation_name_)
 
        def __init__(self, shutdown_func=None):
                telepathy.server.ConnectionManager.__init__(self, constants._telepathy_implementation_name_)
 
+               # self._protos is from super
                self._protos[constants._telepathy_protocol_name_] = connection.TheOneRingConnection
                self._on_shutdown = shutdown_func
                _moduleLogger.info("Connection manager created")
                self._protos[constants._telepathy_protocol_name_] = connection.TheOneRingConnection
                self._on_shutdown = shutdown_func
                _moduleLogger.info("Connection manager created")
index bcce9d5..5838517 100644 (file)
@@ -43,11 +43,11 @@ class ContactHandle(TheOneRingHandle):
                handleName = contactId
                TheOneRingHandle.__init__(self, connection, id, handleType, handleName)
 
                handleName = contactId
                TheOneRingHandle.__init__(self, connection, id, handleType, handleName)
 
-               self._id = contactId
+               self._contactId = contactId
 
        @property
        def contactID(self):
 
        @property
        def contactID(self):
-               return self._id
+               return self._contactId
 
        @property
        def contactDetails(self):
 
        @property
        def contactDetails(self):
@@ -80,6 +80,7 @@ def create_handle_factory():
                        handle = cache[key]
                        isNewHandle = False
                except KeyError:
                        handle = cache[key]
                        isNewHandle = False
                except KeyError:
+                       # The misnamed get_handle_id requests a new handle id
                        handle = Handle(connection, connection.get_handle_id(), *args)
                        cache[key] = handle
                        isNewHandle = True
                        handle = Handle(connection, connection.get_handle_id(), *args)
                        cache[key] = handle
                        isNewHandle = True