Compare commits
5 Commits
personal/m
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a77c5d0179 | ||
|
|
0165d7a37d | ||
|
|
1c86495779 | ||
|
|
b2c8f8026a | ||
|
|
b5d5f52894 |
5
Makefile
5
Makefile
@@ -41,11 +41,12 @@ SRC = \
|
||||
mce_battery.c \
|
||||
mce_charger.c \
|
||||
mce_display.c \
|
||||
mce_inactivity.c \
|
||||
mce_proxy.c
|
||||
GEN_SRC = \
|
||||
com.canonical.Unity.Screen.c
|
||||
com.canonical.Unity.Screen.c \
|
||||
org.freedesktop.UPower.Device.c
|
||||
|
||||
# mce_inactivity.c \
|
||||
#
|
||||
# Directories
|
||||
#
|
||||
|
||||
3
debian/ubports.skip_distro
vendored
Normal file
3
debian/ubports.skip_distro
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# libglibutil is not packaged in both Debian and UBports `devel-debian`.
|
||||
# There's not point in this package in Debian anyway.
|
||||
devel-debian
|
||||
@@ -43,8 +43,8 @@
|
||||
#include <mce_battery.h>
|
||||
#include <mce_charger.h>
|
||||
#include <mce_display.h>
|
||||
#include <mce_inactivity.h>
|
||||
#include <mce_tklock.h>
|
||||
//#include <mce_inactivity.h>
|
||||
//#include <mce_tklock.h>
|
||||
|
||||
/* ========================================================================= *
|
||||
* MAINLOOP
|
||||
@@ -111,12 +111,12 @@ static const char *display_state_repr(MCE_DISPLAY_STATE state)
|
||||
{
|
||||
static const char * const lut[] = {
|
||||
[MCE_DISPLAY_STATE_OFF] = "off",
|
||||
[MCE_DISPLAY_STATE_DIM] = "dim",
|
||||
[MCE_DISPLAY_STATE_ON] = "on",
|
||||
};
|
||||
return lut[state];
|
||||
}
|
||||
|
||||
/*
|
||||
static const char *tklock_mode_repr(MCE_TKLOCK_MODE mode)
|
||||
{
|
||||
static const char * const lut[] = {
|
||||
@@ -130,6 +130,7 @@ static const char *tklock_mode_repr(MCE_TKLOCK_MODE mode)
|
||||
};
|
||||
return lut[mode];
|
||||
}
|
||||
*/
|
||||
|
||||
static void battery_cb(MceBattery *battery, void *arg)
|
||||
{
|
||||
@@ -159,6 +160,7 @@ static void display_cb(MceDisplay *display, void *arg)
|
||||
what_changed);
|
||||
}
|
||||
|
||||
/*
|
||||
static void tklock_cb(MceTklock *tklock, void *arg)
|
||||
{
|
||||
const char *what_changed = arg;
|
||||
@@ -169,6 +171,7 @@ static void tklock_cb(MceTklock *tklock, void *arg)
|
||||
what_changed);
|
||||
}
|
||||
|
||||
|
||||
static void inactivity_cb(MceInactivity *inactivity, void *arg)
|
||||
{
|
||||
const char *what_changed = arg;
|
||||
@@ -177,6 +180,7 @@ static void inactivity_cb(MceInactivity *inactivity, void *arg)
|
||||
bool_repr(inactivity->status),
|
||||
what_changed);
|
||||
}
|
||||
*/
|
||||
|
||||
/* ========================================================================= *
|
||||
* MAIN_ENTRY
|
||||
@@ -218,6 +222,7 @@ main(int argc, char **argv)
|
||||
gulong display_state_id =
|
||||
mce_display_add_state_changed_handler(display, display_cb, "state");
|
||||
|
||||
/*
|
||||
MceTklock *tklock = mce_tklock_new();
|
||||
gulong tklock_valid_id =
|
||||
mce_tklock_add_valid_changed_handler(tklock, tklock_cb, "valid");
|
||||
@@ -231,7 +236,7 @@ main(int argc, char **argv)
|
||||
mce_inactivity_add_valid_changed_handler(inactivity, inactivity_cb, "valid");
|
||||
gulong inactivity_status_id =
|
||||
mce_inactivity_add_status_changed_handler(inactivity, inactivity_cb, "status");
|
||||
|
||||
*/
|
||||
guint timeout_id = 0;
|
||||
gint timeout_s = (argc > 1) ? strtol(argv[1], NULL, 0) : 0;
|
||||
if( timeout_s > 0)
|
||||
@@ -264,6 +269,7 @@ main(int argc, char **argv)
|
||||
mce_display_remove_handler(display, display_state_id);
|
||||
mce_display_unref(display);
|
||||
|
||||
/*
|
||||
mce_tklock_remove_handler(tklock, tklock_valid_id);
|
||||
mce_tklock_remove_handler(tklock, tklock_mode_id);
|
||||
mce_tklock_remove_handler(tklock, tklock_locked_id);
|
||||
@@ -272,7 +278,7 @@ main(int argc, char **argv)
|
||||
mce_inactivity_remove_handler(inactivity, inactivity_valid_id);
|
||||
mce_inactivity_remove_handler(inactivity, inactivity_status_id);
|
||||
mce_inactivity_unref(inactivity);
|
||||
|
||||
*/
|
||||
printf("exit\n");
|
||||
return exitcode;
|
||||
}
|
||||
|
||||
833
spec/org.freedesktop.UPower.Device.xml
Normal file
833
spec/org.freedesktop.UPower.Device.xml
Normal file
@@ -0,0 +1,833 @@
|
||||
<!DOCTYPE node PUBLIC
|
||||
"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd" [
|
||||
<!ENTITY ERROR_GENERAL "org.freedesktop.UPower.Device.GeneralError">
|
||||
]>
|
||||
<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
|
||||
<interface name="org.freedesktop.UPower.Device">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Objects implementing this interface are usually discovered through
|
||||
the <doc:tt>org.freedesktop.UPower</doc:tt> interface on
|
||||
the <doc:tt>/org/freedesktop/UPower</doc:tt> object on
|
||||
the D-Bus system bus service with the well-known
|
||||
name <doc:tt>org.freedesktop.UPower</doc:tt> using
|
||||
the
|
||||
<doc:ref type="method" to="Power.EnumerateDevices">EnumerateDevices</doc:ref>
|
||||
method.
|
||||
</doc:para>
|
||||
<doc:para>
|
||||
<doc:example language="shell" title="simple example">
|
||||
<doc:code>
|
||||
$ dbus-send --print-reply \
|
||||
--system \
|
||||
--dest=org.freedesktop.UPower \
|
||||
/org/freedesktop/UPower/devices/battery_BAT0 \
|
||||
org.freedesktop.DBus.Properties.GetAll \
|
||||
string:org.freedesktop.UPower.Device
|
||||
|
||||
method return sender=:1.386 -> dest=:1.477 reply_serial=2
|
||||
array [
|
||||
dict entry(
|
||||
string "native-path"
|
||||
variant string "/sys/devices/LNXSYSTM:00/device:00/PNP0A08:00/device:01/PNP0C09:00/PNP0C0A:00/power_supply/BAT0"
|
||||
)
|
||||
dict entry(
|
||||
string "vendor"
|
||||
variant string "SONY"
|
||||
)
|
||||
dict entry(
|
||||
string "model"
|
||||
variant string "42T4568"
|
||||
)
|
||||
dict entry(
|
||||
string "serial"
|
||||
variant string "4179"
|
||||
)
|
||||
dict entry(
|
||||
string "update-time"
|
||||
variant uint64 1226417875
|
||||
)
|
||||
dict entry(
|
||||
string "type"
|
||||
variant uint 2
|
||||
)
|
||||
dict entry(
|
||||
string "power-supply"
|
||||
variant boolean true
|
||||
)
|
||||
dict entry(
|
||||
string "has-history"
|
||||
variant boolean true
|
||||
)
|
||||
dict entry(
|
||||
string "has-statistics"
|
||||
variant boolean true
|
||||
)
|
||||
dict entry(
|
||||
string "online"
|
||||
variant boolean false
|
||||
)
|
||||
dict entry(
|
||||
string "energy"
|
||||
variant double 72.85
|
||||
)
|
||||
dict entry(
|
||||
string "energy-empty"
|
||||
variant double 0
|
||||
)
|
||||
dict entry(
|
||||
string "energy-full"
|
||||
variant double 74.55
|
||||
)
|
||||
dict entry(
|
||||
string "energy-full-design"
|
||||
variant double 74.88
|
||||
)
|
||||
dict entry(
|
||||
string "energy-rate"
|
||||
variant double 0
|
||||
)
|
||||
dict entry(
|
||||
string "voltage"
|
||||
variant double 16.415
|
||||
)
|
||||
dict entry(
|
||||
string "time-to-empty"
|
||||
variant int64 0
|
||||
)
|
||||
dict entry(
|
||||
string "time-to-full"
|
||||
variant int64 0
|
||||
)
|
||||
dict entry(
|
||||
string "percentage"
|
||||
variant double 97.7197
|
||||
)
|
||||
dict entry(
|
||||
string "is-present"
|
||||
variant boolean true
|
||||
)
|
||||
dict entry(
|
||||
string "state"
|
||||
variant uint 3
|
||||
)
|
||||
dict entry(
|
||||
string "is-rechargeable"
|
||||
variant boolean true
|
||||
)
|
||||
dict entry(
|
||||
string "capacity"
|
||||
variant double 100
|
||||
)
|
||||
dict entry(
|
||||
string "technology"
|
||||
variant uint 1
|
||||
)
|
||||
]
|
||||
</doc:code>
|
||||
</doc:example>
|
||||
</doc:para>
|
||||
<doc:para>
|
||||
Unless otherwise noted, an empty string or the value 0 in a
|
||||
property on this interface means not set.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
|
||||
|
||||
<!-- ************************************************************ -->
|
||||
<method name="Refresh">
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Refreshes the data collected from the power source.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
<doc:permission>Callers will need to make sure that the daemon was started in debug mode</doc:permission>
|
||||
<doc:errors>
|
||||
<doc:error name="&ERROR_GENERAL;">if an error occured while refreshing</doc:error>
|
||||
</doc:errors>
|
||||
</doc:doc>
|
||||
</method>
|
||||
|
||||
<!-- ************************************************************ -->
|
||||
<method name="GetHistory">
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
|
||||
<arg name="type" direction="in" type="s">
|
||||
<doc:doc><doc:summary>The type of history.
|
||||
Valid types are <doc:tt>rate</doc:tt> or <doc:tt>charge</doc:tt>.</doc:summary></doc:doc>
|
||||
</arg>
|
||||
<arg name="timespan" direction="in" type="u">
|
||||
<doc:doc><doc:summary>The amount of data to return in seconds, or 0 for all.</doc:summary></doc:doc>
|
||||
</arg>
|
||||
<arg name="resolution" direction="in" type="u">
|
||||
<doc:doc>
|
||||
<doc:summary>
|
||||
The approximate number of points to return.
|
||||
A higher resolution is more accurate, at the expense of plotting speed.
|
||||
</doc:summary>
|
||||
</doc:doc>
|
||||
</arg>
|
||||
<arg name="data" direction="out" type="a(udu)">
|
||||
<doc:doc><doc:summary>
|
||||
The history data for the power device, if the device supports history.
|
||||
Data is ordered from the earliest in time, to the newest data point.
|
||||
Each element contains the following members:
|
||||
<doc:list>
|
||||
<doc:item>
|
||||
<doc:term>time</doc:term>
|
||||
<doc:definition>
|
||||
The time value in seconds from the <doc:tt>gettimeofday()</doc:tt> method.
|
||||
</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>value</doc:term>
|
||||
<doc:definition>
|
||||
The data value, for instance the rate in W or the charge in %.
|
||||
</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>state</doc:term>
|
||||
<doc:definition>
|
||||
The state of the device, for instance <doc:tt>charging</doc:tt> or
|
||||
<doc:tt>discharging</doc:tt>.
|
||||
</doc:definition>
|
||||
</doc:item>
|
||||
</doc:list>
|
||||
</doc:summary></doc:doc>
|
||||
</arg>
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Gets history for the power device that is persistent across reboots.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</method>
|
||||
|
||||
<!-- ************************************************************ -->
|
||||
<method name="GetStatistics">
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
|
||||
<arg name="type" direction="in" type="s">
|
||||
<doc:doc><doc:summary>The mode for the statistics.
|
||||
Valid types are <doc:tt>charging</doc:tt> or <doc:tt>discharging</doc:tt>.</doc:summary></doc:doc>
|
||||
</arg>
|
||||
<arg name="data" direction="out" type="a(dd)">
|
||||
<doc:doc><doc:summary>
|
||||
The statistics data for the power device.
|
||||
Each element contains the following members:
|
||||
<doc:list>
|
||||
<doc:item>
|
||||
<doc:term>value</doc:term>
|
||||
<doc:definition>
|
||||
The value of the percentage point, usually in seconds
|
||||
</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>accuracy</doc:term>
|
||||
<doc:definition>
|
||||
The accuracy of the prediction in percent.
|
||||
</doc:definition>
|
||||
</doc:item>
|
||||
</doc:list>
|
||||
</doc:summary></doc:doc>
|
||||
</arg>
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Gets statistics for the power device that may be interesting
|
||||
to show on a graph in the session.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</method>
|
||||
|
||||
<!-- ************************************************************ -->
|
||||
<property name="NativePath" type="s" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
OS specific native path of the power source. On Linux this
|
||||
is the sysfs path, for
|
||||
example <doc:tt>/sys/devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0</doc:tt>. Is
|
||||
blank if the device is being driven by a user space
|
||||
driver.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="Vendor" type="s" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Name of the vendor of the battery.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="Model" type="s" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Name of the model of this battery.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="Serial" type="s" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Unique serial number of the battery.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="UpdateTime" type="t" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
The point in time (seconds since the Epoch Jan 1, 1970
|
||||
0:00 UTC) that data was read from the power source.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="Type" type="u" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Type of power source.
|
||||
</doc:para>
|
||||
<doc:list>
|
||||
<doc:item>
|
||||
<doc:term>0</doc:term><doc:definition>Unknown</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>1</doc:term><doc:definition>Line Power</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>2</doc:term><doc:definition>Battery</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>3</doc:term><doc:definition>Ups</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>4</doc:term><doc:definition>Monitor</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>5</doc:term><doc:definition>Mouse</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>6</doc:term><doc:definition>Keyboard</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>7</doc:term><doc:definition>Pda</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>8</doc:term><doc:definition>Phone</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>9</doc:term><doc:definition>Media Player</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>10</doc:term><doc:definition>Tablet</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>11</doc:term><doc:definition>Computer</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>12</doc:term><doc:definition>Gaming Input</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>13</doc:term><doc:definition>Pen</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>14</doc:term><doc:definition>Touchpad</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>15</doc:term><doc:definition>Modem</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>16</doc:term><doc:definition>Network</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>17</doc:term><doc:definition>Headset</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>18</doc:term><doc:definition>Speakers</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>19</doc:term><doc:definition>Headphones</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>20</doc:term><doc:definition>Video</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>21</doc:term><doc:definition>Other Audio</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>22</doc:term><doc:definition>Remote Control</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>23</doc:term><doc:definition>Printer</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>24</doc:term><doc:definition>Scanner</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>25</doc:term><doc:definition>Camera</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>26</doc:term><doc:definition>Wearable</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>27</doc:term><doc:definition>Toy</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>28</doc:term><doc:definition>Bluetooth Genreic</doc:definition>
|
||||
</doc:item>
|
||||
</doc:list>
|
||||
<doc:para>
|
||||
If the value is set to "Battery", you will need to verify that the
|
||||
property <doc:ref type="property" to="Source:PowerSupply">power-supply</doc:ref>
|
||||
has the value "true" before considering it as a laptop battery. Otherwise it
|
||||
will likely be the battery for a device of an unknown type.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="PowerSupply" type="b" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
If the power device is used to supply the system.
|
||||
This would be set TRUE for laptop batteries and UPS devices,
|
||||
but set FALSE for wireless mice or PDAs.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="HasHistory" type="b" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
If the power device has history.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="HasStatistics" type="b" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
If the power device has statistics.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="Online" type="b" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Whether power is currently being provided through line power.
|
||||
This property is only valid if the property
|
||||
<doc:ref type="property" to="Source:Type">type</doc:ref>
|
||||
has the value "line-power".
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="Energy" type="d" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Amount of energy (measured in Wh) currently available in
|
||||
the power source.
|
||||
</doc:para><doc:para>
|
||||
This property is only valid if the property
|
||||
<doc:ref type="property" to="Source:Type">type</doc:ref>
|
||||
has the value "battery".
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="EnergyEmpty" type="d" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Amount of energy (measured in Wh) in the power source when
|
||||
it's considered to be empty.
|
||||
</doc:para><doc:para>
|
||||
This property is only valid if the property
|
||||
<doc:ref type="property" to="Source:Type">type</doc:ref>
|
||||
has the value "battery".
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="EnergyFull" type="d" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Amount of energy (measured in Wh) in the power source when
|
||||
it's considered full.
|
||||
</doc:para><doc:para>
|
||||
This property is only valid if the property
|
||||
<doc:ref type="property" to="Source:Type">type</doc:ref>
|
||||
has the value "battery".
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="EnergyFullDesign" type="d" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Amount of energy (measured in Wh) the power source is
|
||||
designed to hold when it's considered full.
|
||||
</doc:para><doc:para>
|
||||
This property is only valid if the property
|
||||
<doc:ref type="property" to="Source:Type">type</doc:ref>
|
||||
has the value "battery".
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="EnergyRate" type="d" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Amount of energy being drained from the source, measured
|
||||
in W. If positive, the source is being discharged, if
|
||||
negative it's being charged.
|
||||
</doc:para><doc:para>
|
||||
This property is only valid if the property
|
||||
<doc:ref type="property" to="Source:Type">type</doc:ref>
|
||||
has the value "battery".
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="Voltage" type="d" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Voltage in the Cell or being recorded by the meter.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="ChargeCycles" type="i" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
The number of charge cycles as defined by the TCO certification, or -1 if
|
||||
that value is unknown or not applicable.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="Luminosity" type="d" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Luminosity being recorded by the meter.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="TimeToEmpty" type="x" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Number of seconds until the power source is considered empty.
|
||||
Is set to 0 if unknown.
|
||||
</doc:para><doc:para>
|
||||
This property is only valid if the property
|
||||
<doc:ref type="property" to="Source:Type">type</doc:ref>
|
||||
has the value "battery".
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="TimeToFull" type="x" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Number of seconds until the power source is considered full.
|
||||
Is set to 0 if unknown.
|
||||
</doc:para><doc:para>
|
||||
This property is only valid if the property
|
||||
<doc:ref type="property" to="Source:Type">type</doc:ref>
|
||||
has the value "battery".
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="Percentage" type="d" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
The amount of energy left in the power source expressed as
|
||||
a percentage between 0 and 100. Typically this is the same as
|
||||
(<doc:ref type="property" to="Source:Energy">energy</doc:ref> -
|
||||
<doc:ref type="property" to="Source:EnergyEmpty">energy-empty</doc:ref>) /
|
||||
(<doc:ref type="property" to="Source:EnergyFull">energy-full</doc:ref> -
|
||||
<doc:ref type="property" to="Source:EnergyEmpty">energy-empty</doc:ref>).
|
||||
However, some primitive power sources are capable of only
|
||||
reporting percentages and in this case the energy-*
|
||||
properties will be unset while this property is set.
|
||||
</doc:para><doc:para>
|
||||
This property is only valid if the property
|
||||
<doc:ref type="property" to="Source:Type">type</doc:ref>
|
||||
has the value "battery".
|
||||
</doc:para>
|
||||
<doc:para>
|
||||
The percentage will be an approximation if the <doc:ref type="property" to="BatteryLevel">battery level</doc:ref>
|
||||
is set to something other than None. The percentage is kept for compatibility reasons.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="Temperature" type="d" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
The temperature of the device in degrees Celsius. This property is
|
||||
only valid if the property
|
||||
<doc:ref type="property" to="Source:Type">type</doc:ref>
|
||||
has the value "battery".
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="IsPresent" type="b" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
If the power source is present in the bay.
|
||||
This field is required as some batteries are hot-removable, for example
|
||||
expensive UPS and most laptop batteries.
|
||||
</doc:para><doc:para>
|
||||
This property is only valid if the property
|
||||
<doc:ref type="property" to="Source:Type">type</doc:ref>
|
||||
has the value "battery".
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="State" type="u" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
The battery power state.
|
||||
</doc:para>
|
||||
<doc:list>
|
||||
<doc:item>
|
||||
<doc:term>0</doc:term><doc:definition>Unknown</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>1</doc:term><doc:definition>Charging</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>2</doc:term><doc:definition>Discharging</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>3</doc:term><doc:definition>Empty</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>4</doc:term><doc:definition>Fully charged</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>5</doc:term><doc:definition>Pending charge</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>6</doc:term><doc:definition>Pending discharge</doc:definition>
|
||||
</doc:item>
|
||||
</doc:list>
|
||||
<doc:para>
|
||||
This property is only valid if the property
|
||||
<doc:ref type="property" to="Source:Type">type</doc:ref>
|
||||
has the value "battery".
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="IsRechargeable" type="b" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
If the power source is rechargeable.
|
||||
</doc:para><doc:para>
|
||||
This property is only valid if the property
|
||||
<doc:ref type="property" to="Source:Type">type</doc:ref>
|
||||
has the value "battery".
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="Capacity" type="d" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
The capacity of the power source expressed as a percentage between 0 and 100.
|
||||
The capacity of the battery will reduce with age.
|
||||
A capacity value less than 75% is usually a sign that you should renew your battery.
|
||||
Typically this value is the same as
|
||||
(<doc:ref type="property" to="Source:FullDesign">full-design</doc:ref> /
|
||||
<doc:ref type="property" to="Source:Full">full</doc:ref>) * 100.
|
||||
However, some primitive power sources are not capable reporting capacity
|
||||
and in this case the capacity property will be unset.
|
||||
</doc:para><doc:para>
|
||||
This property is only valid if the property
|
||||
<doc:ref type="property" to="Source:Type">type</doc:ref>
|
||||
has the value "battery".
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="Technology" type="u" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Technology used in the battery:
|
||||
</doc:para>
|
||||
<doc:list>
|
||||
<doc:item>
|
||||
<doc:term>0</doc:term><doc:definition>Unknown</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>1</doc:term><doc:definition>Lithium ion</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>2</doc:term><doc:definition>Lithium polymer</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>3</doc:term><doc:definition>Lithium iron phosphate</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>4</doc:term><doc:definition>Lead acid</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>5</doc:term><doc:definition>Nickel cadmium</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>6</doc:term><doc:definition>Nickel metal hydride</doc:definition>
|
||||
</doc:item>
|
||||
</doc:list>
|
||||
<doc:para>
|
||||
This property is only valid if the property
|
||||
<doc:ref type="property" to="Source:Type">type</doc:ref>
|
||||
has the value "battery".
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="WarningLevel" type="u" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Warning level of the battery:
|
||||
</doc:para>
|
||||
<doc:list>
|
||||
<doc:item>
|
||||
<doc:term>0</doc:term><doc:definition>Unknown</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>1</doc:term><doc:definition>None</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>2</doc:term><doc:definition>Discharging (only for UPSes)</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>3</doc:term><doc:definition>Low</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>4</doc:term><doc:definition>Critical</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>5</doc:term><doc:definition>Action</doc:definition>
|
||||
</doc:item>
|
||||
</doc:list>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="BatteryLevel" type="u" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
The level of the battery for devices which do not report a percentage but rather a coarse battery level. If the value
|
||||
is None, then the device does not support coarse battery reporting, and the percentage should be used instead.
|
||||
</doc:para>
|
||||
<doc:list>
|
||||
<doc:item>
|
||||
<doc:term>0</doc:term><doc:definition>Unknown</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>1</doc:term><doc:definition>None (the battery does not use a coarse level of battery reporting)</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>3</doc:term><doc:definition>Low</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>4</doc:term><doc:definition>Critical</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>6</doc:term><doc:definition>Normal</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>7</doc:term><doc:definition>High</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>8</doc:term><doc:definition>Full</doc:definition>
|
||||
</doc:item>
|
||||
</doc:list>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="IconName" type="s" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
<p>An icon name, following the <a href="http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html">Icon Naming Specification</a></p>
|
||||
<p>Note that the icons might not match end-user expectations in terms of presentation relative to the amount of battery left or perceived to be left. It is recommended that front-ends use the BatteryLevel property first, if available, followed by the Percentage, to present a more realistic battery level to the user.</p>
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
</interface>
|
||||
|
||||
</node>
|
||||
@@ -38,14 +38,16 @@
|
||||
#include "mce_proxy.h"
|
||||
#include "mce_log_p.h"
|
||||
|
||||
#include <mce/dbus-names.h>
|
||||
#include <mce/mode-names.h>
|
||||
|
||||
#include <gutil_misc.h>
|
||||
|
||||
/* Generated headers */
|
||||
#include "com.nokia.mce.request.h"
|
||||
#include "com.nokia.mce.signal.h"
|
||||
#include "org.freedesktop.UPower.Device.h"
|
||||
|
||||
#define MCE_BATTERY_STATUS_OK "ok"
|
||||
#define MCE_BATTERY_STATUS_LOW "low"
|
||||
#define MCE_BATTERY_STATUS_EMPTY "very_low"
|
||||
#define MCE_BATTERY_STATUS_CRITICAL "critical"
|
||||
#define MCE_BATTERY_STATUS_UNKNOWN "unknown"
|
||||
|
||||
enum mce_battery_ind {
|
||||
BATTERY_IND_LEVEL,
|
||||
@@ -65,7 +67,7 @@ struct mce_battery_priv {
|
||||
MceProxy* proxy;
|
||||
BATTERY_FLAGS flags;
|
||||
gulong proxy_valid_id;
|
||||
gulong battery_ind_id[BATTERY_IND_COUNT];
|
||||
gulong battery_ind_id;
|
||||
};
|
||||
|
||||
enum mce_battery_signal {
|
||||
@@ -107,23 +109,6 @@ mce_battery_check_valid(
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
mce_battery_level_update(
|
||||
MceBattery* self,
|
||||
gint level)
|
||||
{
|
||||
MceBatteryPriv* priv = self->priv;
|
||||
const guint new_level = (level < 0) ? 0 : (level > 100) ? 100 : level;
|
||||
|
||||
if (self->level != new_level) {
|
||||
self->level = new_level;
|
||||
g_signal_emit(self, mce_battery_signals[SIGNAL_LEVEL_CHANGED], 0);
|
||||
}
|
||||
priv->flags |= BATTERY_HAVE_LEVEL;
|
||||
mce_battery_check_valid(self);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
mce_battery_status_update(
|
||||
@@ -133,13 +118,13 @@ mce_battery_status_update(
|
||||
MceBatteryPriv* priv = self->priv;
|
||||
MCE_BATTERY_STATUS new_status;
|
||||
|
||||
if (!g_strcmp0(status, MCE_BATTERY_STATUS_FULL)) {
|
||||
new_status = MCE_BATTERY_FULL;
|
||||
} else if (!g_strcmp0(status, MCE_BATTERY_STATUS_OK)) {
|
||||
if (!g_strcmp0(status, MCE_BATTERY_STATUS_OK)) {
|
||||
new_status = MCE_BATTERY_OK;
|
||||
} else if (!g_strcmp0(status, MCE_BATTERY_STATUS_LOW)) {
|
||||
new_status = MCE_BATTERY_LOW;
|
||||
} else if (!g_strcmp0(status, MCE_BATTERY_STATUS_EMPTY)) {
|
||||
new_status = MCE_BATTERY_LOW;
|
||||
} else if (!g_strcmp0(status, MCE_BATTERY_STATUS_CRITICAL)) {
|
||||
new_status = MCE_BATTERY_EMPTY;
|
||||
} else {
|
||||
GASSERT(!g_strcmp0(status, MCE_BATTERY_STATUS_UNKNOWN));
|
||||
@@ -155,71 +140,54 @@ mce_battery_status_update(
|
||||
|
||||
static
|
||||
void
|
||||
mce_battery_level_query_done(
|
||||
GObject* proxy,
|
||||
GAsyncResult* result,
|
||||
gpointer arg)
|
||||
mce_battery_level_update(
|
||||
MceBattery* self,
|
||||
gdouble level)
|
||||
{
|
||||
MceBattery* self = MCE_BATTERY(arg);
|
||||
GError* error = NULL;
|
||||
gint level;
|
||||
// values from ayatana-indicator-power/src/notifier.c
|
||||
char* status;
|
||||
if (level <= 2)
|
||||
status = MCE_BATTERY_STATUS_CRITICAL;
|
||||
else if (level <= 5)
|
||||
status = MCE_BATTERY_STATUS_EMPTY;
|
||||
else if (level <= 10)
|
||||
status = MCE_BATTERY_STATUS_LOW;
|
||||
else
|
||||
status = MCE_BATTERY_STATUS_OK;
|
||||
mce_battery_status_update(self, status);
|
||||
|
||||
if (com_nokia_mce_request_call_get_battery_level_finish(
|
||||
COM_NOKIA_MCE_REQUEST(proxy), &level, result, &error)) {
|
||||
GDEBUG("Battery level is currently %d", level);
|
||||
mce_battery_level_update(self, level);
|
||||
} else {
|
||||
/* Should retry? */
|
||||
GWARN("Failed to query battery level %s", GERRMSG(error));
|
||||
g_error_free(error);
|
||||
MceBatteryPriv* priv = self->priv;
|
||||
const guint new_level = (level < 0) ? 0 : (level > 100) ? 100 : level;
|
||||
|
||||
if (self->level != new_level) {
|
||||
self->level = new_level;
|
||||
g_signal_emit(self, mce_battery_signals[SIGNAL_LEVEL_CHANGED], 0);
|
||||
}
|
||||
mce_battery_unref(self);
|
||||
priv->flags |= BATTERY_HAVE_LEVEL;
|
||||
mce_battery_check_valid(self);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
mce_battery_status_query_done(
|
||||
GObject* proxy,
|
||||
GAsyncResult* result,
|
||||
gpointer arg)
|
||||
static void
|
||||
on_properties_changed (GDBusProxy *proxy,
|
||||
GVariant *changed_properties,
|
||||
const gchar* const *invalidated_properties,
|
||||
gpointer user_data)
|
||||
{
|
||||
MceBattery* self = MCE_BATTERY(arg);
|
||||
GError* error = NULL;
|
||||
char* status = NULL;
|
||||
GVariantIter iter;
|
||||
const gchar *key;
|
||||
GVariant *value;
|
||||
|
||||
if (com_nokia_mce_request_call_get_battery_status_finish(
|
||||
COM_NOKIA_MCE_REQUEST(proxy), &status, result, &error)) {
|
||||
GDEBUG("Battery is currently %s", status);
|
||||
mce_battery_status_update(self, status);
|
||||
g_free(status);
|
||||
} else {
|
||||
/* Should retry? */
|
||||
GWARN("Failed to query battery status %s", GERRMSG(error));
|
||||
g_error_free(error);
|
||||
g_variant_iter_init (&iter, changed_properties);
|
||||
while (g_variant_iter_next (&iter, "{&sv}", &key, &value))
|
||||
{
|
||||
if (!g_strcmp0(key, "Percentage")) {
|
||||
gdouble level;
|
||||
g_variant_get (value, "d", &level);
|
||||
mce_battery_level_update(MCE_BATTERY(user_data), level);
|
||||
}
|
||||
|
||||
g_variant_unref (value);
|
||||
}
|
||||
mce_battery_unref(self);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
mce_battery_level_ind(
|
||||
ComNokiaMceSignal* proxy,
|
||||
gint level,
|
||||
gpointer arg)
|
||||
{
|
||||
GDEBUG("Battery level is %d", level);
|
||||
mce_battery_level_update(MCE_BATTERY(arg), level);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
mce_battery_status_ind(
|
||||
ComNokiaMceSignal* proxy,
|
||||
const char* status,
|
||||
gpointer arg)
|
||||
{
|
||||
GDEBUG("Battery is %s", status);
|
||||
mce_battery_status_update(MCE_BATTERY(arg), status);
|
||||
}
|
||||
|
||||
static
|
||||
@@ -236,24 +204,14 @@ mce_battery_query(
|
||||
* for the valid signal before we can connect the battery state
|
||||
* signal and submit the initial query.
|
||||
*/
|
||||
if (proxy->signal) {
|
||||
if (!priv->battery_ind_id[BATTERY_IND_LEVEL]) {
|
||||
priv->battery_ind_id[BATTERY_IND_LEVEL] =
|
||||
g_signal_connect(proxy->signal, "battery-level-ind",
|
||||
G_CALLBACK(mce_battery_level_ind), self);
|
||||
}
|
||||
|
||||
if (!priv->battery_ind_id[BATTERY_IND_STATUS]) {
|
||||
priv->battery_ind_id[BATTERY_IND_STATUS] =
|
||||
g_signal_connect(proxy->signal, "battery-status-ind",
|
||||
G_CALLBACK(mce_battery_status_ind), self);
|
||||
}
|
||||
if (proxy->upower_request && !priv->battery_ind_id) {
|
||||
priv->battery_ind_id = g_signal_connect(proxy->upower_request, "g-properties-changed",
|
||||
G_CALLBACK(on_properties_changed), self);
|
||||
}
|
||||
if (proxy->request && proxy->valid) {
|
||||
com_nokia_mce_request_call_get_battery_level(proxy->request, NULL,
|
||||
mce_battery_level_query_done, mce_battery_ref(self));
|
||||
com_nokia_mce_request_call_get_battery_status(proxy->request, NULL,
|
||||
mce_battery_status_query_done, mce_battery_ref(self));
|
||||
|
||||
if (proxy->upower_request && proxy->valid) {
|
||||
gdouble level = org_freedesktop_upower_device_get_percentage(proxy->upower_request);
|
||||
mce_battery_level_update(self, level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,8 +347,7 @@ mce_battery_finalize(
|
||||
MceBattery* self = MCE_BATTERY(object);
|
||||
MceBatteryPriv* priv = self->priv;
|
||||
|
||||
gutil_disconnect_handlers(priv->proxy->signal, priv->battery_ind_id,
|
||||
G_N_ELEMENTS(priv->battery_ind_id));
|
||||
mce_proxy_remove_handler(priv->proxy, priv->battery_ind_id);
|
||||
mce_proxy_remove_handler(priv->proxy, priv->proxy_valid_id);
|
||||
mce_proxy_unref(priv->proxy);
|
||||
G_OBJECT_CLASS(PARENT_CLASS)->finalize(object);
|
||||
|
||||
@@ -38,14 +38,25 @@
|
||||
#include "mce_proxy.h"
|
||||
#include "mce_log_p.h"
|
||||
|
||||
#include <mce/dbus-names.h>
|
||||
#include <mce/mode-names.h>
|
||||
|
||||
#include <gutil_misc.h>
|
||||
|
||||
#define MCE_CHARGER_STATE_ON "on"
|
||||
#define MCE_CHARGER_STATE_OFF "off"
|
||||
#define MCE_CHARGER_STATE_UNKNOWN "unknown"
|
||||
|
||||
/* Generated headers */
|
||||
#include "com.nokia.mce.request.h"
|
||||
#include "com.nokia.mce.signal.h"
|
||||
#include "org.freedesktop.UPower.Device.h"
|
||||
|
||||
enum upower_state {
|
||||
UPOWER_STATE_UNKNOWN,
|
||||
UPOWER_STATE_CHARGING,
|
||||
UPOWER_STATE_DISCHARGING,
|
||||
UPOWER_STATE_EMPTY,
|
||||
UPOWER_STATE_FULLY_CHARGED,
|
||||
UPOWER_STATE_PENDING_CHARGE,
|
||||
UPOWER_STATE_PENDING_DISCHARGE,
|
||||
UPOWER_STATE_COUNT
|
||||
};
|
||||
|
||||
struct mce_charger_priv {
|
||||
MceProxy* proxy;
|
||||
@@ -102,44 +113,45 @@ mce_charger_state_update(
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
mce_charger_state_query_done(
|
||||
GObject* proxy,
|
||||
GAsyncResult* result,
|
||||
gpointer arg)
|
||||
static void
|
||||
mce_charger_update_charging_state (
|
||||
MceCharger* self,
|
||||
enum upower_state state)
|
||||
{
|
||||
GError* error = NULL;
|
||||
char* state = NULL;
|
||||
MceCharger* self = MCE_CHARGER(arg);
|
||||
|
||||
if (com_nokia_mce_request_call_get_charger_state_finish(
|
||||
COM_NOKIA_MCE_REQUEST(proxy), &state, result, &error)) {
|
||||
GDEBUG("Charger is currently %s", state);
|
||||
mce_charger_state_update(self, state);
|
||||
g_free(state);
|
||||
} else {
|
||||
/*
|
||||
* We could retry but it's probably not worth the trouble
|
||||
* because the next time charger state changes we receive
|
||||
* charger_state_ind signal and sync our state with mce.
|
||||
* Until then, this object stays invalid.
|
||||
*/
|
||||
GWARN("Failed to query charger state %s", GERRMSG(error));
|
||||
g_error_free(error);
|
||||
gboolean discharging;
|
||||
switch (state) {
|
||||
case UPOWER_STATE_CHARGING:
|
||||
case UPOWER_STATE_FULLY_CHARGED:
|
||||
discharging = 0;
|
||||
break;
|
||||
default:
|
||||
discharging = 1;
|
||||
break;
|
||||
}
|
||||
mce_charger_unref(self);
|
||||
mce_charger_state_update(self, discharging ? MCE_CHARGER_STATE_OFF : MCE_CHARGER_STATE_ON);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
mce_charger_state_ind(
|
||||
ComNokiaMceSignal* proxy,
|
||||
const char* state,
|
||||
gpointer arg)
|
||||
static void
|
||||
on_properties_changed (GDBusProxy *proxy,
|
||||
GVariant *changed_properties,
|
||||
const gchar* const *invalidated_properties,
|
||||
gpointer user_data)
|
||||
{
|
||||
GDEBUG("Charger is %s", state);
|
||||
mce_charger_state_update(MCE_CHARGER(arg), state);
|
||||
GVariantIter iter;
|
||||
const gchar *key;
|
||||
GVariant *value;
|
||||
|
||||
g_variant_iter_init (&iter, changed_properties);
|
||||
while (g_variant_iter_next (&iter, "{&sv}", &key, &value))
|
||||
{
|
||||
if (!g_strcmp0(key, "State")) {
|
||||
enum upower_state state;
|
||||
g_variant_get (value, "u", &state);
|
||||
mce_charger_update_charging_state(MCE_CHARGER(user_data), state);
|
||||
}
|
||||
|
||||
g_variant_unref (value);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
@@ -156,13 +168,14 @@ mce_charger_state_query(
|
||||
* for the valid signal before we can connect the charger state
|
||||
* signal and submit the initial query.
|
||||
*/
|
||||
if (proxy->signal && !priv->charger_state_ind_id) {
|
||||
priv->charger_state_ind_id = g_signal_connect(proxy->signal,
|
||||
MCE_CHARGER_STATE_SIG, G_CALLBACK(mce_charger_state_ind), self);
|
||||
if (proxy->upower_request && !priv->charger_state_ind_id) {
|
||||
priv->charger_state_ind_id = g_signal_connect(proxy->upower_request, "g-properties-changed",
|
||||
G_CALLBACK(on_properties_changed), self);
|
||||
}
|
||||
if (proxy->request && proxy->valid) {
|
||||
com_nokia_mce_request_call_get_charger_state(proxy->request, NULL,
|
||||
mce_charger_state_query_done, mce_charger_ref(self));
|
||||
|
||||
if (proxy->upower_request && proxy->valid) {
|
||||
enum upower_state state = org_freedesktop_upower_device_get_state(proxy->upower_request);
|
||||
mce_charger_update_charging_state(self, state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,7 +303,7 @@ mce_charger_finalize(
|
||||
MceChargerPriv* priv = self->priv;
|
||||
|
||||
if (priv->charger_state_ind_id) {
|
||||
g_signal_handler_disconnect(priv->proxy->signal,
|
||||
g_signal_handler_disconnect(priv->proxy->upower_request,
|
||||
priv->charger_state_ind_id);
|
||||
}
|
||||
mce_proxy_remove_handler(priv->proxy, priv->proxy_valid_id);
|
||||
|
||||
@@ -149,12 +149,12 @@ mce_display_status_query(
|
||||
* for the valid signal before we can connect the display state
|
||||
* signal and submit the initial query.
|
||||
*/
|
||||
if (proxy->signal && !priv->display_status_ind_id) {
|
||||
priv->display_status_ind_id = g_signal_connect(proxy->signal,
|
||||
if (proxy->unity_request && !priv->display_status_ind_id) {
|
||||
priv->display_status_ind_id = g_signal_connect(proxy->unity_request,
|
||||
MCE_DISPLAY_SIG, G_CALLBACK(mce_display_power_state_change), self);
|
||||
}
|
||||
if (proxy->request && proxy->valid) {
|
||||
com_canonical_unity_screen_call_get_display_power_state(proxy->request, NULL,
|
||||
if (proxy->unity_request && proxy->valid) {
|
||||
com_canonical_unity_screen_call_get_display_power_state(proxy->unity_request, NULL,
|
||||
mce_display_status_query_done, mce_display_ref(self));
|
||||
}
|
||||
}
|
||||
@@ -283,7 +283,7 @@ mce_display_finalize(
|
||||
MceDisplayPriv* priv = self->priv;
|
||||
|
||||
if (priv->display_status_ind_id) {
|
||||
g_signal_handler_disconnect(priv->proxy->signal,
|
||||
g_signal_handler_disconnect(priv->proxy->unity_request,
|
||||
priv->display_status_ind_id);
|
||||
}
|
||||
mce_proxy_remove_handler(priv->proxy, priv->proxy_valid_id);
|
||||
|
||||
@@ -39,12 +39,17 @@
|
||||
|
||||
/* Generated headers */
|
||||
#include "com.canonical.Unity.Screen.h"
|
||||
#include "org.freedesktop.UPower.Device.h"
|
||||
|
||||
GLOG_MODULE_DEFINE("mce");
|
||||
|
||||
struct mce_proxy_priv {
|
||||
GDBusConnection* bus;
|
||||
guint mce_watch_id;
|
||||
guint upower_watch_id;
|
||||
|
||||
gboolean unity_valid;
|
||||
gboolean upower_valid;
|
||||
};
|
||||
|
||||
enum mce_proxy_signal {
|
||||
@@ -56,7 +61,9 @@ enum mce_proxy_signal {
|
||||
|
||||
#define MCE_SERVICE "com.canonical.Unity.Screen"
|
||||
#define MCE_REQUEST_PATH "/com/canonical/Unity/Screen"
|
||||
#define MCE_SIGNAL_PATH "/com/canonical/Unity/Screen"
|
||||
|
||||
#define UPOWER_SERVICE "org.freedesktop.UPower"
|
||||
#define UPOWER_REQUEST_PATH "/org/freedesktop/UPower/devices/DisplayDevice"
|
||||
|
||||
static guint mce_proxy_signals[SIGNAL_COUNT] = { 0 };
|
||||
|
||||
@@ -107,11 +114,16 @@ mce_proxy_init_check(
|
||||
{
|
||||
MceProxyPriv* priv = self->priv;
|
||||
|
||||
if (self->signal && self->request && !priv->mce_watch_id) {
|
||||
if ( self->unity_request && !priv->mce_watch_id) {
|
||||
priv->mce_watch_id = g_bus_watch_name_on_connection(priv->bus,
|
||||
MCE_SERVICE, G_BUS_NAME_WATCHER_FLAGS_NONE,
|
||||
mce_name_appeared, mce_name_vanished, self, NULL);
|
||||
}
|
||||
if (self->upower_request && !priv->upower_watch_id) {
|
||||
priv->upower_watch_id = g_bus_watch_name_on_connection(priv->bus,
|
||||
UPOWER_SERVICE, G_BUS_NAME_WATCHER_FLAGS_NONE,
|
||||
mce_name_appeared, mce_name_vanished, self, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
@@ -124,9 +136,9 @@ mce_proxy_request_proxy_new_finished(
|
||||
MceProxy* self = MCE_PROXY(arg);
|
||||
GError* error = NULL;
|
||||
|
||||
GASSERT(!self->request);
|
||||
self->request = com_canonical_unity_screen_proxy_new_finish(result, &error);
|
||||
if (self->request) {
|
||||
GASSERT(!self->unity_request);
|
||||
self->unity_request = com_canonical_unity_screen_proxy_new_finish(result, &error);
|
||||
if (self->unity_request) {
|
||||
mce_proxy_init_check(self);
|
||||
} else {
|
||||
GERR("Failed to initialize MCE request proxy: %s", GERRMSG(error));
|
||||
@@ -137,7 +149,7 @@ mce_proxy_request_proxy_new_finished(
|
||||
|
||||
static
|
||||
void
|
||||
mce_proxy_signal_proxy_new_finished(
|
||||
mce_proxy_request_proxy_upower_new_finished(
|
||||
GObject* object,
|
||||
GAsyncResult* result,
|
||||
gpointer arg)
|
||||
@@ -145,12 +157,12 @@ mce_proxy_signal_proxy_new_finished(
|
||||
MceProxy* self = MCE_PROXY(arg);
|
||||
GError* error = NULL;
|
||||
|
||||
GASSERT(!self->signal);
|
||||
self->signal = com_canonical_unity_screen_proxy_new_finish(result, &error);
|
||||
if (self->signal) {
|
||||
GASSERT(!self->upower_request);
|
||||
self->upower_request = org_freedesktop_upower_device_proxy_new_finish(result, &error);
|
||||
if (self->upower_request) {
|
||||
mce_proxy_init_check(self);
|
||||
} else {
|
||||
GERR("Failed to initialize MCE signal proxy: %s", GERRMSG(error));
|
||||
GERR("Failed to initialize MCE upower request proxy: %s", GERRMSG(error));
|
||||
g_error_free(error);
|
||||
}
|
||||
mce_proxy_unref(self);
|
||||
@@ -170,14 +182,14 @@ mce_proxy_bus_get_finished(
|
||||
priv->bus = g_bus_get_finish(result, &error);
|
||||
if (priv->bus) {
|
||||
com_canonical_unity_screen_proxy_new(priv->bus,
|
||||
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
MCE_SERVICE, MCE_REQUEST_PATH, NULL,
|
||||
mce_proxy_request_proxy_new_finished,
|
||||
mce_proxy_ref(self));
|
||||
com_canonical_unity_screen_proxy_new(priv->bus,
|
||||
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
|
||||
MCE_SERVICE, MCE_SIGNAL_PATH, NULL,
|
||||
mce_proxy_signal_proxy_new_finished,
|
||||
org_freedesktop_upower_device_proxy_new(priv->bus,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
UPOWER_SERVICE, UPOWER_REQUEST_PATH, NULL,
|
||||
mce_proxy_request_proxy_upower_new_finished,
|
||||
mce_proxy_ref(self));
|
||||
} else {
|
||||
GERR("Failed to attach to system bus: %s", GERRMSG(error));
|
||||
@@ -265,11 +277,14 @@ mce_proxy_finalize(
|
||||
if (priv->mce_watch_id) {
|
||||
g_bus_unwatch_name(priv->mce_watch_id);
|
||||
}
|
||||
if (self->signal) {
|
||||
g_object_unref(self->signal);
|
||||
if (priv->upower_watch_id) {
|
||||
g_bus_unwatch_name(priv->upower_watch_id);
|
||||
}
|
||||
if (self->request) {
|
||||
g_object_unref(self->request);
|
||||
if (self->unity_request) {
|
||||
g_object_unref(self->unity_request);
|
||||
}
|
||||
if (self->upower_request) {
|
||||
g_object_unref(self->upower_request);
|
||||
}
|
||||
if (priv->bus) {
|
||||
g_object_unref(priv->bus);
|
||||
|
||||
@@ -43,13 +43,14 @@
|
||||
|
||||
typedef struct mce_proxy_priv MceProxyPriv;
|
||||
struct _ComCanonicalUnityScreen;
|
||||
struct _OrgFreedesktopUPowerDevice;
|
||||
|
||||
typedef struct mce_proxy {
|
||||
GObject object;
|
||||
MceProxyPriv* priv;
|
||||
gboolean valid;
|
||||
struct _ComCanonicalUnityScreen* signal;
|
||||
struct _ComCanonicalUnityScreen* request;
|
||||
struct _ComCanonicalUnityScreen* unity_request;
|
||||
struct _OrgFreedesktopUPowerDevice* upower_request;
|
||||
} MceProxy;
|
||||
|
||||
typedef void
|
||||
|
||||
Reference in New Issue
Block a user