channel_argument_option.cc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. *
  3. * Copyright 2017 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. #include <grpcpp/impl/channel_argument_option.h>
  19. namespace grpc {
  20. std::unique_ptr<ServerBuilderOption> MakeChannelArgumentOption(
  21. const grpc::string& name, const grpc::string& value) {
  22. class StringOption final : public ServerBuilderOption {
  23. public:
  24. StringOption(const grpc::string& name, const grpc::string& value)
  25. : name_(name), value_(value) {}
  26. virtual void UpdateArguments(ChannelArguments* args) override {
  27. args->SetString(name_, value_);
  28. }
  29. virtual void UpdatePlugins(
  30. std::vector<std::unique_ptr<ServerBuilderPlugin>>* plugins) override {}
  31. private:
  32. const grpc::string name_;
  33. const grpc::string value_;
  34. };
  35. return std::unique_ptr<ServerBuilderOption>(new StringOption(name, value));
  36. }
  37. std::unique_ptr<ServerBuilderOption> MakeChannelArgumentOption(
  38. const grpc::string& name, int value) {
  39. class IntOption final : public ServerBuilderOption {
  40. public:
  41. IntOption(const grpc::string& name, int value)
  42. : name_(name), value_(value) {}
  43. virtual void UpdateArguments(ChannelArguments* args) override {
  44. args->SetInt(name_, value_);
  45. }
  46. virtual void UpdatePlugins(
  47. std::vector<std::unique_ptr<ServerBuilderPlugin>>* plugins) override {}
  48. private:
  49. const grpc::string name_;
  50. const int value_;
  51. };
  52. return std::unique_ptr<ServerBuilderOption>(new IntOption(name, value));
  53. }
  54. } // namespace grpc