1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#
# Copyright (C) 2012-2013 Canonical, Ltd.
#
# This file is part of telepathy-ofono.
#
# telepathy-ofono is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3.
#
# telepathy-ofono is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
import dbus
__all__ = ['oFonoCall']
logger = logging.getLogger('oFono.Call')
class oFonoCall:
PROPERTY_KEY_STATE = "State"
PROPERTY_KEY_LINE_IDENTIFICATION = "LineIdentification"
PROPERTY_STATE_ACTIVE = "active"
PROPERTY_STATE_INCOMING = "incoming"
PROPERTY_STATE_HELD = "held"
PROPERTY_STATE_ALERTING = "alerting"
PROPERTY_STATE_DIALING = "dialing"
PROPERTY_STATE_DISCONNECTED = "disconnected"
PROPERTY_STATE_WAITING = "waiting"
def __init__(self, objectPath, properties={}):
self.bus = dbus.SystemBus()
self.objectPath = objectPath
self.properties = properties
ofono_call_object = self.bus.get_object('org.ofono', objectPath)
self.ofono_call_proxy = dbus.Interface(ofono_call_object, 'org.ofono.VoiceCall')
self.bus.add_signal_receiver(self.PropertyChanged, 'PropertyChanged', 'org.ofono.VoiceCall', 'org.ofono', objectPath)
if self.properties == {}:
self.properties = self.ofono_call_proxy.GetProperties()
logger.info("Call properties:")
for key in self.properties:
logger.info(" %s: %s", key, self.properties[key])
self.number = self.properties[self.PROPERTY_KEY_LINE_IDENTIFICATION]
# this is an incoming call if its first state is "incoming"
self.isIncoming = (self.properties[self.PROPERTY_KEY_STATE] == self.PROPERTY_STATE_INCOMING) or \
(self.properties[self.PROPERTY_KEY_STATE] == self.PROPERTY_STATE_WAITING)
self.StatePropertyChanged(self.properties[self.PROPERTY_KEY_STATE], False)
def unregister_from_dbus(self):
self.bus.remove_signal_receiver(self.PropertyChanged, 'PropertyChanged', 'org.ofono.VoiceCall', 'org.ofono')
def PropertyChanged(self, prop, value):
self.properties[prop] = value
if prop == self.PROPERTY_KEY_STATE:
self.StatePropertyChanged(value)
def StatePropertyChanged(self, state, notify=True):
self.isRinging = state == self.PROPERTY_STATE_INCOMING
self.isHeld = state == self.PROPERTY_STATE_HELD
self.isAlerting = state == self.PROPERTY_STATE_ALERTING
self.isDialing = state == self.PROPERTY_STATE_DIALING
self.isActive = state == self.PROPERTY_STATE_ACTIVE
self.isDisconnected = state == self.PROPERTY_STATE_DISCONNECTED
self.isWaiting = state == self.PROPERTY_STATE_WAITING
# notify the call channel about the changed status
if (notify):
self.oFonoCallStateChanged()
def oFonoCallStateChanged(self):
pass
def Hangup(self):
self.ofono_call_proxy.Hangup()
def Answer(self):
self.ofono_call_proxy.Answer()
def isCallIncoming(self):
return self.isIncoming
def isCallRinging(self):
return self.isRinging
def isCallActive(self):
return self.isActive
def isCallDialing(self):
return self.isDialing
def isCallHeld(self):
return self.isHeld
def isCallAlerting(self):
return self.isAlerting
def isCallForeground(self):
return (not self.isCallHeld()) and (not self.isCallRinging()) and (not self.isCallDisconnected())
def isCallDisconnected(self):
return self.isDisconnected
def isCallWaiting(self):
return self.isWaiting
|