Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1572796pxb; Fri, 20 Nov 2020 12:58:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5kyIo8c6h1ZDSN38eSre2vYWsqiWQZrlEe6tZvFDnrDTH4v40VDytLUIQwZwBZ1wEAlGi X-Received: by 2002:a17:906:f286:: with SMTP id gu6mr35769786ejb.182.1605905911267; Fri, 20 Nov 2020 12:58:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605905911; cv=none; d=google.com; s=arc-20160816; b=cfiKGaZmueiTVLYPfSSooxD2YrPT1k4Kaue8FLQpYHvwXGwfa1xWrTL/rZ6bTTUhO9 /HZ1AzcV3w9qMzPuTYbroA6TBSdxQ3po+1Ow8foBzcE1tc6wCm7xagqyg3RLXd119Z36 4G73ansKuzyV/8caU0pYvy6faeKm/SHdQwSC/WpVtgTfBU6at6n8aqk5oDDKRWAmgi1Q BLybiWdibAmUHMfZyYx/8G1Wl2B2D254XlFSO9XDFhQSPRf3m3ggE4xT5VFarFdQl4ih YwrD8UiykbnzMiqcuZDHe/z39vkh718Xflgmfo/JgZhmVIH34vayaCZ7/UAaPLWsZpiC hDpg== 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=qnjOyIqD02WVy6ZZ2x5bkuCTpr4hjumX5jR/HYlXCOk=; b=HFdwBBX4o9J1UJ5tU9LMAVvGiObCoBcpOOv8cs6bc3/zBHWmGjUPmGa2G9rcpdTC5z C037fuukW+jT3SZ8zDOXYAZVsN46h1yYYNSmPCYWKWruWcWtQQpgHq3fmITbiRYBKPDf SG8rjm92VHEnW7VumifFj7DesH2voYDigxpEoJXqDbDFl3Hfi4DQ6RGtsEuDKSA1Lzgz TJ1vEoZ17/MN1NFwXUx893QFDNPps12WEx2a6pMAu32pLDnqFRzJYGxtHkyt4kMAh9G3 WCBAfaq706naiuoR6403LCEyYP0xwNSCDaMAMs3AirQrlAuQXbFh/H1zPTTXNBJbabdq YR8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HWSW4+kV; 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 q1si2513773edr.229.2020.11.20.12.57.59; Fri, 20 Nov 2020 12:58:31 -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=HWSW4+kV; 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 S1730350AbgKTU5z (ORCPT + 99 others); Fri, 20 Nov 2020 15:57:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730288AbgKTU5z (ORCPT ); Fri, 20 Nov 2020 15:57:55 -0500 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C23DBC0613CF for ; Fri, 20 Nov 2020 12:57:53 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id v12so9013400pfm.13 for ; Fri, 20 Nov 2020 12:57:53 -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=qnjOyIqD02WVy6ZZ2x5bkuCTpr4hjumX5jR/HYlXCOk=; b=HWSW4+kVHv6LDsMPsJa9Ydo1fqam3mlCscxKF4kvEmM45cq1fkFbtvpfMuobadx2MK XU4gq9cvko+nQGnZzXwq7j1lr7iBEZcHxSDt2qAF1vID01Y0RJmi3RWkFBwe0oKltVAm vNsDl4sMBVwIOgHQx/DeGbgZVU/EQhZCL2Nn4= 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=qnjOyIqD02WVy6ZZ2x5bkuCTpr4hjumX5jR/HYlXCOk=; b=C+RuRcHvAYjpkIiJ8caSiOCbAslQBklEiQcTZMTcPaaDMfSabSZHTb3O+rQNJgc8Tq HGg9aS0RmQEYe26FBD0hLedgwa5qpTZ6prPqNGK1mjLa8jsn0ifjaSnljsaS5fGn6uxM 194USKXW7WtNGazZgdzIw1bL2Pq09pkm1bsFa/fU+y1InLVly4sg8lQIJsVqzu0ibIPO yrkg9ba2iVRHhh1iXiJ9G8AluYygxD8EHFum7fj7fQwzSIdA0hbDiQC0uNudOLProuvj HMeyfbmqlroZ5ZK04IwuV38Od+pm+HUDfYOV/muI0hr2xm+mdKq5/0xqh/FWirdu4/Vz EtSw== X-Gm-Message-State: AOAM530TcIfvHvb3K1M888eBgELqGD9NdFupZsMZ1ruXAfLZWgJZqQ5z 75y8e3TAya46SmRMgE6mzM7EwiZ2SNaIdQ== X-Received: by 2002:a17:90a:fa13:: with SMTP id cm19mr11620496pjb.80.1605905873026; Fri, 20 Nov 2020 12:57:53 -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 a67sm3232080pfa.77.2020.11.20.12.57.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Nov 2020 12:57:52 -0800 (PST) From: Sonny Sasaka To: linux-bluetooth@vger.kernel.org Cc: Sonny Sasaka , Miao-chen Chou Subject: [PATCH BlueZ v3 3/7] battery: Add Source property to Battery API Date: Fri, 20 Nov 2020 12:57:24 -0800 Message-Id: <20201120205728.339325-3-sonnysasaka@chromium.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201120205728.339325-1-sonnysasaka@chromium.org> References: <20201120205728.339325-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 87a6b91fb..8613d6e23 100644 --- a/src/battery.c +++ b/src/battery.c @@ -31,8 +31,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; @@ -62,13 +63,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; } @@ -78,6 +81,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); } @@ -100,13 +106,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; @@ -122,7 +149,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