2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "plugin_manager.h"
23 static PluginFunc* __pluginFunc = NULL;
24 static void* __pluginLib;
25 bool initializedPluginManager = false;
27 int initializePluginManager(const char* appType)
29 if (initializedPluginManager) {
30 _INFO("Plugin manager already initialized");
34 if (isFile(PLUGIN_PATH)) {
35 __pluginLib = dlopen(PLUGIN_PATH, RTLD_NOW | RTLD_LOCAL | RTLD_NODELETE);
37 _ERR("fail to dlopen plugin library");
41 __pluginFunc = (PluginFunc*)calloc(sizeof(PluginFunc), 1);
43 _ERR("fail to allocate memory for plugin function structure");
48 __pluginFunc->initialize = (plugin_initialize_ptr)dlsym(__pluginLib, "plugin_initialize");
49 __pluginFunc->preload = (plugin_preload_ptr)dlsym(__pluginLib, "plugin_preload");
50 __pluginFunc->has_log_control = (plugin_has_log_control_ptr)dlsym(__pluginLib, "plugin_has_log_control");
51 __pluginFunc->set_app_info = (plugin_set_app_info_ptr)dlsym(__pluginLib, "plugin_set_app_info");
52 __pluginFunc->set_coreclr_info = (plugin_set_coreclr_info_ptr)dlsym(__pluginLib, "plugin_set_coreclr_info");
53 __pluginFunc->get_dll_path = (plugin_get_dll_path_ptr)dlsym(__pluginLib, "plugin_get_dll_path");
54 __pluginFunc->get_extra_dll_path = (plugin_get_extra_dll_path_ptr)dlsym(__pluginLib, "plugin_get_extra_dll_path");
55 __pluginFunc->get_native_dll_searching_path = (plugin_get_native_dll_searching_path_ptr)dlsym(__pluginLib, "plugin_get_native_dll_searching_path");
56 __pluginFunc->get_tpa = (plugin_get_tpa_ptr)dlsym(__pluginLib, "plugin_get_tpa");
57 __pluginFunc->before_execute = (plugin_before_execute_ptr)dlsym(__pluginLib, "plugin_before_execute");
58 __pluginFunc->finalize = (plugin_finalize_ptr)dlsym(__pluginLib, "plugin_finalize");
61 if (__pluginFunc && __pluginFunc->initialize)
62 __pluginFunc->initialize(appType);
64 initializedPluginManager = true;
66 _INFO("Plugin manager initialize success : appType(%s)", appType);
71 void finalizePluginManager()
73 if (!initializedPluginManager)
76 _INFO("Plugin manager finalize called");
88 initializedPluginManager = false;
93 if (__pluginFunc && __pluginFunc->preload) {
94 __pluginFunc->preload();
98 bool pluginHasLogControl()
100 if (__pluginFunc && __pluginFunc->has_log_control) {
101 return __pluginFunc->has_log_control();
107 void pluginSetAppInfo(const char* appId, const char* managedAssemblyPath)
109 if (__pluginFunc && __pluginFunc->set_app_info) {
110 __pluginFunc->set_app_info(appId, managedAssemblyPath);
114 void pluginSetCoreclrInfo(void* hostHandle, unsigned int domainId, coreclr_create_delegate_ptr delegateFunc)
116 if (__pluginFunc && __pluginFunc->set_coreclr_info) {
117 __pluginFunc->set_coreclr_info(hostHandle, domainId, delegateFunc);
121 char* pluginGetDllPath()
123 if (__pluginFunc && __pluginFunc->get_dll_path) {
124 return __pluginFunc->get_dll_path();
130 char* pluginGetExtraDllPath()
132 if (__pluginFunc && __pluginFunc->get_extra_dll_path) {
133 return __pluginFunc->get_extra_dll_path();
139 char* pluginGetNativeDllSearchingPath()
141 if (__pluginFunc && __pluginFunc->get_native_dll_searching_path) {
142 return __pluginFunc->get_native_dll_searching_path();
150 if (__pluginFunc && __pluginFunc->get_tpa) {
151 return __pluginFunc->get_tpa();
157 void pluginBeforeExecute()
159 if (__pluginFunc && __pluginFunc->before_execute) {
160 __pluginFunc->before_execute();
164 void pluginFinalize()
166 if (__pluginFunc && __pluginFunc->finalize) {
167 __pluginFunc->finalize();