• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2015 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 <memory>
20 
21 #include <grpcpp/channel.h>
22 #include <grpcpp/create_channel.h>
23 #include <grpcpp/impl/grpc_library.h>
24 #include <grpcpp/support/channel_arguments.h>
25 
26 #include "src/cpp/client/create_channel_internal.h"
27 
28 namespace grpc {
29 class ChannelArguments;
30 
CreateChannel(const grpc::string & target,const std::shared_ptr<ChannelCredentials> & creds)31 std::shared_ptr<Channel> CreateChannel(
32     const grpc::string& target,
33     const std::shared_ptr<ChannelCredentials>& creds) {
34   return CreateCustomChannel(target, creds, ChannelArguments());
35 }
36 
CreateCustomChannel(const grpc::string & target,const std::shared_ptr<ChannelCredentials> & creds,const ChannelArguments & args)37 std::shared_ptr<Channel> CreateCustomChannel(
38     const grpc::string& target,
39     const std::shared_ptr<ChannelCredentials>& creds,
40     const ChannelArguments& args) {
41   GrpcLibraryCodegen init_lib;  // We need to call init in case of a bad creds.
42   return creds ? creds->CreateChannel(target, args)
43                : CreateChannelInternal(
44                      "", grpc_lame_client_channel_create(
45                              nullptr, GRPC_STATUS_INVALID_ARGUMENT,
46                              "Invalid credentials."));
47 }
48 
49 }  // namespace grpc
50