9de629e7ad436cd1d574cdd15506d7e795098b31
[theonering] / src / channel / call.py
1 import logging
2
3 import telepathy
4
5 import gtk_toolbox
6 import handle
7
8
9 _moduleLogger = logging.getLogger("channel.call")
10
11
12 # @todo Test Calls
13 class CallChannel(
14                 telepathy.server.ChannelTypeStreamedMedia,
15                 telepathy.server.ChannelInterfaceCallState,
16         ):
17
18         def __init__(self, connection, contactHandle):
19                 telepathy.server.ChannelTypeStreamedMedia.__init__(self, connection, None)
20                 telepathy.server.ChannelInterfaceCallState.__init__(self)
21                 self._contactHandle = contactHandle
22
23         @gtk_toolbox.log_exception(_moduleLogger)
24         def Close(self):
25                 self.close()
26
27         def close(self):
28                 telepathy.server.ChannelTypeStreamedMedia.Close(self)
29                 self.remove_from_connection()
30                 self._prop_getters = None # HACK to get around python-telepathy memory leaks
31
32         @gtk_toolbox.log_exception(_moduleLogger)
33         def ListStreams(self):
34                 """
35                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
36                 """
37                 return ()
38
39         @gtk_toolbox.log_exception(_moduleLogger)
40         def RemoveStreams(self, streams):
41                 """
42                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
43                 """
44                 raise telepathy.errors.NotImplemented("Cannot remove a stream")
45
46         @gtk_toolbox.log_exception(_moduleLogger)
47         def RequestStreamDirection(self, stream, streamDirection):
48                 """
49                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
50
51                 @note Since streams are short lived, not bothering to implement this
52                 """
53                 _moduleLogger.info("A request was made to change the stream direction")
54                 raise telepathy.errors.NotImplemented("Cannot change directions")
55
56         @gtk_toolbox.log_exception(_moduleLogger)
57         def RequestStreams(self, contactId, streamTypes):
58                 """
59                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
60
61                 @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)]
62                 """
63                 for streamType in streamTypes:
64                         if streamType != telepathy.constants.MEDIA_STREAM_TYPE_AUDIO:
65                                 raise telepathy.errors.NotImplemented("Audio is the only stream type supported")
66
67                 contact = self._conn.handle(telepathy.constants.HANDLE_TYPE_CONTACT, contactId)
68                 assert self._contactHandle == contact, "%r != %r" % (self._contactHandle, contact)
69                 contactId, contactNumber = handle.ContactHandle.from_handle_name(contact.name)
70
71                 self._conn.session.backend.call(contactNumber)
72
73                 streamId = 0
74                 streamState = telepathy.constants.MEDIA_STREAM_STATE_DISCONNECTED
75                 streamDirection = telepathy.constants.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL
76                 pendingSendFlags = telepathy.constants.MEDIA_STREAM_PENDING_REMOTE_SEND
77                 return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)]
78
79         @gtk_toolbox.log_exception(_moduleLogger)
80         def GetCallStates(self):
81                 """
82                 For org.freedesktop.Telepathy.Channel.Interface.CallState
83
84                 Get the current call states for all contacts involved in this call. 
85                 @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*}
86                 """
87                 return {}