File: dbus-bridge.py

package info (click to toggle)
event-dance 0.2.0-8~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,096 kB
  • sloc: ansic: 29,033; javascript: 2,709; makefile: 434; xml: 247; sh: 30; python: 27
file content (60 lines) | stat: -rw-r--r-- 1,516 bytes parent folder | download | duplicates (4)
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
56
57
58
59
60
#
# dbusBridge.js
#
# EventDance examples
#
# Copyright (C) 2011, Igalia S.L.
#
# Authors:
#   Eduardo Lima Mitev <elima@igalia.com>
#

from gi.repository import GObject
from gi.repository import Gio
from gi.repository import Evd

LISTEN_PORT = '8080'
DBUS_ADDR = 'alias:abstract=/org/eventdance/lib/examples/dbus-bridge'

# Session bus address
session_bus_addr = Gio.dbus_address_get_for_bus_sync(Gio.BusType.SESSION, None)

# Web transport
transport = Evd.WebTransportServer()

def on_new_peer(transport, peer, main_loop):
    # This is to send a virtual DBus address to the peer instead of the real DBus daemon
    # address, for consistency and security reasons.
    Evd.dbus_agent_create_address_alias (peer, session_bus_addr, DBUS_ADDR);

transport.connect('new-peer', on_new_peer, None)

# DBus bridge
dbus_bridge = Evd.DBusBridge()
dbus_bridge.add_transport(transport)

# Web dir
web_dir = Evd.WebDir()
web_dir.set_root ('../common')

# Main loop
main_loop = GObject.MainLoop();

# Web selector
selector = Evd.WebSelector()
selector.set_default_service(web_dir)
transport.set_selector(selector);

def on_listen(self, result, main_loop):
    try:
        self.listen_finish(result)
        print ('Listening on port ' + LISTEN_PORT + ', now point your browser to any of the DBus example web pages')
    except Exception as e:
        print('Error: ' + str(e))
        main_loop.quit()

# start listening
selector.listen('0.0.0.0:' + LISTEN_PORT, None, on_listen, main_loop)

# start the show
main_loop.run();