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 __pluginFunc = (PluginFunc*)calloc(sizeof(PluginFunc), 1);
39 _ERR("fail to allocate memory for plugin function structure");
44 __pluginFunc->initialize = (plugin_initialize_ptr)dlsym(__pluginLib, "plugin_initialize");
45 __pluginFunc->preload = (plugin_preload_ptr)dlsym(__pluginLib, "plugin_preload");
46 __pluginFunc->has_log_control = (plugin_has_log_control_ptr)dlsym(__pluginLib, "plugin_has_log_control");
47 __pluginFunc->set_app_info = (plugin_set_app_info_ptr)dlsym(__pluginLib, "plugin_set_app_info");
48 __pluginFunc->set_coreclr_info = (plugin_set_coreclr_info_ptr)dlsym(__pluginLib, "plugin_set_coreclr_info");
49 __pluginFunc->get_dll_path = (plugin_get_dll_path_ptr)dlsym(__pluginLib, "plugin_get_dll_path");
50 __pluginFunc->get_native_dll_searching_path = (plugin_get_native_dll_searching_path_ptr)dlsym(__pluginLib, "plugin_get_native_dll_searching_path");
51 __pluginFunc->get_tpa = (plugin_get_tpa_ptr)dlsym(__pluginLib, "plugin_get_tpa");
52 __pluginFunc->before_execute = (plugin_before_execute_ptr)dlsym(__pluginLib, "plugin_before_execute");
53 __pluginFunc->finalize = (plugin_finalize_ptr)dlsym(__pluginLib, "plugin_finalize");
56 if (__pluginFunc->initialize)
57 __pluginFunc->initialize(appType);
60 _INFO("Plugin manager initialize success : appType(%s)", appType);
62 initializedPluginManager = true;
66 void finalizePluginManager()
68 if (!initializedPluginManager)
71 _INFO("Plugin manager finalize called");
83 initializedPluginManager = false;
88 if (__pluginFunc && __pluginFunc->preload) {
89 __pluginFunc->preload();
93 bool pluginHasLogControl()
95 if (__pluginFunc && __pluginFunc->has_log_control) {
96 return __pluginFunc->has_log_control();
102 void pluginSetAppInfo(const char* appId, const char* managedAssemblyPath)
104 if (__pluginFunc && __pluginFunc->set_app_info) {
105 __pluginFunc->set_app_info(appId, managedAssemblyPath);
109 void pluginSetCoreclrInfo(void* hostHandle, unsigned int domainId, coreclr_create_delegate_ptr delegateFunc)
111 if (__pluginFunc && __pluginFunc->set_coreclr_info) {
112 __pluginFunc->set_coreclr_info(hostHandle, domainId, delegateFunc);
116 char* pluginGetDllPath()
118 if (__pluginFunc && __pluginFunc->get_dll_path) {
119 return __pluginFunc->get_dll_path();
125 char* pluginGetNativeDllSearchingPath()
127 if (__pluginFunc && __pluginFunc->get_native_dll_searching_path) {
128 return __pluginFunc->get_native_dll_searching_path();
136 if (__pluginFunc && __pluginFunc->get_tpa) {
137 return __pluginFunc->get_tpa();
143 void pluginBeforeExecute()
145 if (__pluginFunc && __pluginFunc->before_execute) {
146 __pluginFunc->before_execute();
150 void pluginFinalize()
152 if (__pluginFunc && __pluginFunc->finalize) {
153 __pluginFunc->finalize();