• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2020 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef IORAP_SRC_INODE2FILENAME_OUT_OF_PROCESS_INDOE_RESOLVER_H_
16 #define IORAP_SRC_INODE2FILENAME_OUT_OF_PROCESS_INDOE_RESOLVER_H_
17 
18 #include "common/expected.h"
19 #include "inode2filename/inode_resolver.h"
20 
21 namespace iorap::inode2filename {
22 
23 // Create an InodeResolver that fork+exec+pipes into the binary 'iorap.inode2filename'
24 // and transmits the results back via an IPC mechanism.
25 //
26 // This is instantiated by InodeResolver::Create + ProcessMode::kOutOfProcessIpc
27 class OutOfProcessInodeResolver : public InodeResolver {
28  public:
29   virtual rxcpp::observable<InodeResult>
30       FindFilenamesFromInodes(std::vector<Inode> inodes) const override;
31 
32   virtual rxcpp::observable<InodeResult>
33       EmitAll() const override;
34 
35   OutOfProcessInodeResolver(InodeResolverDependencies dependencies);
36   ~OutOfProcessInodeResolver();
37  private:
38   struct Impl;
39   Impl* impl_;
40 };
41 
42 // Reads one line data from the stream.
43 // Each line is in the format of "<4 bytes line length><state> <inode info> <file path>"
44 // The <4 bytes line length> is the length rest data of "<state> <inode info> <file path>".
45 // The return string is "<state> <inode info> <file path>".
46 // For example: for "<size>K 253:9:6 ./test", the return value is
47 // "K 253:9:6 ./test". The <size> is encoded in the first 4 bytes.
48 // Note: there is no newline in the end of each line and the line shouldn't be
49 // empty unless there is some error.
50 std::string ReadOneLine(FILE* stream, bool* eof);
51 }
52 
53 #endif  // IORAP_SRC_INODE2FILENAME_OUT_OF_PROCESS_INDOE_RESOLVER_H_
54