generate native image files in the .native_image folder for the pkg aot.
[platform/core/dotnet/launcher.git] / NativeLauncher / inc / utils.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 #ifndef __UTILS_H__
18 #define __UTILS_H__
19
20 #include <string>
21 #include <vector>
22 #include <functional>
23
24 #include <launcher_env.h>
25
26 #ifndef PATH_SEPARATOR
27 #define PATH_SEPARATOR '/'
28 #endif
29
30 /**
31  * @brief get current executable path
32  * return std::string path
33  */
34 std::string readSelfPath();
35
36 /**
37  * @brief concat path with PATH_SEPARATOR
38  * @param[in] destination path
39  * @param[in] source path
40  * return std::string result path
41  */
42 std::string concatPath(const std::string& path1, const std::string& path2);
43
44 /**
45  * @brief get absolute Path
46  * @param[in] source path
47  * return std::string result path
48  */
49 std::string absolutePath(const std::string& path);
50
51 /**
52  * @brief get the directory of file
53  * @param[in] source path
54  * return std::string result path
55  */
56 std::string baseName(const std::string& path);
57
58 /**
59  * @brief split path with ":" delimiter and put that in the vector
60  * @param[in] source path
61  * @param[out] string vector
62  */
63 void splitPath(const std::string& path, std::vector<std::string>& out);
64
65 /**
66  * @brief check file is exist
67  * @param[in] source path
68  * @return bool
69  */
70 bool isFileExist(const std::string& path);
71
72 /**
73  * @brief check the file is managed assembly or not.
74  * @param[in] file path
75  * @return return true when the file is managed assembly.
76  *         otherwise return false including native image case.
77  */
78 bool isManagedAssembly(const std::string& filePath);
79
80 /**
81  * @brief check the file is native image or not.
82  * @param[in] file path
83  * @return return true when the file is native image.
84  */
85 bool isNativeImage(const std::string& filePath);
86
87 /**
88  * @brief find assembly files in the directories
89  * @param[in] directories
90  * @param[out] ":" seperated assembly path list
91  */
92 void assembliesInDirectory(const std::vector<std::string>& directories, std::string& tpaList);
93
94 /**
95  * @brief function pointer for file reader
96  */
97 typedef std::function<void (const std::string&, const char*)> FileReader;
98
99 /**
100  * @brief scan files in the given directory and run file reader function for that
101  * @param[in] directory
102  * @param[in] file reader function
103  * @param[in] scan depth
104  */
105 void scanFilesInDir(const std::string& directory, FileReader reader, unsigned int depth);
106
107 #endif /* __UTILS_H__ */