server_initializer.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #ifndef GRPCPP_IMPL_SERVER_INITIALIZER_H
  19. #define GRPCPP_IMPL_SERVER_INITIALIZER_H
  20. #include <memory>
  21. #include <vector>
  22. #include <grpcpp/server.h>
  23. namespace grpc {
  24. class Server;
  25. class Service;
  26. class ServerInitializer {
  27. public:
  28. explicit ServerInitializer(grpc::Server* server) : server_(server) {}
  29. bool RegisterService(std::shared_ptr<grpc::Service> service) {
  30. if (!server_->RegisterService(nullptr, service.get())) {
  31. return false;
  32. }
  33. default_services_.push_back(service);
  34. return true;
  35. }
  36. const std::vector<TString>* GetServiceList() {
  37. return &server_->services_;
  38. }
  39. private:
  40. grpc::Server* server_;
  41. std::vector<std::shared_ptr<grpc::Service> > default_services_;
  42. };
  43. } // namespace grpc
  44. #endif // GRPCPP_IMPL_SERVER_INITIALIZER_H