Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015, The Android Open Source Project |
| 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 | |
Steven Moreland | 9fccf58 | 2018-08-27 20:36:27 -0700 | [diff] [blame] | 17 | #pragma once |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 18 | |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 19 | #include <memory> |
| 20 | #include <string> |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
| 23 | #include "code_writer.h" |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 24 | #include "line_reader.h" |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 25 | |
| 26 | namespace android { |
| 27 | namespace aidl { |
| 28 | |
| 29 | class IoDelegate { |
| 30 | public: |
| 31 | IoDelegate() = default; |
| 32 | virtual ~IoDelegate() = default; |
| 33 | |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 34 | IoDelegate(const IoDelegate&) = delete; |
| 35 | IoDelegate(IoDelegate&&) = delete; |
| 36 | IoDelegate& operator=(const IoDelegate&) = delete; |
| 37 | IoDelegate& operator=(IoDelegate&&) = delete; |
| 38 | |
Christopher Wiley | 8decf95 | 2016-06-02 16:27:26 -0700 | [diff] [blame] | 39 | // Stores an absolute version of |path| to |*absolute_path|, |
| 40 | // possibly prefixing it with the current working directory. |
| 41 | // Returns false and does not set |*absolute_path| on error. |
| 42 | static bool GetAbsolutePath(const std::string& path, |
| 43 | std::string* absolute_path); |
| 44 | |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 45 | // Returns a unique_ptr to the contents of |filename|. |
| 46 | // Will append the optional |content_suffix| to the returned contents. |
| 47 | virtual std::unique_ptr<std::string> GetFileContents( |
| 48 | const std::string& filename, |
| 49 | const std::string& content_suffix = "") const; |
| 50 | |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 51 | virtual std::unique_ptr<LineReader> GetLineReader( |
| 52 | const std::string& file_path) const; |
| 53 | |
Christopher Wiley | 72877ac | 2015-10-06 14:41:42 -0700 | [diff] [blame] | 54 | virtual bool FileIsReadable(const std::string& path) const; |
| 55 | |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 56 | virtual std::unique_ptr<CodeWriter> GetCodeWriter( |
| 57 | const std::string& file_path) const; |
| 58 | |
Christopher Wiley | 9d6e0b2 | 2015-11-13 12:18:16 -0800 | [diff] [blame] | 59 | virtual void RemovePath(const std::string& file_path) const; |
| 60 | |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 61 | virtual std::vector<std::string> ListFiles(const std::string& dir) const; |
| 62 | |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 63 | private: |
Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 64 | // Create the directory when path is a dir or the parent directory when |
| 65 | // path is a file. Path is a dir if it ends with the path separator. |
| 66 | bool CreateDirForPath(const std::string& path) const; |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 67 | }; // class IoDelegate |
| 68 | |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 69 | } // namespace aidl |
Steven Moreland | f4c64df | 2019-07-29 19:54:04 -0700 | [diff] [blame] | 70 | } // namespace android |