diff mbox series

[libgpiod,v3,1/3] API: add a function for retrieving the capacity of edge event buffers

Message ID 20210727143400.32543-2-brgl@bgdev.pl
State New
Headers show
Series libgpiod v2: C++ bindings | expand

Commit Message

Bartosz Golaszewski July 27, 2021, 2:33 p.m. UTC
Add a getter for the edge-event buffer capacity property. This is useful
if we want to read the maximum number of events that can be stored in
a buffer object without externally storing its capacity.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
 include/gpiod.h  | 9 +++++++++
 lib/edge-event.c | 6 ++++++
 2 files changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/include/gpiod.h b/include/gpiod.h
index 66e6c12..8fc20ed 100644
--- a/include/gpiod.h
+++ b/include/gpiod.h
@@ -989,6 +989,15 @@  unsigned long gpiod_edge_event_get_line_seqno(struct gpiod_edge_event *event);
 struct gpiod_edge_event_buffer *
 gpiod_edge_event_buffer_new(unsigned int capacity);
 
+/**
+ * @brief Get the capacity (the max number of events that can be stored) of
+ *        the event buffer.
+ * @param buffer Edge event buffer.
+ * @return The capacity of the buffer.
+ */
+unsigned int
+gpiod_edge_event_buffer_get_capacity(struct gpiod_edge_event_buffer *buffer);
+
 /**
  * @brief Free the edge event buffer and release all associated resources.
  * @param buffer Edge event buffer to free.
diff --git a/lib/edge-event.c b/lib/edge-event.c
index 4aece4b..ab484ad 100644
--- a/lib/edge-event.c
+++ b/lib/edge-event.c
@@ -109,6 +109,12 @@  gpiod_edge_event_buffer_new(unsigned int capacity)
 	return buf;
 }
 
+GPIOD_API unsigned int
+gpiod_edge_event_buffer_get_capacity(struct gpiod_edge_event_buffer *buffer)
+{
+	return buffer->capacity;
+}
+
 GPIOD_API void
 gpiod_edge_event_buffer_free(struct gpiod_edge_event_buffer *buffer)
 {