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 grpc::string & name,const grpc::string & value)23 std::unique_ptr<ServerBuilderOption> MakeChannelArgumentOption(
24 const grpc::string& name, const grpc::string& value) {
25 class StringOption final : public ServerBuilderOption {
26 public:
27 StringOption(const grpc::string& name, const grpc::string& value)
28 : name_(name), value_(value) {}
29
30 virtual void UpdateArguments(ChannelArguments* args) override {
31 args->SetString(name_, value_);
32 }
33 virtual void UpdatePlugins(
34 std::vector<std::unique_ptr<ServerBuilderPlugin>>* plugins) override {}
35
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
MakeChannelArgumentOption(const grpc::string & name,int value)43 std::unique_ptr<ServerBuilderOption> MakeChannelArgumentOption(
44 const grpc::string& name, int value) {
45 class IntOption final : public ServerBuilderOption {
46 public:
47 IntOption(const grpc::string& name, int value)
48 : name_(name), value_(value) {}
49
50 virtual void UpdateArguments(ChannelArguments* args) override {
51 args->SetInt(name_, value_);
52 }
53 virtual void UpdatePlugins(
54 std::vector<std::unique_ptr<ServerBuilderPlugin>>* plugins) override {}
55
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
64