Revert "api: module: support loading arguments from file"

This reverts commit 2ae1b3cbd9.

This is not a good API. It was only allowed temporarily in 0.4.15
to get things done. We should approach this properly in 0.5
This commit is contained in:
George Kiagiadakis
2023-10-24 11:55:52 +03:00
parent 22cb31571d
commit dbf8204cf9
4 changed files with 3 additions and 84 deletions

View File

@@ -11,7 +11,7 @@ dropped, the module is unloaded.
Constructors
~~~~~~~~~~~~
.. function:: LocalModule(name, arguments, properties, [load_args_from_file])
.. function:: LocalModule(name, arguments, properties)
Loads the named module with the provided arguments and properties (either of
which can be ``nil``).
@@ -21,7 +21,6 @@ Constructors
module arguments
:param table properties: can be ``nil`` or a table that can be
:ref:`converted <lua_gobject_lua_to_c>` to :c:struct:`WpProperties`
:param load_args_from_file: (since 0.4.15) optional. if true, arguments param is treated as a file path to load args from
:returns: a new LocalModule
:rtype: LocalModule (:c:struct:`WpImplModule`)
:since: 0.4.2

View File

@@ -10,10 +10,6 @@
#include "log.h"
#include <pipewire/impl.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/mman.h>
WP_DEFINE_LOCAL_LOG_TOPIC ("wp-module")
@@ -265,63 +261,3 @@ wp_impl_module_load (WpCore * core, const gchar * name,
return module;
}
/*!
* \brief Loads a PipeWire module with arguments from file into the WirePlumber process
*
* \ingroup wpimplmodule
* \since 0.4.15
* \param core (transfer none): The WirePlumber core
* \param name (transfer none): the name of the module to load
* \param filename (transfer none): filename to be used as arguments
* \param properties (nullable) (transfer none): additional properties to be
* provided to the module
* \returns (nullable) (transfer full): the WpImplModule for the module that
* was loaded on success, %NULL on failure.
*/
WpImplModule *
wp_impl_module_load_file (WpCore * core, const gchar * name,
const gchar * filename, WpProperties * properties)
{
char *config = "";
int fd = open(filename, O_RDONLY);
if (fd < 0) {
g_warning("Failed to open config file %s: %m", filename);
return NULL;
}
struct stat stats;
int err = fstat(fd, &stats);
if (err < 0) {
g_warning("Failed to stat config file %s: %m", filename);
close(fd);
return NULL;
}
config = mmap(NULL, stats.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (config == MAP_FAILED){
g_warning("Failed to mmap config file %s: %m", filename);
close(fd);
return NULL;
}
close(fd);
WpImplModule *module = WP_IMPL_MODULE (
g_object_new (WP_TYPE_IMPL_MODULE,
"core", core,
"name", name,
"arguments", config,
"properties", properties,
NULL)
);
munmap(config, stats.st_size);
if (!module->pw_impl_module) {
/* Module loading failed, free and return */
g_object_unref (module);
return NULL;
}
return module;
}

View File

@@ -29,9 +29,6 @@ G_DECLARE_FINAL_TYPE (WpImplModule, wp_impl_module, WP, IMPL_MODULE, GObject);
WP_API
WpImplModule * wp_impl_module_load (WpCore * core, const gchar * name,
const gchar * arguments, WpProperties * properties);
WP_API
WpImplModule * wp_impl_module_load_file (WpCore * core, const gchar * name,
const gchar * filename, WpProperties * properties);
G_END_DECLS

View File

@@ -6,7 +6,6 @@
* SPDX-License-Identifier: MIT
*/
#include "lua.h"
#include <glib/gstdio.h>
#include <wp/wp.h>
#include <pipewire/pipewire.h>
@@ -1537,20 +1536,8 @@ impl_module_new (lua_State *L)
properties = wplua_table_to_properties (L, 3);
}
bool load_file = false; // Load args as file path
if (lua_type (L, 4) != LUA_TNONE && lua_type (L, 4) != LUA_TNIL) {
luaL_checktype (L, 4, LUA_TBOOLEAN);
load_file = lua_toboolean(L, 4);
}
WpImplModule *m = NULL;
if (load_file) {
m = wp_impl_module_load_file (get_wp_export_core (L),
name, args, properties);
} else {
m = wp_impl_module_load (get_wp_export_core (L),
name, args, properties);
}
WpImplModule *m = wp_impl_module_load (get_wp_export_core (L),
name, args, properties);
if (m) {
wplua_pushobject (L, m);