aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Yuchen Zeng <zyc@google.com>2016-06-06 14:21:11 -0700
committerGravatar Yuchen Zeng <zyc@google.com>2016-06-06 14:35:51 -0700
commit7ae31a88980cba5e7e0173cad91e62dbfe1b0374 (patch)
tree8156bd4c5a58c2ae55382ef4fdcfd8fac8d13d9d
parent0601df3a04a91e5e731e829989fd93290e301d97 (diff)
Add more comments, fix format issues
-rw-r--r--include/grpc++/ext/proto_server_reflection_plugin.h10
-rw-r--r--src/cpp/ext/proto_server_reflection.cc14
-rw-r--r--src/cpp/ext/proto_server_reflection.h22
-rw-r--r--src/cpp/ext/proto_server_reflection_plugin.cc6
-rw-r--r--test/cpp/util/proto_reflection_descriptor_database.h37
-rwxr-xr-xtools/distrib/check_include_guards.py2
-rwxr-xr-xtools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh2
-rwxr-xr-xtools/run_tests/sanity/check_sources_and_headers.py3
8 files changed, 63 insertions, 33 deletions
diff --git a/include/grpc++/ext/proto_server_reflection_plugin.h b/include/grpc++/ext/proto_server_reflection_plugin.h
index 774d3439e7..517c4737f5 100644
--- a/include/grpc++/ext/proto_server_reflection_plugin.h
+++ b/include/grpc++/ext/proto_server_reflection_plugin.h
@@ -31,8 +31,8 @@
*
*/
-#ifndef GRPCXX_PROTO_SERVER_REFLECTION_PLUGIN_H
-#define GRPCXX_PROTO_SERVER_REFLECTION_PLUGIN_H
+#ifndef GRPCXX_EXT_PROTO_SERVER_REFLECTION_PLUGIN_H
+#define GRPCXX_EXT_PROTO_SERVER_REFLECTION_PLUGIN_H
#include <grpc++/impl/server_builder_plugin.h>
#include <grpc++/support/config.h>
@@ -59,7 +59,11 @@ class ProtoServerReflectionPlugin : public ::grpc::ServerBuilderPlugin {
std::shared_ptr<::grpc::ProtoServerReflection> reflection_service_;
};
+// Add proto reflection plugin to ServerBuilder. This function should be called
+// at the static initialization time.
+void InitProtoReflectionServerBuilderPlugin();
+
} // namespace reflection
} // namespace grpc
-#endif // GRPCXX_PROTO_SERVER_REFLECTION_PLUGIN_H
+#endif // GRPCXX_EXT_PROTO_SERVER_REFLECTION_PLUGIN_H
diff --git a/src/cpp/ext/proto_server_reflection.cc b/src/cpp/ext/proto_server_reflection.cc
index 6e54bc2720..348a035f0f 100644
--- a/src/cpp/ext/proto_server_reflection.cc
+++ b/src/cpp/ext/proto_server_reflection.cc
@@ -131,7 +131,8 @@ Status ProtoServerReflection::GetFileByName(
return Status::CANCELLED;
}
- const protobuf::FileDescriptor* file_desc = descriptor_pool_->FindFileByName(filename);
+ const protobuf::FileDescriptor* file_desc =
+ descriptor_pool_->FindFileByName(filename);
if (file_desc == nullptr) {
return Status(StatusCode::NOT_FOUND, "File not found.");
}
@@ -170,8 +171,9 @@ Status ProtoServerReflection::GetFileContainingExtension(
return Status(StatusCode::NOT_FOUND, "Type not found.");
}
- const protobuf::FieldDescriptor* field_desc = descriptor_pool_->FindExtensionByNumber(
- desc, request->extension_number());
+ const protobuf::FieldDescriptor* field_desc =
+ descriptor_pool_->FindExtensionByNumber(desc,
+ request->extension_number());
if (field_desc == nullptr) {
return Status(StatusCode::NOT_FOUND, "Extension not found.");
}
@@ -187,7 +189,8 @@ Status ProtoServerReflection::GetAllExtensionNumbers(
return Status::CANCELLED;
}
- const protobuf::Descriptor* desc = descriptor_pool_->FindMessageTypeByName(type);
+ const protobuf::Descriptor* desc =
+ descriptor_pool_->FindMessageTypeByName(type);
if (desc == nullptr) {
return Status(StatusCode::NOT_FOUND, "Type not found.");
}
@@ -202,7 +205,8 @@ Status ProtoServerReflection::GetAllExtensionNumbers(
}
void ProtoServerReflection::FillFileDescriptorResponse(
- const protobuf::FileDescriptor* file_desc, ServerReflectionResponse* response,
+ const protobuf::FileDescriptor* file_desc,
+ ServerReflectionResponse* response,
std::unordered_set<grpc::string>* seen_files) {
if (seen_files->find(file_desc->name()) != seen_files->end()) {
return;
diff --git a/src/cpp/ext/proto_server_reflection.h b/src/cpp/ext/proto_server_reflection.h
index e7ab1fdf34..23c130513d 100644
--- a/src/cpp/ext/proto_server_reflection.h
+++ b/src/cpp/ext/proto_server_reflection.h
@@ -30,16 +30,14 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
-
-#ifndef GRPC_EXTENSIONS_REFLECTION_PROTO_SERVER_REFLECTION_H
-#define GRPC_EXTENSIONS_REFLECTION_PROTO_SERVER_REFLECTION_H
+#ifndef GRPC_INTERNAL_CPP_EXT_PROTO_SERVER_REFLECTION_H
+#define GRPC_INTERNAL_CPP_EXT_PROTO_SERVER_REFLECTION_H
#include <unordered_set>
#include <vector>
-#include <grpc++/grpc++.h>
-
#include <grpc++/ext/reflection.grpc.pb.h>
+#include <grpc++/grpc++.h>
namespace grpc {
@@ -48,21 +46,23 @@ class ProtoServerReflection GRPC_FINAL
public:
ProtoServerReflection();
+ // Add the full names of registered services
void SetServiceList(const std::vector<grpc::string>* services);
+ // implementation of ServerReflectionInfo(stream ServerReflectionRequest) rpc
+ // in ServerReflection service
Status ServerReflectionInfo(
ServerContext* context,
ServerReaderWriter<reflection::v1alpha::ServerReflectionResponse,
- reflection::v1alpha::ServerReflectionRequest>*
- stream) GRPC_OVERRIDE;
+ reflection::v1alpha::ServerReflectionRequest>* stream)
+ GRPC_OVERRIDE;
private:
Status ListService(ServerContext* context,
reflection::v1alpha::ListServiceResponse* response);
- Status GetFileByName(
- ServerContext* context, const grpc::string& file_name,
- reflection::v1alpha::ServerReflectionResponse* response);
+ Status GetFileByName(ServerContext* context, const grpc::string& file_name,
+ reflection::v1alpha::ServerReflectionResponse* response);
Status GetFileContainingSymbol(
ServerContext* context, const grpc::string& symbol,
@@ -91,4 +91,4 @@ class ProtoServerReflection GRPC_FINAL
} // namespace grpc
-#endif // GRPC_EXTENSIONS_REFLECTION_PROTO_SERVER_REFLECTION_H
+#endif // GRPC_INTERNAL_CPP_EXT_PROTO_SERVER_REFLECTION_H
diff --git a/src/cpp/ext/proto_server_reflection_plugin.cc b/src/cpp/ext/proto_server_reflection_plugin.cc
index becc949359..f31d102a9e 100644
--- a/src/cpp/ext/proto_server_reflection_plugin.cc
+++ b/src/cpp/ext/proto_server_reflection_plugin.cc
@@ -78,16 +78,18 @@ static std::unique_ptr<::grpc::ServerBuilderPlugin> CreateProtoReflection() {
new ProtoServerReflectionPlugin());
}
-static void AddProtoReflectionServerBuilderPlugin() {
+void InitProtoReflectionServerBuilderPlugin() {
static bool already_here = false;
if (already_here) return;
already_here = true;
::grpc::ServerBuilder::InternalAddPluginFactory(&CreateProtoReflection);
}
+// Force InitProtoReflectionServerBuilderPlugin() to be called at static
+// initialization time.
struct StaticProtoReflectionPluginInitializer {
StaticProtoReflectionPluginInitializer() {
- AddProtoReflectionServerBuilderPlugin();
+ InitProtoReflectionServerBuilderPlugin();
}
} static_proto_reflection_plugin_initializer;
diff --git a/test/cpp/util/proto_reflection_descriptor_database.h b/test/cpp/util/proto_reflection_descriptor_database.h
index d7b2163cea..99c00675bb 100644
--- a/test/cpp/util/proto_reflection_descriptor_database.h
+++ b/test/cpp/util/proto_reflection_descriptor_database.h
@@ -30,6 +30,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
+#ifndef GRPC_TEST_CPP_PROTO_SERVER_REFLECTION_DATABSE_H
+#define GRPC_TEST_CPP_PROTO_SERVER_REFLECTION_DATABSE_H
#include <mutex>
#include <unordered_map>
@@ -39,11 +41,14 @@
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/descriptor_database.h>
-#include <grpc++/grpc++.h>
#include <grpc++/ext/reflection.grpc.pb.h>
+#include <grpc++/grpc++.h>
namespace grpc {
+// ProtoReflectionDescriptorDatabase takes a stub of ServerReflection and
+// provides the methods defined by DescriptorDatabase interfaces. It can be used
+// to feed a DescriptorPool instance.
class ProtoReflectionDescriptorDatabase
: public google::protobuf::DescriptorDatabase {
public:
@@ -55,28 +60,42 @@ class ProtoReflectionDescriptorDatabase
virtual ~ProtoReflectionDescriptorDatabase();
- // DescriptorDatabase methods
+ // The following four methods implement DescriptorDatabase interfaces.
+ //
+ // Find a file by file name. Fills in in *output and returns true if found.
+ // Otherwise, returns false, leaving the contents of *output undefined.
bool FindFileByName(const string& filename,
google::protobuf::FileDescriptorProto* output)
GRPC_OVERRIDE;
+ // Find the file that declares the given fully-qualified symbol name.
+ // If found, fills in *output and returns true, otherwise returns false
+ // and leaves *output undefined.
bool FindFileContainingSymbol(const string& symbol_name,
google::protobuf::FileDescriptorProto* output)
GRPC_OVERRIDE;
+ // Find the file which defines an extension extending the given message type
+ // with the given field number. If found, fills in *output and returns true,
+ // otherwise returns false and leaves *output undefined. containing_type
+ // must be a fully-qualified type name.
bool FindFileContainingExtension(
const string& containing_type, int field_number,
google::protobuf::FileDescriptorProto* output) GRPC_OVERRIDE;
+ // Finds the tag numbers used by all known extensions of
+ // extendee_type, and appends them to output in an undefined
+ // order. This method is best-effort: it's not guaranteed that the
+ // database will find all extensions, and it's not guaranteed that
+ // FindFileContainingExtension will return true on all of the found
+ // numbers. Returns true if the search was successful, otherwise
+ // returns false and leaves output unchanged.
bool FindAllExtensionNumbers(const string& extendee_type,
std::vector<int>* output) GRPC_OVERRIDE;
+ // Provide a list of full names of registered services
bool GetServices(std::vector<std::string>* output);
- grpc::reflection::v1alpha::ServerReflection::Stub* stub() {
- return stub_.get();
- }
-
private:
typedef ClientReaderWriter<
grpc::reflection::v1alpha::ServerReflectionRequest,
@@ -92,8 +111,8 @@ class ProtoReflectionDescriptorDatabase
const std::shared_ptr<ClientStream> GetStream();
void DoOneRequest(
- const grpc::reflection::v1alpha::ServerReflectionRequest& request,
- grpc::reflection::v1alpha::ServerReflectionResponse& response);
+ const grpc::reflection::v1alpha::ServerReflectionRequest& request,
+ grpc::reflection::v1alpha::ServerReflectionResponse& response);
std::shared_ptr<ClientStream> stream_;
grpc::ClientContext ctx_;
@@ -108,3 +127,5 @@ class ProtoReflectionDescriptorDatabase
};
} // namespace grpc
+
+#endif // GRPC_TEST_CPP_METRICS_SERVER_H
diff --git a/tools/distrib/check_include_guards.py b/tools/distrib/check_include_guards.py
index 9c23a70e00..874ddfe53a 100755
--- a/tools/distrib/check_include_guards.py
+++ b/tools/distrib/check_include_guards.py
@@ -171,6 +171,8 @@ args = argp.parse_args()
KNOWN_BAD = set([
'src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h',
+ 'include/grpc++/ext/reflection.grpc.pb.h',
+ 'include/grpc++/ext/reflection.pb.h',
])
diff --git a/tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh b/tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh
index 6f4155944c..eab7611b3f 100755
--- a/tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh
+++ b/tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh
@@ -44,7 +44,7 @@ for dir in $DIRS
do
for glob in $GLOB
do
- files="$files `find /local-code/$dir -name $glob -and -not -name *.generated.* -and -not -name *.pb.h -and -not -name *.pb.c`"
+ files="$files `find /local-code/$dir -name $glob -and -not -name *.generated.* -and -not -name *.pb.h -and -not -name *.pb.c -and -not -name *.pb.cc`"
done
done
diff --git a/tools/run_tests/sanity/check_sources_and_headers.py b/tools/run_tests/sanity/check_sources_and_headers.py
index 0eb804eb5b..c028499ca6 100755
--- a/tools/run_tests/sanity/check_sources_and_headers.py
+++ b/tools/run_tests/sanity/check_sources_and_headers.py
@@ -57,9 +57,6 @@ def target_has_header(target, name):
return True
if name == 'src/core/lib/profiling/stap_probes.h':
return True
- if not name.startswith('extensions') \
- and target_has_header(target, 'extensions/' + name):
- return True
return False
def produces_object(name):