Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/echo-server
blob: 011a8f788c28e9c4611d127ea0d1225dda2f78b5 (plain)
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
#!/usr/bin/env python
import os
import sys
import subprocess
from optparse import OptionParser

import gobject

import dbus
import dbus.service
import dbus.mainloop.glib

def log(msg, *args):
    if len(args):
        print msg % args
    else:
        print msg

class EchoServer(dbus.service.Object):
    """The echo service."""
    SERVICE_NAME = 'org.laptop.Echo'
    INTERFACE_NAME = 'org.laptop.Echo'

    def __init__(self, bus_or_name):
        dbus.service.Object.__init__(self, bus_or_name, '/')

    @dbus.service.method(INTERFACE_NAME,
                         in_signature='s',
                         out_signature='s')
    def echo(self, msg):
        return msg

def run():
    """Start the Rainbow DBus service."""
    parser = OptionParser(version='0.1')
    parser.add_option('-f', '--bus-config-file', default='./session-olpc.conf',
                      help='The dbus session bus config file to test.')
    opts, args = parser.parse_args()


    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

    bus = dbus.SessionBus()
    name = dbus.service.BusName(EchoServer.SERVICE_NAME, bus)
    EchoServer(name)

    print 'Echo service running mainloop.'
    mainloop = gobject.MainLoop()
    mainloop.run()

def main():
    run()

if __name__ == '__main__':
    main()