blob: b370d8b93dab245d1bdea1df10c0fc3815a515b2 [file] [log] [blame]
Norman Jamesce46e3e2015-08-30 22:25:55 -05001import dbus
2
3BUS_PREFIX = 'org.openbmc'
Norman James362a80f2015-09-14 14:04:39 -05004OBJ_PREFIX = "/org/openbmc"
Norman Jamesce46e3e2015-08-30 22:25:55 -05005GPIO_DEV = '/sys/class/gpio'
Norman James5e792e32015-10-07 17:36:17 -05006BUS = "system"
Norman Jamesce46e3e2015-08-30 22:25:55 -05007
Norman Jamesce46e3e2015-08-30 22:25:55 -05008ENUMS = {
9 'org.openbmc.SensorIntegerThreshold.state' :
10 ['NOT_SET','NORMAL','LOWER_CRITICAL','LOWER_WARNING','UPPER_WARNING','UPPER_CRITICAL'],
Norman James362a80f2015-09-14 14:04:39 -050011}
12
Norman James969227c2015-10-08 15:10:47 -050013def getSystemName():
14 #use filename as system name, strip off path and ext
15 parts = __file__.replace('.pyc','').replace('.py','').split('/')
16 return parts[len(parts)-1]
17
18
Norman James5e792e32015-10-07 17:36:17 -050019def getDBus():
20 bus = None
21 if (BUS == "session"):
22 bus = dbus.SessionBus()
23 else:
24 bus = dbus.SystemBus()
25 return bus
26
Norman James5d78b4d2015-09-05 13:34:34 -050027
Norman James362a80f2015-09-14 14:04:39 -050028def getManagerInterface(bus,manager):
29 bus_name = "org.openbmc.managers."+manager
30 obj_name = "/org/openbmc/managers/"+manager
31 obj = bus.get_object(bus_name,obj_name)
32 return dbus.Interface(obj,bus_name)
Norman James5d78b4d2015-09-05 13:34:34 -050033
Norman James5d78b4d2015-09-05 13:34:34 -050034
Norman Jamesa3e47c42015-10-18 14:43:10 -050035class DbusProperties(dbus.service.Object):
36 def __init__(self):
37 dbus.service.Object.__init__(self)
38 self.properties = {}
Norman James362a80f2015-09-14 14:04:39 -050039
Norman Jamesa3e47c42015-10-18 14:43:10 -050040 @dbus.service.method(dbus.PROPERTIES_IFACE,
41 in_signature='ss', out_signature='v')
42 def Get(self, interface_name, property_name):
43 d = self.GetAll(interface_name)
44 try:
45 v = d[property_name]
46 return v
47 except:
48 raise dbus.exceptions.DBusException(
49 "org.freedesktop.UnknownPropery: "+property_name)
50
51 @dbus.service.method(dbus.PROPERTIES_IFACE,
52 in_signature='s', out_signature='a{sv}')
53 def GetAll(self, interface_name):
54 try:
55 d = self.properties[interface_name]
56 return d
57 except:
58 raise dbus.exceptions.DBusException(
59 "org.freedesktop.UnknownInterface: "+interface_name)
60
61 @dbus.service.method(dbus.PROPERTIES_IFACE,
62 in_signature='ssv')
63 def Set(self, interface_name, property_name, new_value):
64 if (self.properties.has_key(interface_name) == False):
65 self.properties[interface_name] = {}
66 try:
67 old_value = self.properties[interface_name][property_name]
68 if (old_value != new_value):
69 self.properties[interface_name][property_name] = new_value
70 self.PropertiesChanged(interface_name,{ property_name: new_value }, [])
71
72 except:
73 self.properties[interface_name][property_name] = new_value
Norman Jamesf81d4982015-10-26 17:12:14 -050074 self.PropertiesChanged(interface_name,{ property_name: new_value }, [])
Norman Jamesa3e47c42015-10-18 14:43:10 -050075
Norman Jamesf81d4982015-10-26 17:12:14 -050076 @dbus.service.method("org.openbmc.Object.Properties",
Norman James2656f332015-10-26 06:42:41 -050077 in_signature='sa{sv}')
Norman Jamesf81d4982015-10-26 17:12:14 -050078 def SetMultiple(self, interface_name, prop_dict):
Norman James2656f332015-10-26 06:42:41 -050079 if (self.properties.has_key(interface_name) == False):
80 self.properties[interface_name] = {}
81
82 value_changed = False
83 for property_name in prop_dict:
84 new_value = prop_dict[property_name]
85 try:
86 old_value = self.properties[interface_name][property_name]
87 if (old_value != new_value):
88 self.properties[interface_name][property_name] = new_value
89 value_changed = True
90
91 except:
92 self.properties[interface_name][property_name] = new_value
93 value_changed = True
94 if (value_changed == True):
95 self.PropertiesChanged(interface_name, prop_dict, [])
96
97
Norman Jamesa3e47c42015-10-18 14:43:10 -050098 @dbus.service.signal(dbus.PROPERTIES_IFACE,
99 signature='sa{sv}as')
100 def PropertiesChanged(self, interface_name, changed_properties,
101 invalidated_properties):
102 pass
103
Norman James633f04d2015-10-31 17:34:34 -0500104 @dbus.service.signal("org.openbmc.Object.ObjectMapper",
105 signature='ss')
106 def ObjectAdded(self,object_path,interface_name):
107 pass
Norman Jamesa3e47c42015-10-18 14:43:10 -0500108
109
Norman James90baede2015-09-02 20:32:49 -0500110