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