gRPC  0.6.0
 All Classes Namespaces Functions Variables Enumerations Properties Pages
server_context.h
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 
39 #include <grpc/support/time.h>
40 #include <grpc++/config.h>
41 #include <grpc++/time.h>
42 
43 struct gpr_timespec;
44 struct grpc_metadata;
45 struct grpc_call;
46 
47 namespace grpc {
48 
49 template <class W, class R>
51 template <class W>
53 template <class W>
55 template <class R, class W>
57 template <class R>
58 class ServerReader;
59 template <class W>
60 class ServerWriter;
61 template <class R, class W>
62 class ServerReaderWriter;
63 
64 class Call;
65 class CallOpBuffer;
66 class CompletionQueue;
67 class Server;
68 
69 // Interface of server side rpc context.
71  public:
72  ServerContext(); // for async calls
73  ~ServerContext();
74 
75 #ifndef GRPC_CXX0X_NO_CHRONO
76  std::chrono::system_clock::time_point deadline() {
77  return Timespec2Timepoint(deadline_);
78  }
79 #endif // !GRPC_CXX0X_NO_CHRONO
80 
81  gpr_timespec raw_deadline() { return deadline_; }
82 
83  void AddInitialMetadata(const grpc::string& key, const grpc::string& value);
84  void AddTrailingMetadata(const grpc::string& key, const grpc::string& value);
85 
86  bool IsCancelled();
87 
88  const std::multimap<grpc::string, grpc::string>& client_metadata() {
89  return client_metadata_;
90  }
91 
92  private:
93  friend class ::grpc::Server;
94  template <class W, class R>
95  friend class ::grpc::ServerAsyncReader;
96  template <class W>
97  friend class ::grpc::ServerAsyncWriter;
98  template <class W>
99  friend class ::grpc::ServerAsyncResponseWriter;
100  template <class R, class W>
101  friend class ::grpc::ServerAsyncReaderWriter;
102  template <class R>
103  friend class ::grpc::ServerReader;
104  template <class W>
105  friend class ::grpc::ServerWriter;
106  template <class R, class W>
107  friend class ::grpc::ServerReaderWriter;
108 
109  class CompletionOp;
110 
111  void BeginCompletionOp(Call* call);
112 
113  ServerContext(gpr_timespec deadline, grpc_metadata* metadata,
114  size_t metadata_count);
115 
116  CompletionOp* completion_op_;
117 
118  gpr_timespec deadline_;
119  grpc_call* call_;
120  CompletionQueue* cq_;
121  bool sent_initial_metadata_;
122  std::multimap<grpc::string, grpc::string> client_metadata_;
123  std::multimap<grpc::string, grpc::string> initial_metadata_;
124  std::multimap<grpc::string, grpc::string> trailing_metadata_;
125 };
126 
127 } // namespace grpc
128 
129 #endif // GRPCXX_SERVER_CONTEXT_H
Definition: completion_queue.h:76
Definition: completion_queue.h:53
Definition: server_context.h:54
Definition: server_context.h:50
Definition: completion_queue.h:55
Definition: grpc.h:182
Definition: server_context.h:56
Definition: completion_queue.h:57
Definition: _call.h:44
Definition: call.h:53
Definition: server_context.h:70
Definition: time.h:48
Definition: server_context.h:52
Definition: call.c:128
Definition: _server.h:42