GRPC C++  1.3.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, Google Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following disclaimer
14  * in the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of Google Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
34 #ifndef GRPCXX_CHANNEL_H
35 #define GRPCXX_CHANNEL_H
36 
37 #include <memory>
38 
39 #include <grpc++/impl/call.h>
43 #include <grpc/grpc.h>
44 
45 struct grpc_channel;
46 
47 namespace grpc {
49 class Channel final : public ChannelInterface,
50  public CallHook,
51  public std::enable_shared_from_this<Channel>,
52  private GrpcLibraryCodegen {
53  public:
54  ~Channel();
55 
58  grpc_connectivity_state GetState(bool try_to_connect) override;
59 
62 
66 
67  private:
68  template <class InputMessage, class OutputMessage>
70  const RpcMethod& method,
71  ClientContext* context,
72  const InputMessage& request,
73  OutputMessage* result);
74  friend std::shared_ptr<Channel> CreateChannelInternal(
75  const grpc::string& host, grpc_channel* c_channel);
76  Channel(const grpc::string& host, grpc_channel* c_channel);
77 
78  Call CreateCall(const RpcMethod& method, ClientContext* context,
79  CompletionQueue* cq) override;
80  void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) override;
81  void* RegisterMethod(const char* method) override;
82 
83  void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed,
84  gpr_timespec deadline, CompletionQueue* cq,
85  void* tag) override;
86  bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
87  gpr_timespec deadline) override;
88 
89  const grpc::string host_;
90  grpc_channel* const c_channel_; // owned
91 };
92 
93 } // namespace grpc
94 
95 #endif // GRPCXX_CHANNEL_H
std::string string
Definition: config.h:50
struct grpc_channel grpc_channel
The Channel interface allows creation of Call objects.
Definition: grpc_types.h:77
An abstract collection of call ops, used to generate the grpc_call_op structure to pass down to the l...
Definition: call.h:598
Classes that require gRPC to be initialized should inherit from this class.
Definition: grpc_library.h:52
Definition: client_context.h:154
grpc_connectivity_state
Connectivity state of a channel.
Definition: connectivity_state.h:42
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)
Definition: client_unary_call.h:52
Definition: call.h:675
Codegen interface for grpc::Channel.
Definition: channel_interface.h:64
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue.h:101
Definition: rpc_method.h:43
Did it work? If it didn't, why?
Definition: status.h:45
Definition: gpr_types.h:63
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.
Channel and Server implement this to allow them to hook performing ops.
Definition: call_hook.h:43
Channels represent a connection to an endpoint. Created by CreateChannel.
Definition: channel.h:49