summaryrefslogtreecommitdiff
path: root/meta-phosphor/common/recipes-phosphor/obmc-phosphor-qemu/files/obmc-phosphor-qemu.py
blob: 3ef8e852e3f3c0bd15652f5a98794b04b14edae6 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python

# Contributors Listed Below - COPYRIGHT 2015
# [+] International Business Machines Corp.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.

import sys
import dbus
import dbus.service
import dbus.mainloop.glib
import gobject

SERVICE_PREFIX = 'org.openbmc.examples.services'
IFACE_PREFIX = 'org.openbmc.examples.interfaces'
BASE_OBJ_PATH = '/org/openbmc/examples/'

class SampleObjectOne(dbus.service.Object):
	def __init__(self, bus, name):
		super(SampleObjectOne, self).__init__(bus, name)

	@dbus.service.method(IFACE_PREFIX + '.Interface0', 's', 's')
	def echo(self, val):
		return str(type(self).__name__) + ": " + val

class SampleObjectTwo(SampleObjectOne):
	def __init__(self, bus, name):
		super(SampleObjectTwo, self).__init__(bus, name)
		self.map = {}

	@dbus.service.method(IFACE_PREFIX + '.Interface1', 'ss', '')
	def set_a_value_in_the_dict(self, key, value):
		self.map[key] = value

	@dbus.service.method(IFACE_PREFIX + '.Interface1', 's', 's')
	def get_a_value_from_the_dict(self, key):
		return self.map.get(key, "set a value first")

	@dbus.service.method(IFACE_PREFIX + '.Interface1', '', 's')
	def get_all_values_from_the_dict(self):
		return " ".join( [ x+ ':' + self.map[x] for x in self.map.keys() ] )

if __name__ == '__main__':
	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

	bus = dbus.SystemBus()

	services = []
	services.append(dbus.service.BusName(SERVICE_PREFIX + '.Service0', bus))
	services.append(dbus.service.BusName(SERVICE_PREFIX + '.Service1', bus))

	objs = []
	objs.append(SampleObjectOne(bus, BASE_OBJ_PATH + 'path0/Obj'))
	objs.append(SampleObjectTwo(bus, BASE_OBJ_PATH + 'path1/Obj'))

	mainloop = gobject.MainLoop()

	print "obmc-phosphor-qemu starting..."
	mainloop.run()