summaryrefslogtreecommitdiffstats
path: root/src/instance.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-12-10 04:40:00 +0000
committerDavid Robillard <d@drobilla.net>2011-12-10 04:40:00 +0000
commitc545e17c4d3d1f0bf791e9112d2873de01c06e51 (patch)
tree3cb5257796cf59d78d024c6525894ce122a08c60 /src/instance.c
parent5810fec09eee8491744482b882a635ab8e3d7e78 (diff)
downloadsuil-c545e17c4d3d1f0bf791e9112d2873de01c06e51.tar.gz
suil-c545e17c4d3d1f0bf791e9112d2873de01c06e51.tar.bz2
suil-c545e17c4d3d1f0bf791e9112d2873de01c06e51.zip
Rework module interface to support modules that need to pass features.
Pass experimental parent window ID feature for embedding X11 UIs with events working. git-svn-id: http://svn.drobilla.net/lad/trunk/suil@3851 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/instance.c')
-rw-r--r--src/instance.c72
1 files changed, 39 insertions, 33 deletions
diff --git a/src/instance.c b/src/instance.c
index 4998fd3..b36c00d 100644
--- a/src/instance.c
+++ b/src/instance.c
@@ -54,16 +54,11 @@ suil_ui_supported(const char* container_type_uri,
}
}
-struct _SuilModule {
- SuilWrapInitFunc init;
- SuilWrapFunc wrap;
-};
-
-typedef struct _SuilModule* SuilModule;
-
-static SuilModule
-get_wrap_module(const char* container_type_uri,
- const char* ui_type_uri)
+static SuilWrapper*
+open_wrapper(SuilHost* host,
+ const char* container_type_uri,
+ const char* ui_type_uri,
+ const LV2_Feature* const* features)
{
if (!strcmp(container_type_uri, ui_type_uri)) {
return NULL;
@@ -107,20 +102,28 @@ get_wrap_module(const char* container_type_uri,
return NULL;
}
- SuilModule module = (SuilModule)malloc(sizeof(struct _SuilModule));
- module->init = (SuilWrapInitFunc)suil_dlfunc(lib, "suil_wrap_init");
- module->wrap = (SuilWrapFunc)suil_dlfunc(lib, "suil_wrap");
+ SuilWrapperNewFunc wrapper_new = (SuilWrapperNewFunc)suil_dlfunc(
+ lib, "suil_wrapper_new");
- if (!module->init || !module->wrap) {
+ SuilWrapper* wrapper = wrapper_new
+ ? wrapper_new(host,
+ container_type_uri,
+ ui_type_uri,
+ features)
+ : NULL;
+
+ if (!wrapper) {
SUIL_ERRORF("Corrupt module %s\n", path);
+ dlclose(lib);
free(path);
- free(module);
return NULL;
}
free(path);
- return module;
+ wrapper->lib = lib;
+
+ return wrapper;
}
SUIL_API
@@ -177,12 +180,17 @@ suil_instance_new(SuilHost* host,
features = (const LV2_Feature* const*)&local_features;
}
- SuilModule module = get_wrap_module(container_type_uri, ui_type_uri);
- if (module) {
- module->init(host, container_type_uri, ui_type_uri, features);
+ // Open a new wrapper
+ SuilWrapper* wrapper = open_wrapper(host,
+ container_type_uri,
+ ui_type_uri,
+ features);
+
+ if (wrapper) {
+ features = (const LV2_Feature * const*)wrapper->features;
}
- // Instantiate UI
+ // Instantiate UI (possibly with wrapper-provided features)
SuilInstance* instance = malloc(sizeof(struct SuilInstanceImpl));
instance->lib_handle = lib;
instance->descriptor = descriptor;
@@ -197,25 +205,16 @@ suil_instance_new(SuilHost* host,
&instance->ui_widget,
features);
- // Failed to find or instantiate UI
+ // Failed to instantiate UI
if (!instance || !instance->handle) {
SUIL_ERRORF("Failed to instantiate UI <%s> in %s\n",
ui_uri, ui_binary_path);
- free(instance);
- dlclose(lib);
- return NULL;
- }
-
- // Got a handle, but failed to create a widget (buggy UI)
- if (!instance->ui_widget) {
- SUIL_ERRORF("Widget creation failed for UI <%s> in %s\n",
- ui_uri, ui_binary_path);
suil_instance_free(instance);
return NULL;
}
- if (module) {
- if (module->wrap(container_type_uri, ui_type_uri, instance)) {
+ if (wrapper) {
+ if (wrapper->wrap(wrapper, instance)) {
SUIL_ERRORF("Failed to wrap UI <%s> in type <%s>\n",
ui_uri, container_type_uri);
suil_instance_free(instance);
@@ -233,8 +232,15 @@ void
suil_instance_free(SuilInstance* instance)
{
if (instance) {
- instance->descriptor->cleanup(instance->handle);
+ if (instance->handle) {
+ instance->descriptor->cleanup(instance->handle);
+ }
dlclose(instance->lib_handle);
+ if (instance->wrapper) {
+ void* lib = instance->wrapper->lib;
+ instance->wrapper->free(instance->wrapper);
+ dlclose(lib);
+ }
free(instance);
}
}