~dobey/changeup/trunk

« back to all changes in this revision

Viewing changes to changeup-dispatcher

  • Committer: Rodney Dawes
  • Date: 2010-02-08 04:47:16 UTC
  • Revision ID: rodney.dawes@canonical.com-20100208044716-waz7xxsotz7qvtuy
Add an initial dbus service file
Add the necessary __init__.py files
Add mocker.py in a contrib directory for use in tests
Add tests for the dispatcher and client code

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#
18
18
# You should have received a copy of the GNU General Public License along
19
19
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
import dbus.service
 
21
import sys
 
22
 
 
23
from changeup.client import CHANGEUP_BUS_NAME
 
24
from dbus.mainloop.glib import DBusGMainLoop
 
25
from gobject import MainLoop
 
26
 
 
27
DBusGMainLoop(set_as_default=True)
20
28
 
21
29
 
22
30
class Dispatcher(dbus.service.Object):
27
35
        self.queue = []
28
36
        self.path = '/queue'
29
37
        self.bus = dbus.SystemBus()
 
38
        self.__main = MainLoop()
30
39
        name = dbus.service.BusName(CHANGEUP_BUS_NAME,
31
40
                                    bus=self.bus)
32
41
        dbus.service.Object.__init__(self, bus_name=name,
33
42
                                     object_path=self.path)
34
43
 
35
 
    def dispatch_requestsl(self):
 
44
    def main(self):
 
45
        """Main loop.method."""
 
46
        self.__main.run()
 
47
 
 
48
    @dbus.service.method(CHANGEUP_BUS_NAME,
 
49
                         in_signature='', out_signature='')
 
50
    def dispatch_requests(self):
36
51
        '''Dispatch all the requests'''
37
52
        for appname in self.queue:
38
53
            self.RestartDispatched(appname)
 
54
        self.__main.quit()
39
55
 
40
 
    @dbus.service.method(CHANGEUP_QUEUE_NAME,
 
56
    @dbus.service.method(CHANGEUP_BUS_NAME,
41
57
                         in_signature='s', out_signature='')
42
58
    def queue_restart(self, appname):
43
59
        '''Queue an application restart.'''
55
71
    bus = dbus.SystemBus()
56
72
    if bus.request_name(CHANGEUP_BUS_NAME, dbus.bus.NAME_FLAG_DO_NOT_QUEUE) == dbus.bus.REQUEST_NAME_REPLY_EXISTS:
57
73
        sys.exit(0)
 
74
 
 
75
    dispatcher = Dispatcher()
 
76
    dispatcher.main()