More call work
[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 class CallChannel(
13                 telepathy.server.ChannelTypeStreamedMedia,
14                 telepathy.server.ChannelInterfaceCallState,
15                 telepathy.server.ChannelInterfaceGroup,
16         ):
17
18         def __init__(self, connection, contactHandle):
19                 telepathy.server.ChannelTypeStreamedMedia.__init__(self, connection, None)
20                 telepathy.server.ChannelInterfaceCallState.__init__(self)
21                 telepathy.server.ChannelInterfaceGroup.__init__(self)
22                 self._contactHandle = contactHandle
23                 self._implement_property_get(
24                         telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
25                         {
26                                 "InitialAudio": self.initial_audio,
27                                 "InitialVideo": self.initial_video,
28                         },
29                 )
30
31         def initial_audio(self):
32                 return False
33
34         def initial_video(self):
35                 return False
36
37         @gtk_toolbox.log_exception(_moduleLogger)
38         def Close(self):
39                 self.close()
40
41         def close(self):
42                 telepathy.server.ChannelTypeStreamedMedia.Close(self)
43                 self.remove_from_connection()
44                 self._prop_getters = None # HACK to get around python-telepathy memory leaks
45
46         @gtk_toolbox.log_exception(_moduleLogger)
47         def ListStreams(self):
48                 """
49                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
50                 """
51                 return ()
52
53         @gtk_toolbox.log_exception(_moduleLogger)
54         def RemoveStreams(self, streams):
55                 """
56                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
57                 """
58                 raise telepathy.errors.NotImplemented("Cannot remove a stream")
59
60         @gtk_toolbox.log_exception(_moduleLogger)
61         def RequestStreamDirection(self, stream, streamDirection):
62                 """
63                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
64
65                 @note Since streams are short lived, not bothering to implement this
66                 """
67                 _moduleLogger.info("A request was made to change the stream direction")
68                 raise telepathy.errors.NotImplemented("Cannot change directions")
69
70         @gtk_toolbox.log_exception(_moduleLogger)
71         def RequestStreams(self, contactId, streamTypes):
72                 """
73                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
74
75                 @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)]
76                 """
77                 contact = self._conn.handle(telepathy.constants.HANDLE_TYPE_CONTACT, contactId)
78                 assert self._contactHandle == contact, "%r != %r" % (self._contactHandle, contact)
79                 contactId, contactNumber = handle.ContactHandle.from_handle_name(contact.name)
80
81                 self.CallStateChanged(self._contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING)
82                 self._conn.session.backend.call(contactNumber)
83                 self.CallStateChanged(self._contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED)
84
85                 streamId = 0
86                 streamState = telepathy.constants.MEDIA_STREAM_STATE_DISCONNECTED
87                 streamDirection = telepathy.constants.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL
88                 pendingSendFlags = telepathy.constants.MEDIA_STREAM_PENDING_REMOTE_SEND
89                 return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)]
90
91         @gtk_toolbox.log_exception(_moduleLogger)
92         def GetCallStates(self):
93                 """
94                 For org.freedesktop.Telepathy.Channel.Interface.CallState
95
96                 Get the current call states for all contacts involved in this call. 
97                 @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*}
98                 """
99                 return {self._contactHandle: telepathy.constants.CHANNEL_CALL_STATE_FORWARDED}