TensorFlow Serving C++ API Documentation
file_probing_env.h
1 /* Copyright 2016 Google Inc. All Rights Reserved.
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 
16 #ifndef TENSORFLOW_SERVING_UTIL_FILE_PROBING_ENV_H_
17 #define TENSORFLOW_SERVING_UTIL_FILE_PROBING_ENV_H_
18 
19 #include "tensorflow/core/lib/core/status.h"
20 #include "tensorflow/core/platform/env.h"
21 
22 namespace tensorflow {
23 namespace serving {
24 
25 // An interface used to probe the contents of a file system. This allows file
26 // systems other than those supported by tensorflow::Env to be used.
28  public:
29  virtual ~FileProbingEnv() = default;
30 
31  // Returns OK if the named path exists and NOT_FOUND otherwise.
32  virtual Status FileExists(const string& fname) = 0;
33 
34  // Stores in *children the names of the children of the specified
35  // directory. The names are relative to "dir".
36  // Original contents of *children are dropped.
37  virtual Status GetChildren(const string& dir,
38  std::vector<string>* children) = 0;
39 
40  // Returns whether the given path is a directory or not.
41  // See tensorflow::Env::IsDirectory() for possible status code.
42  virtual Status IsDirectory(const string& fname) = 0;
43 
44  // Stores the size of `fname` in `*file_size`.
45  virtual Status GetFileSize(const string& fname, uint64_t* file_size) = 0;
46 };
47 
48 // An implementation of FileProbingEnv which delegates the calls to
49 // tensorflow::Env.
51  public:
52  // 'env' is owned by the caller.
53  TensorflowFileProbingEnv(tensorflow::Env* env) : env_(env) {}
54 
55  ~TensorflowFileProbingEnv() override = default;
56 
57  Status FileExists(const string& fname) override;
58 
59  Status GetChildren(const string& dir, std::vector<string>* children) override;
60 
61  Status IsDirectory(const string& fname) override;
62 
63  Status GetFileSize(const string& fname, uint64_t* file_size) override;
64 
65  private:
66  // Not owned.
67  tensorflow::Env* env_;
68 };
69 
70 } // namespace serving
71 } // namespace tensorflow
72 
73 #endif // TENSORFLOW_SERVING_UTIL_FILE_PROBING_ENV_H_