Add udisks as source for drive temperatures.

This commit is contained in:
Jonas Kümmerlin
2013-10-05 22:55:51 +02:00
parent 0c5674a5a4
commit d713397e54
3 changed files with 190 additions and 1 deletions

View File

@@ -74,6 +74,12 @@ const SensorsMenuButton = new Lang.Class({
this.hddtempArgv = Utilities.detectHDDTemp();
}
this.udisksProxies = [];
Utilities.UDisks.get_drive_ata_proxies((function(proxies) {
this.udisksProxies = proxies;
this._updateDisplay(this._sensorsOutput, this._hddtempOutput);
}).bind(this));
this._settingsChanged = settings.connect("changed", Lang.bind(this,function(){ this._querySensors(false); }));
this._querySensors(true);
@@ -128,6 +134,8 @@ const SensorsMenuButton = new Lang.Class({
if(this.hddtempArgv)
tempInfo = tempInfo.concat(Utilities.parseHddTempOutput(hddtemp_output, !(/nc$/.exec(this.hddtempArgv[0])) ? ': ' : '|'));
tempInfo = tempInfo.concat(Utilities.UDisks.create_list_from_proxies(this.udisksProxies));
tempInfo.sort(function(a,b) { return a['label'].localeCompare(b['label']) });
fanInfo.sort(function(a,b) { return a['label'].localeCompare(b['label']) });
voltageInfo.sort(function(a,b) { return a['label'].localeCompare(b['label']) });

View File

@@ -96,7 +96,7 @@ const SensorsPrefsWidget = new GObject.Class({
}
//List of items of the ComboBox
//List of items of the ComboBox
this._model = new Gtk.ListStore();
this._model.set_column_types([GObject.TYPE_STRING, GObject.TYPE_BOOLEAN]);
this._appendItem(_("Average"));
@@ -110,6 +110,7 @@ const SensorsPrefsWidget = new GObject.Class({
//Fill the list
this._getSensorsLabels();
this._getUdisksLabels();
if(this._display_hdd_temp) {
this._appendSeparator();
@@ -192,6 +193,14 @@ const SensorsPrefsWidget = new GObject.Class({
}
},
_getUdisksLabels: function() {
Utilities.UDisks.get_drive_ata_proxies((function(proxies) {
let list = Utilities.UDisks.create_list_from_proxies(proxies);
this._appendMultipleItems(list);
}).bind(this));
},
_getActiveSensorIter: function() {
/* Get the first iter in the list */
[success, iter] = this._model.get_iter_first();

View File

@@ -231,7 +231,179 @@ const Future = new Lang.Class({
}
});
// Poor man's async.js
const Async = {
// mapping will be done in parallel
map: function(arr, mapClb /* function(in, successClb)) */, resClb /* function(result) */) {
let counter = arr.length;
let result = [];
for (let i = 0; i < arr.length; ++i) {
mapClb(arr[i], (function(i, newVal) {
result[i] = newVal;
if (--counter == 0) resClb(result);
}).bind(null, i)); // i needs to be bound since it will be changed during the next iteration
}
}
}
function debug(str){
//tail -f -n100 ~/.cache/gdm/session.log | grep temperature
print ('LOG temperature@xtranophilist: ' + str);
}
// routines for handling of udisks2
const UDisks = {
// creates a list of sensor objects from the list of proxies given
create_list_from_proxies: function(proxies) {
return proxies.filter(function(proxy) {
// 0K means no data available
return proxy.ata.SmartTemperature > 0;
}).map(function(proxy) {
return {
label: proxy.drive.Model,
temp: proxy.ata.SmartTemperature - 272.15
};
});
},
// calls callback with [{ drive: UDisksDriveProxy, ata: UDisksDriveAtaProxy }, ... ] for every drive that implements both interfaces
get_drive_ata_proxies: function(callback) {
Gio.DBusObjectManagerClient.new(Gio.DBus.system, 0, "org.freedesktop.UDisks2", "/org/freedesktop/UDisks2", null, null, function(src, res) {
try {
let objMgr = Gio.DBusObjectManagerClient.new_finish(res); //might throw
let objPaths = objMgr.get_objects().filter(function(o) {
return o.get_interface("org.freedesktop.UDisks2.Drive") != null
&& o.get_interface("org.freedesktop.UDisks2.Drive.Ata") != null;
}).map(function(o) { return o.get_object_path() });
// now create the proxy objects, log and ignore every failure
Async.map(objPaths, function(obj, callback) {
// create the proxies object
let driveProxy = new UDisksDriveProxy(Gio.DBus.system, "org.freedesktop.UDisks2", obj, function(res, error) {
if (error) { //very unlikely - we even checked the interfaces before!
debug("Could not create proxy on "+obj+":"+error);
callback(null);
return;
}
let ataProxy = new UDisksDriveAtaProxy(Gio.DBus.system, "org.freedesktop.UDisks2", obj, function(res, error) {
if (error) {
debug("Could not create proxy on "+obj+":"+error);
callback(null);
return;
}
callback({ drive: driveProxy, ata: ataProxy });
});
});
}, function(proxies) {
// filter out failed attempts == null values
callback(proxies.filter(function(a) { return a != null; }));
});
} catch (e) {
debug("Could not find UDisks objects: "+e);
}
});
}
};
const UDisksDriveInterface = <interface name="org.freedesktop.UDisks2.Drive">
<method name="Eject">
<arg type="a{sv}" name="options" direction="in"/>
</method>
<method name="SetConfiguration">
<arg type="a{sv}" name="value" direction="in"/>
<arg type="a{sv}" name="options" direction="in"/>
</method>
<method name="PowerOff">
<arg type="a{sv}" name="options" direction="in"/>
</method>
<property type="s" name="Vendor" access="read"/>
<property type="s" name="Model" access="read"/>
<property type="s" name="Revision" access="read"/>
<property type="s" name="Serial" access="read"/>
<property type="s" name="WWN" access="read"/>
<property type="s" name="Id" access="read"/>
<property type="a{sv}" name="Configuration" access="read"/>
<property type="s" name="Media" access="read"/>
<property type="as" name="MediaCompatibility" access="read"/>
<property type="b" name="MediaRemovable" access="read"/>
<property type="b" name="MediaAvailable" access="read"/>
<property type="b" name="MediaChangeDetected" access="read"/>
<property type="t" name="Size" access="read"/>
<property type="t" name="TimeDetected" access="read"/>
<property type="t" name="TimeMediaDetected" access="read"/>
<property type="b" name="Optical" access="read"/>
<property type="b" name="OpticalBlank" access="read"/>
<property type="u" name="OpticalNumTracks" access="read"/>
<property type="u" name="OpticalNumAudioTracks" access="read"/>
<property type="u" name="OpticalNumDataTracks" access="read"/>
<property type="u" name="OpticalNumSessions" access="read"/>
<property type="i" name="RotationRate" access="read"/>
<property type="s" name="ConnectionBus" access="read"/>
<property type="s" name="Seat" access="read"/>
<property type="b" name="Removable" access="read"/>
<property type="b" name="Ejectable" access="read"/>
<property type="s" name="SortKey" access="read"/>
<property type="b" name="CanPowerOff" access="read"/>
<property type="s" name="SiblingId" access="read"/>
</interface>;
const UDisksDriveProxy = Gio.DBusProxy.makeProxyWrapper(UDisksDriveInterface);
const UDisksDriveAtaInterface = <interface name="org.freedesktop.UDisks2.Drive.Ata">
<method name="SmartUpdate">
<arg type="a{sv}" name="options" direction="in"/>
</method>
<method name="SmartGetAttributes">
<arg type="a{sv}" name="options" direction="in"/>
<arg type="a(ysqiiixia{sv})" name="attributes" direction="out"/>
</method>
<method name="SmartSelftestStart">
<arg type="s" name="type" direction="in"/>
<arg type="a{sv}" name="options" direction="in"/>
</method>
<method name="SmartSelftestAbort">
<arg type="a{sv}" name="options" direction="in"/>
</method>
<method name="SmartSetEnabled">
<arg type="b" name="value" direction="in"/>
<arg type="a{sv}" name="options" direction="in"/>
</method>
<method name="PmGetState">
<arg type="a{sv}" name="options" direction="in"/>
<arg type="y" name="state" direction="out"/>
</method>
<method name="PmStandby">
<arg type="a{sv}" name="options" direction="in"/>
</method>
<method name="PmWakeup">
<arg type="a{sv}" name="options" direction="in"/>
</method>
<method name="SecurityEraseUnit">
<arg type="a{sv}" name="options" direction="in"/>
</method>
<property type="b" name="SmartSupported" access="read"/>
<property type="b" name="SmartEnabled" access="read"/>
<property type="t" name="SmartUpdated" access="read"/>
<property type="b" name="SmartFailing" access="read"/>
<property type="t" name="SmartPowerOnSeconds" access="read"/>
<property type="d" name="SmartTemperature" access="read"/>
<property type="i" name="SmartNumAttributesFailing" access="read"/>
<property type="i" name="SmartNumAttributesFailedInThePast" access="read"/>
<property type="x" name="SmartNumBadSectors" access="read"/>
<property type="s" name="SmartSelftestStatus" access="read"/>
<property type="i" name="SmartSelftestPercentRemaining" access="read"/>
<property type="b" name="PmSupported" access="read"/>
<property type="b" name="PmEnabled" access="read"/>
<property type="b" name="ApmSupported" access="read"/>
<property type="b" name="ApmEnabled" access="read"/>
<property type="b" name="AamSupported" access="read"/>
<property type="b" name="AamEnabled" access="read"/>
<property type="i" name="AamVendorRecommendedValue" access="read"/>
<property type="b" name="WriteCacheSupported" access="read"/>
<property type="b" name="WriteCacheEnabled" access="read"/>
<property type="i" name="SecurityEraseUnitMinutes" access="read"/>
<property type="i" name="SecurityEnhancedEraseUnitMinutes" access="read"/>
<property type="b" name="SecurityFrozen" access="read"/>
</interface>;
const UDisksDriveAtaProxy = Gio.DBusProxy.makeProxyWrapper(UDisksDriveAtaInterface);