support launcher plugin 22/135522/1 submit/tizen/20170714.002938
authorCho Woong Suk <ws77.cho@samsung.com>
Fri, 23 Jun 2017 01:29:44 +0000 (10:29 +0900)
committerCho Woong Suk <ws77.cho@samsung.com>
Fri, 23 Jun 2017 01:29:44 +0000 (10:29 +0900)
Change-Id: Ie992819b4918e65fd733edec2e46136324c59e0e

NativeLauncher/launcher/dotnet/dotnet_launcher.cc
NativeLauncher/launcher/dotnet/dotnet_launcher.h
NativeLauncher/launcher/main.cc

index d01c155..6724558 100644 (file)
@@ -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<std::string> 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());
 
index 1e9bee7..931846c 100644 (file)
@@ -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
index 7063a2d..b5fdb17 100644 (file)
@@ -126,5 +126,6 @@ int main(int argc, char *argv[])
                Launchpad.loaderMain(argc, argv);
        }
 
+       runtime->dispose();
        return 0;
 }