aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/config.h10
-rw-r--r--src/compiler/csharp_generator.cc40
-rw-r--r--src/compiler/csharp_generator.h4
-rw-r--r--src/compiler/csharp_plugin.cc24
4 files changed, 65 insertions, 13 deletions
diff --git a/src/compiler/config.h b/src/compiler/config.h
index a534b119d2..d8b95818db 100644
--- a/src/compiler/config.h
+++ b/src/compiler/config.h
@@ -70,6 +70,11 @@
#define GRPC_CUSTOM_PLUGINMAIN ::google::protobuf::compiler::PluginMain
#endif
+#ifndef GRPC_CUSTOM_PARSEGENERATORPARAMETER
+#include <google/protobuf/compiler/code_generator.h>
+#define GRPC_CUSTOM_PARSEGENERATORPARAMETER ::google::protobuf::compiler::ParseGeneratorParameter
+#endif
+
namespace grpc {
namespace protobuf {
typedef GRPC_CUSTOM_DESCRIPTOR Descriptor;
@@ -85,6 +90,11 @@ static inline int PluginMain(int argc, char* argv[],
const CodeGenerator* generator) {
return GRPC_CUSTOM_PLUGINMAIN(argc, argv, generator);
}
+static inline void ParseGeneratorParameter(const string& parameter,
+ std::vector<std::pair<string, string> >* options) {
+ GRPC_CUSTOM_PARSEGENERATORPARAMETER(parameter, options);
+}
+
} // namespace compiler
namespace io {
typedef GRPC_CUSTOM_PRINTER Printer;
diff --git a/src/compiler/csharp_generator.cc b/src/compiler/csharp_generator.cc
index 4def6c5e31..0d1404341d 100644
--- a/src/compiler/csharp_generator.cc
+++ b/src/compiler/csharp_generator.cc
@@ -123,6 +123,10 @@ std::string GetMethodRequestParamMaybe(const MethodDescriptor *method,
return GetClassName(method->input_type()) + " request, ";
}
+std::string GetAccessLevel(bool internal_access) {
+ return internal_access ? "internal" : "public";
+}
+
std::string GetMethodReturnTypeClient(const MethodDescriptor *method) {
switch (GetMethodType(method)) {
case METHODTYPE_NO_STREAMING:
@@ -527,8 +531,11 @@ void GenerateNewStubMethods(Printer* out, const ServiceDescriptor *service) {
out->Print("\n");
}
-void GenerateService(Printer* out, const ServiceDescriptor *service) {
- out->Print("public static class $classname$\n", "classname",
+void GenerateService(Printer* out, const ServiceDescriptor *service,
+ bool generate_client, bool generate_server,
+ bool internal_access) {
+ out->Print("$access_level$ static class $classname$\n", "access_level",
+ GetAccessLevel(internal_access), "classname",
GetServiceClassName(service));
out->Print("{\n");
out->Indent();
@@ -542,13 +549,22 @@ void GenerateService(Printer* out, const ServiceDescriptor *service) {
GenerateStaticMethodField(out, service->method(i));
}
GenerateServiceDescriptorProperty(out, service);
- GenerateClientInterface(out, service);
- GenerateServerInterface(out, service);
- GenerateServerClass(out, service);
- GenerateClientStub(out, service);
- GenerateBindServiceMethod(out, service, false);
- GenerateBindServiceMethod(out, service, true);
- GenerateNewStubMethods(out, service);
+
+ if (generate_client) {
+ GenerateClientInterface(out, service);
+ }
+ if (generate_server) {
+ GenerateServerInterface(out, service);
+ GenerateServerClass(out, service);
+ }
+ if (generate_client) {
+ GenerateClientStub(out, service);
+ GenerateNewStubMethods(out, service);
+ }
+ if (generate_server) {
+ GenerateBindServiceMethod(out, service, false);
+ GenerateBindServiceMethod(out, service, true);
+ }
out->Outdent();
out->Print("}\n");
@@ -556,7 +572,8 @@ void GenerateService(Printer* out, const ServiceDescriptor *service) {
} // anonymous namespace
-grpc::string GetServices(const FileDescriptor *file) {
+grpc::string GetServices(const FileDescriptor *file, bool generate_client,
+ bool generate_server, bool internal_access) {
grpc::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
@@ -584,7 +601,8 @@ grpc::string GetServices(const FileDescriptor *file) {
out.Print("namespace $namespace$ {\n", "namespace", GetFileNamespace(file));
out.Indent();
for (int i = 0; i < file->service_count(); i++) {
- GenerateService(&out, file->service(i));
+ GenerateService(&out, file->service(i), generate_client, generate_server,
+ internal_access);
}
out.Outdent();
out.Print("}\n");
diff --git a/src/compiler/csharp_generator.h b/src/compiler/csharp_generator.h
index 90eb7e2984..f0585af4fd 100644
--- a/src/compiler/csharp_generator.h
+++ b/src/compiler/csharp_generator.h
@@ -40,7 +40,9 @@
namespace grpc_csharp_generator {
-grpc::string GetServices(const grpc::protobuf::FileDescriptor *file);
+grpc::string GetServices(const grpc::protobuf::FileDescriptor *file,
+ bool generate_client, bool generate_server,
+ bool internal_access);
} // namespace grpc_csharp_generator
diff --git a/src/compiler/csharp_plugin.cc b/src/compiler/csharp_plugin.cc
index 8b9395f9e2..5350e73f10 100644
--- a/src/compiler/csharp_plugin.cc
+++ b/src/compiler/csharp_plugin.cc
@@ -48,7 +48,29 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
const grpc::string &parameter,
grpc::protobuf::compiler::GeneratorContext *context,
grpc::string *error) const {
- grpc::string code = grpc_csharp_generator::GetServices(file);
+ std::vector<std::pair<grpc::string, grpc::string> > options;
+ grpc::protobuf::compiler::ParseGeneratorParameter(parameter, &options);
+
+ bool generate_client = true;
+ bool generate_server = true;
+ bool internal_access = false;
+ for (size_t i = 0; i < options.size(); i++) {
+ if (options[i].first == "no_client") {
+ generate_client = false;
+ } else if (options[i].first == "no_server") {
+ generate_server = false;
+ } else if (options[i].first == "internal_access") {
+ internal_access = true;
+ } else {
+ *error = "Unknown generator option: " + options[i].first;
+ return false;
+ }
+ }
+
+ grpc::string code = grpc_csharp_generator::GetServices(file,
+ generate_client,
+ generate_server,
+ internal_access);
if (code.size() == 0) {
return true; // don't generate a file if there are no services
}