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