Support regen-app-ni for read-only app (#301)
[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 Set application root path.
79          *        All application related paths ("bin", "lib", ".tac_symlink", ".native_image") are generated based on it.
80          *        A temporary path (/proc/self/fd/[fd]) is used if this function is never called.
81          * @param[in] rootPath application root path
82          */
83         void setAppRootPath(const std::string& rootPath);
84
85         /**
86          * @brief Get runtime path which contains coreclr and corefx
87          * @return runtime path
88          */
89         const std::string& getRuntimePath();
90
91         /**
92          * @brief Get tizenfx path which contains tizenfx
93          * @return runtime path
94          */
95         const std::string& getTizenFXPath();
96
97         /**
98          * @brief Get platform assemblies paths
99          * @return return path vector
100          */
101         const std::vector<std::string>& getPlatformAssembliesPaths();
102
103         /**
104          * @brief Get application root path
105          * @see setAppRootPath()
106          * @return system paths
107          */
108         const std::string& getAppRootPath();
109
110         /**
111          * @brief Get the path of .tac_symlink of application
112          * @return .tac_symlink path
113          */
114         const std::string& getAppTacPath();
115
116         /**
117          * @brief Get the list of directories where the assemlies of this application exist
118          * @return the list(":" seperated) of paths to probe in for an assembly
119          */
120         const std::string& getAppPaths();
121
122         /**
123          * @brief Get the list of directories where the native image of this application exist
124          * @return the list(":" seperated) of paths to probe in for an native image
125          */
126         const std::string& getAppNIPaths();
127
128         /**
129          * @brief Get the list of directories where the native libraries of this application exist
130          * @return the list(":" seperated) of paths the loader should probe when looking for native libraries
131          */
132         const std::string& getNativeDllSearchingPaths();
133
134 private:
135         /**
136          * @brief Update application related path (bin, lib, tac_symlink, native_image)
137          *        In most cases, appRootPath and appNIRootPath are the same.
138          *        Apps installed in read-only storage may have a different appNIRootPath.
139          * @param[in] root path of application. (APP_PATH is geneated based on root path)
140          * @param[in] root path for native image (APP_NI_PATH is generated based on on ni root path )
141          */
142         void updateAppRelatedPath(const std::string& appRootPath, const std::string& appNIRootPath);
143
144 private:
145         std::vector<std::string> platformAssembliesPaths;
146         std::string systemPaths;
147         std::string appRootPath;
148         std::string appNIRootPath;
149         std::string runtimePath;
150         std::string tizenfxPath;
151         std::string appPaths;
152         std::string appNIPaths;
153         std::string nativeDllSearchingPaths;
154         std::string appTacPath;
155         int rootFD;
156         int niRootFD;
157 };
158
159 #endif /* __DLL_PATH_MANAGER_H__ */