mirror of
https://github.com/clangen/musikcube.git
synced 2024-11-19 20:13:36 +00:00
Added mcsdk_env_init and mcsdk_env_release
This commit is contained in:
parent
34c7afcb6a
commit
a74eb597ad
@ -64,7 +64,7 @@ using namespace musik::core::runtime;
|
||||
* globals
|
||||
*/
|
||||
|
||||
static std::mutex global_mutex;
|
||||
static std::recursive_mutex global_mutex;
|
||||
static bool environment_initialized = false;
|
||||
static mcsdk_context* plugin_context = nullptr;
|
||||
|
||||
@ -135,12 +135,8 @@ struct mcsdk_svc_indexer_callback_proxy: public sigslot::has_slots<> {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* mcsdk_context_*
|
||||
*/
|
||||
|
||||
mcsdk_export void mcsdk_context_init(mcsdk_context** context) {
|
||||
std::unique_lock<std::mutex> lock(global_mutex);
|
||||
mcsdk_export void mcsdk_env_init() {
|
||||
std::unique_lock<std::recursive_mutex> lock(global_mutex);
|
||||
|
||||
if (!environment_initialized) {
|
||||
std::locale locale = std::locale();
|
||||
@ -149,6 +145,26 @@ mcsdk_export void mcsdk_context_init(mcsdk_context** context) {
|
||||
debug::Start();
|
||||
environment_initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
mcsdk_export void mcsdk_env_release() {
|
||||
if (environment_initialized) {
|
||||
LibraryFactory::Instance().Shutdown();
|
||||
debug::Stop();
|
||||
environment_initialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* mcsdk_context_*
|
||||
*/
|
||||
|
||||
mcsdk_export void mcsdk_context_init(mcsdk_context** context) {
|
||||
std::unique_lock<std::recursive_mutex> lock(global_mutex);
|
||||
|
||||
if (!environment_initialized) {
|
||||
mcsdk_env_init();
|
||||
}
|
||||
|
||||
auto c = new mcsdk_context();
|
||||
memset(c, 0, sizeof(mcsdk_context));
|
||||
@ -193,7 +209,7 @@ mcsdk_export void mcsdk_context_init(mcsdk_context** context) {
|
||||
}
|
||||
|
||||
mcsdk_export void mcsdk_context_release(mcsdk_context** context) {
|
||||
std::unique_lock<std::mutex> lock(global_mutex);
|
||||
std::unique_lock<std::recursive_mutex> lock(global_mutex);
|
||||
|
||||
auto c = *context;
|
||||
auto internal = static_cast<mcsdk_context_internal*>(c->internal.opaque);
|
||||
|
@ -283,6 +283,13 @@ typedef struct mcsdk_audio_player_gain {
|
||||
|
||||
typedef bool (*mcsdk_svc_library_run_query_callback)(mcsdk_svc_library l, mcsdk_db_connection db, void* user_context);
|
||||
|
||||
/*
|
||||
* global setup
|
||||
*/
|
||||
|
||||
mcsdk_export void mcsdk_env_init();
|
||||
mcsdk_export void mcsdk_env_release();
|
||||
|
||||
/*
|
||||
* instance context
|
||||
*/
|
||||
|
@ -193,7 +193,7 @@ static void test_library(mcsdk_context* context) {
|
||||
mcsdk_svc_library_query_flag_synchronous);
|
||||
}
|
||||
|
||||
static void configure_environment() {
|
||||
static void configure_stderr() {
|
||||
const char* suffix = "stderr.log";
|
||||
char* dest_path = NULL;
|
||||
int length = mcsdk_env_get_path(mcsdk_path_type_data, NULL, 0) + strlen(suffix);
|
||||
@ -201,12 +201,13 @@ static void configure_environment() {
|
||||
mcsdk_env_get_path(mcsdk_path_type_data, dest_path, length);
|
||||
strncat(dest_path, suffix, length);
|
||||
freopen(dest_path, "w", stderr);
|
||||
printf("[configure_environment] stderr will be written to %s\n", dest_path);
|
||||
printf("[configure_stderr] stderr will be written to %s\n", dest_path);
|
||||
free(dest_path);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
configure_environment();
|
||||
configure_stderr();
|
||||
mcsdk_env_init();
|
||||
mcsdk_context* context = NULL;
|
||||
mcsdk_context_init(&context);
|
||||
if (context) {
|
||||
@ -220,5 +221,6 @@ int main(int argc, char** argv) {
|
||||
mcsdk_context_release(&context);
|
||||
printf("[main] context released\n");
|
||||
}
|
||||
mcsdk_env_release();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user