diff --git a/BUILD b/BUILD index 630bae6c87c..d2f56cd4ecd 100644 --- a/BUILD +++ b/BUILD @@ -345,6 +345,7 @@ GRPCXX_PUBLIC_HDRS = [ "include/grpcpp/impl/delegating_channel.h", "include/grpcpp/impl/grpc_library.h", "include/grpcpp/impl/intercepted_channel.h", + "include/grpcpp/impl/metadata_map.h", "include/grpcpp/impl/method_handler_impl.h", "include/grpcpp/impl/rpc_method.h", "include/grpcpp/impl/rpc_service_method.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 20285a990aa..ea97f9b6c06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3449,6 +3449,7 @@ foreach(_hdr include/grpcpp/impl/delegating_channel.h include/grpcpp/impl/grpc_library.h include/grpcpp/impl/intercepted_channel.h + include/grpcpp/impl/metadata_map.h include/grpcpp/impl/method_handler_impl.h include/grpcpp/impl/rpc_method.h include/grpcpp/impl/rpc_service_method.h @@ -4140,6 +4141,7 @@ foreach(_hdr include/grpcpp/impl/delegating_channel.h include/grpcpp/impl/grpc_library.h include/grpcpp/impl/intercepted_channel.h + include/grpcpp/impl/metadata_map.h include/grpcpp/impl/method_handler_impl.h include/grpcpp/impl/rpc_method.h include/grpcpp/impl/rpc_service_method.h diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 261d64e2515..b56c1ed7962 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -2824,6 +2824,7 @@ libs: - include/grpcpp/impl/delegating_channel.h - include/grpcpp/impl/grpc_library.h - include/grpcpp/impl/intercepted_channel.h + - include/grpcpp/impl/metadata_map.h - include/grpcpp/impl/method_handler_impl.h - include/grpcpp/impl/rpc_method.h - include/grpcpp/impl/rpc_service_method.h @@ -3246,6 +3247,7 @@ libs: - include/grpcpp/impl/delegating_channel.h - include/grpcpp/impl/grpc_library.h - include/grpcpp/impl/intercepted_channel.h + - include/grpcpp/impl/metadata_map.h - include/grpcpp/impl/method_handler_impl.h - include/grpcpp/impl/rpc_method.h - include/grpcpp/impl/rpc_service_method.h diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 190688013c3..8cc2d97d6f3 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -150,6 +150,7 @@ Pod::Spec.new do |s| 'include/grpcpp/impl/delegating_channel.h', 'include/grpcpp/impl/grpc_library.h', 'include/grpcpp/impl/intercepted_channel.h', + 'include/grpcpp/impl/metadata_map.h', 'include/grpcpp/impl/method_handler_impl.h', 'include/grpcpp/impl/rpc_method.h', 'include/grpcpp/impl/rpc_service_method.h', diff --git a/include/grpcpp/client_context.h b/include/grpcpp/client_context.h index a94ff02ab9b..4caecb7d800 100644 --- a/include/grpcpp/client_context.h +++ b/include/grpcpp/client_context.h @@ -42,8 +42,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/include/grpcpp/impl/codegen/metadata_map.h b/include/grpcpp/impl/codegen/metadata_map.h index 931d682d196..3f769021c47 100644 --- a/include/grpcpp/impl/codegen/metadata_map.h +++ b/include/grpcpp/impl/codegen/metadata_map.h @@ -21,87 +21,7 @@ // IWYU pragma: private -#include - -#include -#include - -namespace grpc { - -namespace internal { - -const char kBinaryErrorDetailsKey[] = "grpc-status-details-bin"; - -class MetadataMap { - public: - MetadataMap() { Setup(); } - - ~MetadataMap() { Destroy(); } - - std::string GetBinaryErrorDetails() { - // if filled_, extract from the multimap for O(log(n)) - if (filled_) { - auto iter = map_.find(kBinaryErrorDetailsKey); - if (iter != map_.end()) { - return std::string(iter->second.begin(), iter->second.length()); - } - } - // if not yet filled, take the O(n) lookup to avoid allocating the - // multimap until it is requested. - // TODO(ncteisen): plumb this through core as a first class object, just - // like code and message. - else { - for (size_t i = 0; i < arr_.count; i++) { - if (strncmp(reinterpret_cast( - GRPC_SLICE_START_PTR(arr_.metadata[i].key)), - kBinaryErrorDetailsKey, - GRPC_SLICE_LENGTH(arr_.metadata[i].key)) == 0) { - return std::string(reinterpret_cast( - GRPC_SLICE_START_PTR(arr_.metadata[i].value)), - GRPC_SLICE_LENGTH(arr_.metadata[i].value)); - } - } - } - return std::string(); - } - - std::multimap* map() { - FillMap(); - return &map_; - } - grpc_metadata_array* arr() { return &arr_; } - - void Reset() { - filled_ = false; - map_.clear(); - Destroy(); - Setup(); - } - - private: - bool filled_ = false; - grpc_metadata_array arr_; - std::multimap map_; - - void Destroy() { - g_core_codegen_interface->grpc_metadata_array_destroy(&arr_); - } - - void Setup() { memset(&arr_, 0, sizeof(arr_)); } - - void FillMap() { - if (filled_) return; - filled_ = true; - for (size_t i = 0; i < arr_.count; i++) { - // TODO(yangg) handle duplicates? - map_.insert(std::pair( - StringRefFromSlice(&arr_.metadata[i].key), - StringRefFromSlice(&arr_.metadata[i].value))); - } - } -}; -} // namespace internal - -} // namespace grpc +/// TODO(chengyuc): Remove this file after solving compatibility. +#include #endif // GRPCPP_IMPL_CODEGEN_METADATA_MAP_H diff --git a/include/grpcpp/impl/metadata_map.h b/include/grpcpp/impl/metadata_map.h new file mode 100644 index 00000000000..f5478bbd0d4 --- /dev/null +++ b/include/grpcpp/impl/metadata_map.h @@ -0,0 +1,105 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPCPP_IMPL_METADATA_MAP_H +#define GRPCPP_IMPL_METADATA_MAP_H + +#include + +#include +#include + +namespace grpc { + +namespace internal { + +const char kBinaryErrorDetailsKey[] = "grpc-status-details-bin"; + +class MetadataMap { + public: + MetadataMap() { Setup(); } + + ~MetadataMap() { Destroy(); } + + std::string GetBinaryErrorDetails() { + // if filled_, extract from the multimap for O(log(n)) + if (filled_) { + auto iter = map_.find(kBinaryErrorDetailsKey); + if (iter != map_.end()) { + return std::string(iter->second.begin(), iter->second.length()); + } + } + // if not yet filled, take the O(n) lookup to avoid allocating the + // multimap until it is requested. + // TODO(ncteisen): plumb this through core as a first class object, just + // like code and message. + else { + for (size_t i = 0; i < arr_.count; i++) { + if (strncmp(reinterpret_cast( + GRPC_SLICE_START_PTR(arr_.metadata[i].key)), + kBinaryErrorDetailsKey, + GRPC_SLICE_LENGTH(arr_.metadata[i].key)) == 0) { + return std::string(reinterpret_cast( + GRPC_SLICE_START_PTR(arr_.metadata[i].value)), + GRPC_SLICE_LENGTH(arr_.metadata[i].value)); + } + } + } + return std::string(); + } + + std::multimap* map() { + FillMap(); + return &map_; + } + grpc_metadata_array* arr() { return &arr_; } + + void Reset() { + filled_ = false; + map_.clear(); + Destroy(); + Setup(); + } + + private: + bool filled_ = false; + grpc_metadata_array arr_; + std::multimap map_; + + void Destroy() { + g_core_codegen_interface->grpc_metadata_array_destroy(&arr_); + } + + void Setup() { memset(&arr_, 0, sizeof(arr_)); } + + void FillMap() { + if (filled_) return; + filled_ = true; + for (size_t i = 0; i < arr_.count; i++) { + // TODO(yangg) handle duplicates? + map_.insert(std::pair( + StringRefFromSlice(&arr_.metadata[i].key), + StringRefFromSlice(&arr_.metadata[i].value))); + } + } +}; +} // namespace internal + +} // namespace grpc + +#endif // GRPCPP_IMPL_METADATA_MAP_H diff --git a/include/grpcpp/server_context.h b/include/grpcpp/server_context.h index 352a4ce8a78..0d53a7961fc 100644 --- a/include/grpcpp/server_context.h +++ b/include/grpcpp/server_context.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include diff --git a/include/grpcpp/support/interceptor.h b/include/grpcpp/support/interceptor.h index 6b52d95ebab..ac9290fa74e 100644 --- a/include/grpcpp/support/interceptor.h +++ b/include/grpcpp/support/interceptor.h @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/cpp/server/server_cc.cc b/src/cpp/server/server_cc.cc index e5a3cfaf437..81edc9fb9db 100644 --- a/src/cpp/server/server_cc.cc +++ b/src/cpp/server/server_cc.cc @@ -46,10 +46,10 @@ #include #include #include -#include #include #include #include +#include #include #include #include diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index 4ff84ccfe86..2954053d36a 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -45,9 +45,9 @@ #include #include #include -#include #include #include +#include #include #include #include diff --git a/tools/codegen/core/gen_experiments.py b/tools/codegen/core/gen_experiments.py index 2af288e6046..9b85bf1ac7f 100755 --- a/tools/codegen/core/gen_experiments.py +++ b/tools/codegen/core/gen_experiments.py @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """ -Generate experiment related code artifacts. +Generate experiment related code artifacts. Invoke as: tools/codegen/core/gen_experiments.py Experiment definitions are in src/core/lib/experiments/experiments.yaml diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index 190406bbdf7..045a6fa6ad5 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -1014,6 +1014,7 @@ include/grpcpp/impl/completion_queue_tag.h \ include/grpcpp/impl/delegating_channel.h \ include/grpcpp/impl/grpc_library.h \ include/grpcpp/impl/intercepted_channel.h \ +include/grpcpp/impl/metadata_map.h \ include/grpcpp/impl/method_handler_impl.h \ include/grpcpp/impl/rpc_method.h \ include/grpcpp/impl/rpc_service_method.h \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index efd87f1520a..c132ac30c06 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -1014,6 +1014,7 @@ include/grpcpp/impl/completion_queue_tag.h \ include/grpcpp/impl/delegating_channel.h \ include/grpcpp/impl/grpc_library.h \ include/grpcpp/impl/intercepted_channel.h \ +include/grpcpp/impl/metadata_map.h \ include/grpcpp/impl/method_handler_impl.h \ include/grpcpp/impl/rpc_method.h \ include/grpcpp/impl/rpc_service_method.h \