TensorFlow Serving C++ API Documentation
aspired_versions_manager_builder.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_CORE_ASPIRED_VERSIONS_MANAGER_BUILDER_H_
17 #define TENSORFLOW_SERVING_CORE_ASPIRED_VERSIONS_MANAGER_BUILDER_H_
18 
19 #include <vector>
20 
21 #include "tensorflow/core/lib/core/status.h"
22 #include "tensorflow_serving/core/aspired_versions_manager.h"
23 #include "tensorflow_serving/core/loader.h"
24 #include "tensorflow_serving/core/source.h"
25 #include "tensorflow_serving/core/source_adapter.h"
26 #include "tensorflow_serving/util/unique_ptr_with_deps.h"
27 
28 namespace tensorflow {
29 namespace serving {
30 
31 // TODO(b/64163389): revisit the escaped HTML characters in c2devsite toolchain
32 
60  public:
62  static Status Create(Options options,
63  std::unique_ptr<AspiredVersionsManagerBuilder>* builder);
64 
65  ~AspiredVersionsManagerBuilder() = default;
66 
72  template <typename S>
73  void AddSource(std::unique_ptr<S> source);
74 
85  template <typename S, typename SA, typename... Args>
86  void AddSourceChain(std::unique_ptr<S> source,
87  std::unique_ptr<SA> first_source_adapter,
88  std::unique_ptr<Args>... remaining_source_adapters);
89 
91  std::unique_ptr<Manager> Build();
92 
93  private:
95  std::unique_ptr<AspiredVersionsManager> manager);
96 
97  template <typename S, typename SA, typename... Args>
98  void AddSourceChainImpl(std::unique_ptr<S> source,
99  std::unique_ptr<SA> first_source_adapter,
100  std::unique_ptr<Args>... remaining_source_adapters);
101 
102  template <typename S>
103  void AddSourceChainImpl(std::unique_ptr<S> source);
104 
105  AspiredVersionsManager* const aspired_versions_manager_;
106  UniquePtrWithDeps<Manager> manager_with_sources_;
107 };
108 
110 // Implementation details follow. API readers may skip.
112 
113 template <typename S>
114 void AspiredVersionsManagerBuilder::AddSource(std::unique_ptr<S> source) {
115  static_assert(
116  std::is_convertible<S*, Source<std::unique_ptr<Loader>>*>::value,
117  "Source type should be convertible to Source<std::unique_ptr<Loader>>.");
118  ConnectSourceToTarget(source.get(), aspired_versions_manager_);
119  manager_with_sources_.AddDependency(std::move(source));
120 }
121 
122 template <typename S, typename SA, typename... Args>
124  std::unique_ptr<S> source, std::unique_ptr<SA> first_source_adapter,
125  std::unique_ptr<Args>... remaining_source_adapters) {
126  AddSourceChainImpl(std::move(source), std::move(first_source_adapter),
127  std::move(remaining_source_adapters)...);
128 }
129 
130 template <typename S, typename SA, typename... Args>
131 void AspiredVersionsManagerBuilder::AddSourceChainImpl(
132  std::unique_ptr<S> source, std::unique_ptr<SA> first_source_adapter,
133  std::unique_ptr<Args>... remaining_source_adapters) {
134  auto* const target = first_source_adapter.get();
135  AddSourceChainImpl(std::move(first_source_adapter),
136  std::move(remaining_source_adapters)...);
137  ConnectSourceToTarget(source.get(), target);
138  // We add them in this order because UniquePtrWithDeps will delete them in
139  // the inverse order of entry.
140  manager_with_sources_.AddDependency(std::move(source));
141 }
142 
143 template <typename S>
144 void AspiredVersionsManagerBuilder::AddSourceChainImpl(
145  std::unique_ptr<S> source) {
146  AddSource(std::move(source));
147 }
148 
149 } // namespace serving
150 } // namespace tensorflow
151 
152 #endif // TENSORFLOW_SERVING_CORE_ASPIRED_VERSIONS_MANAGER_BUILDER_H_
void AddSourceChain(std::unique_ptr< S > source, std::unique_ptr< SA > first_source_adapter, std::unique_ptr< Args >... remaining_source_adapters)
std::unique_ptr< Manager > Build()
Builds the AspiredVersionsManager and returns it as the Manager interface.