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;
43 static DllPath* __dllPath = nullptr;
44 static std::string __tpa;
45 bool initializedPathManager = false;
47 // on success, return 0. otherwise return -1.
48 int initializePathManager(const std::string& runtimeDir, const std::string& tizenFXDir, const std::string& extraDir)
50 if (!initializedPathManager) {
51 __dllPath = new DllPath();
53 _ERR("fail to allocate memory for dll path structure\n");
57 if (!runtimeDir.empty()) {
58 __dllPath->runtime_dir = absolutePath(runtimeDir);
60 __dllPath->runtime_dir = absolutePath(__RUNTIME_DIR);
63 if (!tizenFXDir.empty()) {
64 __dllPath->tizenfx_dir = absolutePath(tizenFXDir);
66 char* tmp = vconf_get_str(__TIZEN_API_PATH_KEY);
68 __dllPath->tizenfx_dir = std::string(tmp);
69 _DBG("Device API Directory is set by vconf : %s", tmp);
71 __dllPath->tizenfx_dir = absolutePath(__DEVICE_API_DIR);
75 __dllPath->tizenfx_ref_dir = __dllPath->tizenfx_dir + "/ref";
77 // ":" seperated extra directories
78 if (!extraDir.empty()) {
79 splitPath(extraDir, __dllPath->extra_dirs);
81 char* extraPath = pluginGetDllPath();
83 splitPath(extraPath, __dllPath->extra_dirs);
87 _INFO("Path manager initialize success");
89 _INFO("Skip to initialize Path manager");
91 initializedPathManager = true;
95 void finalizePathManager()
101 initializedPathManager = false;
104 std::string getRuntimeDir()
106 return __dllPath->runtime_dir;
109 std::string getTizenFXDir()
111 return __dllPath->tizenfx_dir;
114 std::string getTizenFXRefDir()
116 return __dllPath->tizenfx_ref_dir;
119 std::vector <std::string> getExtraDirs()
121 return __dllPath->extra_dirs;
124 static std::string getPlatformTPA()
126 std::string platform_tpa;
128 if (isFileExist(PLATFORM_TPA_CACHE)) {
129 _INFO("platform tpa cache found.");
130 std::ifstream cacheFile;
131 cacheFile.open(PLATFORM_TPA_CACHE);
132 std::getline(cacheFile, platform_tpa);
135 std::vector<std::string> tpaDir;
136 tpaDir.push_back(getRuntimeDir());
137 tpaDir.push_back(getTizenFXDir());
138 tpaDir.push_back(getTizenFXRefDir());
139 assembliesInDirectory(tpaDir, platform_tpa);
145 static std::string getPluginTPA()
147 std::string plugin_tpa;
149 char* plugin_tpa_list = pluginGetTPA();
150 if (plugin_tpa_list) {
151 _INFO("plugin TPA list found. use TPA list for plugin");
152 plugin_tpa = plugin_tpa_list;
153 } else if (!__dllPath->extra_dirs.empty()){
154 _INFO("plugin extra directory found. use plugin extra directroy for TPA");
155 assembliesInDirectory(__dllPath->extra_dirs, plugin_tpa);
163 if (!__tpa.empty()) {
167 if (__dllPath == NULL) {
168 return std::string("");
171 return getPlatformTPA() + ":" + getPluginTPA();