libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
Io.h
Go to the documentation of this file.
1 /* Copyright 2013-2019 Homegear GmbH
2  *
3  * libhomegear-base is free software: you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * libhomegear-base is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with libhomegear-base. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  * In addition, as a special exception, the copyright holders give
18  * permission to link the code of portions of this program with the
19  * OpenSSL library under certain conditions as described in each
20  * individual source file, and distribute linked combinations
21  * including the two.
22  * You must obey the GNU Lesser General Public License in all respects
23  * for all of the code used other than OpenSSL. If you modify
24  * file(s) with this exception, you may extend this exception to your
25  * version of the file(s), but you are not obligated to do so. If you
26  * do not wish to do so, delete this exception statement from your
27  * version. If you delete this exception statement from all source
28  * files in the program, then also delete it here.
29 */
30 
31 #ifndef BASELIBIO_H_
32 #define BASELIBIO_H_
33 
34 #include <string>
35 #include <vector>
36 
37 namespace BaseLib {
38 namespace Security {
39 template<typename T>
41 }
42 
43 class SharedObjects;
44 
48 class Io {
49  public:
54  Io();
55 
60  virtual ~Io();
61 
67  void init(SharedObjects *baseLib);
68 
75  static bool directoryExists(const std::string &path);
76 
84  static int32_t isDirectory(const std::string &path, bool &result);
85 
92  static bool linkExists(const std::string &path);
93 
101  static bool createDirectory(const std::string &path, uint32_t mode);
102 
110  static std::string getFileContent(const std::string &filename);
111 
119  static std::vector<char> getBinaryFileContent(const std::string &filename, uint32_t maxBytes = 0);
120 
127  static std::vector<uint8_t> getUBinaryFileContent(const std::string &filename);
128 
137  static Security::SecureVector<uint8_t> getUBinaryFileContentSecure(const std::string &filename);
138 
145  static bool fileExists(const std::string &filename);
146 
153  static void writeFile(const std::string &filename, const std::string &content);
154 
162  static void writeFile(const std::string &filename, const std::vector<char> &content, uint32_t length);
163 
171  static void writeFile(const std::string &filename, const std::vector<uint8_t> &content, uint32_t length);
172 
179  static void appendToFile(const std::string &filename, const std::string &content);
180 
188  static void appendToFile(const std::string &filename, const std::vector<char> &content, uint32_t length);
189 
197  static void appendToFile(const std::string &filename, const std::vector<uint8_t> &content, uint32_t length);
198 
206  static std::vector<std::string> getFiles(const std::string &path, bool recursive = false);
207 
215  static std::vector<std::string> getDirectories(const std::string &path, bool recursive = false);
216 
223  static int32_t getFileLastModifiedTime(const std::string &filename);
224 
232  bool copyFile(const std::string &source, const std::string &dest);
233 
241  static bool moveFile(const std::string &source, const std::string &dest);
242 
249  static bool deleteFile(const std::string &file) noexcept;
250 
259  static bool writeLockFile(int fileDescriptor, bool wait);
260 
269  static bool readLockFile(int fileDescriptor, bool wait);
270 
277  std::string sha512(const std::string &file);
278  private:
282  BaseLib::SharedObjects *_bl = nullptr;
283 };
284 }
285 #endif
This is the base library main class.
Definition: BaseLib.h:95
The class only makes sure that the vector is not copyable and the data is zeroed on destruction...
Definition: Io.h:40
Definition: BaseLib.cpp:34
This class provides functions to make your life easier.
Definition: Io.h:48