blob: 93233153d0810e521da36d755886707771db0af9 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015 gRPC authors.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -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
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -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.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080016 *
17 */
18
19#include <memory>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080020
yang-g8c2be9f2015-08-19 16:28:09 -070021#include <grpc++/channel.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080022#include <grpc++/create_channel.h>
David Garcia Quintase1300de2016-01-27 18:41:26 -080023#include <grpc++/impl/grpc_library.h>
yang-g9e2f90c2015-08-21 15:35:03 -070024#include <grpc++/support/channel_arguments.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080025
yang-gc317f072015-08-20 12:18:08 -070026#include "src/cpp/client/create_channel_internal.h"
27
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080028namespace grpc {
yangg59dfc902014-12-19 14:00:14 -080029class ChannelArguments;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080030
yang-g8c2be9f2015-08-19 16:28:09 -070031std::shared_ptr<Channel> CreateChannel(
Julien Boeuf54a902e2015-10-12 13:26:21 -070032 const grpc::string& target,
33 const std::shared_ptr<ChannelCredentials>& creds) {
yang-gdafcce92015-08-27 11:34:05 -070034 return CreateCustomChannel(target, creds, ChannelArguments());
35}
36
37std::shared_ptr<Channel> CreateCustomChannel(
Julien Boeuf54a902e2015-10-12 13:26:21 -070038 const grpc::string& target,
39 const std::shared_ptr<ChannelCredentials>& creds,
Yang Gao6baa9b62015-03-17 10:49:39 -070040 const ChannelArguments& args) {
Vijay Pai53cec0f2017-10-17 06:46:19 -070041 GrpcLibraryCodegen init_lib; // We need to call init in case of a bad creds.
Craig Tillerbe98d242017-11-10 15:26:57 -080042 return creds ? creds->CreateChannel(target, args)
43 : CreateChannelInternal(
44 "", grpc_lame_client_channel_create(
45 nullptr, GRPC_STATUS_INVALID_ARGUMENT,
46 "Invalid credentials."));
yangg59dfc902014-12-19 14:00:14 -080047}
yang-gdafcce92015-08-27 11:34:05 -070048
Craig Tiller190d3602015-02-18 09:23:38 -080049} // namespace grpc