Skip to content

Commit

Permalink
Merge branch 'master' of github.com:grpc/grpc into infinity_takes_for…
Browse files Browse the repository at this point in the history
…ever
  • Loading branch information
dgquintas committed Jun 1, 2015
2 parents e90cd37 + aa031d6 commit 7b6fc6c
Show file tree
Hide file tree
Showing 47 changed files with 797 additions and 325 deletions.
63 changes: 32 additions & 31 deletions src/compiler/objective_c_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,20 @@
*/

#include <map>
#include <sstream>

#include "src/compiler/config.h"
#include "src/compiler/objective_c_generator.h"
#include "src/compiler/objective_c_generator_helpers.h"

#include "src/compiler/config.h"

#include <sstream>
#include <google/protobuf/compiler/objectivec/objectivec_helpers.h>

using ::google::protobuf::compiler::objectivec::ClassName;
using ::grpc::protobuf::io::Printer;
using ::grpc::protobuf::MethodDescriptor;
using ::grpc::protobuf::ServiceDescriptor;
using ::std::map;
using ::grpc::string;
using ::std::map;

namespace grpc_objective_c_generator {
namespace {
Expand All @@ -69,7 +70,7 @@ void PrintMethodSignature(Printer *printer,
if (method->client_streaming()) {
printer->Print("RequestsWriter:(id<GRXWriter>)request");
} else {
printer->Print(vars, "Request:($prefix$$request_type$ *)request");
printer->Print(vars, "Request:($request_class$ *)request");
}

// TODO(jcanizales): Put this on a new line and align colons.
Expand All @@ -78,8 +79,7 @@ void PrintMethodSignature(Printer *printer,
if (method->server_streaming()) {
printer->Print("BOOL done, ");
}
printer->Print(vars,
"$prefix$$response_type$ *response, NSError *error))handler");
printer->Print(vars, "$response_class$ *response, NSError *error))handler");
}

void PrintSimpleSignature(Printer *printer,
Expand All @@ -99,12 +99,17 @@ void PrintAdvancedSignature(Printer *printer,
PrintMethodSignature(printer, method, vars);
}

inline map<string, string> GetMethodVars(const MethodDescriptor *method) {
return {{ "method_name", method->name() },
{ "request_type", method->input_type()->name() },
{ "response_type", method->output_type()->name() },
{ "request_class", ClassName(method->input_type()) },
{ "response_class", ClassName(method->output_type()) }};
}

void PrintMethodDeclarations(Printer *printer,
const MethodDescriptor *method,
map<string, string> vars) {
vars["method_name"] = method->name();
vars["request_type"] = method->input_type()->name();
vars["response_type"] = method->output_type()->name();
const MethodDescriptor *method) {
map<string, string> vars = GetMethodVars(method);

PrintProtoRpcDeclarationAsPragma(printer, method, vars);

Expand Down Expand Up @@ -141,8 +146,7 @@ void PrintAdvancedImplementation(Printer *printer,
printer->Print("[GRXWriter writerWithValue:request]\n");
}

printer->Print(vars,
" responseClass:[$prefix$$response_type$ class]\n");
printer->Print(vars, " responseClass:[$response_class$ class]\n");

printer->Print(" responsesWriteable:[GRXWriteable ");
if (method->server_streaming()) {
Expand All @@ -155,11 +159,8 @@ void PrintAdvancedImplementation(Printer *printer,
}

void PrintMethodImplementations(Printer *printer,
const MethodDescriptor *method,
map<string, string> vars) {
vars["method_name"] = method->name();
vars["request_type"] = method->input_type()->name();
vars["response_type"] = method->output_type()->name();
const MethodDescriptor *method) {
map<string, string> vars = GetMethodVars(method);

PrintProtoRpcDeclarationAsPragma(printer, method, vars);

Expand All @@ -174,7 +175,7 @@ void PrintMethodImplementations(Printer *printer,

} // namespace

string GetHeader(const ServiceDescriptor *service, const string prefix) {
string GetHeader(const ServiceDescriptor *service) {
string output;
{
// Scope the output stream so it closes and finalizes output to the string.
Expand All @@ -184,43 +185,43 @@ string GetHeader(const ServiceDescriptor *service, const string prefix) {
printer.Print("@protocol GRXWriteable;\n");
printer.Print("@protocol GRXWriter;\n\n");

map<string, string> vars = {{"service_name", service->name()},
{"prefix", prefix}};
printer.Print(vars, "@protocol $prefix$$service_name$ <NSObject>\n\n");
map<string, string> vars = {{"service_class", ServiceClassName(service)}};

printer.Print(vars, "@protocol $service_class$ <NSObject>\n\n");

for (int i = 0; i < service->method_count(); i++) {
PrintMethodDeclarations(&printer, service->method(i), vars);
PrintMethodDeclarations(&printer, service->method(i));
}
printer.Print("@end\n\n");

printer.Print("// Basic service implementation, over gRPC, that only does"
" marshalling and parsing.\n");
printer.Print(vars, "@interface $prefix$$service_name$ :"
" ProtoService<$prefix$$service_name$>\n");
printer.Print(vars, "@interface $service_class$ :"
" ProtoService<$service_class$>\n");
printer.Print("- (instancetype)initWithHost:(NSString *)host"
" NS_DESIGNATED_INITIALIZER;\n");
printer.Print("@end\n");
}
return output;
}

string GetSource(const ServiceDescriptor *service, const string prefix) {
string GetSource(const ServiceDescriptor *service) {
string output;
{
// Scope the output stream so it closes and finalizes output to the string.
grpc::protobuf::io::StringOutputStream output_stream(&output);
Printer printer(&output_stream, '$');

map<string, string> vars = {{"service_name", service->name()},
{"package", service->file()->package()},
{"prefix", prefix}};
{"service_class", ServiceClassName(service)},
{"package", service->file()->package()}};

printer.Print(vars,
"static NSString *const kPackageName = @\"$package$\";\n");
printer.Print(vars,
"static NSString *const kServiceName = @\"$service_name$\";\n\n");

printer.Print(vars, "@implementation $prefix$$service_name$\n\n");
printer.Print(vars, "@implementation $service_class$\n\n");

printer.Print("// Designated initializer\n");
printer.Print("- (instancetype)initWithHost:(NSString *)host {\n");
Expand All @@ -236,7 +237,7 @@ string GetSource(const ServiceDescriptor *service, const string prefix) {
printer.Print("}\n\n\n");

for (int i = 0; i < service->method_count(); i++) {
PrintMethodImplementations(&printer, service->method(i), vars);
PrintMethodImplementations(&printer, service->method(i));
}

printer.Print("@end\n");
Expand Down
9 changes: 5 additions & 4 deletions src/compiler/objective_c_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@

namespace grpc_objective_c_generator {

using ::grpc::protobuf::ServiceDescriptor;
using ::grpc::string;

// Returns the content to be included in the "global_scope" insertion point of
// the generated header file.
grpc::string GetHeader(const grpc::protobuf::ServiceDescriptor *service,
const grpc::string prefix);
string GetHeader(const ServiceDescriptor *service);

// Returns the content to be included in the "global_scope" insertion point of
// the generated implementation file.
grpc::string GetSource(const grpc::protobuf::ServiceDescriptor *service,
const grpc::string prefix);
string GetSource(const ServiceDescriptor *service);

} // namespace grpc_objective_c_generator

Expand Down
12 changes: 11 additions & 1 deletion src/compiler/objective_c_generator_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,19 @@

namespace grpc_objective_c_generator {

inline grpc::string MessageHeaderName(const grpc::protobuf::FileDescriptor *file) {
using ::grpc::protobuf::FileDescriptor;
using ::grpc::protobuf::ServiceDescriptor;
using ::grpc::string;

inline string MessageHeaderName(const FileDescriptor *file) {
return grpc_generator::FileNameInUpperCamel(file) + ".pbobjc.h";
}

inline string ServiceClassName(const ServiceDescriptor *service) {
const FileDescriptor *file = service->file();
string prefix = file->options().objc_class_prefix();
return prefix + service->name();
}

}
#endif // GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_HELPERS_H
4 changes: 2 additions & 2 deletions src/compiler/objective_c_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
string declarations;
for (int i = 0; i < file->service_count(); i++) {
const grpc::protobuf::ServiceDescriptor *service = file->service(i);
declarations += grpc_objective_c_generator::GetHeader(service, prefix);
declarations += grpc_objective_c_generator::GetHeader(service);
}

Write(context, file_name + ".pbrpc.h",
Expand All @@ -95,7 +95,7 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
string definitions;
for (int i = 0; i < file->service_count(); i++) {
const grpc::protobuf::ServiceDescriptor *service = file->service(i);
definitions += grpc_objective_c_generator::GetSource(service, prefix);
definitions += grpc_objective_c_generator::GetSource(service);
}

Write(context, file_name + ".pbrpc.m", imports + '\n' + definitions);
Expand Down
22 changes: 22 additions & 0 deletions src/csharp/Grpc.Tools.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<package>
<metadata>
<id>Grpc.Tools</id>
<title>gRPC C# Tools</title>
<summary>Tools for C# implementation of gRPC - an RPC library and framework</summary>
<description>Precompiled Windows binaries for generating protocol buffer messages and gRPC client/server code</description>
<version>0.5.0</version>
<authors>Google Inc.</authors>
<owners>grpc-packages</owners>
<licenseUrl>https://github.com/grpc/grpc/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/grpc/grpc</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<releaseNotes>protoc.exe - protocol buffer compiler v3.0.0-alpha-3; grpc_csharp_plugin.exe - gRPC C# protoc plugin version 0.5.0</releaseNotes>
<copyright>Copyright 2015, Google Inc.</copyright>
<tags>gRPC RPC Protocol HTTP/2</tags>
</metadata>
<files>
<file src="protoc.exe" target="tools" />
<file src="grpc_csharp_plugin.exe" target="tools" />
</files>
</package>
7 changes: 2 additions & 5 deletions src/csharp/Grpc.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>gRPC C#</title>
<summary>C# implementation of gRPC - an RPC library and framework</summary>
<description>C# implementation of gRPC - an RPC library and framework. See project site for more info.</description>
<version>0.5.0</version>
<version>0.5.0.1</version>
<authors>Google Inc.</authors>
<owners>grpc-packages</owners>
<licenseUrl>https://github.com/grpc/grpc/blob/master/LICENSE</licenseUrl>
Expand All @@ -18,8 +18,5 @@
<dependency id="Grpc.Core" version="0.5.0" />
</dependencies>
</metadata>
<files>
<file src="protoc.exe" target="tools" />
<file src="grpc_csharp_plugin.exe" target="tools" />
</files>
<files/>
</package>
1 change: 1 addition & 0 deletions src/csharp/build_packages.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ endlocal
%NUGET% pack ..\..\vsprojects\nuget_package\grpc.native.csharp_ext.nuspec || goto :error
%NUGET% pack Grpc.Core\Grpc.Core.nuspec -Symbols || goto :error
%NUGET% pack Grpc.Auth\Grpc.Auth.nuspec -Symbols || goto :error
%NUGET% pack Grpc.Tools.nuspec || goto :error
%NUGET% pack Grpc.nuspec || goto :error

goto :EOF
Expand Down
2 changes: 1 addition & 1 deletion src/csharp/buildall.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ setlocal
@call "%VS120COMNTOOLS%\..\..\vc\vcvarsall.bat" x86

@rem Build the C# native extension
msbuild ..\..\vsprojects\grpc.sln /t:grpc_csharp_ext || goto :error
msbuild ..\..\vsprojects\grpc.sln /t:grpc_csharp_ext /p:PlatformToolset=v120 || goto :error

msbuild Grpc.sln /p:Configuration=Debug || goto :error
msbuild Grpc.sln /p:Configuration=Release || goto :error
Expand Down
18 changes: 11 additions & 7 deletions src/objective-c/GRPCClient/private/GRPCSecureChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@
@implementation GRPCSecureChannel

- (instancetype)initWithHost:(NSString *)host {
// TODO(jcanizales): Load certs only once.
NSURL *certsURL = [[NSBundle mainBundle] URLForResource:@"gRPC.bundle/roots" withExtension:@"pem"];
NSData *certsData = [NSData dataWithContentsOfURL:certsURL];
NSString *certsString = [[NSString alloc] initWithData:certsData encoding:NSUTF8StringEncoding];

grpc_credentials *credentials = grpc_ssl_credentials_create(certsString.UTF8String, NULL);
return (self = [super initWithChannel:grpc_secure_channel_create(credentials,
static const grpc_credentials *kCredentials;
static dispatch_once_t loading;
dispatch_once(&loading, ^{
// Do not use NSBundle.mainBundle, as it's nil for tests of library projects.
NSBundle *bundle = [NSBundle bundleForClass:self.class];
NSString *certsPath = [bundle pathForResource:@"gRPC.bundle/roots" ofType:@"pem"];
NSData *certsData = [NSData dataWithContentsOfFile:certsPath];
NSString *certsString = [[NSString alloc] initWithData:certsData encoding:NSUTF8StringEncoding];
kCredentials = grpc_ssl_credentials_create(certsString.UTF8String, NULL);
});
return (self = [super initWithChannel:grpc_secure_channel_create(kCredentials,
host.UTF8String,
NULL)]);
}
Expand Down
6 changes: 4 additions & 2 deletions src/objective-c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ Pod::Spec.new do |s|
s.osx.deployment_target = '10.8'

s.subspec 'Messages' do |ms|
ms.source_files = '*.pbobjc.{h,m}'
ms.source_files = '*.pbobjc.{h,m}', '**/*.pbobjc.{h,m}'
ms.header_mappings_dir = '.'
ms.requires_arc = false
ms.dependency 'Protobuf', '~> 3.0'
end

s.subspec 'Services' do |ss|
ss.source_files = '*.pbrpc.{h,m}'
ss.source_files = '*.pbrpc.{h,m}', '**/*.pbrpc.{h,m}'
ss.header_mappings_dir = '.'
ss.requires_arc = true
ss.dependency 'gRPC', '~> 0.0'
ss.dependency '<Podspec file name>/Messages'
Expand Down
8 changes: 1 addition & 7 deletions src/objective-c/examples/Sample/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ platform :ios, '8.0'

pod 'gRPC', :path => "../../../.."
pod 'Protobuf', :git => 'https://github.com/google/protobuf.git'
pod 'Route_guide', :path => "RouteGuideClient"
pod 'RemoteTest', :path => "RemoteTestClient"

link_with 'Sample', 'SampleTests'
pod 'RemoteTest', :path => "../../generated_libraries/RemoteTestClient"

target 'Sample' do
end

target 'SampleTests' do
end
Loading

0 comments on commit 7b6fc6c

Please sign in to comment.