Brad Bishop | 9ee75e1 | 2015-09-17 16:39:49 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Contributors Listed Below - COPYRIGHT 2015 |
| 4 | # [+] International Business Machines Corp. |
| 5 | # |
| 6 | # |
| 7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | # you may not use this file except in compliance with the License. |
| 9 | # You may obtain a copy of the License at |
| 10 | # |
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, software |
| 14 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 16 | # implied. See the License for the specific language governing |
| 17 | # permissions and limitations under the License. |
| 18 | |
| 19 | import sys |
| 20 | import dbus |
| 21 | import dbus.service |
| 22 | import dbus.mainloop.glib |
| 23 | import gobject |
| 24 | |
| 25 | SERVICE_PREFIX = 'org.openbmc.examples.services' |
| 26 | IFACE_PREFIX = 'org.openbmc.examples.interfaces' |
| 27 | BASE_OBJ_PATH = '/org/openbmc/examples/' |
| 28 | |
| 29 | class SampleObjectOne(dbus.service.Object): |
| 30 | def __init__(self, bus, name): |
| 31 | super(SampleObjectOne, self).__init__(bus, name) |
| 32 | |
| 33 | @dbus.service.method(IFACE_PREFIX + '.Interface0', 's', 's') |
| 34 | def echo(self, val): |
| 35 | return str(type(self).__name__) + ": " + val |
| 36 | |
| 37 | class SampleObjectTwo(SampleObjectOne): |
| 38 | def __init__(self, bus, name): |
| 39 | super(SampleObjectTwo, self).__init__(bus, name) |
| 40 | self.map = {} |
| 41 | |
| 42 | @dbus.service.method(IFACE_PREFIX + '.Interface1', 'ss', '') |
| 43 | def set_a_value_in_the_dict(self, key, value): |
| 44 | self.map[key] = value |
| 45 | |
| 46 | @dbus.service.method(IFACE_PREFIX + '.Interface1', 's', 's') |
| 47 | def get_a_value_from_the_dict(self, key): |
| 48 | return self.map.get(key, "set a value first") |
| 49 | |
| 50 | @dbus.service.method(IFACE_PREFIX + '.Interface1', '', 's') |
| 51 | def get_all_values_from_the_dict(self): |
| 52 | return " ".join( [ x+ ':' + self.map[x] for x in self.map.keys() ] ) |
| 53 | |
| 54 | if __name__ == '__main__': |
| 55 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 56 | |
| 57 | bus = dbus.SystemBus() |
| 58 | |
| 59 | services = [] |
| 60 | services.append(dbus.service.BusName(SERVICE_PREFIX + '.Service0', bus)) |
| 61 | services.append(dbus.service.BusName(SERVICE_PREFIX + '.Service1', bus)) |
| 62 | |
| 63 | objs = [] |
| 64 | objs.append(SampleObjectOne(bus, BASE_OBJ_PATH + 'path0/Obj')) |
| 65 | objs.append(SampleObjectTwo(bus, BASE_OBJ_PATH + 'path1/Obj')) |
| 66 | |
| 67 | mainloop = gobject.MainLoop() |
| 68 | |
| 69 | print "obmc-phosphor-qemu starting..." |
| 70 | mainloop.run() |
| 71 | |