From 84ed68ad40c96b66f7d7c559855534c2b4f9f65a Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Fri, 23 Jun 2017 10:29:44 +0900 Subject: [PATCH] support launcher plugin Change-Id: Ie992819b4918e65fd733edec2e46136324c59e0e --- NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 59 ++++++++++++++++++++++- NativeLauncher/launcher/dotnet/dotnet_launcher.h | 22 +++++++++ NativeLauncher/launcher/main.cc | 1 + 3 files changed, 81 insertions(+), 1 deletion(-) diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index d01c155..6724558 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -26,6 +26,8 @@ #include "launcher.h" #include "dotnet_launcher.h" +#define PLUGIN_PATH "/usr/share/dotnet.tizen/lib/libdotnet_plugin.so" + namespace tizen { namespace runtime { namespace dotnetcore { @@ -39,7 +41,14 @@ CoreRuntime::CoreRuntime() : __hostHandle(nullptr), __domainId(-1), preparedFunction(nullptr), - launchFunction(nullptr) + launchFunction(nullptr), + __pluginLib(nullptr), + pluginInitialize(nullptr), + pluginPreload(nullptr), + pluginSetAppInfo(nullptr), + pluginGetDllPath(nullptr), + pluginBeforeExecute(nullptr), + pluginFinalize(nullptr) { #define __XSTR(x) #x #define __STR(x) __XSTR(x) @@ -63,6 +72,22 @@ CoreRuntime::CoreRuntime() : #undef __STR #undef __XSTR + // support launcher plugin + if (!fileNotExist(PLUGIN_PATH)) { + __pluginLib = dlopen(PLUGIN_PATH, RTLD_NOW | RTLD_LOCAL); + if (__pluginLib) { + pluginInitialize = (plugin_initialize_ptr)dlsym(__pluginLib, "plugin_initialize"); + pluginPreload = (plugin_preload_ptr)dlsym(__pluginLib, "plugin_preload"); + pluginSetAppInfo = (plugin_set_app_info_ptr)dlsym(__pluginLib, "plugin_set_app_info"); + pluginGetDllPath = (plugin_get_dll_path_ptr)dlsym(__pluginLib, "plugin_get_dll_path"); + pluginBeforeExecute = (plugin_before_execute_ptr)dlsym(__pluginLib, "plugin_before_execute"); + pluginFinalize = (plugin_finalize_ptr)dlsym(__pluginLib, "plugin_finalize"); + } + } + + if (pluginInitialize) + pluginInitialize(); + _DBG("Constructor called!!"); } @@ -159,6 +184,9 @@ int CoreRuntime::initialize(bool standalone) _DBG("this addr : %x", this); _DBG("coreclr_initialize : %x", initializeClr); + if (!standalone && pluginPreload) + pluginPreload(); + return 0; } @@ -256,6 +284,22 @@ void CoreRuntime::dispose() __coreclrLib = nullptr; + if (pluginFinalize) + pluginFinalize(); + + if (__pluginLib != nullptr) { + if (dlclose(__pluginLib) != 0) + _ERR("libdotnet_plugin.so close failed"); + + __pluginLib = nullptr; + pluginInitialize = nullptr; + pluginPreload = nullptr; + pluginSetAppInfo = nullptr; + pluginGetDllPath = nullptr; + pluginBeforeExecute = nullptr; + pluginFinalize = nullptr; + } + _DBG("Dotnet runtime disposed"); } @@ -271,6 +315,9 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i return 1; } + if (pluginSetAppInfo) + pluginSetAppInfo(appId, path); + std::string tpa; std::string appRoot = root; std::string appBin = concatPath(appRoot, "bin"); @@ -280,6 +327,13 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i std::vector searchDirectories; searchDirectories.push_back(appBin); searchDirectories.push_back(appLib); + if (pluginGetDllPath) { + std::string pluginPath = pluginGetDllPath(); + if (!pluginPath.empty()) { + probePath = probePath + ":" + pluginPath; + searchDirectories.push_back(pluginPath); + } + } searchDirectories.push_back(__runtimeDirectory); searchDirectories.push_back(__deviceAPIDirectory); searchDirectories.push_back(__refAPIDirectory); @@ -289,6 +343,9 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i assembliesInDirectory(searchDirectories, tpa); + if (pluginBeforeExecute) + pluginBeforeExecute(); + #ifdef USE_MANAGED_LAUNCHER runManagedLauncher(appId, probePath.c_str(), tpa.c_str()); diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.h b/NativeLauncher/launcher/dotnet/dotnet_launcher.h index 1e9bee7..931846c 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.h +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.h @@ -49,6 +49,20 @@ extern "C" const char* entryPointTypeName, const char* entryPointMethodName, void** delegate); + + typedef void (*plugin_initialize_ptr)(); + + typedef void (*plugin_preload_ptr)(); + + typedef void (*plugin_set_app_info_ptr)( + const char* appId, + const char* hostHandle); + + typedef char* (*plugin_get_dll_path_ptr)(); + + typedef void (*plugin_before_execute_ptr)(); + + typedef void (*plugin_finalize_ptr)(); } namespace tizen { @@ -84,6 +98,14 @@ class CoreRuntime : public tizen::runtime::LauncherInterface unsigned int __domainId; PreparedFunctionPtr preparedFunction; LaunchFunctionPtr launchFunction; + // plugin function pointer + void* __pluginLib; + plugin_initialize_ptr pluginInitialize; + plugin_preload_ptr pluginPreload; + plugin_set_app_info_ptr pluginSetAppInfo; + plugin_get_dll_path_ptr pluginGetDllPath; + plugin_before_execute_ptr pluginBeforeExecute; + plugin_finalize_ptr pluginFinalize; }; } // dotnetcore diff --git a/NativeLauncher/launcher/main.cc b/NativeLauncher/launcher/main.cc index 7063a2d..b5fdb17 100644 --- a/NativeLauncher/launcher/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -126,5 +126,6 @@ int main(int argc, char *argv[]) Launchpad.loaderMain(argc, argv); } + runtime->dispose(); return 0; } -- 2.7.4