• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_INTERNAL_CPP_SERVER_DEFAULT_HEALTH_CHECK_SERVICE_H
20 #define GRPC_INTERNAL_CPP_SERVER_DEFAULT_HEALTH_CHECK_SERVICE_H
21 
22 #include <mutex>
23 
24 #include <grpcpp/health_check_service_interface.h>
25 #include <grpcpp/impl/codegen/service_type.h>
26 #include <grpcpp/support/byte_buffer.h>
27 
28 namespace grpc {
29 
30 // Default implementation of HealthCheckServiceInterface. Server will create and
31 // own it.
32 class DefaultHealthCheckService final : public HealthCheckServiceInterface {
33  public:
34   // The service impl to register with the server.
35   class HealthCheckServiceImpl : public Service {
36    public:
37     explicit HealthCheckServiceImpl(DefaultHealthCheckService* service);
38 
39     Status Check(ServerContext* context, const ByteBuffer* request,
40                  ByteBuffer* response);
41 
42    private:
43     const DefaultHealthCheckService* const service_;
44     internal::RpcServiceMethod* method_;
45   };
46 
47   DefaultHealthCheckService();
48   void SetServingStatus(const grpc::string& service_name,
49                         bool serving) override;
50   void SetServingStatus(bool serving) override;
51   enum ServingStatus { NOT_FOUND, SERVING, NOT_SERVING };
52   ServingStatus GetServingStatus(const grpc::string& service_name) const;
53   HealthCheckServiceImpl* GetHealthCheckService();
54 
55  private:
56   mutable std::mutex mu_;
57   std::map<grpc::string, bool> services_map_;
58   std::unique_ptr<HealthCheckServiceImpl> impl_;
59 };
60 
61 }  // namespace grpc
62 
63 #endif  // GRPC_INTERNAL_CPP_SERVER_DEFAULT_HEALTH_CHECK_SERVICE_H
64