GRPC C++  0.11.0.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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/grpc.h>
40 #include <grpc++/impl/call.h>
42 #include <grpc++/support/config.h>
43 
44 struct grpc_channel;
45 
46 namespace grpc {
47 class CallOpSetInterface;
48 class ChannelArguments;
49 class CompletionQueue;
50 class Credentials;
51 class SecureCredentials;
52 
53 template <class R>
55 template <class W>
57 template <class R, class W>
59 template <class R>
61 template <class W>
63 template <class R, class W>
65 template <class R>
67 
70  public CallHook,
71  public std::enable_shared_from_this<Channel> {
72  public:
73  ~Channel();
74 
77  grpc_connectivity_state GetState(bool try_to_connect);
78 
81  template <typename T>
82  void NotifyOnStateChange(grpc_connectivity_state last_observed, T deadline,
83  CompletionQueue* cq, void* tag) {
84  TimePoint<T> deadline_tp(deadline);
85  NotifyOnStateChangeImpl(last_observed, deadline_tp.raw_time(), cq, tag);
86  }
87 
90  template <typename T>
91  bool WaitForStateChange(grpc_connectivity_state last_observed, T deadline) {
92  TimePoint<T> deadline_tp(deadline);
93  return WaitForStateChangeImpl(last_observed, deadline_tp.raw_time());
94  }
95 
96  private:
97  template <class R>
98  friend class ::grpc::ClientReader;
99  template <class W>
100  friend class ::grpc::ClientWriter;
101  template <class R, class W>
102  friend class ::grpc::ClientReaderWriter;
103  template <class R>
104  friend class ::grpc::ClientAsyncReader;
105  template <class W>
106  friend class ::grpc::ClientAsyncWriter;
107  template <class R, class W>
108  friend class ::grpc::ClientAsyncReaderWriter;
109  template <class R>
110  friend class ::grpc::ClientAsyncResponseReader;
111  template <class InputMessage, class OutputMessage>
112  friend Status BlockingUnaryCall(Channel* channel, const RpcMethod& method,
113  ClientContext* context,
114  const InputMessage& request,
115  OutputMessage* result);
116  friend class ::grpc::RpcMethod;
117  friend std::shared_ptr<Channel> CreateChannelInternal(
118  const grpc::string& host, grpc_channel* c_channel);
119 
120  Channel(const grpc::string& host, grpc_channel* c_channel);
121 
122  Call CreateCall(const RpcMethod& method, ClientContext* context,
123  CompletionQueue* cq);
124  void PerformOpsOnCall(CallOpSetInterface* ops, Call* call);
125  void* RegisterMethod(const char* method);
126 
127  void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed,
128  gpr_timespec deadline, CompletionQueue* cq,
129  void* tag);
130  bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
131  gpr_timespec deadline);
132 
133  const grpc::string host_;
134  grpc_channel* const c_channel_; // owned
135 };
136 
137 } // namespace grpc
138 
139 #endif // GRPCXX_CHANNEL_H
Definition: channel.h:64
Definition: channel.h:54
void NotifyOnStateChange(grpc_connectivity_state last_observed, T deadline, CompletionQueue *cq, void *tag)
Return the tag on cq when the channel state is changed or deadline expires.
Definition: channel.h:82
bool WaitForStateChange(grpc_connectivity_state last_observed, T deadline)
Blocking wait for channel state change or deadline expiration.
Definition: channel.h:91
std::string string
Definition: config.h:112
An abstract collection of call ops, used to generate the grpc_call_op structure to pass down to the l...
Definition: call.h:478
Options for channel creation.
Definition: channel_arguments.h:52
grpc_connectivity_state GetState(bool try_to_connect)
Get the current channel state.
#define GRPC_FINAL
Definition: config.h:71
gpr_timespec raw_time()
Definition: time.h:56
Definition: time.h:53
Definition: channel.h:66
Definition: client_context.h:149
Definition: grpc_library.h:41
friend std::shared_ptr< Channel > CreateChannelInternal(const grpc::string &host, grpc_channel *c_channel)
Definition: call.h:560
A credentials object encapsulates all the state needed by a client to authenticate with a server and ...
Definition: credentials.h:53
Definition: channel.h:62
friend Status BlockingUnaryCall(Channel *channel, const RpcMethod &method, ClientContext *context, const InputMessage &request, OutputMessage *result)
Definition: client_unary_call.h:50
A thin wrapper around grpc_completion_queue (see / src/core/surface/completion_queue.h).
Definition: completion_queue.h:81
Definition: rpc_method.h:43
Did it work? If it didn't, why?
Definition: status.h:45
Definition: channel.h:58
Definition: channel.h:60
Definition: channel.h:56
Definition: call.h:553
Channels represent a connection to an endpoint. Created by CreateChannel.
Definition: channel.h:69