GRPC C++ 0.10.0.0

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
server_context.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_SERVER_CONTEXT_H
35 #define GRPCXX_SERVER_CONTEXT_H
36
37 #include <map>
38 #include <memory>
39
40 #include <grpc/compression.h>
41 #include <grpc/support/time.h>
42 #include <grpc++/auth_context.h>
43 #include <grpc++/config.h>
44 #include <grpc++/time.h>
45
46 struct gpr_timespec;
47 struct grpc_metadata;
48 struct grpc_call;
49 struct census_context;
50
51 namespace grpc {
52
53 template <class W, class R>
54 class ServerAsyncReader;
55 template <class W>
56 class ServerAsyncWriter;
57 template <class W>
58 class ServerAsyncResponseWriter;
59 template <class R, class W>
60 class ServerAsyncReaderWriter;
61 template <class R>
62 class ServerReader;
63 template <class W>
64 class ServerWriter;
65 template <class R, class W>
66 class ServerReaderWriter;
67 template <class ServiceType, class RequestType, class ResponseType>
68 class RpcMethodHandler;
69 template <class ServiceType, class RequestType, class ResponseType>
70 class ClientStreamingHandler;
71 template <class ServiceType, class RequestType, class ResponseType>
72 class ServerStreamingHandler;
73 template <class ServiceType, class RequestType, class ResponseType>
74 class BidiStreamingHandler;
75
76 class Call;
77 class CallOpBuffer;
78 class CompletionQueue;
79 class Server;
80
81 namespace testing {
82 class InteropContextInspector;
83 } // namespace testing
84
85 // Interface of server side rpc context.
86 class ServerContext {
87 public:
88 ServerContext(); // for async calls
89 ~ServerContext();
90
91 #ifndef GRPC_CXX0X_NO_CHRONO
92 std::chrono::system_clock::time_point deadline() {
93 return Timespec2Timepoint(deadline_);
94 }
95 #endif // !GRPC_CXX0X_NO_CHRONO
96
97 gpr_timespec raw_deadline() { return deadline_; }
98
99 void AddInitialMetadata(const grpc::string& key, const grpc::string& value);
100 void AddTrailingMetadata(const grpc::string& key, const grpc::string& value);
101
102 bool IsCancelled() const;
103
104 const std::multimap<grpc::string, grpc::string>& client_metadata() {
105 return client_metadata_;
106 }
107
108 grpc_compression_level compression_level() const {
109 return compression_level_;
110 }
111 void set_compression_level(grpc_compression_level level);
112
113 grpc_compression_algorithm compression_algorithm() const {
114 return compression_algorithm_;
115 }
116 void set_compression_algorithm(grpc_compression_algorithm algorithm);
117
118 std::shared_ptr<const AuthContext> auth_context() const;
119
120 // Return the peer uri in a string.
121 // WARNING: this value is never authenticated or subject to any security
122 // related code. It must not be used for any authentication related
123 // functionality. Instead, use auth_context.
124 grpc::string peer() const;
125
126 const struct census_context* census_context() const;
127
128 private:
129 friend class ::grpc::testing::InteropContextInspector;
130 friend class ::grpc::Server;
131 template <class W, class R>
132 friend class ::grpc::ServerAsyncReader;
133 template <class W>
134 friend class ::grpc::ServerAsyncWriter;
135 template <class W>
136 friend class ::grpc::ServerAsyncResponseWriter;
137 template <class R, class W>
138 friend class ::grpc::ServerAsyncReaderWriter;
139 template <class R>
140 friend class ::grpc::ServerReader;
141 template <class W>
142 friend class ::grpc::ServerWriter;
143 template <class R, class W>
144 friend class ::grpc::ServerReaderWriter;
145 template <class ServiceType, class RequestType, class ResponseType>
146 friend class RpcMethodHandler;
147 template <class ServiceType, class RequestType, class ResponseType>
148 friend class ClientStreamingHandler;
149 template <class ServiceType, class RequestType, class ResponseType>
150 friend class ServerStreamingHandler;
151 template <class ServiceType, class RequestType, class ResponseType>
152 friend class BidiStreamingHandler;
153
154 // Prevent copying.
155 ServerContext(const ServerContext&);
156 ServerContext& operator=(const ServerContext&);
157
158 class CompletionOp;
159
160 void BeginCompletionOp(Call* call);
161
162 ServerContext(gpr_timespec deadline, grpc_metadata* metadata,
163 size_t metadata_count);
164
165 void set_call(grpc_call* call);
166
167 CompletionOp* completion_op_;
168
169 gpr_timespec deadline_;
170 grpc_call* call_;
171 CompletionQueue* cq_;
172 bool sent_initial_metadata_;
173 mutable std::shared_ptr<const AuthContext> auth_context_;
174 std::multimap<grpc::string, grpc::string> client_metadata_;
175 std::multimap<grpc::string, grpc::string> initial_metadata_;
176 std::multimap<grpc::string, grpc::string> trailing_metadata_;
177
178 grpc_compression_level compression_level_;
179 grpc_compression_algorithm compression_algorithm_;
180 };
181
182 } // namespace grpc
183
184 #endif // GRPCXX_SERVER_CONTEXT_H
grpc::ServerContext::compression_algorithm
grpc_compression_algorithm compression_algorithm() const
Definition: server_context.h:113
grpc::ServerContext::deadline
std::chrono::system_clock::time_point deadline()
Definition: server_context.h:92
grpc::ServerContext::set_compression_algorithm
void set_compression_algorithm(grpc_compression_algorithm algorithm)
Definition: server_context.cc:159
grpc::ServerContext::compression_level
grpc_compression_level compression_level() const
Definition: server_context.h:108
grpc::string
std::string string
Definition: config.h:112
time.h
grpc::ServerContext::census_context
const struct census_context * census_context() const
Definition: server_context.cc:193
grpc::ServerContext::ServerContext
ServerContext()
Definition: server_context.cc:103
grpc::ServerAsyncReaderWriter
Definition: server_context.h:60
config.h
grpc::ServerContext::set_compression_level
void set_compression_level(grpc_compression_level level)
Definition: server_context.cc:153
grpc::ServerContext::AddInitialMetadata
void AddInitialMetadata(const grpc::string &key, const grpc::string &value)
Definition: server_context.cc:139
grpc::ServerReader
Definition: completion_queue.h:53
grpc::ServerAsyncWriter
Definition: server_context.h:56
auth_context.h
grpc::ServerContext::~ServerContext
~ServerContext()
Definition: server_context.cc:124
grpc::Server
Definition: server.h:61
grpc::Timespec2Timepoint
std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t)
Definition: time.cc:81
grpc::Call
Definition: call.h:565
grpc::RpcMethodHandler
Definition: completion_queue.h:59
grpc::ServerContext::IsCancelled
bool IsCancelled() const
Definition: server_context.cc:149
grpc::ServerContext
Definition: server_context.h:86
grpc::ServerContext::peer
grpc::string peer() const
Definition: server_context.cc:183
grpc::ServerContext::auth_context
std::shared_ptr< const AuthContext > auth_context() const
Definition: server_context.cc:176
grpc::ServerWriter
Definition: completion_queue.h:55
grpc::CompletionQueue
Definition: completion_queue.h:87
grpc::ClientStreamingHandler
Definition: completion_queue.h:61
grpc::ServerContext::client_metadata
const std::multimap< grpc::string, grpc::string > & client_metadata()
Definition: server_context.h:104
grpc::ServerContext::CompletionOp
Definition: server_context.cc:50
grpc::ServerReaderWriter
Definition: completion_queue.h:57
grpc::ServerStreamingHandler
Definition: completion_queue.h:63
grpc::ServerAsyncResponseWriter
Definition: async_unary_call.h:101
grpc::ServerContext::AddTrailingMetadata
void AddTrailingMetadata(const grpc::string &key, const grpc::string &value)
Definition: server_context.cc:144
grpc::ServerContext::raw_deadline
gpr_timespec raw_deadline()
Definition: server_context.h:97
grpc::ServerAsyncReader
Definition: server_context.h:54
grpc::BidiStreamingHandler
Definition: completion_queue.h:65