Line data Source code
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_IMPL_SERVICE_TYPE_H
35 : #define GRPCXX_IMPL_SERVICE_TYPE_H
36 :
37 : #include <grpc++/impl/serialization_traits.h>
38 : #include <grpc++/server.h>
39 : #include <grpc++/support/config.h>
40 : #include <grpc++/support/status.h>
41 :
42 : namespace grpc {
43 :
44 : class Call;
45 : class CompletionQueue;
46 : class RpcService;
47 : class Server;
48 : class ServerCompletionQueue;
49 : class ServerContext;
50 :
51 298 : class SynchronousService {
52 : public:
53 298 : virtual ~SynchronousService() {}
54 : virtual RpcService* service() = 0;
55 : };
56 :
57 2410655 : class ServerAsyncStreamingInterface {
58 : public:
59 1245279 : virtual ~ServerAsyncStreamingInterface() {}
60 :
61 : virtual void SendInitialMetadata(void* tag) = 0;
62 :
63 : private:
64 : friend class Server;
65 : virtual void BindCall(Call* call) = 0;
66 : };
67 :
68 : class AsynchronousService {
69 : public:
70 30 : AsynchronousService(const char** method_names, size_t method_count)
71 : : server_(nullptr),
72 : method_names_(method_names),
73 : method_count_(method_count),
74 30 : request_args_(nullptr) {}
75 :
76 30 : ~AsynchronousService() { delete[] request_args_; }
77 :
78 : protected:
79 : template <class Message>
80 1180638 : void RequestAsyncUnary(int index, ServerContext* context, Message* request,
81 : ServerAsyncStreamingInterface* stream,
82 : CompletionQueue* call_cq,
83 : ServerCompletionQueue* notification_cq, void* tag) {
84 1180638 : server_->RequestAsyncCall(request_args_[index], context, stream, call_cq,
85 : notification_cq, tag, request);
86 1180630 : }
87 2 : void RequestClientStreaming(int index, ServerContext* context,
88 : ServerAsyncStreamingInterface* stream,
89 : CompletionQueue* call_cq,
90 : ServerCompletionQueue* notification_cq,
91 : void* tag) {
92 2 : server_->RequestAsyncCall(request_args_[index], context, stream, call_cq,
93 2 : notification_cq, tag);
94 2 : }
95 : template <class Message>
96 2 : void RequestServerStreaming(int index, ServerContext* context,
97 : Message* request,
98 : ServerAsyncStreamingInterface* stream,
99 : CompletionQueue* call_cq,
100 : ServerCompletionQueue* notification_cq,
101 : void* tag) {
102 2 : server_->RequestAsyncCall(request_args_[index], context, stream, call_cq,
103 : notification_cq, tag, request);
104 2 : }
105 65057 : void RequestBidiStreaming(int index, ServerContext* context,
106 : ServerAsyncStreamingInterface* stream,
107 : CompletionQueue* call_cq,
108 : ServerCompletionQueue* notification_cq, void* tag) {
109 65057 : server_->RequestAsyncCall(request_args_[index], context, stream, call_cq,
110 65057 : notification_cq, tag);
111 65258 : }
112 :
113 : private:
114 : friend class Server;
115 : Server* server_;
116 : const char** const method_names_;
117 : size_t method_count_;
118 : void** request_args_;
119 : };
120 :
121 : } // namespace grpc
122 :
123 : #endif // GRPCXX_IMPL_SERVICE_TYPE_H
|