Switching from the closing being info to debug log
[theonering] / src / channel / call.py
1 import logging
2
3 import gobject
4 import telepathy
5
6 import tp
7 import gtk_toolbox
8
9
10 _moduleLogger = logging.getLogger("channel.call")
11
12
13 class CallChannel(
14                 tp.ChannelTypeStreamedMedia,
15                 tp.ChannelInterfaceCallState,
16                 tp.ChannelInterfaceGroup,
17         ):
18         # @bug On Maemo 5 this is having some kind of "General" error, possibly due to an issue with "GetAll" DBusProperties stuff
19
20         def __init__(self, connection, manager, props, contactHandle):
21                 self.__manager = manager
22                 self.__props = props
23                 self.__cancelId = None
24
25                 tp.ChannelTypeStreamedMedia.__init__(self, connection, manager, props)
26                 tp.ChannelInterfaceCallState.__init__(self)
27                 tp.ChannelInterfaceGroup.__init__(self)
28                 self.__contactHandle = contactHandle
29                 self._implement_property_get(
30                         telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
31                         {
32                                 "InitialAudio": self.initial_audio,
33                                 "InitialVideo": self.initial_video,
34                         },
35                 )
36
37                 self.GroupFlagsChanged(0, 0)
38                 self.MembersChanged(
39                         '', [self._conn.GetSelfHandle()], [], [], [contactHandle],
40                         0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
41                 )
42
43         def initial_audio(self):
44                 return False
45
46         def initial_video(self):
47                 return False
48
49         @gtk_toolbox.log_exception(_moduleLogger)
50         def Close(self):
51                 self.close()
52
53         def close(self):
54                 _moduleLogger.debug("Closing call")
55                 tp.ChannelTypeStreamedMedia.Close(self)
56                 self.remove_from_connection()
57                 if self.__cancelId is not None:
58                         gobject.source_remove(self.__cancelId)
59                         self.__cancelId = None
60
61         @gtk_toolbox.log_exception(_moduleLogger)
62         def ListStreams(self):
63                 """
64                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
65                 """
66                 return ()
67
68         @gtk_toolbox.log_exception(_moduleLogger)
69         def RemoveStreams(self, streams):
70                 """
71                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
72                 """
73                 raise telepathy.errors.NotImplemented("Cannot remove a stream")
74
75         @gtk_toolbox.log_exception(_moduleLogger)
76         def RequestStreamDirection(self, stream, streamDirection):
77                 """
78                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
79
80                 @note Since streams are short lived, not bothering to implement this
81                 """
82                 _moduleLogger.info("A request was made to change the stream direction")
83                 raise telepathy.errors.NotImplemented("Cannot change directions")
84
85         @gtk_toolbox.log_exception(_moduleLogger)
86         def RequestStreams(self, contactId, streamTypes):
87                 """
88                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
89
90                 @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)]
91                 """
92                 contact = self._conn.get_handle_by_id(telepathy.constants.HANDLE_TYPE_CONTACT, contactId)
93                 assert self.__contactHandle == contact, "%r != %r" % (self.__contactHandle, contact)
94                 contactNumber = contact.phoneNumber
95
96                 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING)
97                 self.__cancelId = gobject.idle_add(self._on_cancel)
98                 self._conn.session.backend.call(contactNumber)
99
100                 streamId = 0
101                 streamState = telepathy.constants.MEDIA_STREAM_STATE_DISCONNECTED
102                 streamDirection = telepathy.constants.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL
103                 pendingSendFlags = telepathy.constants.MEDIA_STREAM_PENDING_REMOTE_SEND
104                 return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)]
105
106         @gtk_toolbox.log_exception(_moduleLogger)
107         def GetCallStates(self):
108                 """
109                 For org.freedesktop.Telepathy.Channel.Interface.CallState
110
111                 Get the current call states for all contacts involved in this call. 
112                 @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*}
113                 """
114                 return {self.__contactHandle: telepathy.constants.CHANNEL_CALL_STATE_FORWARDED}
115
116         @gtk_toolbox.log_exception(_moduleLogger)
117         def _on_cancel(self, *args):
118                 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED)
119                 self.close()
120                 self.__cancelId = None
121                 return False