Bug-fix: fix target dll searching logic
[platform/core/dotnet/launcher.git] / NativeLauncher / inc / path_manager.h
index 72dc042..b3bc88e 100644 (file)
  * limitations under the License.
  */
 
+#include <string>
+#include <vector>
+
 #ifndef __DLL_PATH_MANAGER_H__
 #define __DLL_PATH_MANAGER_H__
 
-int initializePathManager(const std::string& runtimeDir, const std::string& tizenFXDir, const std::string& extraDir);
-void finalizePathManager();
+/**
+ * This class helps to easily obtain paths that are frequently used in the implementation.
+ * The following paths are the major paths managed by this class.
+ *
+ * 1. Platform Assemblies Path
+ *    - Paths where the platform assemblies exist
+ *    - Installation directory of coreclr and tizenfx are included by default
+ *
+ * 2. Application Root Path
+ *    - Installation directory of a Tizen application associated with the current process
+ *    - bin, lib, data, res directories are under Application Root Path
+ *
+ * 3. AppPaths
+ *    - The ":" separated paths where applications's managed assemblies exist
+ *    - Returns the bin, lib, and .tac_symlink under AppRootPath
+ *    - ":" separated path list
+ *
+ * 4. AppNIPaths
+ *    - Paths where applications's native image files exist
+ *    - Returns bin/.native_image, lib/.native_image, and .tac_symlink under AppRootPath
+ *    - ":" separated path list
+ *
+ * 5. Native Dll Searching Path
+ *    - Path to find native libraries required by coreclr
+ *
+ * Platform Assemblies Path can be expanded through the addPlatformAssembliesPath () function.
+ * For example, middleware library path which is passed through plugin can be added to platform assemblies path.
+ *
+ * Application related path (AppPath / AppNIPaths / Native Dll Searching Path) is created based on AppRootPath.
+ * Therefore, it has a temporary location before the AppRootPath is set up,
+ * and has the actual location after the setAppRootPath() function is called.
+*/
+class PathManager
+{
+public:
+       /**
+        * @brief Platform defined path (runtime and tizenfx path) is set by default
+        *        Temporal application root path is set by default, and paths which based on application root path is also set.
+        *        These paths are updated by calling @setAppRootPath()
+        */
+       PathManager();
+
+       /**
+        * @brief destructor
+        */
+       ~PathManager();
+
+       /**
+        * @brief Add platform assemblies paths. The TPA(Trusted-Platform-Assembly) is generated based on this paths
+        * @param[in] paths the paths to be added
+        * @param[in] isHighPriority if true, paths are added in front of the current list, otherwise added at the end of the list
+        */
+       void addPlatformAssembliesPaths(const std::string& paths, bool isHighPriority = false);
+
+       /**
+        * @brief Add native dll searching paths.
+        * @param[in] paths the paths to be added
+        * @param[in] isHighPriority if true, paths are added in front of the current list, otherwise added at the end of the list
+        */
+       void addNativeDllSearchingPaths(const std::string& paths, bool isHighPriority = false);
+
+       /**
+        * @brief Set application root path.
+        *        All application related paths ("bin", "lib", ".tac_symlink", ".native_image") are generated based on it.
+        *        A temporary path (/proc/self/fd/[fd]) is used if this function is never called.
+        * @param[in] rootPath application root path
+        */
+       void setAppRootPath(const std::string& rootPath);
+
+       /**
+        * @brief Get runtime path which contains coreclr and corefx
+        * @return runtime path
+        */
+       const std::string& getRuntimePath();
+
+       /**
+        * @brief Get tizenfx path which contains tizenfx
+        * @return runtime path
+        */
+       const std::string& getTizenFXPath();
+
+       /**
+        * @brief Get platform assemblies paths
+        * @return return path vector
+        */
+       const std::vector<std::string>& getPlatformAssembliesPaths();
+
+       /**
+        * @brief Get application root path
+        * @see setAppRootPath()
+        * @return system paths
+        */
+       const std::string& getAppRootPath();
+
+       /**
+        * @brief Get the path of .tac_symlink of application
+        * @return .tac_symlink path
+        */
+       const std::string& getAppTacPath();
+
+       /**
+        * @brief Get the list of directories where the assemlies of this application exist
+        * @return the list(":" seperated) of paths to probe in for an assembly
+        */
+       const std::string& getAppPaths();
+
+       /**
+        * @brief Get the list of directories where the native image of this application exist
+        * @return the list(":" seperated) of paths to probe in for an native image
+        */
+       const std::string& getAppNIPaths();
+
+       /**
+        * @brief Set addtional dll searching path for App.
+        * @param[in] paths path
+        */
+       void setExtraDllPaths(const char* paths);
+
+       /**
+        * @brief Get the list of directories where the native libraries of this application exist
+        * @return the list(":" seperated) of paths the loader should probe when looking for native libraries
+        */
+       const std::string& getNativeDllSearchingPaths();
 
-std::string getRuntimeDir();
-std::string getTizenFXDir();
-std::string getTizenFXRefDir();
-std::string getExtraDirs();
+private:
+       /**
+        * @brief Update application related path (bin, lib, tac_symlink, native_image)
+        *        In most cases, appRootPath and appNIRootPath are the same.
+        *        Apps installed in read-only storage may have a different appNIRootPath.
+        * @param[in] root path of application. (APP_PATH is geneated based on root path)
+        * @param[in] root path for native image (APP_NI_PATH is generated based on on ni root path )
+        */
+       void updateAppRelatedPath(const std::string& appRootPath, const std::string& appNIRootPath);
 
-std::string getTPA();
+private:
+       std::vector<std::string> platformAssembliesPaths;
+       std::string systemPaths;
+       std::string appRootPath;
+       std::string appNIRootPath;
+       std::string runtimePath;
+       std::string tizenfxPath;
+       std::string appPaths;
+       std::string appNIPaths;
+       std::string nativeDllSearchingPaths;
+       std::string appTacPath;
+       std::string extraDllPaths;
+       int rootFD;
+       int niRootFD;
+};
 
-#endif /* __DLL_PATH_MANAGER_H__ */
\ No newline at end of file
+#endif /* __DLL_PATH_MANAGER_H__ */