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
61
62
63
64
65
66
67
68
69
70
|
# Copyright (C) 2013 - 2015 BMW Group
# Author: Manfred Bathelt (manfred.bathelt@bmw.de)
# Author: Juergen Gehring (juergen.gehring@bmw.de)
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import sys
import traceback
import gobject
import math
import dbus
import dbus.service
import dbus.mainloop.glib
loop = gobject.MainLoop()
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
class FakeLegacyService(dbus.service.Object):
def __init__(self, loop):
busName = dbus.service.BusName('fake.legacy.service.connection', bus = dbus.SessionBus())
dbus.service.Object.__init__(self, busName, '/some/legacy/path/6259504')
#self.properties = {'RestartReason': 1, 'ShutdownReason': 2, 'WakeUpReason' :3, 'BootMode' :4}
self.ABus=""
self.APath=""
self.loop=loop
@dbus.service.method(dbus_interface='fake.legacy.service.Introspectable', out_signature = 's')
def Introspect(self):
f = open('fake.legacy.service.xml', "r")
text = f.read()
return text
@dbus.service.method(dbus_interface='fake.legacy.service.LegacyInterface', in_signature = 'i', out_signature = 'ii')
def TestMethod(self, input):
val1=input - 5
val2=input + 5
return val1, val2
@dbus.service.method(dbus_interface='fake.legacy.service.LegacyInterface', out_signature = 'si')
def OtherTestMethod(self):
greeting='Hello'
identifier=42
return greeting, identifier
@dbus.service.method(dbus_interface='fake.legacy.service.LegacyInterface')
def finish(self):
self.loop.quit()
return 0
class ObjectManager(dbus.service.Object):
def __init__(self, loop):
busName = dbus.service.BusName('fake.legacy.service.connection', bus = dbus.SessionBus())
dbus.service.Object.__init__(self, busName, '/')
self.ABus=""
self.APath=""
self.loop=loop
@dbus.service.method(dbus_interface='org.freedesktop.DBus.ObjectManager', out_signature = 'a{oa{sa{sv}}}')
def GetManagedObjects(self):
response = {}
idict = {}
idict['fake.legacy.service.LegacyInterface'] = {}
idict['fake.legacy.service.Introspectable'] = {}
response['/some/legacy/path/6259504'] = idict
return response
nsm = FakeLegacyService(loop)
ObjectManager(loop)
loop.run()
|