From 784c405c31731ae1e8e563c9dbb8de747c8fe647 Mon Sep 17 00:00:00 2001 From: Ashok Sidipotu Date: Wed, 13 Oct 2021 12:11:26 +0530 Subject: [PATCH] wp: support loading optional modules -some modules will not be available during runtime, due to external dependencies. -these modules can now be marked optional. -loading of these optional modules will be attempted and if they are not available, wp will recover and will not be terminated. --- modules/module-lua-scripting/config.c | 19 ++++++++++++++++--- .../bluetooth.lua.d/30-bluez-monitor.lua | 2 +- src/config/common/00-functions.lua | 9 +++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/modules/module-lua-scripting/config.c b/modules/module-lua-scripting/config.c index 5b8c1d05..c80a3ba6 100644 --- a/modules/module-lua-scripting/config.c +++ b/modules/module-lua-scripting/config.c @@ -63,10 +63,23 @@ load_components (lua_State *L, WpCore * core, GError ** error) args = wplua_lua_to_gvariant (L, -1); } - wp_debug ("load component: %s (%s)", component, type); + gboolean optional = FALSE; + if (lua_getfield (L, table, "optional") == LUA_TBOOLEAN) { + optional = lua_toboolean (L, -1); + } - if (!wp_core_load_component (core, component, type, args, error)) - return FALSE; + wp_debug ("load component: %s (%s) optional(%s)", + component, type, (optional ? "true" : "false")); + + g_autoptr (GError) load_error = NULL; + if (!wp_core_load_component (core, component, type, args, &load_error)) { + if (!optional) { + g_propagate_error (error, g_steal_pointer (&load_error)); + return FALSE; + } else { + wp_message ("%s", load_error->message); + } + } /* clear the stack up to the key */ lua_settop (L, key); diff --git a/src/config/bluetooth.lua.d/30-bluez-monitor.lua b/src/config/bluetooth.lua.d/30-bluez-monitor.lua index 2240f57a..266d3e2f 100644 --- a/src/config/bluetooth.lua.d/30-bluez-monitor.lua +++ b/src/config/bluetooth.lua.d/30-bluez-monitor.lua @@ -8,5 +8,5 @@ function bluez_monitor.enable() rules = bluez_monitor.rules, }) - load_module("logind") + load_optional_module("logind") end diff --git a/src/config/common/00-functions.lua b/src/config/common/00-functions.lua index 75c25217..4278e6f9 100644 --- a/src/config/common/00-functions.lua +++ b/src/config/common/00-functions.lua @@ -1,12 +1,21 @@ components = {} function load_module(m, a) + assert(type(m) == "string", "module name is mandatory, bail out"); if not components[m] then components[m] = { "libwireplumber-module-" .. m, type = "module", args = a } end end +function load_optional_module(m, a) + assert(type(m) == "string", "module name is mandatory, bail out"); + if not components[m] then + components[m] = { "libwireplumber-module-" .. m, type = "module", args = a, optional = true } + end +end + function load_pw_module(m) + assert(type(m) == "string", "module name is mandatory, bail out"); if not components[m] then components[m] = { "libpipewire-module-" .. m, type = "pw_module" } end