Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 1 | import dbus |
| 2 | |
| 3 | BUS_PREFIX = 'org.openbmc' |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 4 | OBJ_PREFIX = "/org/openbmc" |
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 5 | GPIO_DEV = '/sys/class/gpio' |
Norman James | 5e792e3 | 2015-10-07 17:36:17 -0500 | [diff] [blame] | 6 | BUS = "system" |
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 7 | |
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 8 | ENUMS = { |
| 9 | 'org.openbmc.SensorIntegerThreshold.state' : |
| 10 | ['NOT_SET','NORMAL','LOWER_CRITICAL','LOWER_WARNING','UPPER_WARNING','UPPER_CRITICAL'], |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 11 | } |
| 12 | |
Norman James | 969227c | 2015-10-08 15:10:47 -0500 | [diff] [blame] | 13 | def 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 James | 5e792e3 | 2015-10-07 17:36:17 -0500 | [diff] [blame] | 19 | def getDBus(): |
| 20 | bus = None |
| 21 | if (BUS == "session"): |
| 22 | bus = dbus.SessionBus() |
| 23 | else: |
| 24 | bus = dbus.SystemBus() |
| 25 | return bus |
| 26 | |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 27 | |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 28 | def 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 James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 33 | |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 34 | |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 35 | class DbusProperties(dbus.service.Object): |
| 36 | def __init__(self): |
| 37 | dbus.service.Object.__init__(self) |
| 38 | self.properties = {} |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 39 | |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 40 | @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 James | f81d498 | 2015-10-26 17:12:14 -0500 | [diff] [blame] | 74 | self.PropertiesChanged(interface_name,{ property_name: new_value }, []) |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 75 | |
Norman James | f81d498 | 2015-10-26 17:12:14 -0500 | [diff] [blame] | 76 | @dbus.service.method("org.openbmc.Object.Properties", |
Norman James | 2656f33 | 2015-10-26 06:42:41 -0500 | [diff] [blame] | 77 | in_signature='sa{sv}') |
Norman James | f81d498 | 2015-10-26 17:12:14 -0500 | [diff] [blame] | 78 | def SetMultiple(self, interface_name, prop_dict): |
Norman James | 2656f33 | 2015-10-26 06:42:41 -0500 | [diff] [blame] | 79 | 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 James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 98 | @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 James | 633f04d | 2015-10-31 17:34:34 -0500 | [diff] [blame] | 104 | @dbus.service.signal("org.openbmc.Object.ObjectMapper", |
| 105 | signature='ss') |
| 106 | def ObjectAdded(self,object_path,interface_name): |
| 107 | pass |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 108 | |
| 109 | |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 110 | |