Addressed reviewer comments.

pull/6915/head
Mark D. Roth 9 years ago
parent ab950ee7c5
commit 97b173dfb8
  1. 53
      src/cpp/common/channel_filter.h

@ -37,6 +37,7 @@
#include <grpc++/impl/codegen/config.h> #include <grpc++/impl/codegen/config.h>
#include <grpc/census.h> #include <grpc/census.h>
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include <grpc/impl/codegen/alloc.h>
#include <functional> #include <functional>
#include <vector> #include <vector>
@ -46,18 +47,20 @@
#include "src/core/lib/surface/channel_init.h" #include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/transport/metadata_batch.h" #include "src/core/lib/transport/metadata_batch.h"
// ///
// An interface to define filters. /// An interface to define filters.
// ///
// To define a filter, implement a subclass of each of CallData and /// To define a filter, implement a subclass of each of \c CallData and
// ChannelData. Then register the filter using something like this: /// \c ChannelData. Then register the filter using something like this:
// RegisterChannelFilter<MyChannelDataSubclass, MyCallDataSubclass>( /// \code{.cpp}
// "name-of-filter", GRPC_SERVER_CHANNEL, INT_MAX, nullptr); /// RegisterChannelFilter<MyChannelDataSubclass, MyCallDataSubclass>(
// /// "name-of-filter", GRPC_SERVER_CHANNEL, INT_MAX, nullptr);
/// \endcode
///
namespace grpc { namespace grpc {
// A C++ wrapper for the grpc_metadata_batch struct. /// A C++ wrapper for the \c grpc_metadata_batch struct.
class MetadataBatch { class MetadataBatch {
public: public:
explicit MetadataBatch(grpc_metadata_batch *batch) : batch_(batch) {} explicit MetadataBatch(grpc_metadata_batch *batch) : batch_(batch) {}
@ -112,10 +115,10 @@ class MetadataBatch {
const_iterator end() const { return const_iterator(nullptr); } const_iterator end() const { return const_iterator(nullptr); }
private: private:
grpc_metadata_batch *batch_; grpc_metadata_batch *batch_; // Not owned.
}; };
// A C++ wrapper for the grpc_transport_op struct. /// A C++ wrapper for the \c grpc_transport_op struct.
class TransportOp { class TransportOp {
public: public:
explicit TransportOp(grpc_transport_op *op) : op_(op) {} explicit TransportOp(grpc_transport_op *op) : op_(op) {}
@ -131,10 +134,10 @@ class TransportOp {
// TODO(roth): Add methods for additional fields as needed. // TODO(roth): Add methods for additional fields as needed.
private: private:
grpc_transport_op *op_; // Do not own. grpc_transport_op *op_; // Not owned.
}; };
// A C++ wrapper for the grpc_transport_stream_op struct. /// A C++ wrapper for the \c grpc_transport_stream_op struct.
class TransportStreamOp { class TransportStreamOp {
public: public:
explicit TransportStreamOp(grpc_transport_stream_op *op) explicit TransportStreamOp(grpc_transport_stream_op *op)
@ -197,18 +200,21 @@ class TransportStreamOp {
} }
private: private:
grpc_transport_stream_op *op_; // Do not own. grpc_transport_stream_op *op_; // Not owned.
MetadataBatch send_initial_metadata_; MetadataBatch send_initial_metadata_;
MetadataBatch send_trailing_metadata_; MetadataBatch send_trailing_metadata_;
MetadataBatch recv_initial_metadata_; MetadataBatch recv_initial_metadata_;
MetadataBatch recv_trailing_metadata_; MetadataBatch recv_trailing_metadata_;
}; };
// Represents channel data. /// Represents channel data.
class ChannelData { class ChannelData {
public: public:
virtual ~ChannelData() {} virtual ~ChannelData() {
if (peer_) gpr_free((void *)peer_);
}
// Caller does NOT take ownership of result.
const char *peer() const { return peer_; } const char *peer() const { return peer_; }
// TODO(roth): Find a way to avoid passing elem into these methods. // TODO(roth): Find a way to avoid passing elem into these methods.
@ -216,13 +222,14 @@ class ChannelData {
grpc_channel_element *elem, TransportOp *op); grpc_channel_element *elem, TransportOp *op);
protected: protected:
/// Takes ownership of \a peer.
ChannelData(const grpc_channel_args &args, const char *peer) : peer_(peer) {} ChannelData(const grpc_channel_args &args, const char *peer) : peer_(peer) {}
private: private:
const char *peer_; // Do not own. const char *peer_;
}; };
// Represents call data. /// Represents call data.
class CallData { class CallData {
public: public:
virtual ~CallData() {} virtual ~CallData() {}
@ -330,11 +337,11 @@ void ChannelFilterPluginShutdown();
} // namespace internal } // namespace internal
// Registers a new filter. /// Registers a new filter.
// Must be called by only one thread at a time. /// Must be called by only one thread at a time.
// The include_filter argument specifies a function that will be called /// The \a include_filter argument specifies a function that will be called
// to determine at run-time whether or not to add the filter. If the /// to determine at run-time whether or not to add the filter. If the
// value is nullptr, the filter will be added unconditionally. /// value is nullptr, the filter will be added unconditionally.
template <typename ChannelDataType, typename CallDataType> template <typename ChannelDataType, typename CallDataType>
void RegisterChannelFilter( void RegisterChannelFilter(
const char *name, grpc_channel_stack_type stack_type, int priority, const char *name, grpc_channel_stack_type stack_type, int priority,

Loading…
Cancel
Save