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.
24 #include "plugin_manager.h"
27 static const char* __TIZEN_API_PATH_KEY = "db/dotnet/tizen_api_path";
30 #define __STR(x) __XSTR(x)
31 static const char* __DEVICE_API_DIR = __STR(DEVICE_API_DIR);
32 static const char* __RUNTIME_DIR = __STR(RUNTIME_DIR);
36 typedef struct DllPath {
37 std::string runtime_dir;
38 std::string tizenfx_dir;
39 std::string tizenfx_ref_dir;
40 std::vector<std::string> extra_dirs;
41 std::vector<std::string> plugin_dirs;
44 static DllPath* __dllPath = nullptr;
45 static std::string __tpa;
46 bool initializedPathManager = false;
48 // on success, return 0. otherwise return -1.
49 int initializePathManager(const std::string& runtimeDir, const std::string& tizenFXDir, const std::string& extraDir)
51 if (initializedPathManager) {
52 _INFO("Path manager already initialized");
56 __dllPath = new DllPath();
58 _ERR("fail to allocate memory for dll path structure\n");
62 if (!runtimeDir.empty()) {
63 __dllPath->runtime_dir = getAbsolutePath(runtimeDir);
65 __dllPath->runtime_dir = getAbsolutePath(__RUNTIME_DIR);
68 if (!tizenFXDir.empty()) {
69 __dllPath->tizenfx_dir = getAbsolutePath(tizenFXDir);
71 char* tmp = vconf_get_str(__TIZEN_API_PATH_KEY);
73 __dllPath->tizenfx_dir = std::string(tmp);
74 _DBG("Device API Directory is set by vconf : %s", tmp);
77 __dllPath->tizenfx_dir = getAbsolutePath(__DEVICE_API_DIR);
81 __dllPath->tizenfx_ref_dir = __dllPath->tizenfx_dir + "/ref";
83 // ":" seperated extra directories
84 if (!extraDir.empty()) {
85 splitPath(extraDir, __dllPath->extra_dirs);
88 char* pluginPath = pluginGetDllPath();
90 splitPath(pluginPath, __dllPath->plugin_dirs);
93 _INFO("Path manager initialize success");
95 initializedPathManager = true;
99 void finalizePathManager()
101 _INFO("Path manager finalize called");
107 initializedPathManager = false;
110 std::string getRuntimeDir()
112 return __dllPath->runtime_dir;
115 std::string getTizenFXDir()
117 return __dllPath->tizenfx_dir;
120 std::string getTizenFXRefDir()
122 return __dllPath->tizenfx_ref_dir;
125 std::vector<std::string> getExtraDirs()
127 return __dllPath->extra_dirs;
130 std::vector<std::string> getPluginDirs()
132 return __dllPath->plugin_dirs;
135 static std::string getPlatformTPA()
137 std::string platform_tpa;
139 if (isFile(PLATFORM_TPA_CACHE)) {
140 _INFO("platform tpa cache found.");
141 std::ifstream cacheFile;
142 cacheFile.open(PLATFORM_TPA_CACHE);
143 std::getline(cacheFile, platform_tpa);
146 std::vector<std::string> tpaDirs = { getRuntimeDir(), getTizenFXDir(), getTizenFXRefDir() };
147 tpaDirs.insert(tpaDirs.end(), getExtraDirs().begin(), getExtraDirs().end());
148 addAssembliesFromDirectories(tpaDirs, platform_tpa);
154 static std::string getPluginTPA()
156 std::string plugin_tpa;
157 char* plugin_tpa_list = pluginGetTPA();
158 if (plugin_tpa_list) {
159 _INFO("plugin TPA list found. use TPA list for plugin");
160 plugin_tpa = plugin_tpa_list;
161 } else if (!getPluginDirs().empty()) {
162 _INFO("Plugin directory found. use plugin directroy for TPA");
163 addAssembliesFromDirectories(getPluginDirs(), plugin_tpa);
171 if (!__tpa.empty()) {
175 if (__dllPath == NULL) {
176 return std::string("");
179 return getPlatformTPA() + ":" + getPluginTPA();