blob: dcad2531d587fa5647a290a51193f1d5d427c395 [file] [log] [blame]
Craig Tiller4751c282017-01-10 14:29:00 -08001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2017 gRPC authors.
Craig Tiller4751c282017-01-10 14:29:00 -08004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * 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
Craig Tiller4751c282017-01-10 14:29:00 -08008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Craig Tiller4751c282017-01-10 14:29:00 -080010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * 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.
Craig Tiller4751c282017-01-10 14:29:00 -080016 *
17 */
18
19#include <grpc++/impl/channel_argument_option.h>
20
21namespace grpc {
22
23std::unique_ptr<ServerBuilderOption> MakeChannelArgumentOption(
Craig Tillerbaa14a92017-11-03 09:09:36 -070024 const grpc::string& name, const grpc::string& value) {
Craig Tiller4751c282017-01-10 14:29:00 -080025 class StringOption final : public ServerBuilderOption {
26 public:
Craig Tillerbaa14a92017-11-03 09:09:36 -070027 StringOption(const grpc::string& name, const grpc::string& value)
Craig Tiller4751c282017-01-10 14:29:00 -080028 : name_(name), value_(value) {}
29
Craig Tillerbaa14a92017-11-03 09:09:36 -070030 virtual void UpdateArguments(ChannelArguments* args) override {
Craig Tiller4751c282017-01-10 14:29:00 -080031 args->SetString(name_, value_);
32 }
33 virtual void UpdatePlugins(
Craig Tillerbaa14a92017-11-03 09:09:36 -070034 std::vector<std::unique_ptr<ServerBuilderPlugin>>* plugins) override {}
Craig Tiller4751c282017-01-10 14:29:00 -080035
36 private:
37 const grpc::string name_;
38 const grpc::string value_;
39 };
40 return std::unique_ptr<ServerBuilderOption>(new StringOption(name, value));
41}
42
43std::unique_ptr<ServerBuilderOption> MakeChannelArgumentOption(
Craig Tillerbaa14a92017-11-03 09:09:36 -070044 const grpc::string& name, int value) {
Craig Tiller4751c282017-01-10 14:29:00 -080045 class IntOption final : public ServerBuilderOption {
46 public:
Craig Tillerbaa14a92017-11-03 09:09:36 -070047 IntOption(const grpc::string& name, int value)
Craig Tiller4751c282017-01-10 14:29:00 -080048 : name_(name), value_(value) {}
49
Craig Tillerbaa14a92017-11-03 09:09:36 -070050 virtual void UpdateArguments(ChannelArguments* args) override {
Craig Tiller4751c282017-01-10 14:29:00 -080051 args->SetInt(name_, value_);
52 }
53 virtual void UpdatePlugins(
Craig Tillerbaa14a92017-11-03 09:09:36 -070054 std::vector<std::unique_ptr<ServerBuilderPlugin>>* plugins) override {}
Craig Tiller4751c282017-01-10 14:29:00 -080055
56 private:
57 const grpc::string name_;
58 const int value_;
59 };
60 return std::unique_ptr<ServerBuilderOption>(new IntOption(name, value));
61}
62
63} // namespace grpc