diff options
Diffstat (limited to 'src/cpp/common')
-rw-r--r-- | src/cpp/common/channel_filter.cc | 44 | ||||
-rw-r--r-- | src/cpp/common/channel_filter.h | 189 | ||||
-rw-r--r-- | src/cpp/common/core_codegen.cc | 7 | ||||
-rw-r--r-- | src/cpp/common/version_cc.cc | 2 |
4 files changed, 124 insertions, 118 deletions
diff --git a/src/cpp/common/channel_filter.cc b/src/cpp/common/channel_filter.cc index ea44cff832..d1cfd2b48a 100644 --- a/src/cpp/common/channel_filter.cc +++ b/src/cpp/common/channel_filter.cc @@ -29,10 +29,10 @@ namespace grpc { // MetadataBatch -grpc_linked_mdelem *MetadataBatch::AddMetadata(grpc_exec_ctx *exec_ctx, - const string &key, - const string &value) { - grpc_linked_mdelem *storage = new grpc_linked_mdelem; +grpc_linked_mdelem* MetadataBatch::AddMetadata(grpc_exec_ctx* exec_ctx, + const string& key, + const string& value) { + grpc_linked_mdelem* storage = new grpc_linked_mdelem; memset(storage, 0, sizeof(grpc_linked_mdelem)); storage->md = grpc_mdelem_from_slices(exec_ctx, SliceFromCopiedString(key), SliceFromCopiedString(value)); @@ -43,28 +43,28 @@ grpc_linked_mdelem *MetadataBatch::AddMetadata(grpc_exec_ctx *exec_ctx, // ChannelData -void ChannelData::StartTransportOp(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, - TransportOp *op) { +void ChannelData::StartTransportOp(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, + TransportOp* op) { grpc_channel_next_op(exec_ctx, elem, op->op()); } -void ChannelData::GetInfo(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, - const grpc_channel_info *channel_info) { +void ChannelData::GetInfo(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + const grpc_channel_info* channel_info) { grpc_channel_next_get_info(exec_ctx, elem, channel_info); } // CallData -void CallData::StartTransportStreamOpBatch(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - TransportStreamOpBatch *op) { +void CallData::StartTransportStreamOpBatch(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + TransportStreamOpBatch* op) { grpc_call_next_op(exec_ctx, elem, op->op()); } -void CallData::SetPollsetOrPollsetSet(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_polling_entity *pollent) { +void CallData::SetPollsetOrPollsetSet(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + grpc_polling_entity* pollent) { grpc_call_stack_ignore_set_pollset_or_pollset_set(exec_ctx, elem, pollent); } @@ -73,15 +73,15 @@ void CallData::SetPollsetOrPollsetSet(grpc_exec_ctx *exec_ctx, namespace internal { // Note: Implicitly initialized to nullptr due to static lifetime. -std::vector<FilterRecord> *channel_filters; +std::vector<FilterRecord>* channel_filters; namespace { -bool MaybeAddFilter(grpc_exec_ctx *exec_ctx, - grpc_channel_stack_builder *builder, void *arg) { - const FilterRecord &filter = *(FilterRecord *)arg; +bool MaybeAddFilter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg) { + const FilterRecord& filter = *(FilterRecord*)arg; if (filter.include_filter) { - const grpc_channel_args *args = + const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder); if (!filter.include_filter(*args)) return true; } @@ -93,9 +93,9 @@ bool MaybeAddFilter(grpc_exec_ctx *exec_ctx, void ChannelFilterPluginInit() { for (size_t i = 0; i < channel_filters->size(); ++i) { - FilterRecord &filter = (*channel_filters)[i]; + FilterRecord& filter = (*channel_filters)[i]; grpc_channel_init_register_stage(filter.stack_type, filter.priority, - MaybeAddFilter, (void *)&filter); + MaybeAddFilter, (void*)&filter); } } diff --git a/src/cpp/common/channel_filter.h b/src/cpp/common/channel_filter.h index c1aeb3f724..4fb81ecb1e 100644 --- a/src/cpp/common/channel_filter.h +++ b/src/cpp/common/channel_filter.h @@ -49,23 +49,23 @@ class MetadataBatch { /// Borrows a pointer to \a batch, but does NOT take ownership. /// The caller must ensure that \a batch continues to exist for as /// long as the MetadataBatch object does. - explicit MetadataBatch(grpc_metadata_batch *batch) : batch_(batch) {} + explicit MetadataBatch(grpc_metadata_batch* batch) : batch_(batch) {} - grpc_metadata_batch *batch() const { return batch_; } + grpc_metadata_batch* batch() const { return batch_; } /// Adds metadata and returns the newly allocated storage. /// The caller takes ownership of the result, which must exist for the /// lifetime of the gRPC call. - grpc_linked_mdelem *AddMetadata(grpc_exec_ctx *exec_ctx, const string &key, - const string &value); + grpc_linked_mdelem* AddMetadata(grpc_exec_ctx* exec_ctx, const string& key, + const string& value); class const_iterator : public std::iterator<std::bidirectional_iterator_tag, const grpc_mdelem> { public: - const grpc_mdelem &operator*() const { return elem_->md; } + const grpc_mdelem& operator*() const { return elem_->md; } const grpc_mdelem operator->() const { return elem_->md; } - const_iterator &operator++() { + const_iterator& operator++() { elem_ = elem_->next; return *this; } @@ -74,7 +74,7 @@ class MetadataBatch { operator++(); return tmp; } - const_iterator &operator--() { + const_iterator& operator--() { elem_ = elem_->prev; return *this; } @@ -84,25 +84,25 @@ class MetadataBatch { return tmp; } - bool operator==(const const_iterator &other) const { + bool operator==(const const_iterator& other) const { return elem_ == other.elem_; } - bool operator!=(const const_iterator &other) const { + bool operator!=(const const_iterator& other) const { return elem_ != other.elem_; } private: friend class MetadataBatch; - explicit const_iterator(grpc_linked_mdelem *elem) : elem_(elem) {} + explicit const_iterator(grpc_linked_mdelem* elem) : elem_(elem) {} - grpc_linked_mdelem *elem_; + grpc_linked_mdelem* elem_; }; const_iterator begin() const { return const_iterator(batch_->list.head); } const_iterator end() const { return const_iterator(nullptr); } private: - grpc_metadata_batch *batch_; // Not owned. + grpc_metadata_batch* batch_; // Not owned. }; /// A C++ wrapper for the \c grpc_transport_op struct. @@ -111,12 +111,12 @@ class TransportOp { /// Borrows a pointer to \a op, but does NOT take ownership. /// The caller must ensure that \a op continues to exist for as /// long as the TransportOp object does. - explicit TransportOp(grpc_transport_op *op) : op_(op) {} + explicit TransportOp(grpc_transport_op* op) : op_(op) {} - grpc_transport_op *op() const { return op_; } + grpc_transport_op* op() const { return op_; } // TODO(roth): Add a C++ wrapper for grpc_error? - grpc_error *disconnect_with_error() const { + grpc_error* disconnect_with_error() const { return op_->disconnect_with_error; } bool send_goaway() const { return op_->goaway_error != GRPC_ERROR_NONE; } @@ -124,7 +124,7 @@ class TransportOp { // TODO(roth): Add methods for additional fields as needed. private: - grpc_transport_op *op_; // Not owned. + grpc_transport_op* op_; // Not owned. }; /// A C++ wrapper for the \c grpc_transport_stream_op_batch struct. @@ -133,7 +133,7 @@ class TransportStreamOpBatch { /// Borrows a pointer to \a op, but does NOT take ownership. /// The caller must ensure that \a op continues to exist for as /// long as the TransportStreamOpBatch object does. - explicit TransportStreamOpBatch(grpc_transport_stream_op_batch *op) + explicit TransportStreamOpBatch(grpc_transport_stream_op_batch* op) : op_(op), send_initial_metadata_( op->send_initial_metadata @@ -152,64 +152,63 @@ class TransportStreamOpBatch { ? op->payload->recv_trailing_metadata.recv_trailing_metadata : nullptr) {} - grpc_transport_stream_op_batch *op() const { return op_; } + grpc_transport_stream_op_batch* op() const { return op_; } - grpc_closure *on_complete() const { return op_->on_complete; } - void set_on_complete(grpc_closure *closure) { op_->on_complete = closure; } + grpc_closure* on_complete() const { return op_->on_complete; } + void set_on_complete(grpc_closure* closure) { op_->on_complete = closure; } - MetadataBatch *send_initial_metadata() { + MetadataBatch* send_initial_metadata() { return op_->send_initial_metadata ? &send_initial_metadata_ : nullptr; } - MetadataBatch *send_trailing_metadata() { + MetadataBatch* send_trailing_metadata() { return op_->send_trailing_metadata ? &send_trailing_metadata_ : nullptr; } - MetadataBatch *recv_initial_metadata() { + MetadataBatch* recv_initial_metadata() { return op_->recv_initial_metadata ? &recv_initial_metadata_ : nullptr; } - MetadataBatch *recv_trailing_metadata() { + MetadataBatch* recv_trailing_metadata() { return op_->recv_trailing_metadata ? &recv_trailing_metadata_ : nullptr; } - uint32_t *send_initial_metadata_flags() const { - return op_->send_initial_metadata - ? &op_->payload->send_initial_metadata - .send_initial_metadata_flags - : nullptr; + uint32_t* send_initial_metadata_flags() const { + return op_->send_initial_metadata ? &op_->payload->send_initial_metadata + .send_initial_metadata_flags + : nullptr; } - grpc_closure *recv_initial_metadata_ready() const { + grpc_closure* recv_initial_metadata_ready() const { return op_->recv_initial_metadata ? op_->payload->recv_initial_metadata.recv_initial_metadata_ready : nullptr; } - void set_recv_initial_metadata_ready(grpc_closure *closure) { + void set_recv_initial_metadata_ready(grpc_closure* closure) { op_->payload->recv_initial_metadata.recv_initial_metadata_ready = closure; } - grpc_byte_stream *send_message() const { + grpc_byte_stream* send_message() const { return op_->send_message ? op_->payload->send_message.send_message : nullptr; } - void set_send_message(grpc_byte_stream *send_message) { + void set_send_message(grpc_byte_stream* send_message) { op_->send_message = true; op_->payload->send_message.send_message = send_message; } - grpc_byte_stream **recv_message() const { + grpc_byte_stream** recv_message() const { return op_->recv_message ? op_->payload->recv_message.recv_message : nullptr; } - void set_recv_message(grpc_byte_stream **recv_message) { + void set_recv_message(grpc_byte_stream** recv_message) { op_->recv_message = true; op_->payload->recv_message.recv_message = recv_message; } - census_context *get_census_context() const { - return (census_context *)op_->payload->context[GRPC_CONTEXT_TRACING].value; + census_context* get_census_context() const { + return (census_context*)op_->payload->context[GRPC_CONTEXT_TRACING].value; } private: - grpc_transport_stream_op_batch *op_; // Not owned. + grpc_transport_stream_op_batch* op_; // Not owned. MetadataBatch send_initial_metadata_; MetadataBatch send_trailing_metadata_; MetadataBatch recv_initial_metadata_; @@ -225,19 +224,19 @@ class ChannelData { // TODO(roth): Come up with a more C++-like API for the channel element. /// Initializes the channel data. - virtual grpc_error *Init(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, - grpc_channel_element_args *args) { + virtual grpc_error* Init(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } // Called before destruction. - virtual void Destroy(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem) {} + virtual void Destroy(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem) {} - virtual void StartTransportOp(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, TransportOp *op); + virtual void StartTransportOp(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, TransportOp* op); - virtual void GetInfo(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, - const grpc_channel_info *channel_info); + virtual void GetInfo(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + const grpc_channel_info* channel_info); }; /// Represents call data. @@ -249,25 +248,25 @@ class CallData { // TODO(roth): Come up with a more C++-like API for the call element. /// Initializes the call data. - virtual grpc_error *Init(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - const grpc_call_element_args *args) { + virtual grpc_error* Init(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + const grpc_call_element_args* args) { return GRPC_ERROR_NONE; } // Called before destruction. - virtual void Destroy(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - const grpc_call_final_info *final_info, - grpc_closure *then_call_closure) {} + virtual void Destroy(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + const grpc_call_final_info* final_info, + grpc_closure* then_call_closure) {} /// Starts a new stream operation. - virtual void StartTransportStreamOpBatch(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - TransportStreamOpBatch *op); + virtual void StartTransportStreamOpBatch(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + TransportStreamOpBatch* op); /// Sets a pollset or pollset set. - virtual void SetPollsetOrPollsetSet(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_polling_entity *pollent); + virtual void SetPollsetOrPollsetSet(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + grpc_polling_entity* pollent); }; namespace internal { @@ -280,70 +279,70 @@ class ChannelFilter final { public: static const size_t channel_data_size = sizeof(ChannelDataType); - static grpc_error *InitChannelElement(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, - grpc_channel_element_args *args) { + static grpc_error* InitChannelElement(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, + grpc_channel_element_args* args) { // Construct the object in the already-allocated memory. - ChannelDataType *channel_data = new (elem->channel_data) ChannelDataType(); + ChannelDataType* channel_data = new (elem->channel_data) ChannelDataType(); return channel_data->Init(exec_ctx, elem, args); } - static void DestroyChannelElement(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem) { - ChannelDataType *channel_data = - reinterpret_cast<ChannelDataType *>(elem->channel_data); + static void DestroyChannelElement(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) { + ChannelDataType* channel_data = + reinterpret_cast<ChannelDataType*>(elem->channel_data); channel_data->Destroy(exec_ctx, elem); channel_data->~ChannelDataType(); } - static void StartTransportOp(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, - grpc_transport_op *op) { - ChannelDataType *channel_data = - reinterpret_cast<ChannelDataType *>(elem->channel_data); + static void StartTransportOp(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, + grpc_transport_op* op) { + ChannelDataType* channel_data = + reinterpret_cast<ChannelDataType*>(elem->channel_data); TransportOp op_wrapper(op); channel_data->StartTransportOp(exec_ctx, elem, &op_wrapper); } - static void GetChannelInfo(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, - const grpc_channel_info *channel_info) { - ChannelDataType *channel_data = - reinterpret_cast<ChannelDataType *>(elem->channel_data); + static void GetChannelInfo(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, + const grpc_channel_info* channel_info) { + ChannelDataType* channel_data = + reinterpret_cast<ChannelDataType*>(elem->channel_data); channel_data->GetInfo(exec_ctx, elem, channel_info); } static const size_t call_data_size = sizeof(CallDataType); - static grpc_error *InitCallElement(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - const grpc_call_element_args *args) { + static grpc_error* InitCallElement(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + const grpc_call_element_args* args) { // Construct the object in the already-allocated memory. - CallDataType *call_data = new (elem->call_data) CallDataType(); + CallDataType* call_data = new (elem->call_data) CallDataType(); return call_data->Init(exec_ctx, elem, args); } - static void DestroyCallElement(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - const grpc_call_final_info *final_info, - grpc_closure *then_call_closure) { - CallDataType *call_data = reinterpret_cast<CallDataType *>(elem->call_data); + static void DestroyCallElement(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + const grpc_call_final_info* final_info, + grpc_closure* then_call_closure) { + CallDataType* call_data = reinterpret_cast<CallDataType*>(elem->call_data); call_data->Destroy(exec_ctx, elem, final_info, then_call_closure); call_data->~CallDataType(); } - static void StartTransportStreamOpBatch(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_transport_stream_op_batch *op) { - CallDataType *call_data = reinterpret_cast<CallDataType *>(elem->call_data); + static void StartTransportStreamOpBatch(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + grpc_transport_stream_op_batch* op) { + CallDataType* call_data = reinterpret_cast<CallDataType*>(elem->call_data); TransportStreamOpBatch op_wrapper(op); call_data->StartTransportStreamOpBatch(exec_ctx, elem, &op_wrapper); } - static void SetPollsetOrPollsetSet(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_polling_entity *pollent) { - CallDataType *call_data = reinterpret_cast<CallDataType *>(elem->call_data); + static void SetPollsetOrPollsetSet(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + grpc_polling_entity* pollent) { + CallDataType* call_data = reinterpret_cast<CallDataType*>(elem->call_data); call_data->SetPollsetOrPollsetSet(exec_ctx, elem, pollent); } }; @@ -351,10 +350,10 @@ class ChannelFilter final { struct FilterRecord { grpc_channel_stack_type stack_type; int priority; - std::function<bool(const grpc_channel_args &)> include_filter; + std::function<bool(const grpc_channel_args&)> include_filter; grpc_channel_filter filter; }; -extern std::vector<FilterRecord> *channel_filters; +extern std::vector<FilterRecord>* channel_filters; void ChannelFilterPluginInit(); void ChannelFilterPluginShutdown(); @@ -368,8 +367,8 @@ void ChannelFilterPluginShutdown(); /// value is nullptr, the filter will be added unconditionally. template <typename ChannelDataType, typename CallDataType> void RegisterChannelFilter( - const char *name, grpc_channel_stack_type stack_type, int priority, - std::function<bool(const grpc_channel_args &)> include_filter) { + const char* name, grpc_channel_stack_type stack_type, int priority, + std::function<bool(const grpc_channel_args&)> include_filter) { // If we haven't been called before, initialize channel_filters and // call grpc_register_plugin(). if (internal::channel_filters == nullptr) { diff --git a/src/cpp/common/core_codegen.cc b/src/cpp/common/core_codegen.cc index 6ea5f1d3c7..3cbf08af9f 100644 --- a/src/cpp/common/core_codegen.cc +++ b/src/cpp/common/core_codegen.cc @@ -76,6 +76,9 @@ void* CoreCodegen::gpr_malloc(size_t size) { return ::gpr_malloc(size); } void CoreCodegen::gpr_free(void* p) { return ::gpr_free(p); } +void CoreCodegen::grpc_init() { ::grpc_init(); } +void CoreCodegen::grpc_shutdown() { ::grpc_shutdown(); } + void CoreCodegen::gpr_mu_init(gpr_mu* mu) { ::gpr_mu_init(mu); }; void CoreCodegen::gpr_mu_destroy(gpr_mu* mu) { ::gpr_mu_destroy(mu); } void CoreCodegen::gpr_mu_lock(gpr_mu* mu) { ::gpr_mu_lock(mu); } @@ -156,6 +159,10 @@ grpc_slice CoreCodegen::grpc_slice_split_head(grpc_slice* s, size_t split) { return ::grpc_slice_split_head(s, split); } +grpc_slice CoreCodegen::grpc_slice_sub(grpc_slice s, size_t begin, size_t end) { + return ::grpc_slice_sub(s, begin, end); +} + grpc_slice CoreCodegen::grpc_slice_from_static_buffer(const void* buffer, size_t length) { return ::grpc_slice_from_static_buffer(buffer, length); diff --git a/src/cpp/common/version_cc.cc b/src/cpp/common/version_cc.cc index 8049cbe0c9..e1e5e895f6 100644 --- a/src/cpp/common/version_cc.cc +++ b/src/cpp/common/version_cc.cc @@ -23,4 +23,4 @@ namespace grpc { grpc::string Version() { return "1.8.0-dev"; } -} +} // namespace grpc |