refactor: Move all hook and IO libraries to use btools log and thread api
Remove usages of AVS threads and logging functions from the bemanitools backend. Use the bemanitools 6 API instead which propagates interfaces to call thread and log APIs. Prior design decisions for using these were: - have a single log stream through the AVS logging system for “neatness”, log output redirection options in launcher, and theoretically logging to an xrpc endpoint - IIDX 19 to IIDX 24 crash the AVS logging engine in libavs due to IO hook code running in a non AVS thread (threads in ezusb library) causing a stackoverflow when trying to acquire a mutex (see dev journal 2018-02-10-logging-breakdown-avs.md for details) With a flexible log sink architecture in the core of bemanitools, and a separate writer function that is hooked up as a log writer to AVS, log streams are still unified on a sink level. This takes care of having all log messaged sinked to the same targets no matter how many logging engines are using them. This avoids going through the AVS logging engine with the IO related hooking code in iidx, which just uses the bemanitools logging engine instead. Furthermore, this removes any needs to having to switch thread and logging implementations once AVS is booted which significantly simplifies the runtime orchestration during bootstrapping. The log-server, which was specifically implemented for iidx to solve the threading issue, can also be removed now. Unfortunately, this also caused performance issues such as stuttering due to it’s rather simplistic implementation.
This commit is contained in:
@@ -2,3 +2,8 @@ LIBRARY bsthook
|
||||
|
||||
EXPORTS
|
||||
DllMain@12 @1 NONAME
|
||||
|
||||
; Bemanitools 6 API
|
||||
bt_module_core_log_api_set
|
||||
bt_module_core_thread_api_set
|
||||
bt_module_hook_api_get
|
||||
+52
-54
@@ -2,37 +2,32 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "avs-ext/log.h"
|
||||
#include "avs-ext/thread.h"
|
||||
|
||||
#include "bsthook/acio.h"
|
||||
#include "bsthook/gfx.h"
|
||||
#include "bsthook/settings.h"
|
||||
|
||||
#include "iface-core/config.h"
|
||||
#include "iface-core/log.h"
|
||||
#include "iface-core/thread.h"
|
||||
|
||||
#include "iface-io/bst.h"
|
||||
#include "iface-io/eam.h"
|
||||
|
||||
#include "hook/iohook.h"
|
||||
|
||||
#include "hooklib/app.h"
|
||||
#include "hooklib/rs232.h"
|
||||
|
||||
#include "imports/avs.h"
|
||||
|
||||
#include "module/io-ext.h"
|
||||
|
||||
#include "sdk/module/core/log.h"
|
||||
#include "sdk/module/core/thread.h"
|
||||
#include "sdk/module/hook.h"
|
||||
|
||||
#include "util/cmdline.h"
|
||||
#include "util/defs.h"
|
||||
|
||||
static module_io_t *_bsthook_module_io_bst;
|
||||
static module_io_t *_bsthook_module_io_eam;
|
||||
|
||||
static bool my_dll_entry_init(char *sidcode, struct property_node *config);
|
||||
static bool my_dll_entry_main(void);
|
||||
|
||||
static void _bsthook_io_bst_init(module_io_t **module)
|
||||
{
|
||||
bt_io_bst_api_t api;
|
||||
@@ -53,10 +48,37 @@ static void _bsthook_io_eam_init(module_io_t **module)
|
||||
bt_io_eam_api_set(&api);
|
||||
}
|
||||
|
||||
static bool my_dll_entry_init(char *sidcode, struct property_node *config)
|
||||
static bool
|
||||
_bsthook_main_init(HMODULE game_module, const bt_core_config_t *config_)
|
||||
{
|
||||
int i;
|
||||
int argc;
|
||||
char **argv;
|
||||
bool ok;
|
||||
|
||||
args_recover(&argc, &argv);
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] != '-') {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (argv[i][1]) {
|
||||
case 'w':
|
||||
gfx_set_windowed();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
args_free(argc, argv);
|
||||
|
||||
iohook_push_handler(ac_io_bus_dispatch_irp);
|
||||
rs232_hook_init();
|
||||
|
||||
gfx_init();
|
||||
settings_hook_init();
|
||||
|
||||
log_info("--- Begin bsthook dll_entry_init ---");
|
||||
|
||||
log_info("Starting up BeatStream IO backend");
|
||||
@@ -81,7 +103,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *config)
|
||||
|
||||
log_info("--- End bsthook dll_entry_init ---");
|
||||
|
||||
return app_hook_invoke_init(sidcode, config);
|
||||
return true;
|
||||
|
||||
eam_io_fail:
|
||||
bt_io_bst_fini();
|
||||
@@ -94,12 +116,8 @@ bst_io_fail:
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool my_dll_entry_main(void)
|
||||
static void _bsthook_main_fini()
|
||||
{
|
||||
bool result;
|
||||
|
||||
result = app_hook_invoke_main();
|
||||
|
||||
log_info("Shutting down card reader backend");
|
||||
bt_io_eam_fini();
|
||||
|
||||
@@ -113,47 +131,27 @@ static bool my_dll_entry_main(void)
|
||||
module_io_free(&_bsthook_module_io_bst);
|
||||
|
||||
ac_io_bus_fini();
|
||||
}
|
||||
|
||||
return result;
|
||||
void bt_module_core_log_api_set(const bt_core_log_api_t *api)
|
||||
{
|
||||
bt_core_log_api_set(api);
|
||||
}
|
||||
|
||||
void bt_module_core_thread_api_set(const bt_core_thread_api_t *api)
|
||||
{
|
||||
bt_core_thread_api_set(api);
|
||||
}
|
||||
|
||||
void bt_module_hook_api_get(bt_hook_api_t *api)
|
||||
{
|
||||
api->version = 1;
|
||||
|
||||
api->v1.main_init = _bsthook_main_init;
|
||||
api->v1.main_fini = _bsthook_main_fini;
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx)
|
||||
{
|
||||
int i;
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
if (reason != DLL_PROCESS_ATTACH) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Use AVS APIs
|
||||
avs_ext_log_core_api_set();
|
||||
avs_ext_thread_core_api_set();
|
||||
|
||||
args_recover(&argc, &argv);
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] != '-') {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (argv[i][1]) {
|
||||
case 'w':
|
||||
gfx_set_windowed();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
args_free(argc, argv);
|
||||
|
||||
app_hook_init(my_dll_entry_init, my_dll_entry_main);
|
||||
iohook_push_handler(ac_io_bus_dispatch_irp);
|
||||
rs232_hook_init();
|
||||
|
||||
gfx_init();
|
||||
settings_hook_init();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user