From: Denis Kenzior <denkenz@gmail.com>
To: ofono@lists.linux.dev
Cc: Denis Kenzior <denkenz@gmail.com>
Subject: [PATCH v2 03/15] module: Add support for ofono modules
Date: Tue, 19 Dec 2023 12:37:00 -0600 [thread overview]
Message-ID: <20231219184016.420116-3-denkenz@gmail.com> (raw)
In-Reply-To: <20231219184016.420116-1-denkenz@gmail.com>
Modules are meant to replace manually calling various __foo_init
and __foo_cleanup calls in main.c. Instead a single ofono_modules_init
and ofono_modules_cleanup invocation will initialize / cleanup all
registered ofono modules.
---
Makefile.am | 3 ++-
src/main.c | 11 ++++-------
src/manager.c | 6 ++++--
src/modem.c | 7 +++++--
src/module.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/ofono.h | 22 ++++++++++++++++++---
6 files changed, 89 insertions(+), 15 deletions(-)
create mode 100644 src/module.c
diff --git a/Makefile.am b/Makefile.am
index e7fd030f..f7b59a47 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -725,7 +725,8 @@ src_ofonod_SOURCES = $(builtin_sources) $(gatchat_sources) src/ofono.ver \
src/handsfree-audio.c src/bluetooth.h \
src/hfp.h src/siri.c \
src/netmon.c src/lte.c src/ims.c \
- src/netmonagent.c src/netmonagent.h
+ src/netmonagent.c src/netmonagent.h \
+ src/module.c
src_ofonod_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) $(ell_ldadd) \
@GLIB_LIBS@ @DBUS_LIBS@ -ldl
diff --git a/src/main.c b/src/main.c
index 4529cde1..82157700 100644
--- a/src/main.c
+++ b/src/main.c
@@ -274,12 +274,10 @@ int main(int argc, char **argv)
__ofono_dbus_init(conn);
- __ofono_modemwatch_init();
-
- __ofono_manager_init();
+ if (__ofono_modules_init() < 0)
+ goto fail_module_init;
__ofono_plugin_init(option_plugin, option_noplugin);
-
g_free(option_plugin);
g_free(option_noplugin);
@@ -287,10 +285,9 @@ int main(int argc, char **argv)
__ofono_plugin_cleanup();
- __ofono_manager_cleanup();
-
- __ofono_modemwatch_cleanup();
+ __ofono_modules_cleanup();
+fail_module_init:
__ofono_dbus_cleanup();
dbus_connection_unref(conn);
diff --git a/src/manager.c b/src/manager.c
index 404f2cad..e3307adb 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -95,7 +95,7 @@ static const GDBusSignalTable manager_signals[] = {
{ }
};
-int __ofono_manager_init(void)
+static int manager_init(void)
{
DBusConnection *conn = ofono_dbus_get_connection();
gboolean ret;
@@ -111,10 +111,12 @@ int __ofono_manager_init(void)
return 0;
}
-void __ofono_manager_cleanup(void)
+static void manager_cleanup(void)
{
DBusConnection *conn = ofono_dbus_get_connection();
g_dbus_unregister_interface(conn, OFONO_MANAGER_PATH,
OFONO_MANAGER_INTERFACE);
}
+
+OFONO_MODULE(manager, manager_init, manager_cleanup)
diff --git a/src/modem.c b/src/modem.c
index 60717717..354d2b86 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -1918,12 +1918,13 @@ static void sim_watch(struct ofono_atom *atom,
modem, NULL);
}
-void __ofono_modemwatch_init(void)
+static int modemwatch_init(void)
{
g_modemwatches = __ofono_watchlist_new(g_free);
+ return 0;
}
-void __ofono_modemwatch_cleanup(void)
+static void modemwatch_cleanup(void)
{
__ofono_watchlist_free(g_modemwatches);
}
@@ -2319,3 +2320,5 @@ void __ofono_modem_dec_emergency_mode(struct ofono_modem *modem)
out:
modem->emergency--;
}
+
+OFONO_MODULE(modemwatch, modemwatch_init, modemwatch_cleanup)
diff --git a/src/module.c b/src/module.c
new file mode 100644
index 00000000..273a7183
--- /dev/null
+++ b/src/module.c
@@ -0,0 +1,55 @@
+/*
+ * oFono - Open Source Telephony
+ * Copyright (C) 2023 Cruise, LLC
+ *
+ * SPDX-License-Identifier: GPL-2.0-only
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <ell/ell.h>
+
+#include "ofono.h"
+
+extern struct ofono_module_desc __start___ofono_module[];
+extern struct ofono_module_desc __stop___ofono_module[];
+
+int __ofono_modules_init(void)
+{
+ struct ofono_module_desc *desc;
+ size_t i;
+ int r;
+ size_t n_modules =__stop___ofono_module - __start___ofono_module;
+
+ DBG("");
+
+ for (i = 0; i < n_modules; i++) {
+ desc = __start___ofono_module + i;
+ r = desc->init();
+
+ if (r < 0) {
+ ofono_error("Module %s failed to start: %s(%d)",
+ desc->name, strerror(-r), -r);
+ return r;
+ }
+ }
+
+ return 0;
+}
+
+void __ofono_modules_cleanup(void)
+{
+ struct ofono_module_desc *desc;
+ size_t i;
+ size_t n_modules = __stop___ofono_module - __start___ofono_module;
+
+ l_debug("");
+
+ for (i = n_modules; i > 0; i--) {
+ desc = __start___ofono_module + i - 1;
+ desc->exit();
+ }
+}
diff --git a/src/ofono.h b/src/ofono.h
index 2e51776b..e289ff08 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -28,9 +28,6 @@
void __ofono_exit(void);
-int __ofono_manager_init(void);
-void __ofono_manager_cleanup(void);
-
int __ofono_handsfree_audio_manager_init(void);
void __ofono_handsfree_audio_manager_cleanup(void);
@@ -97,6 +94,25 @@ gboolean __ofono_watchlist_remove_item(struct ofono_watchlist *watchlist,
unsigned int id);
void __ofono_watchlist_free(struct ofono_watchlist *watchlist);
+struct ofono_module_desc {
+ const char *name;
+ int (*init)(void);
+ void (*exit)(void);
+} __attribute__((aligned(8)));
+
+#define OFONO_MODULE(name, init, exit) \
+ _Pragma("GCC diagnostic push") \
+ _Pragma("GCC diagnostic ignored \"-Wattributes\"") \
+ static struct ofono_module_desc __ofono_module_ ## name \
+ __attribute__((used, retain, section("__ofono_module"), \
+ aligned(8))) = { \
+ #name, init, exit \
+ }; \
+ _Pragma("GCC diagnostic pop")
+
+int __ofono_modules_init(void);
+void __ofono_modules_cleanup(void);
+
#include <ofono/plugin.h>
int __ofono_plugin_init(const char *pattern, const char *exclude);
--
2.43.0
next prev parent reply other threads:[~2023-12-19 18:41 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-19 18:36 [PATCH v2 01/15] build: Fix typo that breaks --fsanitize=leak check Denis Kenzior
2023-12-19 18:36 ` [PATCH v2 02/15] include: Allow multiple context types Denis Kenzior
2023-12-19 18:37 ` Denis Kenzior [this message]
2023-12-19 18:37 ` [PATCH v2 04/15] doc: docs for intermediate provisioning db format Denis Kenzior
2023-12-19 18:37 ` [PATCH v2 05/15] tools: Add provision.py Denis Kenzior
2023-12-19 18:37 ` [PATCH v2 06/15] core: Add utilities to read the provisioning db Denis Kenzior
2023-12-19 18:37 ` [PATCH v2 07/15] tools: lookup-apn: Use the new provision_db utils Denis Kenzior
2023-12-19 18:37 ` [PATCH v2 08/15] provision: Import initial JSON db Denis Kenzior
2023-12-19 18:37 ` [PATCH v2 09/15] provision: Add new module Denis Kenzior
2023-12-19 18:37 ` [PATCH v2 10/15] gprs: Use the new provisioning module Denis Kenzior
2023-12-19 18:37 ` [PATCH v2 11/15] plugins: Remove support for file-provision plugin Denis Kenzior
2023-12-19 18:37 ` [PATCH v2 12/15] plugins: provision: Remove mbpi support Denis Kenzior
2023-12-19 18:37 ` [PATCH v2 13/15] examples: Remove provision example Denis Kenzior
2023-12-19 18:37 ` [PATCH v2 14/15] gprs-provision: Remove no longer used atom/driver Denis Kenzior
2023-12-19 18:37 ` [PATCH v2 15/15] provision: Detect duplicates Denis Kenzior
2024-01-02 17:18 ` [PATCH v2 01/15] build: Fix typo that breaks --fsanitize=leak check Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231219184016.420116-3-denkenz@gmail.com \
--to=denkenz@gmail.com \
--cc=ofono@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).