GRPC C++  1.6.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 GRPCXX_CHANNEL_H
20 #define GRPCXX_CHANNEL_H
21 
22 #include <memory>
23 
24 #include <grpc++/impl/call.h>
28 #include <grpc/grpc.h>
29 
30 struct grpc_channel;
31 
32 namespace grpc {
34 class Channel final : public ChannelInterface,
35  public 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  const RpcMethod& method,
56  ClientContext* context,
57  const InputMessage& request,
58  OutputMessage* result);
59  friend std::shared_ptr<Channel> CreateChannelInternal(
60  const grpc::string& host, grpc_channel* c_channel);
61  Channel(const grpc::string& host, grpc_channel* c_channel);
62 
63  Call CreateCall(const RpcMethod& method, ClientContext* context,
64  CompletionQueue* cq) override;
65  void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) override;
66  void* RegisterMethod(const char* method) override;
67 
68  void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed,
69  gpr_timespec deadline, CompletionQueue* cq,
70  void* tag) override;
71  bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
72  gpr_timespec deadline) override;
73 
74  const grpc::string host_;
75  grpc_channel* const c_channel_; // owned
76 };
77 
78 } // namespace grpc
79 
80 #endif // GRPCXX_CHANNEL_H
std::string string
Definition: config.h:35
struct grpc_channel grpc_channel
The Channel interface allows creation of Call objects.
Definition: grpc_types.h:63
An abstract collection of call ops, used to generate the grpc_call_op structure to pass down to the l...
Definition: call.h:575
Classes that require gRPC to be initialized should inherit from this class.
Definition: grpc_library.h:37
A ClientContext allows the person implementing a service client to:
Definition: client_context.h:153
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)
friend Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method, ClientContext *context, const InputMessage &request, OutputMessage *result)
Wrapper that performs a blocking unary call.
Definition: client_unary_call.h:37
Straightforward wrapping of the C call object.
Definition: call.h:647
Codegen interface for grpc::Channel.
Definition: channel_interface.h:49
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue.h:86
Descriptor of an RPC method.
Definition: rpc_method.h:29
Did it work? If it didn't, why?
Definition: status.h:30
Analogous to struct timespec.
Definition: gpr_types.h:47
grpc::string GetServiceConfigJSON() const
Returns the service config in JSON form, or the empty string if not available.
grpc_connectivity_state GetState(bool try_to_connect) override
Get the current channel state.
grpc::string GetLoadBalancingPolicyName() const
Returns the LB policy name, or the empty string if not yet available.
This is an interface that Channel and Server implement to allow them to hook performing ops...
Definition: call_hook.h:29
Channels represent a connection to an endpoint. Created by CreateChannel.
Definition: channel.h:34