GRPC C++  1.13.0-dev
channel.h
Go to the documentation of this file.
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 #ifndef GRPCPP_CHANNEL_H
20 #define GRPCPP_CHANNEL_H
21 
22 #include <memory>
23 
24 #include <grpc/grpc.h>
25 #include <grpcpp/impl/call.h>
29 
30 struct grpc_channel;
31 
32 namespace grpc {
34 class Channel final : public ChannelInterface,
35  public internal::CallHook,
36  public std::enable_shared_from_this<Channel>,
37  private GrpcLibraryCodegen {
38  public:
39  ~Channel();
40 
43  grpc_connectivity_state GetState(bool try_to_connect) override;
44 
47 
51 
52  private:
53  template <class InputMessage, class OutputMessage>
55  friend std::shared_ptr<Channel> CreateChannelInternal(
56  const grpc::string& host, grpc_channel* c_channel);
57  Channel(const grpc::string& host, grpc_channel* c_channel);
58 
59  internal::Call CreateCall(const internal::RpcMethod& method,
60  ClientContext* context,
61  CompletionQueue* cq) override;
62  void PerformOpsOnCall(internal::CallOpSetInterface* ops,
63  internal::Call* call) override;
64  void* RegisterMethod(const char* method) override;
65 
66  void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed,
67  gpr_timespec deadline, CompletionQueue* cq,
68  void* tag) override;
69  bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
70  gpr_timespec deadline) override;
71 
72  const grpc::string host_;
73  grpc_channel* const c_channel_; // owned
74 };
75 
76 } // namespace grpc
77 
78 #endif // GRPCPP_CHANNEL_H
grpc::string GetLoadBalancingPolicyName() const
Returns the LB policy name, or the empty string if not yet available.
std::string string
Definition: config.h:35
struct grpc_channel grpc_channel
The Channel interface allows creation of Call objects.
Definition: grpc_types.h:62
grpc::string GetServiceConfigJSON() const
Returns the service config in JSON form, or the empty string if not available.
Classes that require gRPC to be initialized should inherit from this class.
Definition: grpc_library.h:38
A ClientContext allows the person implementing a service client to:
Definition: client_context.h:162
Descriptor of an RPC method.
Definition: rpc_method.h:29
grpc_connectivity_state
Connectivity state of a channel.
Definition: connectivity_state.h:27
friend std::shared_ptr< Channel > CreateChannelInternal(const grpc::string &host, grpc_channel *c_channel)
An Alarm posts the user provided tag to its associated completion queue upon expiry or cancellation...
Definition: alarm.h:31
Codegen interface for grpc::Channel.
Definition: channel_interface.h:55
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue.h:94
An abstract collection of call ops, used to generate the grpc_call_op structure to pass down to the l...
Definition: call.h:603
Definition: channel_interface.h:43
Analogous to struct timespec.
Definition: gpr_types.h:47
grpc_connectivity_state GetState(bool try_to_connect) override
Get the current channel state.
This is an interface that Channel and Server implement to allow them to hook performing ops...
Definition: call_hook.h:30
Straightforward wrapping of the C call object.
Definition: call.h:660
Channels represent a connection to an endpoint. Created by CreateChannel.
Definition: channel.h:34