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.
17 #include <sys/types.h>
27 #include "path_manager.h"
28 #include "plugin_manager.h"
31 static const char* __TIZEN_API_PATH_KEY = "db/dotnet/tizen_api_path";
32 static const char* __TIZEN_RID_VERSION_KEY = "db/dotnet/tizen_rid_version";
35 #define __STR(x) __XSTR(x)
36 static const char* __DEVICE_API_DIR = __STR(DEVICE_API_DIR);
37 static const char* __RUNTIME_DIR = __STR(RUNTIME_DIR);
38 static const char* __NATIVE_LIB_DIR = __STR(NATIVE_LIB_DIR);
42 // The sequence of RID_FALLBACK graphs must be:
43 // 1. Tizen + Version + Architecture
45 // 3. OS(tizen, linux, unix) + Architecture
46 // 4. OS(tizen, linux, unix)
48 static std::string getExtraNativeLibDirs(const std::string& appRoot)
50 std::vector<std::string> RID_FALLBACK_GRAPH;
51 char* tizen_rid = vconf_get_str(__TIZEN_RID_VERSION_KEY);
53 std::vector<std::string> version;
54 splitPath(tizen_rid, version);
55 std::reverse(std::begin(version), std::end(version));
56 for (unsigned int i = 0; i < version.size(); i++) {
57 RID_FALLBACK_GRAPH.push_back(std::string("tizen." + version[i] + "-" + ARCHITECTURE_IDENTIFIER));
58 RID_FALLBACK_GRAPH.push_back(std::string("tizen." + version[i]));
63 std::vector<std::string> RID_FALLBACK_OS = {"tizen", "linux", "unix"};
64 for (unsigned int i = 0; i < RID_FALLBACK_OS.size(); i++) {
65 RID_FALLBACK_GRAPH.push_back(std::string(RID_FALLBACK_OS[i] + "-" + ARCHITECTURE_IDENTIFIER));
66 RID_FALLBACK_GRAPH.push_back(std::string(RID_FALLBACK_OS[i]));
68 RID_FALLBACK_GRAPH.push_back("any");
69 RID_FALLBACK_GRAPH.push_back("base");
71 std::string candidate;
72 for (unsigned int i = 0; i < RID_FALLBACK_GRAPH.size(); i++) {
73 if (!candidate.empty()) {
76 candidate += concatPath(appRoot, "bin/runtimes/" + RID_FALLBACK_GRAPH[i] + "/native");
79 candidate = candidate + ":" + concatPath(appRoot, "lib/" ARCHITECTURE_IDENTIFIER);
80 if (!strncmp(ARCHITECTURE_IDENTIFIER, "arm64", 5)) {
81 candidate = candidate + ":" + concatPath(appRoot, "lib/aarch64");
82 } else if (!strncmp(ARCHITECTURE_IDENTIFIER, "armel", 5)) {
83 candidate = candidate + ":" + concatPath(appRoot, "lib/arm");
89 void PathManager::updateAppRelatedPath(const std::string& appRootPath)
91 std::string appBinPath = concatPath(appRootPath, "bin");
92 std::string appLibPath = concatPath(appRootPath, "lib");
94 appTacPath = concatPath(appBinPath, TAC_SYMLINK_SUB_DIR);
95 appPaths = appRootPath + ":" + appBinPath + ":" + appLibPath + ":" + appTacPath;
96 appNIPaths = concatPath(appBinPath, APP_NI_SUB_DIR) + ":" + concatPath(appLibPath, APP_NI_SUB_DIR) + ":"+ appTacPath;
97 nativeDllSearchingPaths = runtimePath + ":" + __NATIVE_LIB_DIR + ":" + getExtraNativeLibDirs(appRootPath) + ":" + appBinPath + ":" + appLibPath;
100 PathManager::PathManager() :
104 runtimePath = getAbsolutePath(__RUNTIME_DIR);
105 platformAssembliesPaths.push_back(runtimePath);
108 char* tmp = vconf_get_str(__TIZEN_API_PATH_KEY);
110 tizenfxPath = std::string(tmp);
111 _DBG("Device API Directory is set by vconf : %s", tmp);
114 tizenfxPath = getAbsolutePath(__DEVICE_API_DIR);
116 platformAssembliesPaths.push_back(tizenfxPath);
117 platformAssembliesPaths.push_back(tizenfxPath + "/ref");
119 // set temporal application root path for candidate process
120 rootFD = open("/proc/self", O_DIRECTORY);
122 _ERR("Failed to open /proc/self");
123 throw std::ios_base::failure("Fail to open /proc/self");
126 appRootPath = std::string("/proc/self/fd/") + std::to_string(rootFD);
127 updateAppRelatedPath(appRootPath);
129 _INFO("Path manager created successfully");
132 PathManager::~PathManager()
134 _INFO("Path manager destroyed");
137 // paths: ":" separated muliple path.
138 void PathManager::addPlatformAssembliesPaths(const std::string& paths, bool isHighPriority)
140 std::vector<std::string>::iterator it;
141 std::vector<std::string> pathVec;
142 splitPath(paths, pathVec);
144 for (unsigned int i = 0; i < pathVec.size(); i++) {
145 pathVec[i] = getAbsolutePath(pathVec[i]);
148 if (isHighPriority) {
149 it = platformAssembliesPaths.begin();
151 it = platformAssembliesPaths.end();
154 platformAssembliesPaths.insert(it, pathVec.begin(), pathVec.end());
157 void PathManager::setAppRootPath(const std::string& rootPath)
159 // override root path for application launch mode (candidate / standalone mode)
161 int tmpFD = open(rootPath.c_str(), O_DIRECTORY);
162 dup3(tmpFD, rootFD, O_CLOEXEC);
167 appRootPath = getAbsolutePath(rootPath);
168 updateAppRelatedPath(appRootPath);
171 const std::string& PathManager::getRuntimePath()
176 const std::string& PathManager::getTizenFXPath()
181 // return platform assembly paths
182 const std::vector<std::string>& PathManager::getPlatformAssembliesPaths()
184 return platformAssembliesPaths;
187 // return app root path
188 const std::string& PathManager::getAppRootPath()
193 // return .tac_symlink path
194 const std::string& PathManager::getAppTacPath()
199 // return dll searching paths for app
200 const std::string& PathManager::getAppPaths()
205 // return ni dll searching paths for app
206 const std::string& PathManager::getAppNIPaths()
211 // return native dll searching paths for app
212 const std::string& PathManager::getNativeDllSearchingPaths()
214 return nativeDllSearchingPaths;