Adding coverage and fixing bugs
[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 ListStreams(self):
25                 """
26                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
27                 """
28                 return ()
29
30         @gtk_toolbox.log_exception(_moduleLogger)
31         def RemoveStreams(self, streams):
32                 """
33                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
34                 """
35                 raise telepathy.errors.NotImplemented("Cannot remove a stream")
36
37         @gtk_toolbox.log_exception(_moduleLogger)
38         def RequestStreamDirection(self, stream, streamDirection):
39                 """
40                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
41
42                 @note Since streams are short lived, not bothering to implement this
43                 """
44                 _moduleLogger.info("A request was made to change the stream direction")
45                 raise telepathy.errors.NotImplemented("Cannot change directions")
46
47         @gtk_toolbox.log_exception(_moduleLogger)
48         def RequestStreams(self, contact, streamTypes):
49                 """
50                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
51
52                 @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)]
53                 """
54                 for streamType in streamTypes:
55                         if streamType != telepathy.constants.MEDIA_STREAM_TYPE_AUDIO:
56                                 raise telepathy.errors.NotImplemented("Audio is the only stream type supported")
57
58                 print self._contactHandle, contact
59                 contactId, contactNumber = handle.ContactHandle.from_handle_name(contact.name)
60
61                 self._conn.session.backend.call(contactNumber)
62
63                 streamId = 0
64                 streamState = telepathy.constants.MEDIA_STREAM_STATE_DISCONNECTED
65                 streamDirection = telepathy.constants.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL
66                 pendingSendFlags = telepathy.constants.MEDIA_STREAM_PENDING_REMOTE_SEND
67                 return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)]
68
69         @gtk_toolbox.log_exception(_moduleLogger)
70         def GetCallStates(self):
71                 """
72                 For org.freedesktop.Telepathy.Channel.Interface.CallState
73
74                 Get the current call states for all contacts involved in this call. 
75                 @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*}
76                 """
77                 return {}