Skip to content
Snippets Groups Projects
Commit 7ae31a88 authored by Yuchen Zeng's avatar Yuchen Zeng
Browse files

Add more comments, fix format issues

parent 0601df3a
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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;
......
......@@ -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,20 +46,22 @@ 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,
Status GetFileByName(ServerContext* context, const grpc::string& file_name,
reflection::v1alpha::ServerReflectionResponse* response);
Status GetFileContainingSymbol(
......@@ -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
......@@ -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;
......
......@@ -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,
......@@ -108,3 +127,5 @@ class ProtoReflectionDescriptorDatabase
};
} // namespace grpc
#endif // GRPC_TEST_CPP_METRICS_SERVER_H
......@@ -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',
])
......
......@@ -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
......
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment