Norman James | 91dac39 | 2015-10-14 09:38:55 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import sys |
| 4 | #from gi.repository import GObject |
| 5 | import gobject |
| 6 | import dbus |
| 7 | import dbus.service |
| 8 | import dbus.mainloop.glib |
| 9 | import Openbmc |
| 10 | |
| 11 | SENSOR_INTERFACE = 'org.openbmc.SensorValue' |
| 12 | DBUS_NAME = 'org.openbmc.sensor.Power8Virtual' |
| 13 | OBJ_NAME = '/org/openbmc/sensor/virtual/' |
| 14 | |
| 15 | class BootProgress(dbus.service.Object): |
| 16 | def __init__(self,bus,name): |
| 17 | self.object_name = "BootProgress" |
| 18 | self.value = 0 |
| 19 | self.units = "" |
| 20 | dbus.service.Object.__init__(self,bus,name+self.object_name) |
| 21 | |
| 22 | @dbus.service.method(SENSOR_INTERFACE, |
| 23 | in_signature='v', out_signature='') |
| 24 | def setValue(self,value): |
| 25 | if (value != self.value): |
| 26 | self.value=value |
| 27 | self.Changed() |
| 28 | |
| 29 | @dbus.service.method(SENSOR_INTERFACE, |
| 30 | in_signature='', out_signature='v') |
| 31 | def getValue(self): |
| 32 | return self.value; |
| 33 | |
| 34 | @dbus.service.method(SENSOR_INTERFACE, |
| 35 | in_signature='', out_signature='s') |
| 36 | def getUnits(self): |
| 37 | return self.units; |
| 38 | |
| 39 | @dbus.service.signal(SENSOR_INTERFACE,signature='vs') |
| 40 | def Changed(self,value,units): |
| 41 | pass |
| 42 | |
| 43 | class HostStatus(dbus.service.Object): |
| 44 | def __init__(self,bus,name): |
| 45 | self.object_name = "HostStatus" |
| 46 | self.value = 0 |
| 47 | self.units = "" |
| 48 | dbus.service.Object.__init__(self,bus,name+self.object_name) |
| 49 | |
| 50 | @dbus.service.method(SENSOR_INTERFACE, |
| 51 | in_signature='v', out_signature='') |
| 52 | def setValue(self,value): |
| 53 | if (value != self.value): |
| 54 | self.value=value |
| 55 | self.Changed(self.value,self.units) |
| 56 | |
| 57 | @dbus.service.method(SENSOR_INTERFACE, |
| 58 | in_signature='', out_signature='v') |
| 59 | def getValue(self): |
| 60 | return self.value; |
| 61 | |
| 62 | @dbus.service.method(SENSOR_INTERFACE, |
| 63 | in_signature='', out_signature='s') |
| 64 | def getUnits(self): |
| 65 | return self.units; |
| 66 | |
| 67 | @dbus.service.signal(SENSOR_INTERFACE,signature='vs') |
| 68 | def Changed(self,value,units): |
| 69 | pass |
| 70 | |
| 71 | class OsStatus(dbus.service.Object): |
| 72 | def __init__(self,bus,name): |
| 73 | self.object_name = "OperatingSystemStatus" |
| 74 | self.value = 0 |
| 75 | self.units = "" |
| 76 | dbus.service.Object.__init__(self,bus,name+self.object_name) |
| 77 | |
| 78 | @dbus.service.method(SENSOR_INTERFACE, |
| 79 | in_signature='v', out_signature='') |
| 80 | def setValue(self,value): |
| 81 | if (value != self.value): |
| 82 | self.value=value |
| 83 | self.Changed(self.value,self.units) |
| 84 | |
| 85 | @dbus.service.method(SENSOR_INTERFACE, |
| 86 | in_signature='', out_signature='v') |
| 87 | def getValue(self): |
| 88 | return self.value; |
| 89 | |
| 90 | @dbus.service.method(SENSOR_INTERFACE, |
| 91 | in_signature='', out_signature='s') |
| 92 | def getUnits(self): |
| 93 | return self.units; |
| 94 | |
| 95 | @dbus.service.signal(SENSOR_INTERFACE,signature='vs') |
| 96 | def Changed(self,value,units): |
| 97 | pass |
| 98 | |
| 99 | class BootCount(dbus.service.Object): |
| 100 | def __init__(self,bus,name): |
| 101 | self.object_name = "BootCount" |
| 102 | self.value = 0 |
| 103 | self.units = "" |
| 104 | dbus.service.Object.__init__(self,bus,name+self.object_name) |
| 105 | |
| 106 | @dbus.service.method(SENSOR_INTERFACE, |
| 107 | in_signature='v', out_signature='') |
| 108 | def setValue(self,value): |
| 109 | if (value != self.value): |
| 110 | self.value=value |
| 111 | self.Changed(self.value,self.units) |
| 112 | |
| 113 | @dbus.service.method(SENSOR_INTERFACE, |
| 114 | in_signature='', out_signature='v') |
| 115 | def getValue(self): |
| 116 | return self.value; |
| 117 | |
| 118 | @dbus.service.method(SENSOR_INTERFACE, |
| 119 | in_signature='', out_signature='s') |
| 120 | def getUnits(self): |
| 121 | return self.units; |
| 122 | |
| 123 | @dbus.service.signal(SENSOR_INTERFACE,signature='vs') |
| 124 | def Changed(self,value,units): |
| 125 | pass |
| 126 | |
| 127 | |
| 128 | class OccStatus(dbus.service.Object): |
| 129 | def __init__(self,bus,name): |
| 130 | self.object_name = "OccStatus" |
| 131 | self.value = 0 |
| 132 | self.units = "" |
| 133 | dbus.service.Object.__init__(self,bus,name+self.object_name) |
| 134 | |
| 135 | @dbus.service.method(SENSOR_INTERFACE, |
| 136 | in_signature='v', out_signature='') |
| 137 | def setValue(self,value): |
| 138 | if (value != self.value): |
| 139 | self.value=value |
| 140 | self.Changed(self.value,self.units) |
| 141 | |
| 142 | @dbus.service.method(SENSOR_INTERFACE, |
| 143 | in_signature='', out_signature='v') |
| 144 | def getValue(self): |
| 145 | return self.value; |
| 146 | |
| 147 | @dbus.service.method(SENSOR_INTERFACE, |
| 148 | in_signature='', out_signature='s') |
| 149 | def getUnits(self): |
| 150 | return self.units; |
| 151 | |
| 152 | @dbus.service.signal(SENSOR_INTERFACE,signature='vs') |
| 153 | def Changed(self,value,units): |
| 154 | pass |
| 155 | |
| 156 | |
| 157 | if __name__ == '__main__': |
| 158 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 159 | bus = Openbmc.getDBus() |
| 160 | name = dbus.service.BusName(DBUS_NAME,bus) |
| 161 | boot_progress = BootProgress(bus,OBJ_NAME) |
| 162 | host_status = HostStatus(bus,OBJ_NAME) |
| 163 | os_status = OsStatus(bus,OBJ_NAME) |
| 164 | boot_count = BootCount(bus,OBJ_NAME) |
| 165 | occ_status = OccStatus(bus,OBJ_NAME) |
| 166 | mainloop = gobject.MainLoop() |
| 167 | |
| 168 | print "Starting virtual sensors" |
| 169 | mainloop.run() |
| 170 | |