OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * |
| 3 * Copyright 2016, 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 #ifndef GRPC_TEST_CPP_END2END_TEST_SERVICE_IMPL_H |
| 34 #define GRPC_TEST_CPP_END2END_TEST_SERVICE_IMPL_H |
| 35 |
| 36 #include <memory> |
| 37 #include <mutex> |
| 38 |
| 39 #include <grpc++/server_context.h> |
| 40 #include <grpc/grpc.h> |
| 41 |
| 42 #include "src/proto/grpc/testing/echo.grpc.pb.h" |
| 43 |
| 44 namespace grpc { |
| 45 namespace testing { |
| 46 |
| 47 const int kNumResponseStreamsMsgs = 3; |
| 48 const char* const kServerCancelAfterReads = "cancel_after_reads"; |
| 49 const char* const kServerTryCancelRequest = "server_try_cancel"; |
| 50 |
| 51 typedef enum { |
| 52 DO_NOT_CANCEL = 0, |
| 53 CANCEL_BEFORE_PROCESSING, |
| 54 CANCEL_DURING_PROCESSING, |
| 55 CANCEL_AFTER_PROCESSING |
| 56 } ServerTryCancelRequestPhase; |
| 57 |
| 58 class TestServiceImpl : public ::grpc::testing::EchoTestService::Service { |
| 59 public: |
| 60 TestServiceImpl() : signal_client_(false), host_() {} |
| 61 explicit TestServiceImpl(const grpc::string& host) |
| 62 : signal_client_(false), host_(new grpc::string(host)) {} |
| 63 |
| 64 Status Echo(ServerContext* context, const EchoRequest* request, |
| 65 EchoResponse* response) GRPC_OVERRIDE; |
| 66 |
| 67 // Unimplemented is left unimplemented to test the returned error. |
| 68 |
| 69 Status RequestStream(ServerContext* context, |
| 70 ServerReader<EchoRequest>* reader, |
| 71 EchoResponse* response) GRPC_OVERRIDE; |
| 72 |
| 73 Status ResponseStream(ServerContext* context, const EchoRequest* request, |
| 74 ServerWriter<EchoResponse>* writer) GRPC_OVERRIDE; |
| 75 |
| 76 Status BidiStream(ServerContext* context, |
| 77 ServerReaderWriter<EchoResponse, EchoRequest>* stream) |
| 78 GRPC_OVERRIDE; |
| 79 |
| 80 bool signal_client() { |
| 81 std::unique_lock<std::mutex> lock(mu_); |
| 82 return signal_client_; |
| 83 } |
| 84 |
| 85 private: |
| 86 int GetIntValueFromMetadata( |
| 87 const char* key, |
| 88 const std::multimap<grpc::string_ref, grpc::string_ref>& metadata, |
| 89 int default_value); |
| 90 |
| 91 void ServerTryCancel(ServerContext* context); |
| 92 |
| 93 private: |
| 94 bool signal_client_; |
| 95 std::mutex mu_; |
| 96 std::unique_ptr<grpc::string> host_; |
| 97 }; |
| 98 |
| 99 } // namespace testing |
| 100 } // namespace grpc |
| 101 |
| 102 #endif // GRPC_TEST_CPP_END2END_TEST_SERVICE_IMPL_H |
OLD | NEW |