LCOV - code coverage report
Current view: top level - include/grpc++ - server_context.h (source / functions) Hit Total Coverage
Test: tmp.zDYK9MVh93 Lines: 8 8 100.0 %
Date: 2015-10-10 Functions: 3 3 100.0 %

          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_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++/security/auth_context.h>
      43             : #include <grpc++/support/config.h>
      44             : #include <grpc++/support/string_ref.h>
      45             : #include <grpc++/support/time.h>
      46             : 
      47             : struct gpr_timespec;
      48             : struct grpc_metadata;
      49             : struct grpc_call;
      50             : struct census_context;
      51             : 
      52             : namespace grpc {
      53             : 
      54             : class ClientContext;
      55             : template <class W, class R>
      56             : class ServerAsyncReader;
      57             : template <class W>
      58             : class ServerAsyncWriter;
      59             : template <class W>
      60             : class ServerAsyncResponseWriter;
      61             : template <class R, class W>
      62             : class ServerAsyncReaderWriter;
      63             : template <class R>
      64             : class ServerReader;
      65             : template <class W>
      66             : class ServerWriter;
      67             : template <class R, class W>
      68             : class ServerReaderWriter;
      69             : template <class ServiceType, class RequestType, class ResponseType>
      70             : class RpcMethodHandler;
      71             : template <class ServiceType, class RequestType, class ResponseType>
      72             : class ClientStreamingHandler;
      73             : template <class ServiceType, class RequestType, class ResponseType>
      74             : class ServerStreamingHandler;
      75             : template <class ServiceType, class RequestType, class ResponseType>
      76             : class BidiStreamingHandler;
      77             : class UnknownMethodHandler;
      78             : 
      79             : class Call;
      80             : class CallOpBuffer;
      81             : class CompletionQueue;
      82             : class Server;
      83             : 
      84             : namespace testing {
      85             : class InteropServerContextInspector;
      86             : }  // namespace testing
      87             : 
      88             : // Interface of server side rpc context.
      89             : class ServerContext {
      90             :  public:
      91             :   ServerContext();  // for async calls
      92             :   ~ServerContext();
      93             : 
      94             : #ifndef GRPC_CXX0X_NO_CHRONO
      95          12 :   std::chrono::system_clock::time_point deadline() {
      96          12 :     return Timespec2Timepoint(deadline_);
      97             :   }
      98             : #endif  // !GRPC_CXX0X_NO_CHRONO
      99             : 
     100             :   gpr_timespec raw_deadline() { return deadline_; }
     101             : 
     102             :   void AddInitialMetadata(const grpc::string& key, const grpc::string& value);
     103             :   void AddTrailingMetadata(const grpc::string& key, const grpc::string& value);
     104             : 
     105             :   bool IsCancelled() const;
     106             : 
     107          26 :   const std::multimap<grpc::string_ref, grpc::string_ref>& client_metadata() {
     108          26 :     return client_metadata_;
     109             :   }
     110             : 
     111             :   grpc_compression_level compression_level() const {
     112             :     return compression_level_;
     113             :   }
     114             :   void set_compression_level(grpc_compression_level level);
     115             : 
     116             :   grpc_compression_algorithm compression_algorithm() const {
     117             :     return compression_algorithm_;
     118             :   }
     119             :   void set_compression_algorithm(grpc_compression_algorithm algorithm);
     120             : 
     121             :   std::shared_ptr<const AuthContext> auth_context() const;
     122             : 
     123             :   // Return the peer uri in a string.
     124             :   // WARNING: this value is never authenticated or subject to any security
     125             :   // related code. It must not be used for any authentication related
     126             :   // functionality. Instead, use auth_context.
     127             :   grpc::string peer() const;
     128             : 
     129             :   const struct census_context* census_context() const;
     130             : 
     131             :   // Async only. Has to be called before the rpc starts.
     132             :   // Returns the tag in completion queue when the rpc finishes.
     133             :   // IsCancelled() can then be called to check whether the rpc was cancelled.
     134           4 :   void AsyncNotifyWhenDone(void* tag) {
     135           4 :     has_notify_when_done_tag_ = true;
     136           4 :     async_notify_when_done_tag_ = tag;
     137           4 :   }
     138             : 
     139             :  private:
     140             :   friend class ::grpc::testing::InteropServerContextInspector;
     141             :   friend class ::grpc::Server;
     142             :   template <class W, class R>
     143             :   friend class ::grpc::ServerAsyncReader;
     144             :   template <class W>
     145             :   friend class ::grpc::ServerAsyncWriter;
     146             :   template <class W>
     147             :   friend class ::grpc::ServerAsyncResponseWriter;
     148             :   template <class R, class W>
     149             :   friend class ::grpc::ServerAsyncReaderWriter;
     150             :   template <class R>
     151             :   friend class ::grpc::ServerReader;
     152             :   template <class W>
     153             :   friend class ::grpc::ServerWriter;
     154             :   template <class R, class W>
     155             :   friend class ::grpc::ServerReaderWriter;
     156             :   template <class ServiceType, class RequestType, class ResponseType>
     157             :   friend class RpcMethodHandler;
     158             :   template <class ServiceType, class RequestType, class ResponseType>
     159             :   friend class ClientStreamingHandler;
     160             :   template <class ServiceType, class RequestType, class ResponseType>
     161             :   friend class ServerStreamingHandler;
     162             :   template <class ServiceType, class RequestType, class ResponseType>
     163             :   friend class BidiStreamingHandler;
     164             :   friend class UnknownMethodHandler;
     165             :   friend class ::grpc::ClientContext;
     166             : 
     167             :   // Prevent copying.
     168             :   ServerContext(const ServerContext&);
     169             :   ServerContext& operator=(const ServerContext&);
     170             : 
     171             :   class CompletionOp;
     172             : 
     173             :   void BeginCompletionOp(Call* call);
     174             : 
     175             :   ServerContext(gpr_timespec deadline, grpc_metadata* metadata,
     176             :                 size_t metadata_count);
     177             : 
     178             :   void set_call(grpc_call* call);
     179             : 
     180             :   CompletionOp* completion_op_;
     181             :   bool has_notify_when_done_tag_;
     182             :   void* async_notify_when_done_tag_;
     183             : 
     184             :   gpr_timespec deadline_;
     185             :   grpc_call* call_;
     186             :   CompletionQueue* cq_;
     187             :   bool sent_initial_metadata_;
     188             :   mutable std::shared_ptr<const AuthContext> auth_context_;
     189             :   std::multimap<grpc::string_ref, grpc::string_ref> client_metadata_;
     190             :   std::multimap<grpc::string, grpc::string> initial_metadata_;
     191             :   std::multimap<grpc::string, grpc::string> trailing_metadata_;
     192             : 
     193             :   grpc_compression_level compression_level_;
     194             :   grpc_compression_algorithm compression_algorithm_;
     195             : };
     196             : 
     197             : }  // namespace grpc
     198             : 
     199             : #endif  // GRPCXX_SERVER_CONTEXT_H

Generated by: LCOV version 1.10