Skip to content

Commit

Permalink
Revert "Folding the Channel class into the grpc_impl namespace."
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasnoble committed Feb 15, 2019
1 parent 04cdb18 commit 2ad245c
Show file tree
Hide file tree
Showing 35 changed files with 162 additions and 259 deletions.
1 change: 0 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ GRPCXX_PUBLIC_HDRS = [
"include/grpcpp/alarm.h",
"include/grpcpp/alarm_impl.h",
"include/grpcpp/channel.h",
"include/grpcpp/channel_impl.h",
"include/grpcpp/client_context.h",
"include/grpcpp/completion_queue.h",
"include/grpcpp/create_channel.h",
Expand Down
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2991,7 +2991,6 @@ foreach(_hdr
include/grpcpp/alarm.h
include/grpcpp/alarm_impl.h
include/grpcpp/channel.h
include/grpcpp/channel_impl.h
include/grpcpp/client_context.h
include/grpcpp/completion_queue.h
include/grpcpp/create_channel.h
Expand Down Expand Up @@ -3583,7 +3582,6 @@ foreach(_hdr
include/grpcpp/alarm.h
include/grpcpp/alarm_impl.h
include/grpcpp/channel.h
include/grpcpp/channel_impl.h
include/grpcpp/client_context.h
include/grpcpp/completion_queue.h
include/grpcpp/create_channel.h
Expand Down Expand Up @@ -4539,7 +4537,6 @@ foreach(_hdr
include/grpcpp/alarm.h
include/grpcpp/alarm_impl.h
include/grpcpp/channel.h
include/grpcpp/channel_impl.h
include/grpcpp/client_context.h
include/grpcpp/completion_queue.h
include/grpcpp/create_channel.h
Expand Down
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5397,7 +5397,6 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/alarm.h \
include/grpcpp/alarm_impl.h \
include/grpcpp/channel.h \
include/grpcpp/channel_impl.h \
include/grpcpp/client_context.h \
include/grpcpp/completion_queue.h \
include/grpcpp/create_channel.h \
Expand Down Expand Up @@ -5998,7 +5997,6 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/alarm.h \
include/grpcpp/alarm_impl.h \
include/grpcpp/channel.h \
include/grpcpp/channel_impl.h \
include/grpcpp/client_context.h \
include/grpcpp/completion_queue.h \
include/grpcpp/create_channel.h \
Expand Down Expand Up @@ -6911,7 +6909,6 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/alarm.h \
include/grpcpp/alarm_impl.h \
include/grpcpp/channel.h \
include/grpcpp/channel_impl.h \
include/grpcpp/client_context.h \
include/grpcpp/completion_queue.h \
include/grpcpp/create_channel.h \
Expand Down
1 change: 0 additions & 1 deletion build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,6 @@ filegroups:
- include/grpcpp/alarm.h
- include/grpcpp/alarm_impl.h
- include/grpcpp/channel.h
- include/grpcpp/channel_impl.h
- include/grpcpp/client_context.h
- include/grpcpp/completion_queue.h
- include/grpcpp/create_channel.h
Expand Down
1 change: 0 additions & 1 deletion gRPC-C++.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ Pod::Spec.new do |s|
ss.source_files = 'include/grpcpp/alarm.h',
'include/grpcpp/alarm_impl.h',
'include/grpcpp/channel.h',
'include/grpcpp/channel_impl.h',
'include/grpcpp/client_context.h',
'include/grpcpp/completion_queue.h',
'include/grpcpp/create_channel.h',
Expand Down
86 changes: 83 additions & 3 deletions include/grpcpp/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,96 @@
#ifndef GRPCPP_CHANNEL_H
#define GRPCPP_CHANNEL_H

#include <grpcpp/channel_impl.h>
#include <memory>
#include <mutex>

namespace grpc {
#include <grpc/grpc.h>
#include <grpcpp/impl/call.h>
#include <grpcpp/impl/codegen/channel_interface.h>
#include <grpcpp/impl/codegen/client_interceptor.h>
#include <grpcpp/impl/codegen/config.h>
#include <grpcpp/impl/codegen/grpc_library.h>

struct grpc_channel;

typedef ::grpc_impl::Channel Channel;
namespace grpc {

namespace experimental {
/// Resets the channel's connection backoff.
/// TODO(roth): Once we see whether this proves useful, either create a gRFC
/// and change this to be a method of the Channel class, or remove it.
void ChannelResetConnectionBackoff(Channel* channel);
} // namespace experimental

/// Channels represent a connection to an endpoint. Created by \a CreateChannel.
class Channel final : public ChannelInterface,
public internal::CallHook,
public std::enable_shared_from_this<Channel>,
private GrpcLibraryCodegen {
public:
~Channel();

/// Get the current channel state. If the channel is in IDLE and
/// \a try_to_connect is set to true, try to connect.
grpc_connectivity_state GetState(bool try_to_connect) override;

/// Returns the LB policy name, or the empty string if not yet available.
grpc::string GetLoadBalancingPolicyName() const;

/// Returns the service config in JSON form, or the empty string if
/// not available.
grpc::string GetServiceConfigJSON() const;

private:
template <class InputMessage, class OutputMessage>
friend class internal::BlockingUnaryCallImpl;
friend void experimental::ChannelResetConnectionBackoff(Channel* channel);
friend std::shared_ptr<Channel> CreateChannelInternal(
const grpc::string& host, grpc_channel* c_channel,
std::vector<
std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
interceptor_creators);
friend class internal::InterceptedChannel;
Channel(const grpc::string& host, grpc_channel* c_channel,
std::vector<
std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
interceptor_creators);

internal::Call CreateCall(const internal::RpcMethod& method,
ClientContext* context,
CompletionQueue* cq) override;
void PerformOpsOnCall(internal::CallOpSetInterface* ops,
internal::Call* call) override;
void* RegisterMethod(const char* method) override;

void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed,
gpr_timespec deadline, CompletionQueue* cq,
void* tag) override;
bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
gpr_timespec deadline) override;

CompletionQueue* CallbackCQ() override;

internal::Call CreateCallInternal(const internal::RpcMethod& method,
ClientContext* context, CompletionQueue* cq,
size_t interceptor_pos) override;

const grpc::string host_;
grpc_channel* const c_channel_; // owned

// mu_ protects callback_cq_ (the per-channel callbackable completion queue)
std::mutex mu_;

// callback_cq_ references the callbackable completion queue associated
// with this channel (if any). It is set on the first call to CallbackCQ().
// It is _not owned_ by the channel; ownership belongs with its internal
// shutdown callback tag (invoked when the CQ is fully shutdown).
CompletionQueue* callback_cq_ = nullptr;

std::vector<std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
interceptor_creators_;
};

} // namespace grpc

#endif // GRPCPP_CHANNEL_H
115 changes: 0 additions & 115 deletions include/grpcpp/channel_impl.h

This file was deleted.

5 changes: 1 addition & 4 deletions include/grpcpp/impl/codegen/client_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@
#include <grpcpp/impl/codegen/core_codegen_interface.h>
#include <grpcpp/impl/codegen/status.h>

namespace grpc_impl {
class Channel;
}

namespace grpc {

class Channel;
class ClientContext;
class CompletionQueue;

Expand Down
13 changes: 4 additions & 9 deletions include/grpcpp/impl/codegen/client_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,9 @@
struct census_context;
struct grpc_call;

namespace grpc_impl {

class Channel;
}

namespace grpc {

class Channel;
class ChannelInterface;
class CompletionQueue;
class CallCredentials;
Expand Down Expand Up @@ -395,7 +391,7 @@ class ClientContext {
friend class ::grpc::testing::InteropClientContextInspector;
friend class ::grpc::internal::CallOpClientRecvStatus;
friend class ::grpc::internal::CallOpRecvInitialMetadata;
friend class ::grpc_impl::Channel;
friend class Channel;
template <class R>
friend class ::grpc::ClientReader;
template <class W>
Expand Down Expand Up @@ -427,8 +423,7 @@ class ClientContext {
}

grpc_call* call() const { return call_; }
void set_call(grpc_call* call,
const std::shared_ptr<::grpc_impl::Channel>& channel);
void set_call(grpc_call* call, const std::shared_ptr<Channel>& channel);

experimental::ClientRpcInfo* set_client_rpc_info(
const char* method, internal::RpcMethod::RpcType type,
Expand Down Expand Up @@ -461,7 +456,7 @@ class ClientContext {
bool wait_for_ready_explicitly_set_;
bool idempotent_;
bool cacheable_;
std::shared_ptr<::grpc_impl::Channel> channel_;
std::shared_ptr<Channel> channel_;
std::mutex mu_;
grpc_call* call_;
bool call_canceled_;
Expand Down
6 changes: 1 addition & 5 deletions include/grpcpp/impl/codegen/client_interceptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@
#include <grpcpp/impl/codegen/rpc_method.h>
#include <grpcpp/impl/codegen/string_ref.h>

namespace grpc_impl {

class Channel;
}

namespace grpc {

class ClientContext;
class Channel;

namespace internal {
class InterceptorBatchMethodsImpl;
Expand Down
8 changes: 2 additions & 6 deletions include/grpcpp/impl/codegen/completion_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@

struct grpc_completion_queue;

namespace grpc_impl {

class Channel;
}

namespace grpc {

template <class R>
Expand All @@ -63,6 +58,7 @@ template <class W, class R>
class ServerReaderWriterBody;
} // namespace internal

class Channel;
class ChannelInterface;
class ClientContext;
class CompletionQueue;
Expand Down Expand Up @@ -282,7 +278,7 @@ class CompletionQueue : private GrpcLibraryCodegen {
friend class ::grpc::internal::BlockingUnaryCallImpl;

// Friends that need access to constructor for callback CQ
friend class ::grpc_impl::Channel;
friend class ::grpc::Channel;

// For access to Register/CompleteAvalanching
template <class Op1, class Op2, class Op3, class Op4, class Op5, class Op6>
Expand Down
Loading

0 comments on commit 2ad245c

Please sign in to comment.