@@ -126,7 +126,8 @@ static void batt_io_ccc_written_cb(uint16_t att_ecode, void *user_data)
return;
}
- batt->battery = btd_battery_register(device_get_path(batt->device));
+ batt->battery = btd_battery_register(device_get_path(batt->device),
+ "GATT Battery Service");
if (!batt->battery) {
batt_reset(batt);
@@ -30,8 +30,9 @@
#define BATTERY_MAX_PERCENTAGE 100
struct btd_battery {
- char *path; /* D-Bus object path, owns pointer */
+ char *path; /* D-Bus object path */
uint8_t percentage; /* valid between 0 to 100 inclusively */
+ char *source; /* Descriptive source of the battery info */
};
static struct queue *batteries = NULL;
@@ -59,13 +60,15 @@ static bool match_path(const void *data, const void *user_data)
return g_strcmp0(battery->path, path) == 0;
}
-static struct btd_battery *battery_new(const char *path)
+static struct btd_battery *battery_new(const char *path, const char *source)
{
struct btd_battery *battery;
battery = new0(struct btd_battery, 1);
battery->path = g_strdup(path);
battery->percentage = UINT8_MAX;
+ if (source)
+ battery->source = g_strdup(source);
return battery;
}
@@ -75,6 +78,9 @@ static void battery_free(struct btd_battery *battery)
if (battery->path)
g_free(battery->path);
+ if (battery->source)
+ g_free(battery->source);
+
free(battery);
}
@@ -97,13 +103,34 @@ static gboolean property_percentage_exists(const GDBusPropertyTable *property,
return battery->percentage <= BATTERY_MAX_PERCENTAGE;
}
+static gboolean property_source_get(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct btd_battery *battery = data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
+ &battery->source);
+
+ return TRUE;
+}
+
+static gboolean property_source_exists(const GDBusPropertyTable *property,
+ void *data)
+{
+ struct btd_battery *battery = data;
+
+ return battery->source != NULL;
+}
+
static const GDBusPropertyTable battery_properties[] = {
{ "Percentage", "y", property_percentage_get, NULL,
property_percentage_exists },
+ { "Source", "s", property_source_get, NULL, property_source_exists,
+ G_DBUS_PROPERTY_FLAG_EXPERIMENTAL },
{}
};
-struct btd_battery *btd_battery_register(const char *path)
+struct btd_battery *btd_battery_register(const char *path, const char *source)
{
struct btd_battery *battery;
@@ -119,7 +146,7 @@ struct btd_battery *btd_battery_register(const char *path)
return NULL;
}
- battery = battery_new(path);
+ battery = battery_new(path, source);
battery_add(battery);
if (!g_dbus_register_interface(btd_get_dbus_connection(), battery->path,
@@ -10,6 +10,6 @@
struct btd_battery;
-struct btd_battery *btd_battery_register(const char *path);
+struct btd_battery *btd_battery_register(const char *path, const char *source);
bool btd_battery_unregister(struct btd_battery *battery);
bool btd_battery_update(struct btd_battery *battery, uint8_t percentage);
As Battery API will be generalized for other battery reporting protocols, the Source property is useful for diagnostics purposes. Reviewed-by: Miao-chen Chou <mcchou@chromium.org> --- profiles/battery/battery.c | 3 ++- src/battery.c | 35 +++++++++++++++++++++++++++++++---- src/battery.h | 2 +- 3 files changed, 34 insertions(+), 6 deletions(-)