Add plugin api to add native dll searching path (#343)
[platform/core/dotnet/launcher.git] / NativeLauncher / inc / path_manager.h
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <string>
18 #include <vector>
19
20 #ifndef __DLL_PATH_MANAGER_H__
21 #define __DLL_PATH_MANAGER_H__
22
23 /**
24  * This class helps to easily obtain paths that are frequently used in the implementation.
25  * The following paths are the major paths managed by this class.
26  *
27  * 1. Platform Assemblies Path
28  *    - Paths where the platform assemblies exist
29  *    - Installation directory of coreclr and tizenfx are included by default
30  *
31  * 2. Application Root Path
32  *    - Installation directory of a Tizen application associated with the current process
33  *    - bin, lib, data, res directories are under Application Root Path
34  *
35  * 3. AppPaths
36  *    - The ":" separated paths where applications's managed assemblies exist
37  *    - Returns the bin, lib, and .tac_symlink under AppRootPath
38  *    - ":" separated path list
39  *
40  * 4. AppNIPaths
41  *    - Paths where applications's native image files exist
42  *    - Returns bin/.native_image, lib/.native_image, and .tac_symlink under AppRootPath
43  *    - ":" separated path list
44  *
45  * 5. Native Dll Searching Path
46  *    - Path to find native libraries required by coreclr
47  *
48  * Platform Assemblies Path can be expanded through the addPlatformAssembliesPath () function.
49  * For example, middleware library path which is passed through plugin can be added to platform assemblies path.
50  *
51  * Application related path (AppPath / AppNIPaths / Native Dll Searching Path) is created based on AppRootPath.
52  * Therefore, it has a temporary location before the AppRootPath is set up,
53  * and has the actual location after the setAppRootPath() function is called.
54 */
55 class PathManager
56 {
57 public:
58         /**
59          * @brief Platform defined path (runtime and tizenfx path) is set by default
60          *        Temporal application root path is set by default, and paths which based on application root path is also set.
61          *        These paths are updated by calling @setAppRootPath()
62          */
63         PathManager();
64
65         /**
66          * @brief destructor
67          */
68         ~PathManager();
69
70         /**
71          * @brief Add platform assemblies paths. The TPA(Trusted-Platform-Assembly) is generated based on this paths
72          * @param[in] paths the paths to be added
73          * @param[in] isHighPriority if true, paths are added in front of the current list, otherwise added at the end of the list
74          */
75         void addPlatformAssembliesPaths(const std::string& paths, bool isHighPriority = false);
76
77         /**
78          * @brief Add native dll searching paths.
79          * @param[in] paths the paths to be added
80          * @param[in] isHighPriority if true, paths are added in front of the current list, otherwise added at the end of the list
81          */
82         void addNativeDllSearchingPaths(const std::string& paths, bool isHighPriority = false);
83
84         /**
85          * @brief Set application root path.
86          *        All application related paths ("bin", "lib", ".tac_symlink", ".native_image") are generated based on it.
87          *        A temporary path (/proc/self/fd/[fd]) is used if this function is never called.
88          * @param[in] rootPath application root path
89          */
90         void setAppRootPath(const std::string& rootPath);
91
92         /**
93          * @brief Get runtime path which contains coreclr and corefx
94          * @return runtime path
95          */
96         const std::string& getRuntimePath();
97
98         /**
99          * @brief Get tizenfx path which contains tizenfx
100          * @return runtime path
101          */
102         const std::string& getTizenFXPath();
103
104         /**
105          * @brief Get platform assemblies paths
106          * @return return path vector
107          */
108         const std::vector<std::string>& getPlatformAssembliesPaths();
109
110         /**
111          * @brief Get application root path
112          * @see setAppRootPath()
113          * @return system paths
114          */
115         const std::string& getAppRootPath();
116
117         /**
118          * @brief Get the path of .tac_symlink of application
119          * @return .tac_symlink path
120          */
121         const std::string& getAppTacPath();
122
123         /**
124          * @brief Get the list of directories where the assemlies of this application exist
125          * @return the list(":" seperated) of paths to probe in for an assembly
126          */
127         const std::string& getAppPaths();
128
129         /**
130          * @brief Get the list of directories where the native image of this application exist
131          * @return the list(":" seperated) of paths to probe in for an native image
132          */
133         const std::string& getAppNIPaths();
134
135         /**
136          * @brief Get the list of directories where the native libraries of this application exist
137          * @return the list(":" seperated) of paths the loader should probe when looking for native libraries
138          */
139         const std::string& getNativeDllSearchingPaths();
140
141 private:
142         /**
143          * @brief Update application related path (bin, lib, tac_symlink, native_image)
144          *        In most cases, appRootPath and appNIRootPath are the same.
145          *        Apps installed in read-only storage may have a different appNIRootPath.
146          * @param[in] root path of application. (APP_PATH is geneated based on root path)
147          * @param[in] root path for native image (APP_NI_PATH is generated based on on ni root path )
148          */
149         void updateAppRelatedPath(const std::string& appRootPath, const std::string& appNIRootPath);
150
151 private:
152         std::vector<std::string> platformAssembliesPaths;
153         std::string systemPaths;
154         std::string appRootPath;
155         std::string appNIRootPath;
156         std::string runtimePath;
157         std::string tizenfxPath;
158         std::string appPaths;
159         std::string appNIPaths;
160         std::string nativeDllSearchingPaths;
161         std::string appTacPath;
162         int rootFD;
163         int niRootFD;
164 };
165
166 #endif /* __DLL_PATH_MANAGER_H__ */