TensorFlow Serving C++ API Documentation
server_support.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 // This pure interface provides callbacks from a request object to the
17 // server object so the two are properly decoupled.
18 // This may turn out to be generally useful with no libevents specifics.
19 
20 #ifndef TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_INTERNAL_SERVER_SUPPORT_H_
21 #define TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_INTERNAL_SERVER_SUPPORT_H_
22 
23 #include <functional>
24 
25 #include "tensorflow_serving/util/net_http/server/public/server_request_interface.h"
26 
27 namespace tensorflow {
28 namespace serving {
29 namespace net_http {
30 
32  public:
33  virtual ~ServerSupport() = default;
34 
35  ServerSupport(const ServerSupport& other) = delete;
36  ServerSupport& operator=(const ServerSupport& other) = delete;
37 
38  // book-keeping of active requests
39  virtual void IncOps() = 0;
40  virtual void DecOps() = 0;
41 
42  // Schedules the callback function to run immediately from the event loop.
43  // Returns false if any error.
44  virtual bool EventLoopSchedule(std::function<void()> fn) = 0;
45 
46  protected:
47  ServerSupport() = default;
48 };
49 
50 } // namespace net_http
51 } // namespace serving
52 } // namespace tensorflow
53 
54 #endif // TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_INTERNAL_SERVER_SUPPORT_H_