diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-02-20 10:22:14 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-02-20 10:22:14 -0700 |
commit | 860a75bd4dee36880c9372d1f78ced18d1246988 (patch) | |
tree | 0464f4068ee86c600d57cb2ca4d16de41f4db907 | |
parent | c7a0945ffcb5f17953109a6b4ac77a5c64980f4f (diff) | |
download | wetterhorn-860a75bd4dee36880c9372d1f78ced18d1246988.tar.gz wetterhorn-860a75bd4dee36880c9372d1f78ced18d1246988.tar.bz2 wetterhorn-860a75bd4dee36880c9372d1f78ced18d1246988.zip |
add back the metaload
-rw-r--r-- | harness/include/plugin.h | 8 | ||||
-rw-r--r-- | harness/src/plugin.c | 48 | ||||
-rw-r--r-- | src/harness_adapter.c | 9 |
3 files changed, 50 insertions, 15 deletions
diff --git a/harness/include/plugin.h b/harness/include/plugin.h index 145fe52..bde8990 100644 --- a/harness/include/plugin.h +++ b/harness/include/plugin.h @@ -85,6 +85,14 @@ typedef struct PLUGIN { * will be NULL. */ const char *plugin_name; + /** + * Initializes the plugin on the first time, and only the first time, it is + * loaded. This is used to do things like setup a runtime that cannot be + * reliably torn down. It is up to the plugin to ensure this won't interfere + * with hot-reloading. + */ + EXPORT(void (*plugin_metaload)(int argc, char** argv)); + /** Intializes the plugin with the given argc/argv. This is the first thing * called on the plugin and is called immediately after the library is loaded. */ diff --git a/harness/src/plugin.c b/harness/src/plugin.c index 1d7c992..b46cb5f 100644 --- a/harness/src/plugin.c +++ b/harness/src/plugin.c @@ -46,17 +46,11 @@ static void shx(uint8_t *state, uint32_t sz) int load_plugin_from_dl_(dlhandle_t dl, plugin_t *plug); -static void lock(plugin_t *plugin) -{ - pthread_mutex_lock(&plugin->lock); -}; +static void lock(plugin_t *plugin) { pthread_mutex_lock(&plugin->lock); }; -static void unlock(plugin_t *plugin) -{ - pthread_mutex_unlock(&plugin->lock); -}; +static void unlock(plugin_t *plugin) { pthread_mutex_unlock(&plugin->lock); }; -static int plugin_hot_reload_same_state_action_(plugin_t *plugin, void* ignore) +static int plugin_hot_reload_same_state_action_(plugin_t *plugin, void *ignore) { return plugin_hot_reload_same_state(plugin); } @@ -72,14 +66,14 @@ void do_request_hot_reload(void *plugv) } } -static int plugin_do_log(plugin_t* plugin, void* chrs) +static int plugin_do_log(plugin_t *plugin, void *chrs) { - char* str = chrs; + char *str = chrs; puts(str); return 0; } -void do_request_log(void *plugv, const char* str) +void do_request_log(void *plugv, const char *str) { plugin_t *plugin = plugv; @@ -91,7 +85,7 @@ void do_request_log(void *plugv, const char* str) } } -static int plugin_do_exit(void* plugv, int ec) +static int plugin_do_exit(void *plugv, int ec) { exit(ec); return 0; @@ -103,7 +97,8 @@ void do_request_exit(void *plugv, int ec) size_t n = plugin->n_requested_actions++; if (n < 8) { - plugin->requested_actions[n].action = (int(*)(plugin_t*,void*)) plugin_do_exit; + plugin->requested_actions[n].action = + (int (*)(plugin_t *, void *))plugin_do_exit; plugin->requested_actions[n].int_arg = ec; plugin->requested_actions[n].arg_dtor = NULL; } @@ -142,6 +137,23 @@ end: return ec; } +static void maybe_run_metaload(int argc, char **argv, plugin_t *plugin) +{ + static char *loaded_plugins[12]; + int i; + for (i = 0; i < 12 && loaded_plugins[i]; ++i) { + if (strcmp(loaded_plugins[i], plugin->plugin_name) == 0) { + return; // Plugin is already loaded + } + } + loaded_plugins[i] = strdup(plugin->plugin_name); + + printf("First time loading %s, running metaload.\n", plugin->plugin_name); + if (plugin->plugin_metaload) { + plugin->plugin_metaload(argc, argv); + } +} + int load_plugin_from_file(int argc, char **argv, const char *filename, plugin_t *plugin) { @@ -164,7 +176,13 @@ int load_plugin_from_file(int argc, char **argv, const char *filename, return 1; } pthread_mutexattr_destroy(&attr); - return load_plugin_from_file_(argc, argv, filename, plugin); + int rc = load_plugin_from_file_(argc, argv, filename, plugin); + + if (rc == 0) { + maybe_run_metaload(argc, argv, plugin); + } + + return rc; } int plugin_hot_reload_same_state(plugin_t *plugin) diff --git a/src/harness_adapter.c b/src/harness_adapter.c index 8585d7e..b18f8d2 100644 --- a/src/harness_adapter.c +++ b/src/harness_adapter.c @@ -16,6 +16,11 @@ void* get_foreign_interface() return foreign_interface; } +void plugin_metaload(int argc, char** argv) +{ + hs_init(&argc, &argv); +} + void plugin_load(int argc, char **argv, foreign_interface_t* fintf) { hs_init(&argc, &argv); foreign_interface = fintf; @@ -38,6 +43,10 @@ static const char msg[] = "That will allow you to see how this compositor works in all its glory!\n"; static const int msg_sz = sizeof(msg); +/* + * Implemens a basic _start that prints inforamtion and exits for users on an + * x86_64 system. + */ __attribute__((naked)) void _start() { |