Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4426655pxb; Tue, 10 Nov 2020 16:39:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjs2Hpcedf6V+d0IJ892clinP4ANUfZ+VfbzCxPvXv0XvEl1U+AuwoarzkPy1VRKHnO37C X-Received: by 2002:a17:906:3795:: with SMTP id n21mr22118650ejc.502.1605055182337; Tue, 10 Nov 2020 16:39:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605055182; cv=none; d=google.com; s=arc-20160816; b=oqqgthPAhNDCUkhSUtims3EjoxnNDdVsBZaN+nVQUaT3EpQkqBnsFDDhT4NxyHx5v+ +6Xuf5GJpn5Yi79OWf6MNPxAT6Z6K4CtkCK26Al9XkLPPTMm1Vf8bfU0SpI9MQfwMHfw 52iXvG4hOP1IV8nJ8txFMqMytNFnFcb8pZVTRBs/TG5cjs1B4A156hyHwbOUNkuUtlnZ QuRFDPjAmy6f6ivRy2/hR0UX5ZVoopZQsWAFr5qt6/a3TDZI0jZYOa3oon8ZMxj87+fT hG4D+ao8ZOWV0q49OxuALIVFDqgu8gDiWIx2WbIX/meNgaxWicgUW+rgQ/YCLeBGUxkk OOiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+bk/zaKkKssK84GHRxHMA/rKqU6DwlFfzMwIUdK3ls4=; b=hiYBr25t5Og9yaBX42sv2XgUF8qdYa9YQUvKzFSGKRqFqgoHCrTaNKGooSgLJHE+bD VNGMQVq9sBPikfaHhEBCmKb2xUj6CwdBnAmb0zTKHNAFf381eNCvIxdzpl4C+vxc88ad uhwrEPh+0rttnuhSVHbBqMCz5thIYlHIQiY9ZfIJ7KS5tW/FFEGtqrQxTDZW44icsz1c uU9TM2aZEnmIZj2ARLNfo+VLdyRKFR8FCSXoZEd92GwIcamAXpfonIj4NhLUIIOA3B+i mGEUElAQn31hDBeD/eulIgv3KieLaS95ygMqqB2k80fa8oziKBKViEHNfw91aoVpiceH 2Ipg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iYYhzMAZ; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p61si289402edd.445.2020.11.10.16.39.05; Tue, 10 Nov 2020 16:39:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iYYhzMAZ; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732213AbgKKAhp (ORCPT + 99 others); Tue, 10 Nov 2020 19:37:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732209AbgKKAho (ORCPT ); Tue, 10 Nov 2020 19:37:44 -0500 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAD8FC0613D1 for ; Tue, 10 Nov 2020 16:37:44 -0800 (PST) Received: by mail-pl1-x641.google.com with SMTP id k7so66431plk.3 for ; Tue, 10 Nov 2020 16:37:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+bk/zaKkKssK84GHRxHMA/rKqU6DwlFfzMwIUdK3ls4=; b=iYYhzMAZQOjccJZRdNK57oYyNbz2oKcO+ATE6ClUr9YHdlDo/YSX2qk6H5EA3Wd/D+ EXMyXq/MG4RHeBbrwIkS1VN4eePJlGelvm84XRvkDZvXDsvYPy+cMfl2MY2+LTzFsCYp YPd3PLmhTBgy/YiPflrdVVW8Otqq9xmfmpves= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+bk/zaKkKssK84GHRxHMA/rKqU6DwlFfzMwIUdK3ls4=; b=UhmBg+iY3YV1D/b9ekpnLgGUa3TC6UAMse2kDNQqWkU6XCVTd/NraIvgYiWLo/cknR 0rzU1TZ4nOC+TLEfYesmBQFK0WvfS7digNdAkAp+FoEjmHxKD2sFPlgP6TpB8Z4OxgDo RJZjZ6wIylxEWKOQHz5aBVv3NnLYRNRSuv9RoCczbHPmd/PB3uzcfUztfJF62y+JuiWO 86ov5kG/JRjjc5wWto3+CPlDH8G3tnow7rbXcrxSFrgkByEuYOoMV/RAX43r4uRGw6NG d6QtX49GUB90p24UY+i47NI1ujeSdTBnbBCA58m+RElcW93WhwH7DPrQ0dAZha9aLDNb D3Kg== X-Gm-Message-State: AOAM531UYgvCktKpMRZXnPmDDTTVenJm8/vfxf9UA+8qXH6j1gas81Yf Z2a/hVXwNE0KCr1gDh/EMhmW7vmH513Hzw== X-Received: by 2002:a17:902:7606:b029:d3:d2dd:2b3b with SMTP id k6-20020a1709027606b02900d3d2dd2b3bmr19118740pll.67.1605055063946; Tue, 10 Nov 2020 16:37:43 -0800 (PST) Received: from sonnysasaka-chrome.mtv.corp.google.com ([2620:15c:202:201:4a0f:cfff:fe66:e60c]) by smtp.gmail.com with ESMTPSA id b16sm180655pju.16.2020.11.10.16.37.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Nov 2020 16:37:43 -0800 (PST) From: Sonny Sasaka To: linux-bluetooth@vger.kernel.org Cc: Sonny Sasaka , Miao-chen Chou Subject: [PATCH BlueZ 3/7] battery: Add Source property to Battery API Date: Tue, 10 Nov 2020 16:37:16 -0800 Message-Id: <20201111003720.1727-4-sonnysasaka@chromium.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201111003720.1727-1-sonnysasaka@chromium.org> References: <20201111003720.1727-1-sonnysasaka@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org As Battery API will be generalized for other battery reporting protocols, the Source property is useful for diagnostics purposes. Reviewed-by: Miao-chen Chou --- profiles/battery/battery.c | 3 ++- src/battery.c | 35 +++++++++++++++++++++++++++++++---- src/battery.h | 2 +- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/profiles/battery/battery.c b/profiles/battery/battery.c index e1a61dd0b..2478816a4 100644 --- a/profiles/battery/battery.c +++ b/profiles/battery/battery.c @@ -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); diff --git a/src/battery.c b/src/battery.c index b2adf41fa..a2769f687 100644 --- a/src/battery.c +++ b/src/battery.c @@ -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, diff --git a/src/battery.h b/src/battery.h index 9c69b7afa..ff63454cd 100644 --- a/src/battery.h +++ b/src/battery.h @@ -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); -- 2.26.2