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 
17 #ifndef AIDL_IO_DELEGATE_H_
18 #define AIDL_IO_DELEGATE_H_
19 
20 #include <android-base/macros.h>
21 
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include "code_writer.h"
27 #include "line_reader.h"
28 
29 namespace android {
30 namespace aidl {
31 
32 class IoDelegate {
33  public:
34   IoDelegate() = default;
35   virtual ~IoDelegate() = default;
36 
37   // Stores an absolute version of |path| to |*absolute_path|,
38   // possibly prefixing it with the current working directory.
39   // Returns false and does not set |*absolute_path| on error.
40   static bool GetAbsolutePath(const std::string& path,
41                               std::string* absolute_path);
42 
43   // Returns a unique_ptr to the contents of |filename|.
44   // Will append the optional |content_suffix| to the returned contents.
45   virtual std::unique_ptr<std::string> GetFileContents(
46       const std::string& filename,
47       const std::string& content_suffix = "") const;
48 
49   virtual std::unique_ptr<LineReader> GetLineReader(
50       const std::string& file_path) const;
51 
52   virtual bool FileIsReadable(const std::string& path) const;
53 
54   virtual bool CreatedNestedDirs(
55       const std::string& base_dir,
56       const std::vector<std::string>& nested_subdirs) const;
57 
58   bool CreatePathForFile(const std::string& path) const;
59 
60   virtual std::unique_ptr<CodeWriter> GetCodeWriter(
61       const std::string& file_path) const;
62 
63   virtual void RemovePath(const std::string& file_path) const;
64 
65  private:
66   DISALLOW_COPY_AND_ASSIGN(IoDelegate);
67 };  // class IoDelegate
68 
69 }  // namespace android
70 }  // namespace aidl
71 
72 #endif // AIDL_IO_DELEGATE_H_
73