Add comments for added function in utils.h
[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 #include <boost/filesystem.hpp>
24
25 #ifndef PATH_SEPARATOR
26 #define PATH_SEPARATOR '/'
27 #endif
28
29 namespace bf = boost::filesystem;
30 namespace bs = boost::system;
31
32 enum FSFlag : int {
33   FS_NONE              = 0,
34   FS_MERGE_SKIP        = (1 << 0),
35   FS_MERGE_OVERWRITE   = (1 << 1),
36   FS_COMMIT_COPY_FILE  = (1 << 2),
37   FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS = (1 << 3)
38 };
39
40 /**
41  * @brief get current executable path
42  * return std::string path
43  */
44 std::string readSelfPath();
45
46 /**
47  * @brief concat path with PATH_SEPARATOR
48  * @param[in] destination path
49  * @param[in] source path
50  * return std::string result path
51  */
52 std::string concatPath(const std::string& path1, const std::string& path2);
53
54 /**
55  * @brief get absolute Path
56  * @param[in] source path
57  * return std::string result path
58  */
59 std::string absolutePath(const std::string& path);
60
61 /**
62  * @brief get the directory of file
63  * @param[in] source path
64  * return std::string result path
65  */
66 std::string baseName(const std::string& path);
67
68 /**
69  * @brief split path with ":" delimiter and put that in the vector
70  * @param[in] source path
71  * @param[out] string vector
72  */
73 void splitPath(const std::string& path, std::vector<std::string>& out);
74
75 /**
76  * @brief check file is exist
77  * @param[in] source path
78  * @return bool
79  */
80 bool isFileExist(const std::string& path);
81
82 /**
83  * @brief check the file is managed assembly or not.
84  * @param[in] file path
85  * @return return true when the file is managed assembly.
86  *         otherwise return false including native image case.
87  */
88 bool isManagedAssembly(const std::string& filePath);
89
90 /**
91  * @brief check the file is native image or not.
92  * @param[in] file path
93  * @return return true when the file is native image.
94  */
95 bool isNativeImage(const std::string& filePath);
96
97 /**
98  * @brief find assembly files in the directories
99  * @param[in] directories
100  * @param[out] ":" seperated assembly path list
101  */
102 void assembliesInDirectory(const std::vector<std::string>& directories, std::string& tpaList);
103
104 /**
105  * @brief function pointer for file reader
106  */
107 typedef std::function<void (const std::string&, const char*)> FileReader;
108
109 /**
110  * @brief scan files in the given directory and run file reader function for that
111  * @param[in] directory
112  * @param[in] file reader function
113  * @param[in] scan depth
114  */
115 void scanFilesInDir(const std::string& directory, FileReader reader, unsigned int depth);
116
117 /**
118  * @brief create the new directory.
119  * @param[in] source path
120  * @return return true when the directory was created.
121  */
122 bool createDir(const bf::path& path);
123
124 /**
125  * @brief copy the directory.
126  * @param[in] path to the source directory
127  * @param[in] path to the target directory
128  * @param[in] filesystem flag
129  * @return return true when the directory was copied.
130  */
131 bool copyDir(const bf::path& path1, const bf::path& path2, FSFlag flags = FS_NONE);
132
133 /**
134  * @brief copy the file.
135  * @param[in] path to the source file
136  * @param[in] path to the target file
137  * @return return true when the file was copied.
138  */
139 bool copyFile(const bf::path& path1, const bf::path& path2);
140
141 /**
142  * @brief moves of renames the file or directory.
143  * @param[in] path to the source file
144  * @param[in] path to the target file
145  * @return return true when the file was moved.
146  */
147 bool moveFile(const bf::path& path1, const bf::path& path2);
148
149 /**
150  * @brief removes the file or empty directory.
151  * @param[in] source path
152  * @return return true when the file was deleted.
153  */
154 bool removeFile(const bf::path& path);
155
156 /**
157  * @brief removes the file or directory and all its contents.
158  * @param[in] source path
159  * @return return true when the file or directory was deleted.
160  */
161 bool removeAll(const bf::path& path);
162
163 #endif /* __UTILS_H__ */