| 1 | // SPDX-License-Identifier: LGPL-2.1-or-latercxx . . $ `<file>/lib/info-event.c`/ |
| 2 | // SPDX-FileCopyrightText: 2021 Bartosz Golaszewski <[email protected]> |
| 3 | |
| 4 | #include <assert.h> |
| 5 | #include <errno.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <string.h> |
| 8 | #include <unistd.h> |
| 9 | |
| 10 | #include "internal.h"cxx . . $ `<file>/lib/internal.h`/ |
| 11 | |
| 12 | struct gpiod_info_eventcxx . . $ gpiod_info_event# { |
| 13 | enum gpiod_info_event_typecxx . . $ gpiod_info_event_type# event_typecxx . . $ gpiod_info_event#event_type.; |
| 14 | uint64_tcxx . . $ uint64_t# timestampcxx . . $ gpiod_info_event#timestamp.; |
| 15 | struct gpiod_line_infocxx . . $ gpiod_line_info# *infocxx . . $ gpiod_info_event#info.; |
| 16 | }; |
| 17 | |
| 18 | struct gpiod_info_eventcxx . . $ gpiod_info_event# * |
| 19 | gpiod_info_event_from_uapicxx . . $ gpiod_info_event_from_uapi(9734c2416807fa82).(struct gpio_v2_line_info_changedcxx . . $ gpio_v2_line_info_changed# *uapi_evt) |
| 20 | { |
| 21 | struct gpiod_info_eventcxx . . $ gpiod_info_event# *event; |
| 22 | |
| 23 | event = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(*event)); |
| 24 | if (!event) |
| 25 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 26 | |
| 27 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(event, 0, sizeof(*event)); |
| 28 | event->timestampcxx . . $ gpiod_info_event#timestamp. = uapi_evt->timestamp_nscxx . . $ gpio_v2_line_info_changed#timestamp_ns.; |
| 29 | |
| 30 | switch (uapi_evt->event_typecxx . . $ gpio_v2_line_info_changed#event_type.) { |
| 31 | case GPIOLINE_CHANGED_REQUESTEDcxx . . $ GPIOLINE_CHANGED_REQUESTED.: |
| 32 | event->event_typecxx . . $ gpiod_info_event#event_type. = GPIOD_INFO_EVENT_LINE_REQUESTEDcxx . . $ GPIOD_INFO_EVENT_LINE_REQUESTED.; |
| 33 | break; |
| 34 | case GPIOLINE_CHANGED_RELEASEDcxx . . $ GPIOLINE_CHANGED_RELEASED.: |
| 35 | event->event_typecxx . . $ gpiod_info_event#event_type. = GPIOD_INFO_EVENT_LINE_RELEASEDcxx . . $ GPIOD_INFO_EVENT_LINE_RELEASED.; |
| 36 | break; |
| 37 | case GPIOLINE_CHANGED_CONFIGcxx . . $ GPIOLINE_CHANGED_CONFIG.: |
| 38 | event->event_typecxx . . $ gpiod_info_event#event_type. = GPIOD_INFO_EVENT_LINE_CONFIG_CHANGEDcxx . . $ GPIOD_INFO_EVENT_LINE_CONFIG_CHANGED.; |
| 39 | break; |
| 40 | default: |
| 41 | /* Can't happen unless there's a bug in the kernel. */ |
| 42 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = ENOMSGcxx . . $ `<external>/17922322188510340118/errno.h:23:9`!; |
| 43 | freecxx . . $ free(5d22bdacc48458e8).(event); |
| 44 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 45 | } |
| 46 | |
| 47 | event->infocxx . . $ gpiod_info_event#info. = gpiod_line_info_from_uapicxx . . $ gpiod_line_info_from_uapi(273b4a357bdfb836).(&uapi_evt->infocxx . . $ gpio_v2_line_info_changed#info.); |
| 48 | if (!event->infocxx . . $ gpiod_info_event#info.) { |
| 49 | freecxx . . $ free(5d22bdacc48458e8).(event); |
| 50 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 51 | } |
| 52 | |
| 53 | return event; |
| 54 | } |
| 55 | |
| 56 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! void gpiod_info_event_freecxx . . $ gpiod_info_event_free(afe5f20585ec2d4b).(struct gpiod_info_eventcxx . . $ gpiod_info_event# *event) |
| 57 | { |
| 58 | if (!event) |
| 59 | return; |
| 60 | |
| 61 | gpiod_line_info_freecxx . . $ gpiod_line_info_free(518ebc771aa28e67).(event->infocxx . . $ gpiod_info_event#info.); |
| 62 | freecxx . . $ free(5d22bdacc48458e8).(event); |
| 63 | } |
| 64 | |
| 65 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! enum gpiod_info_event_typecxx . . $ gpiod_info_event_type# |
| 66 | gpiod_info_event_get_event_typecxx . . $ gpiod_info_event_get_event_type(4e48e71f2539789f).(struct gpiod_info_eventcxx . . $ gpiod_info_event# *event) |
| 67 | { |
| 68 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(event); |
| 69 | |
| 70 | return event->event_typecxx . . $ gpiod_info_event#event_type.; |
| 71 | } |
| 72 | |
| 73 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! uint64_tcxx . . $ uint64_t# |
| 74 | gpiod_info_event_get_timestamp_nscxx . . $ gpiod_info_event_get_timestamp_ns(92533cedc8875c2).(struct gpiod_info_eventcxx . . $ gpiod_info_event# *event) |
| 75 | { |
| 76 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(event); |
| 77 | |
| 78 | return event->timestampcxx . . $ gpiod_info_event#timestamp.; |
| 79 | } |
| 80 | |
| 81 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! struct gpiod_line_infocxx . . $ gpiod_line_info# * |
| 82 | gpiod_info_event_get_line_infocxx . . $ gpiod_info_event_get_line_info(20d3f46bc4054346).(struct gpiod_info_eventcxx . . $ gpiod_info_event# *event) |
| 83 | { |
| 84 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(event); |
| 85 | |
| 86 | return event->infocxx . . $ gpiod_info_event#info.; |
| 87 | } |
| 88 | |
| 89 | struct gpiod_info_eventcxx . . $ gpiod_info_event# *gpiod_info_event_read_fdcxx . . $ gpiod_info_event_read_fd(8e0dbd7b7e89c9bb).(int fd) |
| 90 | { |
| 91 | struct gpio_v2_line_info_changedcxx . . $ gpio_v2_line_info_changed# uapi_evt; |
| 92 | ssize_tcxx . . $ ssize_t# rd; |
| 93 | |
| 94 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&uapi_evt, 0, sizeof(uapi_evt)); |
| 95 | |
| 96 | rd = readcxx . . $ read(7e34d0a36f355389).(fd, &uapi_evt, sizeof(uapi_evt)); |
| 97 | if (rd < 0) { |
| 98 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 99 | } else if ((unsigned int)rd < sizeof(uapi_evt)) { |
| 100 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 101 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 102 | } |
| 103 | |
| 104 | return gpiod_info_event_from_uapicxx . . $ gpiod_info_event_from_uapi(9734c2416807fa82).(&uapi_evt); |
| 105 | } |