Debian Codegraph @

dbus/client/release.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 int gpiocli_release_main(int argc, char **argv)
9 {
10 static const gchar *const summary =
11 "Release one of the line requests controlled by the manager.";
12
13 g_autoptr(GDBusObjectManager) manager = NULL;
14 g_autoptr(GpiodbusObject) obj = NULL;
15 g_autofree gchar *obj_path = NULL;
16 g_auto(GStrv) remaining = NULL;
17 g_autoptr(GError) err = NULL;
18 const gchar *request_name;
19 GpiodbusRequest *request;
20 gboolean ret;
21
22 const GOptionEntry opts[] = {
23 {
24 .long_name = G_OPTION_REMAINING,
25 .flags = G_OPTION_FLAG_NONE,
26 .arg = G_OPTION_ARG_STRING_ARRAY,
27 .arg_data = &remaining,
28 .arg_description = "<request>",
29 },
30 { }
31 };
32
33 parse_options(opts, summary, NULL, &argc, &argv);
34
35 if (!remaining || g_strv_length(remaining) != 1)
36 die_parsing_opts("Exactly one request to release must be specified.");
37
38 check_manager();
39
40 request_name = remaining[0];
41
42 obj_path = make_request_obj_path(request_name);
43 manager = get_object_manager_client("/io/gpiod1/requests");
44 obj = GPIODBUS_OBJECT(g_dbus_object_manager_get_object(manager,
45 obj_path));
46 if (!obj)
47 goto no_request;
48
49 request = gpiodbus_object_peek_request(obj);
50 if (!request)
51 goto no_request;
52
53 ret = gpiodbus_request_call_release_sync(request,
54 G_DBUS_CALL_FLAGS_NONE,
55 -1, NULL, &err);
56 if (!ret)
57 die_gerror(err, "Failed to release request '%s': %s",
58 request_name, err->message);
59
60 return EXIT_SUCCESS;
61
62 no_request:
63 die("No such request: '%s'", request_name);
64 }