From patchwork Wed Jul 19 19:20:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 704736 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E4C6C001B0 for ; Wed, 19 Jul 2023 19:21:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231129AbjGSTVL (ORCPT ); Wed, 19 Jul 2023 15:21:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230515AbjGSTVJ (ORCPT ); Wed, 19 Jul 2023 15:21:09 -0400 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2E3C199A for ; Wed, 19 Jul 2023 12:21:07 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2b74310566cso114967731fa.2 for ; Wed, 19 Jul 2023 12:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1689794466; x=1690399266; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=m19EQo5etSidZKXJ+Gl1lEYk7Z3MuIHM1vz96l3RVZ4=; b=uppUOq2Sag8mEHq5g2wnoP46dHFUH94fWmaN+YcvngPxb9kZr6oNxg4ImkNxKvOWDd cwmUP4IXQntQxhJSYeNT04xSrL681oAs2fOLTJgJJ0YXpjSF3ObV+i1i3vtzuVopn5Tn piwtaHjuqyPk4gNanC+++FQwTRGBMLxWjNhCZUu6f23bC35oHZiCqS1EGG2PkLFeeMb+ vsiO2VutD6jO0ePFB8O2rkUlabLQ2XWE/na+6GnLBL1MtOlRr5S/OWf1S5ZysmmhRfFC uJ+tPcGsXWoFKIN9LGq/3DunFgrcxq7rMhnuLqSZfzEfozq8hUzYcPnACYWcci5X3wps hd9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689794466; x=1690399266; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m19EQo5etSidZKXJ+Gl1lEYk7Z3MuIHM1vz96l3RVZ4=; b=IduGj6m7FjEpl7NW3OHIX1ABbbJQTOZiuP5cbrC9qGmL+Cpkx99IUxwsR7aHZNZIyH HmFJ018kmgEtpoaz+sS9I/hA5tJg+HdSDG2d2eUIOXqwiWI9xBS8HHtbrpSmX0kN3kG0 dcvMSIhIcL+/C/i0oLlMPg9MsStD64RX3UUhW3HlzasG50Sz88XcBCasueAZx+G0iGJC vP+MJgDi2LiABYCfhYvDJ76n9uUjGsUiNryy3bxG3RHWM/okZWAB2yqouV1bW11660R0 Zl2BXjM4IEdJfObaJXpm52qgTG5HpddUv57qAXCzClZTHxXIS7boExwhSZZwfQjc3rB2 qKiw== X-Gm-Message-State: ABy/qLZPIEnDKlr4DywiH9TlN6Hq9KqfmaYASROFWdlceH3/LrB9rrwO buc24EA5ZyIV7VnYzVwMXfGbp7sYJ4+q1VoXCVA= X-Google-Smtp-Source: APBJJlE2frtMNKk9U6QuCNCiSWpDfGecH8dSQIV+LEjBAJqKevMZxH8ngUWmAcAypYwfZbPW+gWUjA== X-Received: by 2002:a2e:9c4e:0:b0:2b9:4805:a039 with SMTP id t14-20020a2e9c4e000000b002b94805a039mr498873ljj.51.1689794465698; Wed, 19 Jul 2023 12:21:05 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:f884:f48d:2867:5c1d]) by smtp.gmail.com with ESMTPSA id b14-20020a05600c11ce00b003fbc0a49b57sm2373454wmi.6.2023.07.19.12.21.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 12:21:05 -0700 (PDT) From: Bartosz Golaszewski To: Kent Gibson , Linus Walleij , Andy Shevchenko , Viresh Kumar Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [libgpiod][PATCH 1/5] core: provide gpiod_line_request_get_chip_path() Date: Wed, 19 Jul 2023 21:20:53 +0200 Message-Id: <20230719192057.172560-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230719192057.172560-1-brgl@bgdev.pl> References: <20230719192057.172560-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski While we can get the list of requested offsets from a line-request object, this information lacks context if we don't provide any data about the GPIO chip the request was made on. Add a helper allowing users to get the path to the character device used to create the parent chip. Signed-off-by: Bartosz Golaszewski --- include/gpiod.h | 9 +++++++++ lib/chip.c | 2 +- lib/internal.h | 3 ++- lib/line-request.c | 20 +++++++++++++++++++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/include/gpiod.h b/include/gpiod.h index 3c13783..61f8ef1 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -1007,6 +1007,15 @@ gpiod_request_config_get_event_buffer_size(struct gpiod_request_config *config); */ void gpiod_line_request_release(struct gpiod_line_request *request); +/** + * @brief Get the path to the chip this request was made on. + * @param request Line request object. + * @return Path to the GPIO chip device. The returned pointer is valid for the + * lifetime of the request object and must not be freed by the caller. + */ +const char * +gpiod_line_request_get_chip_path(struct gpiod_line_request *request); + /** * @brief Get the number of lines in the request. * @param request Line request object. diff --git a/lib/chip.c b/lib/chip.c index 7d4d21e..e94d750 100644 --- a/lib/chip.c +++ b/lib/chip.c @@ -237,7 +237,7 @@ gpiod_chip_request_lines(struct gpiod_chip *chip, if (ret < 0) return NULL; - request = gpiod_line_request_from_uapi(&uapi_req); + request = gpiod_line_request_from_uapi(&uapi_req, chip->path); if (!request) { close(uapi_req.fd); return NULL; diff --git a/lib/internal.h b/lib/internal.h index ef9b17e..e9ada42 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -26,7 +26,8 @@ void gpiod_request_config_to_uapi(struct gpiod_request_config *config, int gpiod_line_config_to_uapi(struct gpiod_line_config *config, struct gpio_v2_line_request *uapi_cfg); struct gpiod_line_request * -gpiod_line_request_from_uapi(struct gpio_v2_line_request *uapi_req); +gpiod_line_request_from_uapi(struct gpio_v2_line_request *uapi_req, + const char *chip_path); int gpiod_edge_event_buffer_read_fd(int fd, struct gpiod_edge_event_buffer *buffer, size_t max_events); diff --git a/lib/line-request.c b/lib/line-request.c index e536355..99cbe2c 100644 --- a/lib/line-request.c +++ b/lib/line-request.c @@ -13,13 +13,15 @@ #include "internal.h" struct gpiod_line_request { + char *chip_path; unsigned int offsets[GPIO_V2_LINES_MAX]; size_t num_lines; int fd; }; struct gpiod_line_request * -gpiod_line_request_from_uapi(struct gpio_v2_line_request *uapi_req) +gpiod_line_request_from_uapi(struct gpio_v2_line_request *uapi_req, + const char *chip_path) { struct gpiod_line_request *request; @@ -28,6 +30,13 @@ gpiod_line_request_from_uapi(struct gpio_v2_line_request *uapi_req) return NULL; memset(request, 0, sizeof(*request)); + + request->chip_path = strdup(chip_path); + if (!request->chip_path) { + free(request); + return NULL; + } + request->fd = uapi_req->fd; request->num_lines = uapi_req->num_lines; memcpy(request->offsets, uapi_req->offsets, @@ -42,9 +51,18 @@ GPIOD_API void gpiod_line_request_release(struct gpiod_line_request *request) return; close(request->fd); + free(request->chip_path); free(request); } +GPIOD_API const char * +gpiod_line_request_get_chip_path(struct gpiod_line_request *request) +{ + assert(request); + + return request->chip_path; +} + GPIOD_API size_t gpiod_line_request_get_num_requested_lines(struct gpiod_line_request *request) { From patchwork Wed Jul 19 19:20:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 704478 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0385C05053 for ; Wed, 19 Jul 2023 19:21:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231143AbjGSTVM (ORCPT ); Wed, 19 Jul 2023 15:21:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230516AbjGSTVJ (ORCPT ); Wed, 19 Jul 2023 15:21:09 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 987FC1BF7 for ; Wed, 19 Jul 2023 12:21:08 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fbfcc6daa9so67808725e9.3 for ; Wed, 19 Jul 2023 12:21:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1689794467; x=1690399267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PM7MC2D3VSlqahUBU+HsG655VTszMrDx6ek6kDLjkZI=; b=viBsolprfjSb0ZUWXyQUqoT7iiQKKJTTdwqXEFogDidmbutbO3oXZqv9YZscAeUuTm 9iQj5JKA+pQ51X4wZE3IKNkgoE4MjGpIjWTFK0AaGi6Oj9sF7PFRwaEa5YYYodLlNmUI skpoZbxDd7y77e3WhGaVzm/9KaL5kC/Yu0GupMMq7BMNaefRfG6Ov1ZtEyLAmHj4FDcB 5nTCmSeSxDIaRuem0Tw4LULr0ht7QUogKQ8zsMCIMUW2n07+B4iFvIqcsO9KNUR3q/0O Edm8tp4+rQKNLP7qHoSc3I9LWU2HE4F+fJH96F6kYKPfochYvCPjdF4t6co6gd0pm9oF UJLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689794467; x=1690399267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PM7MC2D3VSlqahUBU+HsG655VTszMrDx6ek6kDLjkZI=; b=Q0A9T/oydRSAk13I8Pzn+bZv758K8FqAHIhQN7AXiYCP4OlPn99Qj+WIpPfidbmjd4 rocU4jrLYTrqRRE1yNVnY8a2NSEEsx++TPBZSSyaY1yn8W+jAABw8hfo8puoBW8VqgUq rki3AThIceW9ECvfBulUFbOt+z+4l2TiYJAEYieLqSOXdX3KewHMrhQg3qXv6wVc44NJ N798bs0TsYjG1gI3MmZaNCy3s63V9WKEJU1rhYSAcihDkMICMxWTiBE/RVf2nPizcBgZ QCSKXiZ3IjLj9Wva+dqWa+QClmrsdIMM4u+KE4HQoBzyY806YYH15mOi5AhR7BR2QNJ2 OBAg== X-Gm-Message-State: ABy/qLY40haKfsWoE37EXtBudZrlLjgRLlGpgSgzvRLJuuXh2u9Ff55d biOJKFnhC9ucFnF/oNtCfQRt+BQz0xDiruJlSQA= X-Google-Smtp-Source: APBJJlGWXHAMS3cj6MBZA3A0CODyIYmGeqhjPT/fDvCkUyAyODUkB4h+30NOAx5EedFaX5/lo95lMg== X-Received: by 2002:a05:600c:acf:b0:3fa:770c:5918 with SMTP id c15-20020a05600c0acf00b003fa770c5918mr2810407wmr.9.1689794466813; Wed, 19 Jul 2023 12:21:06 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:f884:f48d:2867:5c1d]) by smtp.gmail.com with ESMTPSA id b14-20020a05600c11ce00b003fbc0a49b57sm2373454wmi.6.2023.07.19.12.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 12:21:06 -0700 (PDT) From: Bartosz Golaszewski To: Kent Gibson , Linus Walleij , Andy Shevchenko , Viresh Kumar Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [libgpiod][PATCH 2/5] tests: add a test-case for gpiod_line_request_get_chip_path() Date: Wed, 19 Jul 2023 21:20:54 +0200 Message-Id: <20230719192057.172560-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230719192057.172560-1-brgl@bgdev.pl> References: <20230719192057.172560-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Add a test case for the chip path getter on line-request objects. Signed-off-by: Bartosz Golaszewski --- tests/tests-line-request.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/tests-line-request.c b/tests/tests-line-request.c index 0b985e2..2c8c497 100644 --- a/tests/tests-line-request.c +++ b/tests/tests-line-request.c @@ -675,3 +675,24 @@ GPIOD_TEST_CASE(get_requested_offsets_less_and_more) g_assert_cmpuint(retrieved[2], ==, 2); g_assert_cmpuint(retrieved[3], ==, 3); } + +GPIOD_TEST_CASE(get_chip_path) +{ + static const guint offset = 4; + + g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new("num-lines", 8, NULL); + g_autoptr(struct_gpiod_chip) chip = NULL; + g_autoptr(struct_gpiod_line_config) line_cfg = NULL; + g_autoptr(struct_gpiod_line_request) request = NULL; + + chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim)); + line_cfg = gpiod_test_create_line_config_or_fail(); + + gpiod_test_line_config_add_line_settings_or_fail(line_cfg, &offset, 1, + NULL); + + request = gpiod_test_chip_request_lines_or_fail(chip, NULL, line_cfg); + + g_assert_cmpstr(gpiod_chip_get_path(chip), ==, + gpiod_line_request_get_chip_path(request)); +} From patchwork Wed Jul 19 19:20:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 704735 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E23D3C001E0 for ; Wed, 19 Jul 2023 19:21:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230390AbjGSTVN (ORCPT ); Wed, 19 Jul 2023 15:21:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230508AbjGSTVL (ORCPT ); Wed, 19 Jul 2023 15:21:11 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21C771FDD for ; Wed, 19 Jul 2023 12:21:09 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fbf1b82d9cso67744755e9.2 for ; Wed, 19 Jul 2023 12:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1689794467; x=1690399267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t7K3qwb55HKjciBSgVIQGZ+zljzs8UyMHnuxo6J/lLQ=; b=MU+t5zywXyC0PqPaUuPjrN4QhNqt0IUeAU14Qvz1CYeF44L1+lI7jXwSP75x0hx+w4 UWx2qhlF5pnw7BvOF6BBGB4xMrMAlhWpP6+H3rbvJwyySQPIolrBRiLWrqCU89o9gzK/ jD0xx5fKaLmKjVEWNqZcP1B0aXWZfLtdkADMDSuifreaYbuItyiK+Pnz0nUxPOwHb13N LaPgx+0K11ibJiJnAKIQ511B6l9zbHnujz4NU/ruz41BHp/+xdVTctF1F4j9fzuwflzL bbY7ToOaaeYk9zZ40/NQcfWi5UWvFdY+7guVNkypS2dAxPt6GU7djLqNMJ1HHeed9hx9 Hahw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689794467; x=1690399267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t7K3qwb55HKjciBSgVIQGZ+zljzs8UyMHnuxo6J/lLQ=; b=ICNDxk/ExSBB/1xx4kSL1aTffNmwcrWIGkEV5fZRAoIoidR9xJVHOIr0Gn1uKjazI9 bzPpLgDj1dvpQ8LPw4r+nmN6XFdHkIf8n7VuMt5N5Ywh2myAsYgfzmBVlohD0ZejwP8g fWo+8t8Cl+WJZkQTigPVbHa+f99FUjJLgNNMTxJaDYRUJ5ysPcHbglT+hK6Bar/MOrsM ZfdQ2DWIbjddZP2bHcgps7OcO3DV8qmfsSvE6y5QAZqR0xSoD7zdrrsM/3WLnnVt4Lq+ OWYmFmbrP26Ap04Ab8snp4aEkY8gOXHRtKZZcLAJFlJCFd8ZdxNC8dAV1nkJ7VvqwcfN YaEg== X-Gm-Message-State: ABy/qLZg9bJZF9EYcGsQ+RgFKLedFdX2nQp5EmdT6F5zDUhWQOhD6tY2 y+X+7ALF3XoLf6DD0ChBJ8rtvA== X-Google-Smtp-Source: APBJJlG8kOT++BzM8Vxa0YnA8w6bqnPFBhDWszfKDhOLbJ/qdJpQ3wg/k1nyqyUV1jyKzrGBWQEZoA== X-Received: by 2002:a7b:ca52:0:b0:3fc:3f31:422f with SMTP id m18-20020a7bca52000000b003fc3f31422fmr2660880wml.3.1689794467638; Wed, 19 Jul 2023 12:21:07 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:f884:f48d:2867:5c1d]) by smtp.gmail.com with ESMTPSA id b14-20020a05600c11ce00b003fbc0a49b57sm2373454wmi.6.2023.07.19.12.21.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 12:21:07 -0700 (PDT) From: Bartosz Golaszewski To: Kent Gibson , Linus Walleij , Andy Shevchenko , Viresh Kumar Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [libgpiod][PATCH 3/5] bindings: cxx: provide line_request::chip_path() Date: Wed, 19 Jul 2023 21:20:55 +0200 Message-Id: <20230719192057.172560-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230719192057.172560-1-brgl@bgdev.pl> References: <20230719192057.172560-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Provide a wrapper around gpiod_line_request_get_chip_path() for C++ bindings and update the tests. Signed-off-by: Bartosz Golaszewski --- bindings/cxx/gpiodcxx/line-request.hpp | 7 +++++++ bindings/cxx/line-request.cpp | 10 +++++++++- bindings/cxx/tests/tests-line-request.cpp | 6 ++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/bindings/cxx/gpiodcxx/line-request.hpp b/bindings/cxx/gpiodcxx/line-request.hpp index c1e1520..dd8b5b9 100644 --- a/bindings/cxx/gpiodcxx/line-request.hpp +++ b/bindings/cxx/gpiodcxx/line-request.hpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -75,6 +76,12 @@ public: */ void release(); + /** + * @brief Get the path of the chip this request was made on. + * @return Path to the GPIO chip device. + */ + ::std::filesystem::path chip_path() const; + /** * @brief Get the number of requested lines. * @return Number of lines in this request. diff --git a/bindings/cxx/line-request.cpp b/bindings/cxx/line-request.cpp index b0723c3..33e9d6e 100644 --- a/bindings/cxx/line-request.cpp +++ b/bindings/cxx/line-request.cpp @@ -63,6 +63,13 @@ GPIOD_CXX_API void line_request::release() this->_m_priv->request.reset(); } +GPIOD_CXX_API ::std::filesystem::path line_request::chip_path() const +{ + this->_m_priv->throw_if_released(); + + return ::gpiod_line_request_get_chip_path(this->_m_priv->request.get()); +} + GPIOD_CXX_API ::std::size_t line_request::num_lines() const { this->_m_priv->throw_if_released(); @@ -222,7 +229,8 @@ GPIOD_CXX_API ::std::ostream& operator<<(::std::ostream& out, const line_request if (!request) out << "gpiod::line_request(released)"; else - out << "gpiod::line_request(num_lines=" << request.num_lines() << + out << "gpiod::line_request(chip_path=\"" << request.chip_path() << + "\", num_lines=" << request.num_lines() << ", line_offsets=" << request.offsets() << ", fd=" << request.fd() << ")"; diff --git a/bindings/cxx/tests/tests-line-request.cpp b/bindings/cxx/tests/tests-line-request.cpp index d1a56ae..914a60a 100644 --- a/bindings/cxx/tests/tests-line-request.cpp +++ b/bindings/cxx/tests/tests-line-request.cpp @@ -468,14 +468,16 @@ TEST_CASE("line_request stream insertion operator works", "[line-request]") .set_num_lines(4) .build(); - auto request = ::gpiod::chip(sim.dev_path()) + auto chip = ::gpiod::chip(sim.dev_path()); + auto request = chip .prepare_request() .add_line_settings({ 3, 1, 0, 2}, ::gpiod::line_settings()) .do_request(); ::std::stringstream buf, expected; - expected << "gpiod::line_request(num_lines=4, line_offsets=gpiod::offsets(3, 1, 0, 2), fd=" << + expected << "gpiod::line_request(chip_path=\"" << chip.path() << + "\", num_lines=4, line_offsets=gpiod::offsets(3, 1, 0, 2), fd=" << request.fd() << ")"; SECTION("active request") From patchwork Wed Jul 19 19:20:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 704476 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6E9AC0015E for ; Wed, 19 Jul 2023 19:21:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231154AbjGSTVP (ORCPT ); Wed, 19 Jul 2023 15:21:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230515AbjGSTVL (ORCPT ); Wed, 19 Jul 2023 15:21:11 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4394F199A for ; Wed, 19 Jul 2023 12:21:10 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2b70bfc8db5so111691341fa.2 for ; Wed, 19 Jul 2023 12:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1689794468; x=1690399268; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3vePYdMZFJuQihmH3yi3T9i4hjCbxXtyqAjrUjGuTH8=; b=SQQ5i+YVZGdqAbrvYRwdcSkj0ELEKiBC9Lp9A+2uUNnKfeFCraHc66HABKnwV3k45+ OpqOG2sApyQB8Xl5Tn3xpr0B12/wYD3JQ0tdgroCekXj3s2m+9ILX2UFnwZNKYamgSVw 8r4/TuqlETMZFnMJokBODAJBOrhw2m7RDCp8AKQjisR6miHsUKUIoPk2LAS0jgRWEybG Q00MRhtII1Yy7MtMYvmmsonzLpaoRE0H+e/AfllcFdQPsFYS8RC+bhqjRwSwtyxBvpOr xjUjGI0CgvoZyXUP1xH2iU2tBIRhI4Cl0JAtrhtnEhs+1pmsxVJC3BQht+jmvWeHq30T ECIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689794468; x=1690399268; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3vePYdMZFJuQihmH3yi3T9i4hjCbxXtyqAjrUjGuTH8=; b=AcxDG1teH1EIwqkXLBFp2Nak/OpajVXbSl115hjYu1USAUR9EWWLavEtvc/0b106LN UuVOJpTnNquMCMqKQJf6xR8vDFek5bWHhgM08tiTsSiexN6AtShhppOLs+eY/E7vjc4U Ha2A0/tbdfox2yIgnNMr0v9yifkNkU7tQrCFsqDi+wYPyLrXAb7sv2g77OzL/ogk1HCR 2gdoUQHjTSNbcQpvVbINc9brt1Ei+KhYlgcofoUAgvp94lF4ZbhaxTu9Jxe9biQTc4UI bvZJIGSzWYBo9ulDf4/Ztt3HCyQ993JqLVmXYau/d0P0cpFOG9Fx6xTsFZAdaTUX3lc5 JRsQ== X-Gm-Message-State: ABy/qLZTRjPkUz04X6VDdwlZrG8GNr0/6yWSgYHUblraUFR0bqG/+GYo B/4IG7cdchrHr6BXZAm5mBn0aA== X-Google-Smtp-Source: APBJJlFDzDTqI6Q5kKS3mpX17ESSsFj9HiLxAaG7SkKqS8uYy9ntQlcJAptCd7cf2fG9y3RMZC1Obw== X-Received: by 2002:a2e:3a09:0:b0:2b6:de52:357 with SMTP id h9-20020a2e3a09000000b002b6de520357mr570164lja.40.1689794468529; Wed, 19 Jul 2023 12:21:08 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:f884:f48d:2867:5c1d]) by smtp.gmail.com with ESMTPSA id b14-20020a05600c11ce00b003fbc0a49b57sm2373454wmi.6.2023.07.19.12.21.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 12:21:08 -0700 (PDT) From: Bartosz Golaszewski To: Kent Gibson , Linus Walleij , Andy Shevchenko , Viresh Kumar Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [libgpiod][PATCH 4/5] bindings: python: provide the chip_path property in line_request Date: Wed, 19 Jul 2023 21:20:56 +0200 Message-Id: <20230719192057.172560-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230719192057.172560-1-brgl@bgdev.pl> References: <20230719192057.172560-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Provide a wrapper around gpiod_line_request_get_chip_path() for Python bindings and update the tests. Signed-off-by: Bartosz Golaszewski --- bindings/python/gpiod/chip.py | 1 + bindings/python/gpiod/line_request.py | 12 ++++++++++-- bindings/python/tests/tests_line_request.py | 13 ++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py index da93370..0629db0 100644 --- a/bindings/python/gpiod/chip.py +++ b/bindings/python/gpiod/chip.py @@ -315,6 +315,7 @@ class Chip: req_internal = self._chip.request_lines(line_cfg, consumer, event_buffer_size) request = LineRequest(req_internal) + request._chip_path = self.path request._offsets = req_internal.offsets request._name_map = name_map request._offset_map = offset_map diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index 096bf18..aaae37c 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -212,10 +212,18 @@ class LineRequest: if not self._req: return "" - return "".format( - self.num_lines, self.offsets, self.fd + return ''.format( + self.chip_path, self.num_lines, self.offsets, self.fd ) + @property + def chip_path(self) -> str: + """ + Path of the chip this request was made on. + """ + self._check_released() + return self._chip_path + @property def num_lines(self) -> int: """ diff --git a/bindings/python/tests/tests_line_request.py b/bindings/python/tests/tests_line_request.py index aa84b9a..4ab3ea5 100644 --- a/bindings/python/tests/tests_line_request.py +++ b/bindings/python/tests/tests_line_request.py @@ -529,11 +529,14 @@ class LineRequestStringRepresentation(TestCase): del self.sim def test_str(self): - with gpiod.request_lines(self.sim.dev_path, config={(2, 6, 4, 1): None}) as req: - self.assertEqual( - str(req), - "".format(req.fd), - ) + with gpiod.Chip(self.sim.dev_path) as chip: + with chip.request_lines(config={(2, 6, 4, 1): None}) as req: + self.assertEqual( + str(req), + ''.format( + chip.path, req.fd + ), + ) def test_str_released(self): req = gpiod.request_lines(self.sim.dev_path, config={(2, 6, 4, 1): None}) From patchwork Wed Jul 19 19:20:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 704734 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83F14C00528 for ; Wed, 19 Jul 2023 19:21:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231159AbjGSTVR (ORCPT ); Wed, 19 Jul 2023 15:21:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229819AbjGSTVM (ORCPT ); Wed, 19 Jul 2023 15:21:12 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47D601FC0 for ; Wed, 19 Jul 2023 12:21:11 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3fbc656873eso76189595e9.1 for ; Wed, 19 Jul 2023 12:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1689794470; x=1690399270; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T+gm+qYKa1L0/EhrRIjsdKa1RHDSkybsYzUsyDLPbEg=; b=sG23YalEVK5/31K9p+iTP5UJWPHy353lMC4Ej0PK3wQd33+i+oVVGSkmb0Li7V8Ahw nFn1SjOQhDgqRyHmJuZba3fgdZajJJ6dceTpX6+X79A1Xz3lXaaJDcLC/0LBl99rRMti ziwGlBFKvjbovbkNmsORUFCBOXz/KFk9yV4fldhxj0J/0WDwQ4YPduEx3L93mqrZHAKM iRzdmt4m/fis3+uwH62IM6L9UazSbkk9Mv0MJ+IiDYEvEO4feok88QIztuKjN8cLDeXd 5kGXCCcnIi58SCtBPfP7NdyO1pA/5LuSEUinwIcLRu7LpvZmxqxJ6wn1mS6/k9fiNtOm 04JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689794470; x=1690399270; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T+gm+qYKa1L0/EhrRIjsdKa1RHDSkybsYzUsyDLPbEg=; b=EMxWxpWybmn4L21MDFdked3jy8v59JBVKu8Kwu3M2F4Pdp9TL5eLl8xtN0fF90Z+/u zjKuXo1F/xJnmrhk6zWm1sqAWhw2M70aJOyCqE2m+OOCjJZAuAT//yElDDl6beAMI97n oHzThVEf375K+/55A2nRCGcGDAfCvZ15ZD866V8XYGmvMFEEc2zVuFO8vYY2qWT01rPJ /9/HYXR5ZPnivAC29X0qN/MofGtJ82hvCG+2RWo8G3RlfUl5OXQMeC9Kh5eFUOEB0tHY XPuZD9NOVRp/tX4uX4+GlEkhEfNw4cKs17/gfzOwQs29DBIkQRVKZlthg4hqrcn18olP lF9Q== X-Gm-Message-State: ABy/qLaFmPRKIkAsT9SOKegG5DdffTEcgmzcP6SfjOfQlMzxp/DBTFdZ 3fnWMF9X2DPHggFc31cbki1/pg== X-Google-Smtp-Source: APBJJlHFXYaP3OP9Onccee1mzjS7IwdZzRZv+JlGA0nG/N0LUhyfncUjQvLQc5hkcfvsJmev2TwLRQ== X-Received: by 2002:a7b:c3d0:0:b0:3fb:fef1:68b7 with SMTP id t16-20020a7bc3d0000000b003fbfef168b7mr6328072wmj.27.1689794469434; Wed, 19 Jul 2023 12:21:09 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:f884:f48d:2867:5c1d]) by smtp.gmail.com with ESMTPSA id b14-20020a05600c11ce00b003fbc0a49b57sm2373454wmi.6.2023.07.19.12.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 12:21:09 -0700 (PDT) From: Bartosz Golaszewski To: Kent Gibson , Linus Walleij , Andy Shevchenko , Viresh Kumar Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [libgpiod][PATCH 5/5] bindings: rust: provide LineRequest::chip_path() Date: Wed, 19 Jul 2023 21:20:57 +0200 Message-Id: <20230719192057.172560-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230719192057.172560-1-brgl@bgdev.pl> References: <20230719192057.172560-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Provide a wrapper around gpiod_line_request_get_chip_path() for Rust bindings and add a test-case. Signed-off-by: Bartosz Golaszewski --- bindings/rust/libgpiod/src/line_request.rs | 12 ++++++++++++ bindings/rust/libgpiod/tests/line_request.rs | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/bindings/rust/libgpiod/src/line_request.rs b/bindings/rust/libgpiod/src/line_request.rs index 1140aa9..2caab14 100644 --- a/bindings/rust/libgpiod/src/line_request.rs +++ b/bindings/rust/libgpiod/src/line_request.rs @@ -2,6 +2,7 @@ // SPDX-FileCopyrightText: 2022 Linaro Ltd. // SPDX-FileCopyrightText: 2022 Viresh Kumar +use std::ffi::CStr; use std::os::unix::prelude::AsRawFd; use std::time::Duration; @@ -25,6 +26,17 @@ impl Request { Ok(Self { request }) } + pub fn chip_path(&self) -> Result<&str> { + // SAFETY: The string returned by libgpiod is guaranteed to live as long + // as the `struct LineRequest`. + let path = unsafe { gpiod::gpiod_line_request_get_chip_path(self.request) }; + + // SAFETY: The string is guaranteed to be valid here by the C API. + unsafe { CStr::from_ptr(path) } + .to_str() + .map_err(Error::StringNotUtf8) + } + /// Get the number of lines in the request. pub fn num_lines(&self) -> usize { // SAFETY: `gpiod_line_request` is guaranteed to be valid here. diff --git a/bindings/rust/libgpiod/tests/line_request.rs b/bindings/rust/libgpiod/tests/line_request.rs index d49874f..e4ed9c2 100644 --- a/bindings/rust/libgpiod/tests/line_request.rs +++ b/bindings/rust/libgpiod/tests/line_request.rs @@ -59,6 +59,19 @@ mod line_request { mod verify { use super::*; + #[test] + fn chip_path() { + const GPIO: Offset = 2; + let mut config = TestConfig::new(NGPIO).unwrap(); + config.lconfig_add_settings(&[GPIO]); + config.request_lines().unwrap(); + + let dev_path = config.sim().lock().unwrap().dev_path(); + let s = dev_path.into_os_string().into_string().unwrap(); + + assert_eq!(config.request().chip_path().unwrap(), s); + } + #[test] fn custom_consumer() { const GPIO: Offset = 2;