2 # LADITools - Linux Audio Desktop Integration Tools
3 # Copyright (C) 2012 Alessio Treglia <quadrispro@ubuntu.com>
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 class LadiController(object):
22 """Wrap common routines used by D-Bus objects.
24 It is recommended to use one of the available implementations
25 instead of creating instances of this class.
28 def __init__(self
, dbus_type
, service_name
, obj_path
, iface_name
, args
= None):
30 self
.bus
= getattr(dbus
, dbus_type
)()
31 self
.controller_obj
= self
.bus
.get_object (service_name
, obj_path
)
32 self
.controller_iface
= dbus
.Interface (self
.controller_obj
, iface_name
)
34 def is_available (self
):
35 """Check if the service is available."""
39 except Exception, err
:
40 sys
.stderr
.write(str(err
) + '\n')
44 def is_started (self
):
45 """Check if the service is running."""
46 return self
.controller_iface
.is_started ()
49 """Start the service."""
50 self
.controller_iface
.start()
53 """Stop the service."""
54 self
.controller_iface
.stop()
57 """Kill the service."""
58 self
.controller_iface
.exit()