diff options
author | Marja Hassinen <ext-marja.2.hassinen@nokia.com> | 2009-04-23 14:51:08 +0300 |
---|---|---|
committer | Marja Hassinen <ext-marja.2.hassinen@nokia.com> | 2009-04-23 14:51:08 +0300 |
commit | f4a72c0ff5a3b6af2bddcecc3ae9d3ae3d3d780f (patch) | |
tree | 1e736cb8fcc4d757cf6ae21e856798a3c0df2bf8 | |
parent | 9eb857caee7ae2983554fff40950e0f7149a30bf (diff) |
Cleaning up. Addind documentation for properties. Adding the missing IsCharging property.
-rw-r--r-- | contextd/Makefile.am | 4 | ||||
-rw-r--r-- | contextd/hal_plugin.vala | 49 | ||||
-rw-r--r-- | contextd/main.vala | 4 | ||||
-rw-r--r-- | spec/context.xml | 16 |
4 files changed, 44 insertions, 29 deletions
diff --git a/contextd/Makefile.am b/contextd/Makefile.am index 973864d1..0101b15f 100644 --- a/contextd/Makefile.am +++ b/contextd/Makefile.am @@ -15,10 +15,10 @@ contextd_SOURCES = \ $(NULL) # FIXME: Remove the hal.vapi once the official version includes the needed functions -#$(VALAC) -C -g --basedir $(top_srcdir)/contextd --vapidir=$(top_srcdir)/vapi --pkg dbus-glib-1 --pkg gee-1.0 --pkg hal --disable-dbus-transformation $^ $(top_srcdir)/libcontextprovider/contextprovider.vapi +#$(VALAC) -C -g --basedir $(top_srcdir)/contextd --vapidir=$(top_srcdir)/vapi --pkg dbus-glib-1 --pkg gee-1.0 --pkg hal --disable-dbus-transformation $^ posix.vapi $(top_srcdir)/libcontextprovider/contextprovider.vapi contextd.vala.stamp: $(contextd_VALASOURCES) - $(VALAC) -C -g --basedir $(top_srcdir)/contextd --vapidir=$(top_srcdir)/vapi --pkg dbus-glib-1 --pkg gee-1.0 --disable-dbus-transformation $^ $(top_srcdir)/libcontextprovider/contextprovider.vapi hal.vapi + $(VALAC) -C -g --basedir $(top_srcdir)/contextd --vapidir=$(top_srcdir)/vapi --pkg dbus-glib-1 --pkg gee-1.0 --disable-dbus-transformation $^ ../vapi/posix.vapi $(top_srcdir)/libcontextprovider/contextprovider.vapi hal.vapi touch contextd.vala.stamp contextd_CFLAGS = \ diff --git a/contextd/hal_plugin.vala b/contextd/hal_plugin.vala index bbbd6602..72521c4e 100644 --- a/contextd/hal_plugin.vala +++ b/contextd/hal_plugin.vala @@ -54,6 +54,7 @@ namespace Plugins { private const string keyChargePercentage = "Context.Battery.ChargePercentage"; private const string keyOnBattery = "Context.Battery.OnBattery"; private const string keyLowBattery = "Context.Battery.LowBattery"; + private const string keyIsCharging = "Context.Battery.IsCharging"; private const string keyTimeUntilLow = "Context.Battery.TimeUntilLow"; private const string keyTimeUntilFull = "Context.Battery.TimeUntilFull"; @@ -81,7 +82,7 @@ namespace Plugins { bool success = halContext.set_dbus_connection(connection); if (!success) { - debug ("Error: initializing HAL failed"); + warning ("Error: initializing HAL failed"); return false; } @@ -92,7 +93,7 @@ namespace Plugins { // Note: this needs to be called after the dbus connection is set halContext.init (ref error); if (error.is_set ()) { - debug ("Error: initializing HAL failed"); + warning ("Error: initializing HAL failed"); return false; } @@ -100,12 +101,12 @@ namespace Plugins { success = halContext.set_device_property_modified (property_modified); if (!success) { - debug ("Error: initializing HAL failed"); + warning ("Error: initializing HAL failed"); return false; } // Finally, install the plugin with libcontextprovider. - string[] keys = {keyChargePercentage, keyOnBattery, keyLowBattery, keyTimeUntilLow, keyTimeUntilFull}; + string[] keys = {keyChargePercentage, keyOnBattery, keyLowBattery, keyIsCharging, keyTimeUntilLow, keyTimeUntilFull}; ContextProvider.install_group(keys, true, this.subscription_changed); return true; @@ -128,23 +129,21 @@ namespace Plugins { var deviceNames = halContext.find_device_by_capability("battery", ref error); if (error.is_set()) { - debug ("Error: finding devices failed"); + warning ("Warning: finding devices failed"); return; } if (deviceNames == null) { - debug ("Error: finding devices failed"); + warning ("Warning: finding devices failed"); return; } foreach (var udi in deviceNames) { - debug ("Found device %s", udi); - // Start listening to property changes bool success = halContext.device_add_property_watch (udi, ref error); if (!success || error.is_set()) { - debug ("Error: adding property watch failed"); + warning ("Warning: adding property watch failed"); } // Read initial values @@ -190,7 +189,7 @@ namespace Plugins { // Is called when HAL notifies us that a property has changed private static void property_modified (Hal.Context ctx, string udi, string key, bool is_removed, bool is_added) { - debug ("Property modified: %s, %s", udi, key); + // debug ("Property modified: %s, %s", udi, key); BatteryInfo info = batteries.get (udi); @@ -244,9 +243,9 @@ namespace Plugins { value = halContext.device_get_property_int(udi, property, ref error); if (error.is_set()) { - debug ("Error: querying property %s failed", property); + warning ("Warning: querying property %s failed", property); } else { - debug ("Read property: %s %d", property, value); + // debug ("Read property: %s %d", property, value); success = true; } } @@ -259,9 +258,9 @@ namespace Plugins { value = halContext.device_get_property_bool(udi, property, ref error); if (error.is_set()) { - debug ("Error: querying property %s failed", property); + warning ("Warning: querying property %s failed", property); } else { - debug ("Read property: %s %s", property, value ? "true" : "false"); + // debug ("Read property: %s %s", property, value ? "true" : "false"); success = true; } } @@ -273,42 +272,33 @@ namespace Plugins { // e.g. is the average charge level unknown if one of the charge levels // is unknown or only when all of them are unknown. private static void calculateProperties () { - - debug ("Calculating properties"); if (batteries.size != 1) { - debug ("Not supported: no batteries / more than one battery"); + warning ("Warning: no batteries / more than one battery"); + return; } var udis = batteries.get_keys (); string udi = ""; foreach (var temp in batteries.get_keys ()) { - debug ("battery %s", temp); udi = temp; } BatteryInfo info = batteries.get (udi); - - debug ("%d %d %d %d %s %s", info.percentage, info.charge, info.lastNonzeroChargingRate, info.lastFull, info.charging? "true" : "false", info.discharging? "true" : "false"); - // Compute ChargePercentage if (info.percentageKnown == false) { - debug ("percentage unknown"); ContextProvider.set_null (keyChargePercentage); } else { - debug ("percentage %d",info.percentage); ContextProvider.set_integer (keyChargePercentage, info.percentage); } // Compute OnBattery if (info.dischargingKnown == false) { - debug ("onbattery unknown"); ContextProvider.set_null (keyOnBattery); } else { - debug ("onbattery %s", info.discharging ? "true" : "false"); ContextProvider.set_boolean (keyOnBattery, info.discharging); } @@ -334,6 +324,15 @@ namespace Plugins { // we need to check against the "global" OnBattery (if some device // is on battery) and not the OnBattery of this particular device. + // Compute IsCharging + if (info.chargingKnown == false) { + ContextProvider.set_null (keyIsCharging); + } + else { + ContextProvider.set_boolean (keyIsCharging, info.charging); + } + + // Compute TimeUntilLow if (info.lastNonzeroDischargingRate > 0 && info.chargeKnown && info.lastFullKnown) { double timeUntilLow = (1.0 * info.charge - thresholdForLow / 100.0 * info.lastFull) / info.lastNonzeroDischargingRate; diff --git a/contextd/main.vala b/contextd/main.vala index ac06f27c..90077afd 100644 --- a/contextd/main.vala +++ b/contextd/main.vala @@ -50,8 +50,8 @@ namespace ContextD { // Install all plugins install_plugins (); - - //Posix.Signal.set_handler (Posix.Signal.QUIT, exit); + + Posix.Signal.set_handler (Posix.Signal.QUIT, exit); loop.run (); } diff --git a/spec/context.xml b/spec/context.xml index bd02dc5e..8b78f1e4 100644 --- a/spec/context.xml +++ b/spec/context.xml @@ -124,6 +124,22 @@ True if OnBattery is true and the charge levels of all batteries are below 10%. </doc> </key> + <key name="IsCharging" type="TRUTH"> + <doc> +Whether or not the device is currently charging at least one of its batteries. + </doc> + </key> + <key name="TimeUntilLow" type="INT"> + <doc> +Estimates the time that the device can run on battery before the property +OnLowBattery becomes true. In seconds. + </doc> + </key> + <key name="TimeUntilFull" type="INT"> + <doc> +Estimates the needed charging time of the device. In seconds. + </doc> + </key> </node> <node name="Connectivity"> <doc> |