TensorFlow Serving C++ API Documentation
httpserver.h
1 /* Copyright 2018 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 // The entry point to access different HTTP server implementations.
17 
18 #ifndef TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_PUBLIC_HTTPSERVER_H_
19 #define TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_PUBLIC_HTTPSERVER_H_
20 
21 #include <memory>
22 
23 #include "absl/memory/memory.h"
24 
25 #include "tensorflow_serving/util/net_http/server/internal/evhttp_server.h"
26 #include "tensorflow_serving/util/net_http/server/public/httpserver_interface.h"
27 
28 namespace tensorflow {
29 namespace serving {
30 namespace net_http {
31 
32 // Creates a server implemented based on the libevents library.
33 // Returns nullptr if there is any error.
34 //
35 // Must call WaitForTermination() or WaitForTerminationWithTimeout() before
36 // the server is to be destructed.
37 inline std::unique_ptr<HTTPServerInterface> CreateEvHTTPServer(
38  std::unique_ptr<ServerOptions> options) {
39  auto server = absl::make_unique<EvHTTPServer>(std::move(options));
40  bool result = server->Initialize();
41  if (!result) {
42  return nullptr;
43  }
44 
45  return std::move(server);
46 }
47 
48 } // namespace net_http
49 } // namespace serving
50 } // namespace tensorflow
51 
52 #endif // TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_PUBLIC_HTTPSERVER_H_