3
""" The wicd DBus Manager.
5
A module for managing wicd's dbus interfaces.
10
# Copyright (C) 2008-2009 Adam Blackburn
11
# Copyright (C) 2008-2009 Dan O'Reilly
13
# This program is free software; you can redistribute it and/or modify
14
# it under the terms of the GNU General Public License Version 2 as
15
# published by the Free Software Foundation.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License
23
# along with this program. If not, see <http://www.gnu.org/licenses/>.
27
if getattr(dbus, "version", (0, 0, 0)) < (0, 80, 0):
30
from dbus.mainloop.glib import DBusGMainLoop
31
DBusGMainLoop(set_as_default=True)
35
def get_dbus_ifaces():
36
return DBUS_MANAGER.get_dbus_ifaces()
38
def get_interface(iface):
39
return DBUS_MANAGER.get_interface(iface)
42
return DBUS_MANAGER.get_bus()
45
return DBUS_MANAGER.set_mainloop()
47
def connect_to_dbus():
48
return DBUS_MANAGER.connect_to_dbus()
51
dbus.mainloop.glib.threads_init()
54
class DBusManager(object):
55
""" Manages the DBus objects used by wicd. """
57
self._bus = dbus.SystemBus()
58
self._dbus_ifaces = {}
60
def get_dbus_ifaces(self):
61
""" Returns a dict of dbus interfaces. """
62
if not self._dbus_ifaces: connect_to_dbus()
63
return self._dbus_ifaces
65
def get_interface(self, iface):
66
""" Returns a DBus Interface. """
67
if not self._dbus_ifaces: connect_to_dbus()
68
return self._dbus_ifaces[iface]
71
""" Returns the loaded SystemBus. """
74
def set_mainloop(self, loop):
75
dbus.set_default_main_loop(loop)
77
def connect_to_dbus(self):
78
""" Connects to wicd's dbus interfaces and loads them into a dict. """
79
proxy_obj = self._bus.get_object("org.wicd.daemon", '/org/wicd/daemon')
80
daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon')
82
proxy_obj = self._bus.get_object("org.wicd.daemon",
83
'/org/wicd/daemon/wireless')
84
wireless = dbus.Interface(proxy_obj, 'org.wicd.daemon.wireless')
86
proxy_obj = self._bus.get_object("org.wicd.daemon",
87
'/org/wicd/daemon/wired')
88
wired = dbus.Interface(proxy_obj, 'org.wicd.daemon.wired')
90
self._dbus_ifaces = {"daemon" : daemon, "wireless" : wireless,
93
DBUS_MANAGER = DBusManager()
b'\\ No newline at end of file'