forked from willprice/python-omxplayer-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbus_connection.py
More file actions
48 lines (40 loc) · 1.82 KB
/
Copy pathdbus_connection.py
File metadata and controls
48 lines (40 loc) · 1.82 KB
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
import dbus
class DBusConnectionError(Exception):
""" Connection error raised when DBusConnection can't set up a connection
"""
pass
class DBusConnection(object):
"""
Attributes:
proxy: The proxy object by which one interacts with a dbus object,
this makes communicating with a similar to that of communicating
with a POJO.
root_interface: org.mpris.MediaPlayer2 interface proxy object
player_interface: org.mpris.MediaPlayer2.Player interface proxy object
"""
def __init__(self, bus_address):
self.root_interface = None
self.player_interface = None
self._address = bus_address
self._bus = self._create_connection()
self.proxy = self._create_proxy()
def _create_connection(self):
return dbus.bus.BusConnection(self._address)
def _create_proxy(self):
try:
# introspection fails so it is disabled
proxy = self._bus.get_object('org.mpris.MediaPlayer2.omxplayer',
'/org/mpris/MediaPlayer2',
introspect=False)
self._create_media_interfaces_on_proxy(proxy)
return proxy
except dbus.DBusException:
raise DBusConnectionError('Could not get proxy object')
def _create_media_interfaces_on_proxy(self, proxy):
self.root_interface = self._interface(proxy, 'org.mpris.MediaPlayer2')
self.player_interface = self._interface(proxy,
'org.mpris.MediaPlayer2.Player')
self.properties_interface = self._interface(proxy,
'org.freedesktop.DBus.Properties')
def _interface(self, proxy, interface):
return dbus.Interface(proxy, interface)