Debian Codegraph @

dbus/client/requests.c

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 // SPDX-FileCopyrightText: 2023 Bartosz Golaszewski <[email protected]>
3
4 #include <stdlib.h>
5
6 #include "common.h"
7
8 static void show_request(gpointer elem, gpointer user_data G_GNUC_UNUSED)
9 {
10 g_autoptr(GDBusObjectManager) manager = NULL;
11 g_autofree gchar *request_name = NULL;
12 g_autofree gchar *offsets_str = NULL;
13 g_autoptr(GVariant) voffsets = NULL;
14 g_autofree gchar *chip_name = NULL;
15 g_autoptr(GArray) offsets = NULL;
16 GpiodbusObject *obj = elem;
17 GpiodbusRequest *request;
18 GVariantBuilder builder;
19 const gchar *chip_path;
20 gsize i;
21
22 request_name = g_path_get_basename(
23 g_dbus_object_get_object_path(G_DBUS_OBJECT(obj)));
24 request = gpiodbus_object_peek_request(obj);
25 chip_path = gpiodbus_request_get_chip_path(request);
26 manager = get_object_manager_client(chip_path);
27 /* FIXME: Use chip proxy? */
28 chip_name = g_path_get_basename(chip_path);
29
30 offsets = get_request_offsets(request);
31 g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
32 for (i = 0; i < offsets->len; i++)
33 g_variant_builder_add(&builder, "u",
34 g_array_index(offsets, guint, i));
35 voffsets = g_variant_ref_sink(g_variant_builder_end(&builder));
36 offsets_str = g_variant_print(voffsets, FALSE);
37
38 g_print("%s (%s) Offsets: %s\n",
39 request_name, chip_name, offsets_str);
40 }
41
42 int gpiocli_requests_main(int argc, char **argv)
43 {
44 static const gchar *const summary =
45 "List all line requests controlled by the manager.";
46
47 g_autolist(GpiodbusObject) request_objs = NULL;
48 g_auto(GStrv) remaining = NULL;
49
50 const GOptionEntry opts[] = {
51 {
52 .long_name = G_OPTION_REMAINING,
53 .flags = G_OPTION_FLAG_NONE,
54 .arg = G_OPTION_ARG_STRING_ARRAY,
55 .arg_data = &remaining,
56 .arg_description = NULL,
57 },
58 { }
59 };
60
61 parse_options(opts, summary, NULL, &argc, &argv);
62 check_manager();
63
64 if (remaining)
65 die_parsing_opts("command doesn't take additional arguments");
66
67 request_objs = get_request_objs();
68 g_list_foreach(request_objs, show_request, NULL);
69
70 return EXIT_SUCCESS;
71 }