From: Ed Page Date: Sat, 3 Oct 2009 23:08:25 +0000 (-0500) Subject: Lessons learned from looking at telepathy-python to better understand what it was... X-Git-Url: http://git.maemo.org/git/?p=theonering;a=commitdiff_plain;h=a1133bfb13b2e4924f0c196d20750832f6058c90 Lessons learned from looking at telepathy-python to better understand what it was doing on my behalf --- diff --git a/src/channel/call.py b/src/channel/call.py index 21613b7..29b56b1 100644 --- a/src/channel/call.py +++ b/src/channel/call.py @@ -1,4 +1,3 @@ -import weakref import logging import telepathy @@ -13,16 +12,11 @@ class CallChannel( ): 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) - self.GroupFlagsChanged(telepathy.CHANNEL_GROUP_FLAG_CAN_ADD, 0) - self.__add_initial_participants() - def ListStreams(self): """ For org.freedesktop.Telepathy.Channel.Type.StreamedMedia diff --git a/src/channel/contact_list.py b/src/channel/contact_list.py index 7f538db..b51a050 100644 --- a/src/channel/contact_list.py +++ b/src/channel/contact_list.py @@ -1,4 +1,3 @@ -import weakref import logging import telepathy @@ -21,7 +20,6 @@ class AbstractListChannel( telepathy.server.ChannelTypeContactList.__init__(self, connection, h) telepathy.server.ChannelInterfaceGroup.__init__(self) - self._conn_ref = weakref.ref(connection) 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 """ - connection = self._conn_ref() + connection = self._conn handlesAdded = [ handle.create_handle(connection, "contact", contactId) for contactId in added diff --git a/src/channel/text.py b/src/channel/text.py index e882bfd..51d1a91 100644 --- a/src/channel/text.py +++ b/src/channel/text.py @@ -1,8 +1,13 @@ import time -import weakref +import logger import telepathy +import handle + + +_moduleLogger = logger.getLogger("channel.text") + class TextChannel(telepathy.server.ChannelTypeText): """ @@ -10,22 +15,37 @@ class TextChannel(telepathy.server.ChannelTypeText): """ 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): - if messageType == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL: - pass - else: + if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL: raise telepathy.NotImplemented("Unhandled message type") + # @todo implement sending message self.Sent(int(time.time()), messageType, text) def Close(self): - self._conversation.leave() 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 diff --git a/src/connection.py b/src/connection.py index 591f7b7..a772bb5 100644 --- a/src/connection.py +++ b/src/connection.py @@ -129,6 +129,7 @@ class TheOneRingConnection(telepathy.server.Connection): @returns DBus object path for the channel created or retrieved """ self.check_connected() + self.check_handle(handleType, handleId) 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 + Overiding telepathy.server.Connecton to allow custom handles """ self.check_connected() self.check_handle_type(handleType) diff --git a/src/connection_manager.py b/src/connection_manager.py index 50f15f7..f169789 100644 --- a/src/connection_manager.py +++ b/src/connection_manager.py @@ -15,6 +15,7 @@ class TheOneRingConnectionManager(telepathy.server.ConnectionManager): 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") diff --git a/src/handle.py b/src/handle.py index bcce9d5..5838517 100644 --- a/src/handle.py +++ b/src/handle.py @@ -43,11 +43,11 @@ class ContactHandle(TheOneRingHandle): handleName = contactId TheOneRingHandle.__init__(self, connection, id, handleType, handleName) - self._id = contactId + self._contactId = contactId @property def contactID(self): - return self._id + return self._contactId @property def contactDetails(self): @@ -80,6 +80,7 @@ def create_handle_factory(): 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