Debian Codegraph @

bindings/glib/edge-event.c

raw symbols SCIP
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 // SPDX-FileCopyrightText: 2023-2024 Bartosz Golaszewski <[email protected]>
3
4 #include <gio/gio.h>
5
6 #include "internal.h"
7
8 /**
9 * GpiodglibEdgeEvent:
10 *
11 * #GpiodglibEdgeEvent stores information about a single line edge event.
12 * It contains the event type, timestamp and the offset of the line on which
13 * the event occurred as well as two sequence numbers (global for all lines
14 * in the associated request and local for this line only).
15 */
16 struct _GpiodglibEdgeEvent {
17 GObject parent_instance;
18 struct gpiod_edge_event *handle;
19 };
20
21 typedef enum {
22 GPIODGLIB_EDGE_EVENT_PROP_EVENT_TYPE = 1,
23 GPIODGLIB_EDGE_EVENT_PROP_TIMESTAMP_NS,
24 GPIODGLIB_EDGE_EVENT_PROP_LINE_OFFSET,
25 GPIODGLIB_EDGE_EVENT_PROP_GLOBAL_SEQNO,
26 GPIODGLIB_EDGE_EVENT_PROP_LINE_SEQNO,
27 } GpiodglibEdgeEventProp;
28
29 G_DEFINE_TYPE(GpiodglibEdgeEvent, gpiodglib_edge_event, G_TYPE_OBJECT);
30
31 static void gpiodglib_edge_event_get_property(GObject *obj, guint prop_id,
32 GValue *val, GParamSpec *pspec)
33 {
34 GpiodglibEdgeEvent *self = GPIODGLIB_EDGE_EVENT_OBJ(obj);
35 GpiodglibEdgeEventType type;
36
37 g_assert(self->handle);
38
39 switch ((GpiodglibEdgeEventProp)prop_id) {
40 case GPIODGLIB_EDGE_EVENT_PROP_EVENT_TYPE:
41 type = _gpiodglib_edge_event_type_from_library(
42 gpiod_edge_event_get_event_type(self->handle));
43 g_value_set_enum(val, type);
44 break;
45 case GPIODGLIB_EDGE_EVENT_PROP_TIMESTAMP_NS:
46 g_value_set_uint64(val,
47 gpiod_edge_event_get_timestamp_ns(self->handle));
48 break;
49 case GPIODGLIB_EDGE_EVENT_PROP_LINE_OFFSET:
50 g_value_set_uint(val,
51 gpiod_edge_event_get_line_offset(self->handle));
52 break;
53 case GPIODGLIB_EDGE_EVENT_PROP_GLOBAL_SEQNO:
54 g_value_set_ulong(val,
55 gpiod_edge_event_get_global_seqno(self->handle));
56 break;
57 case GPIODGLIB_EDGE_EVENT_PROP_LINE_SEQNO:
58 g_value_set_ulong(val,
59 gpiod_edge_event_get_line_seqno(self->handle));
60 break;
61 default:
62 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);
63 }
64 }
65
66 static void gpiodglib_edge_event_finalize(GObject *obj)
67 {
68 GpiodglibEdgeEvent *self = GPIODGLIB_EDGE_EVENT_OBJ(obj);
69
70 g_clear_pointer(&self->handle, gpiod_edge_event_free);
71
72 G_OBJECT_CLASS(gpiodglib_edge_event_parent_class)->finalize(obj);
73 }
74
75 static void
76 gpiodglib_edge_event_class_init(GpiodglibEdgeEventClass *edge_event_class)
77 {
78 GObjectClass *class = G_OBJECT_CLASS(edge_event_class);
79
80 class->get_property = gpiodglib_edge_event_get_property;
81 class->finalize = gpiodglib_edge_event_finalize;
82
83 /**
84 * GpiodglibEdgeEvent:event-type:
85 *
86 * Type of the edge event.
87 */
88 g_object_class_install_property(class,
89 GPIODGLIB_EDGE_EVENT_PROP_EVENT_TYPE,
90 g_param_spec_enum("event-type", "Event Type",
91 "Type of the edge event.",
92 GPIODGLIB_EDGE_EVENT_TYPE_TYPE,
93 GPIODGLIB_EDGE_EVENT_RISING_EDGE,
94 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
95
96 /**
97 * GpiodglibEdgeEvent:timestamp-ns:
98 *
99 * Timestamp of the edge event expressed in nanoseconds.
100 */
101 g_object_class_install_property(class,
102 GPIODGLIB_EDGE_EVENT_PROP_TIMESTAMP_NS,
103 g_param_spec_uint64("timestamp-ns",
104 "Timestamp (in nanoseconds)",
105 "Timestamp of the edge event expressed in nanoseconds.",
106 0, G_MAXUINT64, 0,
107 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
108
109 /**
110 * GpiodglibEdgeEvent:line-offset:
111 *
112 * Offset of the line on which this event was registered.
113 */
114 g_object_class_install_property(class,
115 GPIODGLIB_EDGE_EVENT_PROP_LINE_OFFSET,
116 g_param_spec_uint("line-offset", "Line Offset",
117 "Offset of the line on which this event was registered.",
118 0, G_MAXUINT, 0,
119 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
120
121 /**
122 * GpiodglibEdgeEvent:global-seqno:
123 *
124 * Global sequence number of this event.
125 */
126 g_object_class_install_property(class,
127 GPIODGLIB_EDGE_EVENT_PROP_GLOBAL_SEQNO,
128 g_param_spec_ulong("global-seqno", "Global Sequence Number",
129 "Global sequence number of this event.",
130 0, G_MAXULONG, 0,
131 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
132
133 /**
134 * GpiodglibEdgeEvent:line-seqno:
135 *
136 * Event sequence number specific to the line.
137 */
138 g_object_class_install_property(class,
139 GPIODGLIB_EDGE_EVENT_PROP_LINE_SEQNO,
140 g_param_spec_ulong("line-seqno", "Line Sequence Number",
141 "Event sequence number specific to the line.",
142 0, G_MAXULONG, 0,
143 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
144 }
145
146 static void gpiodglib_edge_event_init(GpiodglibEdgeEvent *self)
147 {
148 self->handle = NULL;
149 }
150
151 GpiodglibEdgeEventType
152 gpiodglib_edge_event_get_event_type(GpiodglibEdgeEvent *self)
153 {
154 return _gpiodglib_get_prop_enum(G_OBJECT(self), "event-type");
155 }
156
157 guint64 gpiodglib_edge_event_get_timestamp_ns(GpiodglibEdgeEvent *self)
158 {
159 return _gpiodglib_get_prop_uint64(G_OBJECT(self), "timestamp-ns");
160 }
161
162 guint gpiodglib_edge_event_get_line_offset(GpiodglibEdgeEvent *self)
163 {
164 return _gpiodglib_get_prop_uint(G_OBJECT(self), "line-offset");
165 }
166
167 gulong gpiodglib_edge_event_get_global_seqno(GpiodglibEdgeEvent *self)
168 {
169 return _gpiodglib_get_prop_ulong(G_OBJECT(self), "global-seqno");
170 }
171
172 gulong gpiodglib_edge_event_get_line_seqno(GpiodglibEdgeEvent *self)
173 {
174 return _gpiodglib_get_prop_ulong(G_OBJECT(self), "line-seqno");
175 }
176
177 GpiodglibEdgeEvent *_gpiodglib_edge_event_new(struct gpiod_edge_event *handle)
178 {
179 GpiodglibEdgeEvent *event;
180
181 event = GPIODGLIB_EDGE_EVENT_OBJ(
182 g_object_new(GPIODGLIB_EDGE_EVENT_TYPE, NULL));
183 event->handle = handle;
184
185 return event;
186 }