Skip to contentSkip to conversation

notifylist: add notifylist class

PATCH New Denis Kenzior 1 participant 2 messages May 31, 2024 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 notifylist: add notifylist class

oFono and iwd projects use a 'watch' pattern to register clients for notifications about object events, such as state changes. This pattern is quite common and both iwd and oFono implement utilities for adding, removing and notifying 'watch' clients. This can be thought of as a primitive signal / slot framework.

Implementing 'watches' properly, including handling possible call stack re-entrancy conditions can be tricky. The notifylist class implements a generic 'watch' framework and aims to be the shared implementation for iwd, oFono and other projects.

---
 Makefile.am      |   6 +-
 ell/ell.h        |   1 +
 ell/ell.sym      |   7 ++
 ell/notifylist.c | 208 +++++++++++++++++++++++++++++++++++++++++++++++
 ell/notifylist.h |  53 ++++++++++++
 5 files changed, 273 insertions(+), 2 deletions(-)
 create mode 100644 ell/notifylist.c
 create mode 100644 ell/notifylist.h
Makefile.am +4 -2
index 6c86e94e963e..77a6e81a9766 100644
@@ -63,7 +63,8 @@ pkginclude_HEADERS = ell/ell.h \
 			ell/cleanup.h \
 			ell/netconfig.h \
 			ell/sysctl.h \
-			ell/minheap.h
+			ell/minheap.h \
+			ell/notifylist.h
 
 lib_LTLIBRARIES = ell/libell.la
 
@@ -153,7 +154,8 @@ ell_libell_la_SOURCES = $(linux_headers) \
 			ell/tester.c \
 			ell/netconfig.c \
 			ell/sysctl.c \
-			ell/minheap.c
+			ell/minheap.c \
+			ell/notifylist.c
 
 ell_libell_la_LDFLAGS = -Wl,--no-undefined \
 			-Wl,--version-script=$(top_srcdir)/ell/ell.sym \
ell/ell.h +1 -0
index f67339105e8f..7a263e9376de 100644
@@ -53,3 +53,4 @@
 #include <ell/netconfig.h>
 #include <ell/sysctl.h>
 #include <ell/minheap.h>
+#include <ell/notifylist.h>
ell/ell.sym +7 -0
index 803906c586e8..0587beb398bc 100644
@@ -788,6 +788,13 @@ global:
 	/* sysctl */
 	l_sysctl_get_u32;
 	l_sysctl_set_u32;
+	/* notifylist */
+	l_notifylist_new;
+	l_notifylist_free;
+	l_notifylist_add;
+	l_notifylist_remove;
+	l_notifylist_notify;
+	l_notifylist_notify_matches;
 local:
 	*;
 };
ell/notifylist.c new file +208 -0

208 lines not on this page · raw message

ell/notifylist.h new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
2.45.0
#1 lore raw

PATCH 2/2 unit: Add notifylist unit tests

---
 Makefile.am            |   5 +-
 unit/test-notifylist.c | 206 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 210 insertions(+), 1 deletion(-)
 create mode 100644 unit/test-notifylist.c
Makefile.am +4 -1
index 77a6e81a9766..fc7683397b6a 100644
@@ -207,7 +207,8 @@ unit_tests = unit/test-unit \
 			unit/test-path \
 			unit/test-net \
 			unit/test-sysctl \
-			unit/test-minheap
+			unit/test-minheap \
+			unit/test-notifylist
 
 dbus_tests = unit/test-hwdb \
 			unit/test-dbus \
@@ -360,6 +361,8 @@ unit_test_sysctl_LDADD = ell/libell-private.la
 
 unit_test_minheap_LDADD = ell/libell-private.la
 
+unit_test_notifylist_LDADD = ell/libell-private.la
+
 unit_test_data_files = unit/settings.test unit/dbus.conf
 
 if EXAMPLES
unit/test-notifylist.c new file +206 -0

206 lines not on this page · raw message

Signature · 1 line
2.45.0