Debian Codegraph @

dbus/client/detect.c

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 // SPDX-FileCopyrightText: 2022-2023 Bartosz Golaszewski <[email protected]>
3
4 #include <stdlib.h>
5
6 #include "common.h"
7
8 static void show_chip(gpointer elem, gpointer user_data G_GNUC_UNUSED)
9 {
10 GpiodbusObject *chip_obj = elem;
11 GpiodbusChip *chip;
12
13 chip = gpiodbus_object_peek_chip(chip_obj);
14
15 g_print("%s [%s] (%u lines)\n",
16 gpiodbus_chip_get_name(chip),
17 gpiodbus_chip_get_label(chip),
18 gpiodbus_chip_get_num_lines(chip));
19 }
20
21 int gpiocli_detect_main(int argc, char **argv)
22 {
23 static const gchar *const summary =
24 "List GPIO chips, print their labels and number of GPIO lines.";
25
26 static const gchar *const description =
27 "Chips may be identified by name or number. e.g. '0' and 'gpiochip0' refer to\n"
28 "the same chip.\n"
29 "\n"
30 "If no chips are specified - display information for all chips in the system.";
31
32 g_autolist(GpiodbusObject) chip_objs = NULL;
33 g_auto(GStrv) chip_names = NULL;
34
35 const GOptionEntry opts[] = {
36 {
37 .long_name = G_OPTION_REMAINING,
38 .flags = G_OPTION_FLAG_NONE,
39 .arg = G_OPTION_ARG_STRING_ARRAY,
40 .arg_data = &chip_names,
41 .arg_description = "[chip]...",
42 },
43 { }
44 };
45
46 parse_options(opts, summary, description, &argc, &argv);
47 check_manager();
48
49 chip_objs = get_chip_objs(chip_names);
50 g_list_foreach(chip_objs, show_chip, NULL);
51
52 return EXIT_SUCCESS;
53 }