Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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 |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include <memory> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 20 | |
yang-g | 8c2be9f | 2015-08-19 16:28:09 -0700 | [diff] [blame] | 21 | #include <grpc++/channel.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 22 | #include <grpc++/create_channel.h> |
David Garcia Quintas | e1300de | 2016-01-27 18:41:26 -0800 | [diff] [blame] | 23 | #include <grpc++/impl/grpc_library.h> |
yang-g | 9e2f90c | 2015-08-21 15:35:03 -0700 | [diff] [blame] | 24 | #include <grpc++/support/channel_arguments.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 25 | |
yang-g | c317f07 | 2015-08-20 12:18:08 -0700 | [diff] [blame] | 26 | #include "src/cpp/client/create_channel_internal.h" |
| 27 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 28 | namespace grpc { |
yangg | 59dfc90 | 2014-12-19 14:00:14 -0800 | [diff] [blame] | 29 | class ChannelArguments; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 30 | |
yang-g | 8c2be9f | 2015-08-19 16:28:09 -0700 | [diff] [blame] | 31 | std::shared_ptr<Channel> CreateChannel( |
Julien Boeuf | 54a902e | 2015-10-12 13:26:21 -0700 | [diff] [blame] | 32 | const grpc::string& target, |
| 33 | const std::shared_ptr<ChannelCredentials>& creds) { |
yang-g | dafcce9 | 2015-08-27 11:34:05 -0700 | [diff] [blame] | 34 | return CreateCustomChannel(target, creds, ChannelArguments()); |
| 35 | } |
| 36 | |
| 37 | std::shared_ptr<Channel> CreateCustomChannel( |
Julien Boeuf | 54a902e | 2015-10-12 13:26:21 -0700 | [diff] [blame] | 38 | const grpc::string& target, |
| 39 | const std::shared_ptr<ChannelCredentials>& creds, |
Yang Gao | 6baa9b6 | 2015-03-17 10:49:39 -0700 | [diff] [blame] | 40 | const ChannelArguments& args) { |
David Garcia Quintas | e1300de | 2016-01-27 18:41:26 -0800 | [diff] [blame] | 41 | internal::GrpcLibrary |
| 42 | init_lib; // We need to call init in case of a bad creds. |
yang-g | c317f07 | 2015-08-20 12:18:08 -0700 | [diff] [blame] | 43 | return creds |
yang-g | d59ad7e | 2016-02-10 12:42:53 -0800 | [diff] [blame] | 44 | ? creds->CreateChannel(target, args) |
yang-g | c317f07 | 2015-08-20 12:18:08 -0700 | [diff] [blame] | 45 | : CreateChannelInternal("", grpc_lame_client_channel_create( |
| 46 | NULL, GRPC_STATUS_INVALID_ARGUMENT, |
| 47 | "Invalid credentials.")); |
yangg | 59dfc90 | 2014-12-19 14:00:14 -0800 | [diff] [blame] | 48 | } |
yang-g | dafcce9 | 2015-08-27 11:34:05 -0700 | [diff] [blame] | 49 | |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 50 | } // namespace grpc |