From 52af470d5b2b26e1e138fb39e11758f626fcf0c3 Mon Sep 17 00:00:00 2001 From: Nobutaka Takushima Date: Mon, 20 Apr 2015 12:13:19 +0900 Subject: [PATCH 01/26] fix android app build broken by https://github.com/grpc/grpc-java/commit/3666de4427460a307bfb86a7f93b3a04cb28f8c4 In grpc-java, io.grpc.nano was renamed to io.grpc.protobuf.nano. Therefore, android app fails to build with the latest version of grpc-java. --- java/android/app/build.gradle | 2 +- .../main/java/io/grpc/helloworldexample/GreeterGrpc.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/java/android/app/build.gradle b/java/android/app/build.gradle index 6940ad0a2a8..aedf4fe92a0 100644 --- a/java/android/app/build.gradle +++ b/java/android/app/build.gradle @@ -28,7 +28,7 @@ dependencies { // You need to build the https://github.com/grpc/grpc-java // to obtain these libraries below. compile 'io.grpc:grpc-core:0.1.0-SNAPSHOT' - compile 'io.grpc:grpc-nano:0.1.0-SNAPSHOT' + compile 'io.grpc:grpc-protobuf-nano:0.1.0-SNAPSHOT' compile 'io.grpc:grpc-okhttp:0.1.0-SNAPSHOT' compile 'io.grpc:grpc-stub:0.1.0-SNAPSHOT' } diff --git a/java/android/app/src/main/java/io/grpc/helloworldexample/GreeterGrpc.java b/java/android/app/src/main/java/io/grpc/helloworldexample/GreeterGrpc.java index 595c1402349..2a22b004d17 100644 --- a/java/android/app/src/main/java/io/grpc/helloworldexample/GreeterGrpc.java +++ b/java/android/app/src/main/java/io/grpc/helloworldexample/GreeterGrpc.java @@ -15,15 +15,15 @@ public class GreeterGrpc { Helloworld.HelloReply> METHOD_SAY_HELLO = io.grpc.stub.Method.create( io.grpc.MethodType.UNARY, "SayHello", - io.grpc.nano.NanoUtils.marshaller( - new io.grpc.nano.Parser() { + io.grpc.protobuf.nano.NanoUtils.marshaller( + new io.grpc.protobuf.nano.Parser() { @Override public Helloworld.HelloRequest parse(com.google.protobuf.nano.CodedInputByteBufferNano input) throws IOException { return Helloworld.HelloRequest.parseFrom(input); } }), - io.grpc.nano.NanoUtils.marshaller( - new io.grpc.nano.Parser() { + io.grpc.protobuf.nano.NanoUtils.marshaller( + new io.grpc.protobuf.nano.Parser() { @Override public Helloworld.HelloReply parse(com.google.protobuf.nano.CodedInputByteBufferNano input) throws IOException { return Helloworld.HelloReply.parseFrom(input); From 7c3a04d20fe658392b337c481ba0dd3b524342a2 Mon Sep 17 00:00:00 2001 From: David Young-Chan Kay Date: Fri, 24 Apr 2015 19:47:38 -0400 Subject: [PATCH 02/26] corrected references to io.grpc.protobuf.nano package. --- java/android/app/build.gradle | 2 +- .../main/java/io/grpc/helloworldexample/GreeterGrpc.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/java/android/app/build.gradle b/java/android/app/build.gradle index 6940ad0a2a8..aedf4fe92a0 100644 --- a/java/android/app/build.gradle +++ b/java/android/app/build.gradle @@ -28,7 +28,7 @@ dependencies { // You need to build the https://github.com/grpc/grpc-java // to obtain these libraries below. compile 'io.grpc:grpc-core:0.1.0-SNAPSHOT' - compile 'io.grpc:grpc-nano:0.1.0-SNAPSHOT' + compile 'io.grpc:grpc-protobuf-nano:0.1.0-SNAPSHOT' compile 'io.grpc:grpc-okhttp:0.1.0-SNAPSHOT' compile 'io.grpc:grpc-stub:0.1.0-SNAPSHOT' } diff --git a/java/android/app/src/main/java/io/grpc/helloworldexample/GreeterGrpc.java b/java/android/app/src/main/java/io/grpc/helloworldexample/GreeterGrpc.java index 595c1402349..2a22b004d17 100644 --- a/java/android/app/src/main/java/io/grpc/helloworldexample/GreeterGrpc.java +++ b/java/android/app/src/main/java/io/grpc/helloworldexample/GreeterGrpc.java @@ -15,15 +15,15 @@ public class GreeterGrpc { Helloworld.HelloReply> METHOD_SAY_HELLO = io.grpc.stub.Method.create( io.grpc.MethodType.UNARY, "SayHello", - io.grpc.nano.NanoUtils.marshaller( - new io.grpc.nano.Parser() { + io.grpc.protobuf.nano.NanoUtils.marshaller( + new io.grpc.protobuf.nano.Parser() { @Override public Helloworld.HelloRequest parse(com.google.protobuf.nano.CodedInputByteBufferNano input) throws IOException { return Helloworld.HelloRequest.parseFrom(input); } }), - io.grpc.nano.NanoUtils.marshaller( - new io.grpc.nano.Parser() { + io.grpc.protobuf.nano.NanoUtils.marshaller( + new io.grpc.protobuf.nano.Parser() { @Override public Helloworld.HelloReply parse(com.google.protobuf.nano.CodedInputByteBufferNano input) throws IOException { return Helloworld.HelloReply.parseFrom(input); From d9c1090cdb611037abb97338d318a08d37fe447a Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 5 Jun 2015 14:48:38 -0700 Subject: [PATCH 03/26] update C# greeter to use the latest gRPC packages --- csharp/.nuget/packages.config | 2 +- csharp/Greeter/Greeter.csproj | 15 ++++++++------- csharp/Greeter/packages.config | 6 +++--- csharp/GreeterClient/GreeterClient.csproj | 15 ++++++++------- csharp/GreeterClient/packages.config | 6 +++--- csharp/GreeterServer/GreeterServer.csproj | 15 ++++++++------- csharp/GreeterServer/packages.config | 6 +++--- 7 files changed, 34 insertions(+), 31 deletions(-) diff --git a/csharp/.nuget/packages.config b/csharp/.nuget/packages.config index e667d9847ee..966d46a2833 100644 --- a/csharp/.nuget/packages.config +++ b/csharp/.nuget/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/csharp/Greeter/Greeter.csproj b/csharp/Greeter/Greeter.csproj index dc820140ae4..8899836e97a 100644 --- a/csharp/Greeter/Greeter.csproj +++ b/csharp/Greeter/Greeter.csproj @@ -1,6 +1,6 @@  - + @@ -13,7 +13,7 @@ Greeter Greeter v4.5 - 276b758f + 4d99595a true @@ -40,8 +40,9 @@ ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.Serialization.dll - - ..\packages\Grpc.Core.0.5.0\lib\net45\Grpc.Core.dll + + False + ..\packages\Grpc.Core.0.5.1\lib\net45\Grpc.Core.dll @@ -70,10 +71,10 @@ - - + + - + \ No newline at end of file diff --git a/csharp/Greeter/packages.config b/csharp/Greeter/packages.config index 0fdc11821b0..481390ef9d0 100644 --- a/csharp/Greeter/packages.config +++ b/csharp/Greeter/packages.config @@ -1,11 +1,11 @@  - - + + - + \ No newline at end of file diff --git a/csharp/GreeterClient/GreeterClient.csproj b/csharp/GreeterClient/GreeterClient.csproj index c36b064d678..3a1feb367ef 100644 --- a/csharp/GreeterClient/GreeterClient.csproj +++ b/csharp/GreeterClient/GreeterClient.csproj @@ -1,6 +1,6 @@  - + @@ -13,7 +13,7 @@ GreeterClient GreeterClient v4.5 - 52fefe3d + 9e922694 true @@ -40,8 +40,9 @@ ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.Serialization.dll - - ..\packages\Grpc.Core.0.5.0\lib\net45\Grpc.Core.dll + + False + ..\packages\Grpc.Core.0.5.1\lib\net45\Grpc.Core.dll @@ -73,10 +74,10 @@ - - + + - + \ No newline at end of file diff --git a/csharp/GreeterClient/packages.config b/csharp/GreeterClient/packages.config index 0fdc11821b0..481390ef9d0 100644 --- a/csharp/GreeterClient/packages.config +++ b/csharp/GreeterClient/packages.config @@ -1,11 +1,11 @@  - - + + - + \ No newline at end of file diff --git a/csharp/GreeterServer/GreeterServer.csproj b/csharp/GreeterServer/GreeterServer.csproj index 5f9b665aa2d..da73168dc5e 100644 --- a/csharp/GreeterServer/GreeterServer.csproj +++ b/csharp/GreeterServer/GreeterServer.csproj @@ -1,6 +1,6 @@  - + @@ -13,7 +13,7 @@ GreeterServer GreeterServer v4.5 - 07074f3d + d79af25e true @@ -40,8 +40,9 @@ ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.Serialization.dll - - ..\packages\Grpc.Core.0.5.0\lib\net45\Grpc.Core.dll + + False + ..\packages\Grpc.Core.0.5.1\lib\net45\Grpc.Core.dll @@ -73,10 +74,10 @@ - - + + - + \ No newline at end of file diff --git a/csharp/GreeterServer/packages.config b/csharp/GreeterServer/packages.config index 0fdc11821b0..481390ef9d0 100644 --- a/csharp/GreeterServer/packages.config +++ b/csharp/GreeterServer/packages.config @@ -1,11 +1,11 @@  - - + + - + \ No newline at end of file From add9c29da84d76d87b8aeb1d7a37f71f64ca830a Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 5 Jun 2015 15:04:59 -0700 Subject: [PATCH 04/26] update C# routeguide to use the latest nuget package --- csharp/route_guide/.nuget/packages.config | 2 +- csharp/route_guide/RouteGuide/RouteGuide.csproj | 15 ++++++++------- csharp/route_guide/RouteGuide/packages.config | 6 +++--- .../RouteGuideClient/RouteGuideClient.csproj | 15 ++++++++------- .../route_guide/RouteGuideClient/packages.config | 6 +++--- .../RouteGuideServer/RouteGuideServer.csproj | 15 ++++++++------- .../route_guide/RouteGuideServer/packages.config | 6 +++--- 7 files changed, 34 insertions(+), 31 deletions(-) diff --git a/csharp/route_guide/.nuget/packages.config b/csharp/route_guide/.nuget/packages.config index e667d9847ee..966d46a2833 100644 --- a/csharp/route_guide/.nuget/packages.config +++ b/csharp/route_guide/.nuget/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/csharp/route_guide/RouteGuide/RouteGuide.csproj b/csharp/route_guide/RouteGuide/RouteGuide.csproj index 9b5daa6e4bc..3de2417c708 100644 --- a/csharp/route_guide/RouteGuide/RouteGuide.csproj +++ b/csharp/route_guide/RouteGuide/RouteGuide.csproj @@ -1,6 +1,6 @@  - + @@ -14,7 +14,7 @@ RouteGuide v4.5 512 - 247686dc + 58253d57 true @@ -40,8 +40,9 @@ ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.Serialization.dll - - ..\packages\Grpc.Core.0.5.0\lib\net45\Grpc.Core.dll + + False + ..\packages\Grpc.Core.0.5.1\lib\net45\Grpc.Core.dll False @@ -83,12 +84,12 @@ - - + + - + + + + + + + + + + + + + + + + + + + diff --git a/objective-c/HelloWorld/HelloWorld/Images.xcassets/AppIcon.appiconset/Contents.json b/objective-c/HelloWorld/HelloWorld/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000000..36d2c80d889 --- /dev/null +++ b/objective-c/HelloWorld/HelloWorld/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/objective-c/HelloWorld/HelloWorld/Info.plist b/objective-c/HelloWorld/HelloWorld/Info.plist new file mode 100644 index 00000000000..77352c99aa4 --- /dev/null +++ b/objective-c/HelloWorld/HelloWorld/Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + Google.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/objective-c/HelloWorld/HelloWorld/ViewController.h b/objective-c/HelloWorld/HelloWorld/ViewController.h new file mode 100644 index 00000000000..c822a66cedc --- /dev/null +++ b/objective-c/HelloWorld/HelloWorld/ViewController.h @@ -0,0 +1,15 @@ +// +// ViewController.h +// HelloWorld +// +// Created by Michael Lumish on 6/11/15. +// Copyright (c) 2015 Google. All rights reserved. +// + +#import + +@interface ViewController : UIViewController + + +@end + diff --git a/objective-c/HelloWorld/HelloWorld/ViewController.m b/objective-c/HelloWorld/HelloWorld/ViewController.m new file mode 100644 index 00000000000..5aa4441879b --- /dev/null +++ b/objective-c/HelloWorld/HelloWorld/ViewController.m @@ -0,0 +1,27 @@ +// +// ViewController.m +// HelloWorld +// +// Created by Michael Lumish on 6/11/15. +// Copyright (c) 2015 Google. All rights reserved. +// + +#import "ViewController.h" + +@interface ViewController () + +@end + +@implementation ViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view, typically from a nib. +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +@end diff --git a/objective-c/HelloWorld/HelloWorld/main.m b/objective-c/HelloWorld/HelloWorld/main.m new file mode 100644 index 00000000000..c912b6345a2 --- /dev/null +++ b/objective-c/HelloWorld/HelloWorld/main.m @@ -0,0 +1,26 @@ +// +// main.m +// HelloWorld +// +// Created by Michael Lumish on 6/11/15. +// Copyright (c) 2015 Google. All rights reserved. +// + +#import +#import "AppDelegate.h" + +#import + +static NSString * const kHostAddress = @"http://localhost:50051"; + +int main(int argc, char * argv[]) { + @autoreleasepool { + HLWGreeter *client = [[HLWGreeter alloc] initWithHost:kHostAddress]; + HLWHelloRequest *request = [HLWHelloRequest message]; + request.name = @"Objective C"; + [client sayHelloWithRequest:request handler:^(HLWHelloReply *response, NSError *error) { + NSLog(@"%@", response.message); + }]; + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/objective-c/HelloWorld/Podfile b/objective-c/HelloWorld/Podfile new file mode 100644 index 00000000000..2934ebc2c8a --- /dev/null +++ b/objective-c/HelloWorld/Podfile @@ -0,0 +1,7 @@ +source 'https://github.com/CocoaPods/Specs.git' +platform :ios, '8.0' + +target 'HelloWorld' do + # Depend on the generated HelloWorld library. + pod 'HelloWorld', :path => '.' +end From 042b91253eeeca0f7da38d0c881a0072506f9289 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Thu, 11 Jun 2015 14:23:32 -0700 Subject: [PATCH 10/26] Added Objective C HelloWorld README --- objective-c/HelloWorld/README.md | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 objective-c/HelloWorld/README.md diff --git a/objective-c/HelloWorld/README.md b/objective-c/HelloWorld/README.md new file mode 100644 index 00000000000..db3bcb18fe7 --- /dev/null +++ b/objective-c/HelloWorld/README.md @@ -0,0 +1,48 @@ +#gRPC in 3 minutes (Objective C) + +## Installation + +To run this example you should have [Cocoapods](https://cocoapods.org/#install) installed, as well as the relevant tools to generate the client library code (and a server in another language, for testing). You can obtain the latter by following [these setup instructions](https://github.com/grpc/homebrew-grpc). + +## Hello Objective C gRPC! + +Here's how to build and run the Objective C implementation of the [Hello World](https://github.com/grpc/grpc-common/blob/master/protos/helloworld.proto) example used in [Getting started](https://github.com/grpc/grpc-common). + +The example code for this and our other examples lives in the `grpc-common` +GitHub repository. Clone this repository to your local machine by running the +following command: + + +```sh +$ git clone https://github.com/grpc/grpc-common.git +``` + +Change your current directory to grpc-common/objective-c/HelloWorld + +```sh +$ cd grpc-common/objective-c/HelloWorld +``` + +### Try it! +To try the sample app, we need a gRPC server running locally. Let's compile and run, for example, the C++ server in this repository: + +```shell +$ pushd ../../cpp/helloworld +$ make +$ ./greeter_server & +$ popd +``` + +Now have Cocoapods generate and install the client library for our .proto files: + +```shell +$ pod install +``` + +This might have to compile OpenSSL, which takes around 15 minutes if Cocoapods doesn't have it yet on your computer's cache). + +Finally, open the XCode workspace created by Cocoapods, and run the app. You can check the calling code in `Supporting Files/main.m` and see the results in XCode's log console. + +## Tutorial + +You can find a more detailed tutorial in [gRPC Basics: Objective C](https://github.com/grpc/grpc-common/blob/master/objective-c/route_guide/README.md) \ No newline at end of file From 3bcfcba3ef516b9633363670542215d5e952d86d Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Thu, 11 Jun 2015 15:23:00 -0700 Subject: [PATCH 11/26] node client uses the db_path file as well --- node/route_guide/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/route_guide/README.md b/node/route_guide/README.md index 25cb39d2ccd..5460c9905dc 100644 --- a/node/route_guide/README.md +++ b/node/route_guide/README.md @@ -358,5 +358,5 @@ $ node ./route_guide_server.js --db_path=route_guide_db.json ``` Run the client (in a different terminal): ```shell -$ node ./route_guide_client.js +$ node ./route_guide_client.js --db_path=route_guide_db.json ``` From 7e814077aa2fcc6989625a398c15591e44718914 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Thu, 11 Jun 2015 16:54:34 -0700 Subject: [PATCH 12/26] ruby route_guide server logger is undefined --- ruby/route_guide/route_guide_server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/route_guide/route_guide_server.rb b/ruby/route_guide/route_guide_server.rb index 8f12ba250d3..2b2b8084ef9 100755 --- a/ruby/route_guide/route_guide_server.rb +++ b/ruby/route_guide/route_guide_server.rb @@ -203,7 +203,7 @@ def main port = '0.0.0.0:50051' s = GRPC::RpcServer.new s.add_http2_port(port) - logger.info("... running insecurely on #{port}") + GRPC.logger.info("... running insecurely on #{port}") s.handle(ServerImpl.new(feature_db)) s.run end From 5de22f5146abf273f1d54aeeb29c02e651d63b7b Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 12 Jun 2015 11:21:55 -0700 Subject: [PATCH 13/26] Removed what I could, fixed some nits --- .../HelloWorld.xcodeproj/project.pbxproj | 12 ---- .../HelloWorld/HelloWorld/AppDelegate.h | 40 ++++++++--- .../HelloWorld/HelloWorld/AppDelegate.m | 71 +++++++++---------- .../HelloWorld/Base.lproj/LaunchScreen.xib | 41 ----------- objective-c/HelloWorld/HelloWorld/Info.plist | 2 +- .../HelloWorld/HelloWorld/ViewController.h | 39 ++++++++-- .../HelloWorld/HelloWorld/ViewController.m | 53 ++++++++------ objective-c/HelloWorld/HelloWorld/main.m | 41 ++++++++--- objective-c/HelloWorld/README.md | 12 ++-- 9 files changed, 169 insertions(+), 142 deletions(-) delete mode 100644 objective-c/HelloWorld/HelloWorld/Base.lproj/LaunchScreen.xib diff --git a/objective-c/HelloWorld/HelloWorld.xcodeproj/project.pbxproj b/objective-c/HelloWorld/HelloWorld.xcodeproj/project.pbxproj index 6cc49ead373..9a7b3057e09 100644 --- a/objective-c/HelloWorld/HelloWorld.xcodeproj/project.pbxproj +++ b/objective-c/HelloWorld/HelloWorld.xcodeproj/project.pbxproj @@ -12,7 +12,6 @@ 5E36906C1B2A23800040F884 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E36906B1B2A23800040F884 /* ViewController.m */; }; 5E36906F1B2A23800040F884 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5E36906D1B2A23800040F884 /* Main.storyboard */; }; 5E3690711B2A23800040F884 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5E3690701B2A23800040F884 /* Images.xcassets */; }; - 5E3690741B2A23800040F884 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5E3690721B2A23800040F884 /* LaunchScreen.xib */; }; 5E3690801B2A23800040F884 /* HelloWorldTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E36907F1B2A23800040F884 /* HelloWorldTests.m */; }; EF61CF6AE2536A31D47F0E63 /* libPods-HelloWorld.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B4E1F55F8A2EC95A0E7EE88 /* libPods-HelloWorld.a */; }; /* End PBXBuildFile section */ @@ -38,7 +37,6 @@ 5E36906B1B2A23800040F884 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 5E36906E1B2A23800040F884 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 5E3690701B2A23800040F884 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; - 5E3690731B2A23800040F884 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 5E3690791B2A23800040F884 /* HelloWorldTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = HelloWorldTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 5E36907E1B2A23800040F884 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 5E36907F1B2A23800040F884 /* HelloWorldTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HelloWorldTests.m; sourceTree = ""; }; @@ -94,7 +92,6 @@ 5E36906B1B2A23800040F884 /* ViewController.m */, 5E36906D1B2A23800040F884 /* Main.storyboard */, 5E3690701B2A23800040F884 /* Images.xcassets */, - 5E3690721B2A23800040F884 /* LaunchScreen.xib */, 5E3690631B2A23800040F884 /* Supporting Files */, ); path = HelloWorld; @@ -226,7 +223,6 @@ buildActionMask = 2147483647; files = ( 5E36906F1B2A23800040F884 /* Main.storyboard in Resources */, - 5E3690741B2A23800040F884 /* LaunchScreen.xib in Resources */, 5E3690711B2A23800040F884 /* Images.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -311,14 +307,6 @@ name = Main.storyboard; sourceTree = ""; }; - 5E3690721B2A23800040F884 /* LaunchScreen.xib */ = { - isa = PBXVariantGroup; - children = ( - 5E3690731B2A23800040F884 /* Base */, - ); - name = LaunchScreen.xib; - sourceTree = ""; - }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ diff --git a/objective-c/HelloWorld/HelloWorld/AppDelegate.h b/objective-c/HelloWorld/HelloWorld/AppDelegate.h index b1eaba90a4f..b1857f28e08 100644 --- a/objective-c/HelloWorld/HelloWorld/AppDelegate.h +++ b/objective-c/HelloWorld/HelloWorld/AppDelegate.h @@ -1,10 +1,35 @@ -// -// AppDelegate.h -// HelloWorld -// -// Created by Michael Lumish on 6/11/15. -// Copyright (c) 2015 Google. All rights reserved. -// +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ #import @@ -12,6 +37,5 @@ @property (strong, nonatomic) UIWindow *window; - @end diff --git a/objective-c/HelloWorld/HelloWorld/AppDelegate.m b/objective-c/HelloWorld/HelloWorld/AppDelegate.m index cd6498d058d..27b1f00f989 100644 --- a/objective-c/HelloWorld/HelloWorld/AppDelegate.m +++ b/objective-c/HelloWorld/HelloWorld/AppDelegate.m @@ -1,45 +1,38 @@ -// -// AppDelegate.m -// HelloWorld -// -// Created by Michael Lumish on 6/11/15. -// Copyright (c) 2015 Google. All rights reserved. -// +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ #import "AppDelegate.h" -@interface AppDelegate () - -@end - @implementation AppDelegate - -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - // Override point for customization after application launch. - return YES; -} - -- (void)applicationWillResignActive:(UIApplication *)application { - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. -} - -- (void)applicationDidEnterBackground:(UIApplication *)application { - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. -} - -- (void)applicationWillEnterForeground:(UIApplication *)application { - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. -} - -- (void)applicationDidBecomeActive:(UIApplication *)application { - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. -} - -- (void)applicationWillTerminate:(UIApplication *)application { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. -} - @end diff --git a/objective-c/HelloWorld/HelloWorld/Base.lproj/LaunchScreen.xib b/objective-c/HelloWorld/HelloWorld/Base.lproj/LaunchScreen.xib deleted file mode 100644 index 8fcc4fd8ed5..00000000000 --- a/objective-c/HelloWorld/HelloWorld/Base.lproj/LaunchScreen.xib +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/objective-c/HelloWorld/HelloWorld/Info.plist b/objective-c/HelloWorld/HelloWorld/Info.plist index 77352c99aa4..1078fff7235 100644 --- a/objective-c/HelloWorld/HelloWorld/Info.plist +++ b/objective-c/HelloWorld/HelloWorld/Info.plist @@ -23,7 +23,7 @@ LSRequiresIPhoneOS UILaunchStoryboardName - LaunchScreen + Main UIMainStoryboardFile Main UIRequiredDeviceCapabilities diff --git a/objective-c/HelloWorld/HelloWorld/ViewController.h b/objective-c/HelloWorld/HelloWorld/ViewController.h index c822a66cedc..38cd7f92b66 100644 --- a/objective-c/HelloWorld/HelloWorld/ViewController.h +++ b/objective-c/HelloWorld/HelloWorld/ViewController.h @@ -1,10 +1,35 @@ -// -// ViewController.h -// HelloWorld -// -// Created by Michael Lumish on 6/11/15. -// Copyright (c) 2015 Google. All rights reserved. -// +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ #import diff --git a/objective-c/HelloWorld/HelloWorld/ViewController.m b/objective-c/HelloWorld/HelloWorld/ViewController.m index 5aa4441879b..91df435ed92 100644 --- a/objective-c/HelloWorld/HelloWorld/ViewController.m +++ b/objective-c/HelloWorld/HelloWorld/ViewController.m @@ -1,27 +1,38 @@ -// -// ViewController.m -// HelloWorld -// -// Created by Michael Lumish on 6/11/15. -// Copyright (c) 2015 Google. All rights reserved. -// +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ #import "ViewController.h" -@interface ViewController () - -@end - @implementation ViewController -- (void)viewDidLoad { - [super viewDidLoad]; - // Do any additional setup after loading the view, typically from a nib. -} - -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - @end diff --git a/objective-c/HelloWorld/HelloWorld/main.m b/objective-c/HelloWorld/HelloWorld/main.m index c912b6345a2..458580be302 100644 --- a/objective-c/HelloWorld/HelloWorld/main.m +++ b/objective-c/HelloWorld/HelloWorld/main.m @@ -1,10 +1,35 @@ -// -// main.m -// HelloWorld -// -// Created by Michael Lumish on 6/11/15. -// Copyright (c) 2015 Google. All rights reserved. -// +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ #import #import "AppDelegate.h" @@ -17,7 +42,7 @@ int main(int argc, char * argv[]) { @autoreleasepool { HLWGreeter *client = [[HLWGreeter alloc] initWithHost:kHostAddress]; HLWHelloRequest *request = [HLWHelloRequest message]; - request.name = @"Objective C"; + request.name = @"Objective-C"; [client sayHelloWithRequest:request handler:^(HLWHelloReply *response, NSError *error) { NSLog(@"%@", response.message); }]; diff --git a/objective-c/HelloWorld/README.md b/objective-c/HelloWorld/README.md index db3bcb18fe7..cb25882867c 100644 --- a/objective-c/HelloWorld/README.md +++ b/objective-c/HelloWorld/README.md @@ -1,12 +1,12 @@ -#gRPC in 3 minutes (Objective C) +#gRPC in 3 minutes (Objective-C) ## Installation To run this example you should have [Cocoapods](https://cocoapods.org/#install) installed, as well as the relevant tools to generate the client library code (and a server in another language, for testing). You can obtain the latter by following [these setup instructions](https://github.com/grpc/homebrew-grpc). -## Hello Objective C gRPC! +## Hello Objective-C gRPC! -Here's how to build and run the Objective C implementation of the [Hello World](https://github.com/grpc/grpc-common/blob/master/protos/helloworld.proto) example used in [Getting started](https://github.com/grpc/grpc-common). +Here's how to build and run the Objective-C implementation of the [Hello World](https://github.com/grpc/grpc-common/blob/master/protos/helloworld.proto) example used in [Getting started](https://github.com/grpc/grpc-common). The example code for this and our other examples lives in the `grpc-common` GitHub repository. Clone this repository to your local machine by running the @@ -17,7 +17,7 @@ following command: $ git clone https://github.com/grpc/grpc-common.git ``` -Change your current directory to grpc-common/objective-c/HelloWorld +Change your current directory to `grpc-common/objective-c/HelloWorld` ```sh $ cd grpc-common/objective-c/HelloWorld @@ -43,6 +43,8 @@ This might have to compile OpenSSL, which takes around 15 minutes if Cocoapods d Finally, open the XCode workspace created by Cocoapods, and run the app. You can check the calling code in `Supporting Files/main.m` and see the results in XCode's log console. +The code sends a `HLWHelloRequest` containing the string "Objective-C" to a local server. The server responds with a `HLWHelloResponse`, which contains a string that is then output to the log. + ## Tutorial -You can find a more detailed tutorial in [gRPC Basics: Objective C](https://github.com/grpc/grpc-common/blob/master/objective-c/route_guide/README.md) \ No newline at end of file +You can find a more detailed tutorial in [gRPC Basics: Objective-C](https://github.com/grpc/grpc-common/blob/master/objective-c/route_guide/README.md) \ No newline at end of file From b92da5f8fb419871042d498d47dab09083f8a6b7 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 12 Jun 2015 11:24:08 -0700 Subject: [PATCH 14/26] Renamed HelloWorld to helloworld --- objective-c/{HelloWorld => helloworld}/HelloWorld.podspec | 0 .../HelloWorld.xcodeproj/project.pbxproj | 0 .../project.xcworkspace/contents.xcworkspacedata | 0 objective-c/{HelloWorld => helloworld}/HelloWorld/AppDelegate.h | 0 objective-c/{HelloWorld => helloworld}/HelloWorld/AppDelegate.m | 0 .../HelloWorld/Base.lproj/Main.storyboard | 0 .../HelloWorld/Images.xcassets/AppIcon.appiconset/Contents.json | 0 objective-c/{HelloWorld => helloworld}/HelloWorld/Info.plist | 0 .../{HelloWorld => helloworld}/HelloWorld/ViewController.h | 0 .../{HelloWorld => helloworld}/HelloWorld/ViewController.m | 0 objective-c/{HelloWorld => helloworld}/HelloWorld/main.m | 0 objective-c/{HelloWorld => helloworld}/Podfile | 0 objective-c/{HelloWorld => helloworld}/README.md | 0 13 files changed, 0 insertions(+), 0 deletions(-) rename objective-c/{HelloWorld => helloworld}/HelloWorld.podspec (100%) rename objective-c/{HelloWorld => helloworld}/HelloWorld.xcodeproj/project.pbxproj (100%) rename objective-c/{HelloWorld => helloworld}/HelloWorld.xcodeproj/project.xcworkspace/contents.xcworkspacedata (100%) rename objective-c/{HelloWorld => helloworld}/HelloWorld/AppDelegate.h (100%) rename objective-c/{HelloWorld => helloworld}/HelloWorld/AppDelegate.m (100%) rename objective-c/{HelloWorld => helloworld}/HelloWorld/Base.lproj/Main.storyboard (100%) rename objective-c/{HelloWorld => helloworld}/HelloWorld/Images.xcassets/AppIcon.appiconset/Contents.json (100%) rename objective-c/{HelloWorld => helloworld}/HelloWorld/Info.plist (100%) rename objective-c/{HelloWorld => helloworld}/HelloWorld/ViewController.h (100%) rename objective-c/{HelloWorld => helloworld}/HelloWorld/ViewController.m (100%) rename objective-c/{HelloWorld => helloworld}/HelloWorld/main.m (100%) rename objective-c/{HelloWorld => helloworld}/Podfile (100%) rename objective-c/{HelloWorld => helloworld}/README.md (100%) diff --git a/objective-c/HelloWorld/HelloWorld.podspec b/objective-c/helloworld/HelloWorld.podspec similarity index 100% rename from objective-c/HelloWorld/HelloWorld.podspec rename to objective-c/helloworld/HelloWorld.podspec diff --git a/objective-c/HelloWorld/HelloWorld.xcodeproj/project.pbxproj b/objective-c/helloworld/HelloWorld.xcodeproj/project.pbxproj similarity index 100% rename from objective-c/HelloWorld/HelloWorld.xcodeproj/project.pbxproj rename to objective-c/helloworld/HelloWorld.xcodeproj/project.pbxproj diff --git a/objective-c/HelloWorld/HelloWorld.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/objective-c/helloworld/HelloWorld.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from objective-c/HelloWorld/HelloWorld.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to objective-c/helloworld/HelloWorld.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/objective-c/HelloWorld/HelloWorld/AppDelegate.h b/objective-c/helloworld/HelloWorld/AppDelegate.h similarity index 100% rename from objective-c/HelloWorld/HelloWorld/AppDelegate.h rename to objective-c/helloworld/HelloWorld/AppDelegate.h diff --git a/objective-c/HelloWorld/HelloWorld/AppDelegate.m b/objective-c/helloworld/HelloWorld/AppDelegate.m similarity index 100% rename from objective-c/HelloWorld/HelloWorld/AppDelegate.m rename to objective-c/helloworld/HelloWorld/AppDelegate.m diff --git a/objective-c/HelloWorld/HelloWorld/Base.lproj/Main.storyboard b/objective-c/helloworld/HelloWorld/Base.lproj/Main.storyboard similarity index 100% rename from objective-c/HelloWorld/HelloWorld/Base.lproj/Main.storyboard rename to objective-c/helloworld/HelloWorld/Base.lproj/Main.storyboard diff --git a/objective-c/HelloWorld/HelloWorld/Images.xcassets/AppIcon.appiconset/Contents.json b/objective-c/helloworld/HelloWorld/Images.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from objective-c/HelloWorld/HelloWorld/Images.xcassets/AppIcon.appiconset/Contents.json rename to objective-c/helloworld/HelloWorld/Images.xcassets/AppIcon.appiconset/Contents.json diff --git a/objective-c/HelloWorld/HelloWorld/Info.plist b/objective-c/helloworld/HelloWorld/Info.plist similarity index 100% rename from objective-c/HelloWorld/HelloWorld/Info.plist rename to objective-c/helloworld/HelloWorld/Info.plist diff --git a/objective-c/HelloWorld/HelloWorld/ViewController.h b/objective-c/helloworld/HelloWorld/ViewController.h similarity index 100% rename from objective-c/HelloWorld/HelloWorld/ViewController.h rename to objective-c/helloworld/HelloWorld/ViewController.h diff --git a/objective-c/HelloWorld/HelloWorld/ViewController.m b/objective-c/helloworld/HelloWorld/ViewController.m similarity index 100% rename from objective-c/HelloWorld/HelloWorld/ViewController.m rename to objective-c/helloworld/HelloWorld/ViewController.m diff --git a/objective-c/HelloWorld/HelloWorld/main.m b/objective-c/helloworld/HelloWorld/main.m similarity index 100% rename from objective-c/HelloWorld/HelloWorld/main.m rename to objective-c/helloworld/HelloWorld/main.m diff --git a/objective-c/HelloWorld/Podfile b/objective-c/helloworld/Podfile similarity index 100% rename from objective-c/HelloWorld/Podfile rename to objective-c/helloworld/Podfile diff --git a/objective-c/HelloWorld/README.md b/objective-c/helloworld/README.md similarity index 100% rename from objective-c/HelloWorld/README.md rename to objective-c/helloworld/README.md From b056066235453b55c7678374c85dde373d03f86f Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 12 Jun 2015 12:37:08 -0700 Subject: [PATCH 15/26] Moved file within project --- .../HelloWorld.xcodeproj/project.pbxproj | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/objective-c/helloworld/HelloWorld.xcodeproj/project.pbxproj b/objective-c/helloworld/HelloWorld.xcodeproj/project.pbxproj index 9a7b3057e09..018e722cb70 100644 --- a/objective-c/helloworld/HelloWorld.xcodeproj/project.pbxproj +++ b/objective-c/helloworld/HelloWorld.xcodeproj/project.pbxproj @@ -30,7 +30,7 @@ 0C432EF610DB15C0F47A66BB /* Pods-HelloWorld.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HelloWorld.release.xcconfig"; path = "Pods/Target Support Files/Pods-HelloWorld/Pods-HelloWorld.release.xcconfig"; sourceTree = ""; }; 5E3690601B2A23800040F884 /* HelloWorld.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HelloWorld.app; sourceTree = BUILT_PRODUCTS_DIR; }; 5E3690641B2A23800040F884 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 5E3690651B2A23800040F884 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 5E3690651B2A23800040F884 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = main.m; path = HelloWorld/main.m; sourceTree = ""; }; 5E3690671B2A23800040F884 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 5E3690681B2A23800040F884 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 5E36906A1B2A23800040F884 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; @@ -66,6 +66,7 @@ 5E3690571B2A23800040F884 = { isa = PBXGroup; children = ( + 5E3690651B2A23800040F884 /* main.m */, 5E3690621B2A23800040F884 /* HelloWorld */, 5E36907C1B2A23800040F884 /* HelloWorldTests */, 5E3690611B2A23800040F884 /* Products */, @@ -86,12 +87,6 @@ 5E3690621B2A23800040F884 /* HelloWorld */ = { isa = PBXGroup; children = ( - 5E3690671B2A23800040F884 /* AppDelegate.h */, - 5E3690681B2A23800040F884 /* AppDelegate.m */, - 5E36906A1B2A23800040F884 /* ViewController.h */, - 5E36906B1B2A23800040F884 /* ViewController.m */, - 5E36906D1B2A23800040F884 /* Main.storyboard */, - 5E3690701B2A23800040F884 /* Images.xcassets */, 5E3690631B2A23800040F884 /* Supporting Files */, ); path = HelloWorld; @@ -100,8 +95,13 @@ 5E3690631B2A23800040F884 /* Supporting Files */ = { isa = PBXGroup; children = ( + 5E3690701B2A23800040F884 /* Images.xcassets */, + 5E36906D1B2A23800040F884 /* Main.storyboard */, + 5E36906B1B2A23800040F884 /* ViewController.m */, + 5E36906A1B2A23800040F884 /* ViewController.h */, + 5E3690681B2A23800040F884 /* AppDelegate.m */, + 5E3690671B2A23800040F884 /* AppDelegate.h */, 5E3690641B2A23800040F884 /* Info.plist */, - 5E3690651B2A23800040F884 /* main.m */, ); name = "Supporting Files"; sourceTree = ""; From 3ea5cc927c733b8e8bba9f8bbce1f2ac8634ceb9 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 12 Jun 2015 16:06:37 -0700 Subject: [PATCH 16/26] Fixed path names in README --- objective-c/helloworld/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/objective-c/helloworld/README.md b/objective-c/helloworld/README.md index cb25882867c..8f6d0d3a8d0 100644 --- a/objective-c/helloworld/README.md +++ b/objective-c/helloworld/README.md @@ -17,10 +17,10 @@ following command: $ git clone https://github.com/grpc/grpc-common.git ``` -Change your current directory to `grpc-common/objective-c/HelloWorld` +Change your current directory to `grpc-common/objective-c/helloworld` ```sh -$ cd grpc-common/objective-c/HelloWorld +$ cd grpc-common/objective-c/helloworld ``` ### Try it! @@ -41,7 +41,7 @@ $ pod install This might have to compile OpenSSL, which takes around 15 minutes if Cocoapods doesn't have it yet on your computer's cache). -Finally, open the XCode workspace created by Cocoapods, and run the app. You can check the calling code in `Supporting Files/main.m` and see the results in XCode's log console. +Finally, open the XCode workspace created by Cocoapods, and run the app. You can check the calling code in `main.m` and see the results in XCode's log console. The code sends a `HLWHelloRequest` containing the string "Objective-C" to a local server. The server responds with a `HLWHelloResponse`, which contains a string that is then output to the log. From a0117adab0f764f499e839eea922e070418c6f14 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 12 Jun 2015 16:08:18 -0700 Subject: [PATCH 17/26] Moved main.m up a level --- objective-c/helloworld/HelloWorld.xcodeproj/project.pbxproj | 2 +- objective-c/helloworld/{HelloWorld => }/main.m | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename objective-c/helloworld/{HelloWorld => }/main.m (100%) diff --git a/objective-c/helloworld/HelloWorld.xcodeproj/project.pbxproj b/objective-c/helloworld/HelloWorld.xcodeproj/project.pbxproj index 018e722cb70..8d92247a913 100644 --- a/objective-c/helloworld/HelloWorld.xcodeproj/project.pbxproj +++ b/objective-c/helloworld/HelloWorld.xcodeproj/project.pbxproj @@ -30,7 +30,7 @@ 0C432EF610DB15C0F47A66BB /* Pods-HelloWorld.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HelloWorld.release.xcconfig"; path = "Pods/Target Support Files/Pods-HelloWorld/Pods-HelloWorld.release.xcconfig"; sourceTree = ""; }; 5E3690601B2A23800040F884 /* HelloWorld.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HelloWorld.app; sourceTree = BUILT_PRODUCTS_DIR; }; 5E3690641B2A23800040F884 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 5E3690651B2A23800040F884 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = main.m; path = HelloWorld/main.m; sourceTree = ""; }; + 5E3690651B2A23800040F884 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 5E3690671B2A23800040F884 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 5E3690681B2A23800040F884 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 5E36906A1B2A23800040F884 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; diff --git a/objective-c/helloworld/HelloWorld/main.m b/objective-c/helloworld/main.m similarity index 100% rename from objective-c/helloworld/HelloWorld/main.m rename to objective-c/helloworld/main.m From 5fd27c9a52e518dc1fca74579badbe7d9fd40eec Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Thu, 11 Jun 2015 09:29:06 -0700 Subject: [PATCH 18/26] PHP route guide --- php/greeter_client.php | 4 +- php/route_guide/README.md | 232 +++++++ php/route_guide/route_guide.php | 731 ++++++++++++++++++++++ php/route_guide/route_guide.proto | 120 ++++ php/route_guide/route_guide_client.php | 205 ++++++ php/route_guide/run_route_guide_client.sh | 36 ++ php/run_greeter_client.sh | 18 +- 7 files changed, 1329 insertions(+), 17 deletions(-) create mode 100644 php/route_guide/README.md create mode 100644 php/route_guide/route_guide.php create mode 100644 php/route_guide/route_guide.proto create mode 100644 php/route_guide/route_guide_client.php create mode 100755 php/route_guide/run_route_guide_client.sh diff --git a/php/greeter_client.php b/php/greeter_client.php index 663ed7d5d77..8ae19ae46c5 100644 --- a/php/greeter_client.php +++ b/php/greeter_client.php @@ -32,8 +32,8 @@ * */ -require 'vendor/autoload.php'; -require 'helloworld.php'; +require dirname(__FILE__) . '/vendor/autoload.php'; +require dirname(__FILE__) . '/helloworld.php'; function greet($name) { $client = new helloworld\GreeterClient( diff --git a/php/route_guide/README.md b/php/route_guide/README.md new file mode 100644 index 00000000000..2d3c4d311de --- /dev/null +++ b/php/route_guide/README.md @@ -0,0 +1,232 @@ +#gRPC Basics: PHP + +This tutorial provides a basic PHP programmer's introduction to working with gRPC. By walking through this example you'll learn how to: + +- Define a service in a .proto file. +- Use the PHP gRPC API to write a simple client for your service. + +It assumes that you have read the [Getting started](https://github.com/grpc/grpc-common) guide and are familiar with [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). + +This isn't a comprehensive guide to using gRPC in PHP: more reference documentation is coming soon. + +## Why use gRPC? + +Our example is a simple route mapping application that lets clients get information about features on their route, create a summary of their route, and exchange route information such as traffic updates with the server and other clients. + +With gRPC we can define our service once in a .proto file and implement clients and servers in any of gRPC's supported languages, which in turn can be run in environments ranging from servers inside Google to your own tablet - all the complexity of communication between different languages and environments is handled for you by gRPC. We also get all the advantages of working with protocol buffers, including efficient serialization, a simple IDL, and easy interface updating. + +## Example code and setup + +The example code for our tutorial is in [grpc/grpc-common/php/route_guide](https://github.com/grpc/grpc-common/tree/master/php/route_guide). To download the example, clone the `grpc-common` repository by running the following command: +```shell +$ git clone https://github.com/grpc/grpc-common.git +``` + +Then change your current directory to `grpc-common/php/route_guide`: +```shell +$ cd grpc-common/php/route_guide +``` + +You also should have the relevant tools installed to generate the client interface code - if you don't already, follow the setup instructions in [the PHP quick start guide](https://github.com/grpc/grpc-common/tree/master/php). + +Please note that currently we only support gRPC clients implemented in PHP. Please see other supported languages (e.g. [Node.js](https://github.com/grpc/grpc-common/tree/master/node/route_guide)) to see how gRPC servers are implemented. + + +## Defining the service + +Our first step (as you'll know from [Getting started](https://github.com/grpc/grpc-common)) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`grpc-common/protos/route_guide.proto`](https://github.com/grpc/grpc-common/blob/master/protos/route_guide.proto). + +To define a service, you specify a named `service` in your .proto file: + +```protobuf +service RouteGuide { + ... +} +``` + +Then you define `rpc` methods inside your service definition, specifying their request and response types. gRPC lets you define four kinds of service method, all of which are used in the `RouteGuide` service: + +- A *simple RPC* where the client sends a request to the server using the stub and waits for a response to come back, just like a normal function call. +```protobuf + // Obtains the feature at a given position. + rpc GetFeature(Point) returns (Feature) {} +``` + +- A *server-side streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from the returned stream until there are no more messages. As you can see in our example, you specify a server-side streaming method by placing the `stream` keyword before the *response* type. +```protobuf + // Obtains the Features available within the given Rectangle. Results are + // streamed rather than returned at once (e.g. in a response message with a + // repeated field), as the rectangle may cover a large area and contain a + // huge number of features. + rpc ListFeatures(Rectangle) returns (stream Feature) {} +``` + +- A *client-side streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client has finished writing the messages, it waits for the server to read them all and return its response. You specify a server-side streaming method by placing the `stream` keyword before the *request* type. +```protobuf + // Accepts a stream of Points on a route being traversed, returning a + // RouteSummary when traversal is completed. + rpc RecordRoute(stream Point) returns (RouteSummary) {} +``` + +- A *bidirectional streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients and servers can read and write in whatever order they like: for example, the server could wait to receive all the client messages before writing its responses, or it could alternately read a message then write a message, or some other combination of reads and writes. The order of messages in each stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response. +```protobuf + // Accepts a stream of RouteNotes sent while a route is being traversed, + // while receiving other RouteNotes (e.g. from other users). + rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} +``` + +Our .proto file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type: +```protobuf +// Points are represented as latitude-longitude pairs in the E7 representation +// (degrees multiplied by 10**7 and rounded to the nearest integer). +// Latitudes should be in the range +/- 90 degrees and longitude should be in +// the range +/- 180 degrees (inclusive). +message Point { + int32 latitude = 1; + int32 longitude = 2; +} +``` + + +## Generating client stub from proto files + +The PHP client stub implementation of the proto files can be generated by the [`protoc-gen-php`](https://github.com/datto/protobuf-php) tool. + +```sh +$ cd grpc-common/php +$ php composer.phar install +$ cd vendor/datto/protobuf-php +$ gem install rake ronn +$ rake pear:package version=1.0 +$ sudo pear install Protobuf-1.0.tgz +``` + +To generate the client stub implementation .php file: + +```sh +$ cd php/route_guide +$ protoc-gen-php -i . -o . ./route_guide.proto +``` + +A `route_guide.php` file will be generated in the `php/route_guide` directory. You do not need to modify the file. + +To load the generated client stub file, simply `require` it in your PHP application: + +```php +require dirname(__FILE__) . '/route_guide.php'; +``` + +Once you've done this, the client classes are in the `examples\` namespace (e.g. `examples\RouteGuideClient`). + + + +## Creating the client + +In this section, we'll look at creating a PHP client for our `RouteGuide` service. You can see our complete example client code in [grpc-common/php/route_guide/route_guide_client.php](https://github.com/grpc/grpc-common/blob/master/php/route_guide/route_guide_client.php). Again, please consult other languages (e.g. [Node.js](https://github.com/grpc/grpc-common/blob/master/node/route_guide/) to see how to start the route guide example server. + +### Creating a stub + +To call service methods, we first need to create a *stub*. To do this, we just need to call the RouteGuide stub constructor, specifying the server address and port. + +```php +$client = new examples\RouteGuideClient(new Grpc\BaseStub('localhost:50051', [])); +``` + +### Calling service methods + +Now let's look at how we call our service methods. + +#### Simple RPC + +Calling the simple RPC `GetFeature` is nearly as straightforward as calling a local asynchronous method. + +```php +$point = new examples\Point(); +$point->setLatitude(409146138); +$point->setLongitude(-746188906); +list($feature, $status) = $client->GetFeature($point)->wait(); +``` + +As you can see, we create and populate a request object, i.e. an `examples\Point` object. Then, we call the method on the stub, passing it the request object. If there is no error, then we can read the response information from the server from our response object, i.e. an `examples\Feature` object. + +```php + print sprintf("Found %s \n at %f, %f\n", $feature->getName(), + $feature->getLocation()->getLatitude() / COORD_FACTOR, + $feature->getLocation()->getLongitude() / COORD_FACTOR); +``` + +#### Streaming RPCs + +Now let's look at our streaming methods. Here's where we call the server-side streaming method `ListFeatures`, which returns a stream of geographical `Feature`s: + +```php + $lo_point = new examples\Point(); + $hi_point = new examples\Point(); + + $lo_point->setLatitude(400000000); + $lo_point->setLongitude(-750000000); + $hi_point->setLatitude(420000000); + $hi_point->setLongitude(-730000000); + + $rectangle = new examples\Rectangle(); + $rectangle->setLo($lo_point); + $rectangle->setHi($hi_point); + + $call = $client->ListFeatures($rectangle); + // an iterator over the server streaming responses + $features = $call->responses(); + foreach ($features as $feature) { + // process each feature + } // the loop will end when the server indicates there is no more responses to be sent. +``` + +The `$call->responses()` method call returns an iterator. When the server sends a response, a `$feature` object will be returned in the `foreach` loop, until the server indiciates that there will be no more responses to be sent. + +The client-side streaming method `RecordRoute` is similar, except there we pass the method an iterator and get back a `examples\RouteSummary`. + +```php + $points_iter = function($db) { + for ($i = 0; $i < $num_points; $i++) { + $point = new examples\Point(); + $point->setLatitude($lat); + $point->setLongitude($long); + yield $point; + } + }; + // $points_iter is an iterator simulating client streaming + list($route_summary, $status) = + $client->RecordRoute($points_iter($db))->wait(); +``` + +Finally, let's look at our bidirectional streaming RPC `routeChat()`. In this case, we just pass a context to the method and get back a `Duplex` stream object, which we can use to both write and read messages. + +```php +$call = $client->RouteChat(); +``` + +To write messages from the client: + +```php + foreach ($notes as $n) { + $route_note = new examples\RouteNote(); + $call->write($route_note); + } + $call->writesDone(); +``` + +To read messages from the server: + +```php + while ($route_note_reply = $call->read()) { + // process $route_note_reply + } +``` + +Each side will always get the other's messages in the order they were written, both the client and server can read and write in any order — the streams operate completely independently. + +## Try it out! + +Run the client (in a different terminal): +```shell +$ ./run_route_guide_client.sh +``` diff --git a/php/route_guide/route_guide.php b/php/route_guide/route_guide.php new file mode 100644 index 00000000000..a836e03b55b --- /dev/null +++ b/php/route_guide/route_guide.php @@ -0,0 +1,731 @@ +number = 1; + $f->name = "latitude"; + $f->type = \DrSlump\Protobuf::TYPE_INT32; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->default = 0; + $descriptor->addField($f); + + // OPTIONAL INT32 longitude = 2 + $f = new \DrSlump\Protobuf\Field(); + $f->number = 2; + $f->name = "longitude"; + $f->type = \DrSlump\Protobuf::TYPE_INT32; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->default = 0; + $descriptor->addField($f); + + foreach (self::$__extensions as $cb) { + $descriptor->addField($cb(), true); + } + + return $descriptor; + } + + /** + * Check if has a value + * + * @return boolean + */ + public function hasLatitude(){ + return $this->_has(1); + } + + /** + * Clear value + * + * @return \examples\Point + */ + public function clearLatitude(){ + return $this->_clear(1); + } + + /** + * Get value + * + * @return int + */ + public function getLatitude(){ + return $this->_get(1); + } + + /** + * Set value + * + * @param int $value + * @return \examples\Point + */ + public function setLatitude( $value){ + return $this->_set(1, $value); + } + + /** + * Check if has a value + * + * @return boolean + */ + public function hasLongitude(){ + return $this->_has(2); + } + + /** + * Clear value + * + * @return \examples\Point + */ + public function clearLongitude(){ + return $this->_clear(2); + } + + /** + * Get value + * + * @return int + */ + public function getLongitude(){ + return $this->_get(2); + } + + /** + * Set value + * + * @param int $value + * @return \examples\Point + */ + public function setLongitude( $value){ + return $this->_set(2, $value); + } + } +} + +namespace examples { + + class Rectangle extends \DrSlump\Protobuf\Message { + + /** @var \examples\Point */ + public $lo = null; + + /** @var \examples\Point */ + public $hi = null; + + + /** @var \Closure[] */ + protected static $__extensions = array(); + + public static function descriptor() + { + $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'examples.Rectangle'); + + // OPTIONAL MESSAGE lo = 1 + $f = new \DrSlump\Protobuf\Field(); + $f->number = 1; + $f->name = "lo"; + $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->reference = '\examples\Point'; + $descriptor->addField($f); + + // OPTIONAL MESSAGE hi = 2 + $f = new \DrSlump\Protobuf\Field(); + $f->number = 2; + $f->name = "hi"; + $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->reference = '\examples\Point'; + $descriptor->addField($f); + + foreach (self::$__extensions as $cb) { + $descriptor->addField($cb(), true); + } + + return $descriptor; + } + + /** + * Check if has a value + * + * @return boolean + */ + public function hasLo(){ + return $this->_has(1); + } + + /** + * Clear value + * + * @return \examples\Rectangle + */ + public function clearLo(){ + return $this->_clear(1); + } + + /** + * Get value + * + * @return \examples\Point + */ + public function getLo(){ + return $this->_get(1); + } + + /** + * Set value + * + * @param \examples\Point $value + * @return \examples\Rectangle + */ + public function setLo(\examples\Point $value){ + return $this->_set(1, $value); + } + + /** + * Check if has a value + * + * @return boolean + */ + public function hasHi(){ + return $this->_has(2); + } + + /** + * Clear value + * + * @return \examples\Rectangle + */ + public function clearHi(){ + return $this->_clear(2); + } + + /** + * Get value + * + * @return \examples\Point + */ + public function getHi(){ + return $this->_get(2); + } + + /** + * Set value + * + * @param \examples\Point $value + * @return \examples\Rectangle + */ + public function setHi(\examples\Point $value){ + return $this->_set(2, $value); + } + } +} + +namespace examples { + + class Feature extends \DrSlump\Protobuf\Message { + + /** @var string */ + public $name = null; + + /** @var \examples\Point */ + public $location = null; + + + /** @var \Closure[] */ + protected static $__extensions = array(); + + public static function descriptor() + { + $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'examples.Feature'); + + // OPTIONAL STRING name = 1 + $f = new \DrSlump\Protobuf\Field(); + $f->number = 1; + $f->name = "name"; + $f->type = \DrSlump\Protobuf::TYPE_STRING; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $descriptor->addField($f); + + // OPTIONAL MESSAGE location = 2 + $f = new \DrSlump\Protobuf\Field(); + $f->number = 2; + $f->name = "location"; + $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->reference = '\examples\Point'; + $descriptor->addField($f); + + foreach (self::$__extensions as $cb) { + $descriptor->addField($cb(), true); + } + + return $descriptor; + } + + /** + * Check if has a value + * + * @return boolean + */ + public function hasName(){ + return $this->_has(1); + } + + /** + * Clear value + * + * @return \examples\Feature + */ + public function clearName(){ + return $this->_clear(1); + } + + /** + * Get value + * + * @return string + */ + public function getName(){ + return $this->_get(1); + } + + /** + * Set value + * + * @param string $value + * @return \examples\Feature + */ + public function setName( $value){ + return $this->_set(1, $value); + } + + /** + * Check if has a value + * + * @return boolean + */ + public function hasLocation(){ + return $this->_has(2); + } + + /** + * Clear value + * + * @return \examples\Feature + */ + public function clearLocation(){ + return $this->_clear(2); + } + + /** + * Get value + * + * @return \examples\Point + */ + public function getLocation(){ + return $this->_get(2); + } + + /** + * Set value + * + * @param \examples\Point $value + * @return \examples\Feature + */ + public function setLocation(\examples\Point $value){ + return $this->_set(2, $value); + } + } +} + +namespace examples { + + class RouteNote extends \DrSlump\Protobuf\Message { + + /** @var \examples\Point */ + public $location = null; + + /** @var string */ + public $message = null; + + + /** @var \Closure[] */ + protected static $__extensions = array(); + + public static function descriptor() + { + $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'examples.RouteNote'); + + // OPTIONAL MESSAGE location = 1 + $f = new \DrSlump\Protobuf\Field(); + $f->number = 1; + $f->name = "location"; + $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->reference = '\examples\Point'; + $descriptor->addField($f); + + // OPTIONAL STRING message = 2 + $f = new \DrSlump\Protobuf\Field(); + $f->number = 2; + $f->name = "message"; + $f->type = \DrSlump\Protobuf::TYPE_STRING; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $descriptor->addField($f); + + foreach (self::$__extensions as $cb) { + $descriptor->addField($cb(), true); + } + + return $descriptor; + } + + /** + * Check if has a value + * + * @return boolean + */ + public function hasLocation(){ + return $this->_has(1); + } + + /** + * Clear value + * + * @return \examples\RouteNote + */ + public function clearLocation(){ + return $this->_clear(1); + } + + /** + * Get value + * + * @return \examples\Point + */ + public function getLocation(){ + return $this->_get(1); + } + + /** + * Set value + * + * @param \examples\Point $value + * @return \examples\RouteNote + */ + public function setLocation(\examples\Point $value){ + return $this->_set(1, $value); + } + + /** + * Check if has a value + * + * @return boolean + */ + public function hasMessage(){ + return $this->_has(2); + } + + /** + * Clear value + * + * @return \examples\RouteNote + */ + public function clearMessage(){ + return $this->_clear(2); + } + + /** + * Get value + * + * @return string + */ + public function getMessage(){ + return $this->_get(2); + } + + /** + * Set value + * + * @param string $value + * @return \examples\RouteNote + */ + public function setMessage( $value){ + return $this->_set(2, $value); + } + } +} + +namespace examples { + + class RouteSummary extends \DrSlump\Protobuf\Message { + + /** @var int */ + public $point_count = 0; + + /** @var int */ + public $feature_count = 0; + + /** @var int */ + public $distance = 0; + + /** @var int */ + public $elapsed_time = 0; + + + /** @var \Closure[] */ + protected static $__extensions = array(); + + public static function descriptor() + { + $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'examples.RouteSummary'); + + // OPTIONAL INT32 point_count = 1 + $f = new \DrSlump\Protobuf\Field(); + $f->number = 1; + $f->name = "point_count"; + $f->type = \DrSlump\Protobuf::TYPE_INT32; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->default = 0; + $descriptor->addField($f); + + // OPTIONAL INT32 feature_count = 2 + $f = new \DrSlump\Protobuf\Field(); + $f->number = 2; + $f->name = "feature_count"; + $f->type = \DrSlump\Protobuf::TYPE_INT32; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->default = 0; + $descriptor->addField($f); + + // OPTIONAL INT32 distance = 3 + $f = new \DrSlump\Protobuf\Field(); + $f->number = 3; + $f->name = "distance"; + $f->type = \DrSlump\Protobuf::TYPE_INT32; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->default = 0; + $descriptor->addField($f); + + // OPTIONAL INT32 elapsed_time = 4 + $f = new \DrSlump\Protobuf\Field(); + $f->number = 4; + $f->name = "elapsed_time"; + $f->type = \DrSlump\Protobuf::TYPE_INT32; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->default = 0; + $descriptor->addField($f); + + foreach (self::$__extensions as $cb) { + $descriptor->addField($cb(), true); + } + + return $descriptor; + } + + /** + * Check if has a value + * + * @return boolean + */ + public function hasPointCount(){ + return $this->_has(1); + } + + /** + * Clear value + * + * @return \examples\RouteSummary + */ + public function clearPointCount(){ + return $this->_clear(1); + } + + /** + * Get value + * + * @return int + */ + public function getPointCount(){ + return $this->_get(1); + } + + /** + * Set value + * + * @param int $value + * @return \examples\RouteSummary + */ + public function setPointCount( $value){ + return $this->_set(1, $value); + } + + /** + * Check if has a value + * + * @return boolean + */ + public function hasFeatureCount(){ + return $this->_has(2); + } + + /** + * Clear value + * + * @return \examples\RouteSummary + */ + public function clearFeatureCount(){ + return $this->_clear(2); + } + + /** + * Get value + * + * @return int + */ + public function getFeatureCount(){ + return $this->_get(2); + } + + /** + * Set value + * + * @param int $value + * @return \examples\RouteSummary + */ + public function setFeatureCount( $value){ + return $this->_set(2, $value); + } + + /** + * Check if has a value + * + * @return boolean + */ + public function hasDistance(){ + return $this->_has(3); + } + + /** + * Clear value + * + * @return \examples\RouteSummary + */ + public function clearDistance(){ + return $this->_clear(3); + } + + /** + * Get value + * + * @return int + */ + public function getDistance(){ + return $this->_get(3); + } + + /** + * Set value + * + * @param int $value + * @return \examples\RouteSummary + */ + public function setDistance( $value){ + return $this->_set(3, $value); + } + + /** + * Check if has a value + * + * @return boolean + */ + public function hasElapsedTime(){ + return $this->_has(4); + } + + /** + * Clear value + * + * @return \examples\RouteSummary + */ + public function clearElapsedTime(){ + return $this->_clear(4); + } + + /** + * Get value + * + * @return int + */ + public function getElapsedTime(){ + return $this->_get(4); + } + + /** + * Set value + * + * @param int $value + * @return \examples\RouteSummary + */ + public function setElapsedTime( $value){ + return $this->_set(4, $value); + } + } +} + +namespace examples { + + class RouteGuideClient{ + + private $rpc_impl; + + public function __construct($rpc_impl) { + $this->rpc_impl = $rpc_impl; + } + /** + * @param examples\Point $input + */ + public function GetFeature(\examples\Point $argument, $metadata = array()) { + return $this->rpc_impl->_simpleRequest('/examples.RouteGuide/GetFeature', $argument, '\examples\Feature::deserialize', $metadata); + } + /** + * @param examples\Rectangle $input + */ + public function ListFeatures($argument, $metadata = array()) { + return $this->rpc_impl->_serverStreamRequest('/examples.RouteGuide/ListFeatures', $argument, '\examples\Feature::deserialize', $metadata); + } + /** + * @param examples\Point $input + */ + public function RecordRoute($arguments, $metadata = array()) { + return $this->rpc_impl->_clientStreamRequest('/examples.RouteGuide/RecordRoute', $arguments, '\examples\RouteSummary::deserialize', $metadata); + } + /** + * @param examples\RouteNote $input + */ + public function RouteChat($metadata = array()) { + return $this->rpc_impl->_bidiRequest('/examples.RouteGuide/RouteChat', '\examples\RouteNote::deserialize', $metadata); + } + } +} diff --git a/php/route_guide/route_guide.proto b/php/route_guide/route_guide.proto new file mode 100644 index 00000000000..0947184dbbd --- /dev/null +++ b/php/route_guide/route_guide.proto @@ -0,0 +1,120 @@ +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +option java_package = "io.grpc.examples"; + +package examples; + +// Interface exported by the server. +service RouteGuide { + // A simple RPC. + // + // Obtains the feature at a given position. + rpc GetFeature(Point) returns (Feature) {} + + // A server-to-client streaming RPC. + // + // Obtains the Features available within the given Rectangle. Results are + // streamed rather than returned at once (e.g. in a response message with a + // repeated field), as the rectangle may cover a large area and contain a + // huge number of features. + rpc ListFeatures(Rectangle) returns (stream Feature) {} + + // A client-to-server streaming RPC. + // + // Accepts a stream of Points on a route being traversed, returning a + // RouteSummary when traversal is completed. + rpc RecordRoute(stream Point) returns (RouteSummary) {} + + // A Bidirectional streaming RPC. + // + // Accepts a stream of RouteNotes sent while a route is being traversed, + // while receiving other RouteNotes (e.g. from other users). + rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} +} + +// Points are represented as latitude-longitude pairs in the E7 representation +// (degrees multiplied by 10**7 and rounded to the nearest integer). +// Latitudes should be in the range +/- 90 degrees and longitude should be in +// the range +/- 180 degrees (inclusive). +message Point { + optional int32 latitude = 1 [default = 0]; + optional int32 longitude = 2 [default = 0]; +} + +// A latitude-longitude rectangle, represented as two diagonally opposite +// points "lo" and "hi". +message Rectangle { + // One corner of the rectangle. + optional Point lo = 1; + + // The other corner of the rectangle. + optional Point hi = 2; +} + +// A feature names something at a given point. +// +// If a feature could not be named, the name is empty. +message Feature { + // The name of the feature. + optional string name = 1; + + // The point where the feature is detected. + optional Point location = 2; +} + +// A RouteNote is a message sent while at a given point. +message RouteNote { + // The location from which the message is sent. + optional Point location = 1; + + // The message to be sent. + optional string message = 2; +} + +// A RouteSummary is received in response to a RecordRoute rpc. +// +// It contains the number of individual points received, the number of +// detected features, and the total distance covered as the cumulative sum of +// the distance between each point. +message RouteSummary { + // The number of points received. + optional int32 point_count = 1 [default = 0]; + + // The number of known features passed while traversing the route. + optional int32 feature_count = 2 [default = 0]; + + // The distance covered in metres. + optional int32 distance = 3 [default = 0]; + + // The duration of the traversal in seconds. + optional int32 elapsed_time = 4 [default = 0]; +} diff --git a/php/route_guide/route_guide_client.php b/php/route_guide/route_guide_client.php new file mode 100644 index 00000000000..6d9ae58b66c --- /dev/null +++ b/php/route_guide/route_guide_client.php @@ -0,0 +1,205 @@ +getName(); + if (!$name) { + $name_str = "no feature"; + } else { + $name_str = "feature called $name"; + } + print sprintf("Found %s \n at %f, %f\n", $name_str, + $feature->getLocation()->getLatitude() / COORD_FACTOR, + $feature->getLocation()->getLongitude() / COORD_FACTOR); +} + +/** + * Run the getFeature demo. Calls getFeature with a point known to have a + * feature and a point known not to have a feature. + */ +function runGetFeature() { + print "Running GetFeature...\n"; + global $client; + + $point = new examples\Point(); + $points = array( + array(409146138, -746188906), + array(0, 0), + ); + + foreach ($points as $p) { + $point->setLatitude($p[0]); + $point->setLongitude($p[1]); + // make a unary grpc call + list($feature, $status) = $client->GetFeature($point)->wait(); + printFeature($feature); + } +} + +/** + * Run the listFeatures demo. Calls listFeatures with a rectangle + * containing all of the features in the pre-generated + * database. Prints each response as it comes in. + */ +function runListFeatures() { + print "Running ListFeatures...\n"; + global $client; + + $lo_point = new examples\Point(); + $hi_point = new examples\Point(); + + $lo_point->setLatitude(400000000); + $lo_point->setLongitude(-750000000); + $hi_point->setLatitude(420000000); + $hi_point->setLongitude(-730000000); + + $rectangle = new examples\Rectangle(); + $rectangle->setLo($lo_point); + $rectangle->setHi($hi_point); + + $call = $client->ListFeatures($rectangle); + // an iterator over the server streaming responses + $features = $call->responses(); + foreach ($features as $feature) { + printFeature($feature); + } +} + +/** + * Run the recordRoute demo. Sends several randomly chosen points from the + * pre-generated feature database with a variable delay in between. Prints + * the statistics when they are sent from the server. + */ +function runRecordRoute() { + print "Running RecordRoute...\n"; + global $client, $argv; + + $db = json_decode(file_get_contents($argv[1]), true); + $points_iter = function($db) { + $num_points_in_db = count($db); + $num_points = 10; + for ($i = 0; $i < $num_points; $i++) { + $point = new examples\Point(); + $index = rand(0, $num_points_in_db - 1); + $lat = $db[$index]['location']['latitude']; + $long = $db[$index]['location']['longitude']; + $feature_name = $db[$index]['name']; + $point->setLatitude($lat); + $point->setLongitude($long); + print sprintf("Visiting point %f, %f,\n with feature name: %s\n", + $lat / COORD_FACTOR, $long / COORD_FACTOR, + $feature_name ? $feature_name : ''); + usleep(rand(300000, 800000)); + yield $point; + } + }; + // $points_iter is an iterator simulating client streaming + list($route_summary, $status) = + $client->RecordRoute($points_iter($db))->wait(); + print sprintf("Finished trip with %d points\nPassed %d features\n". + "Travelled %d meters\nIt took %d seconds\n", + $route_summary->getPointCount(), + $route_summary->getFeatureCount(), + $route_summary->getDistance(), + $route_summary->getElapsedTime()); +} + +/** + * Run the routeChat demo. Send some chat messages, and print any chat + * messages that are sent from the server. + */ +function runRouteChat() { + print "Running RouteChat...\n"; + global $client; + + // start the bidirectional streaming call + $call = $client->RouteChat(); + + $notes = array( + array(1, 1, 'first message'), + array(1, 2, 'second message'), + array(2, 1, 'third message'), + array(1, 1, 'fourth message'), + array(1, 1, 'fifth message'), + ); + + foreach ($notes as $n) { + $point = new examples\Point(); + $point->setLatitude($lat = $n[0]); + $point->setLongitude($long = $n[1]); + + $route_note = new examples\RouteNote(); + $route_note->setLocation($point); + $route_note->setMessage($message = $n[2]); + + print sprintf("Sending message: '%s' at (%d, %d)\n", + $message, $lat, $long); + // send a bunch of messages to the server + $call->write($route_note); + } + $call->writesDone(); + + // read from the server until there's no more + while ($route_note_reply = $call->read()) { + print sprintf("Previous left message at (%d, %d): '%s'\n", + $route_note_reply->getLocation()->getLatitude(), + $route_note_reply->getLocation()->getLongitude(), + $route_note_reply->getMessage()); + } +} + +/** + * Run all of the demos in order + */ +function main() { + runGetFeature(); + runListFeatures(); + runRecordRoute(); + runRouteChat(); +} + +if (empty($argv[1])) { + print "Usage: php -d extension=grpc.so route_guide_client.php " . + "\n"; + exit(1); +} +main(); diff --git a/php/route_guide/run_route_guide_client.sh b/php/route_guide/run_route_guide_client.sh new file mode 100755 index 00000000000..e5ca07796be --- /dev/null +++ b/php/route_guide/run_route_guide_client.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# Copyright 2015, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +set -e +cd $(dirname $0) +command -v brew >/dev/null 2>&1 && \ + extension_dir="-d extension_dir="`brew --prefix`/opt/grpc-php +php $extension_dir -d extension=grpc.so \ + route_guide_client.php ../../node/route_guide/route_guide_db.json diff --git a/php/run_greeter_client.sh b/php/run_greeter_client.sh index 4fdea897f96..2906de9af89 100755 --- a/php/run_greeter_client.sh +++ b/php/run_greeter_client.sh @@ -30,18 +30,6 @@ set -e cd $(dirname $0) -which brew >> /dev/null || { echo 'please make sure brew is in the PATH'; exit 1; } -default_extension_dir=`php -i 2>/dev/null | grep extension_dir | sed 's/.*=> //g'` -brew_home=`brew --prefix` -module_dir=$brew_home/opt/grpc-php - -# sym-link in system supplied extensions -for f in $default_extension_dir/*.so -do - ln -s $f $module_dir/$(basename $f) &> /dev/null || true -done - -php \ - -d extension_dir=$module_dir \ - -d extension=grpc.so \ - greeter_client.php +command -v brew >/dev/null 2>&1 && \ + extension_dir="-d extension_dir="`brew --prefix`/opt/grpc-php +php $extension_dir -d extension=grpc.so greeter_client.php $1 From dcfa963d6e3b1f10ae89a0f16d05b6668af8a505 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Tue, 16 Jun 2015 08:17:42 -0700 Subject: [PATCH 19/26] Fix readme as per feedback --- php/route_guide/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/route_guide/README.md b/php/route_guide/README.md index 2d3c4d311de..39a9a56d7e6 100644 --- a/php/route_guide/README.md +++ b/php/route_guide/README.md @@ -29,7 +29,7 @@ $ cd grpc-common/php/route_guide You also should have the relevant tools installed to generate the client interface code - if you don't already, follow the setup instructions in [the PHP quick start guide](https://github.com/grpc/grpc-common/tree/master/php). -Please note that currently we only support gRPC clients implemented in PHP. Please see other supported languages (e.g. [Node.js](https://github.com/grpc/grpc-common/tree/master/node/route_guide)) to see how gRPC servers are implemented. +Please note that currently we only support gRPC clients implemented in PHP. See the tutorials for our other supported languages (e.g. [Node.js](https://github.com/grpc/grpc-common/tree/master/node/route_guide)) to see how gRPC servers are implemented. ## Defining the service From 45e4380ebd9f56d21494391507967ed466e25eb2 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Tue, 16 Jun 2015 08:59:07 -0700 Subject: [PATCH 20/26] restructure PHP route guide README using the Objective-C one as guideline --- php/route_guide/README.md | 73 +++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/php/route_guide/README.md b/php/route_guide/README.md index 39a9a56d7e6..931dd0c68a1 100644 --- a/php/route_guide/README.md +++ b/php/route_guide/README.md @@ -3,18 +3,28 @@ This tutorial provides a basic PHP programmer's introduction to working with gRPC. By walking through this example you'll learn how to: - Define a service in a .proto file. +- Generate client code using the protocol buffer compiler. - Use the PHP gRPC API to write a simple client for your service. -It assumes that you have read the [Getting started](https://github.com/grpc/grpc-common) guide and are familiar with [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). +It assumes a passing familiarity with [protocol buffers](https://developers.google.com/protocol-buffers/docs/overview). Note that the example in this tutorial uses the proto2 version of the protocol buffers language. This isn't a comprehensive guide to using gRPC in PHP: more reference documentation is coming soon. +- [Why use gRPC?](#why-grpc) +- [Example code and setup](#setup) +- [Defining the service](#proto) +- [Generating client code](#protoc) +- [Creating the client](#client) +- [Try it out!](#try) + + + ## Why use gRPC? -Our example is a simple route mapping application that lets clients get information about features on their route, create a summary of their route, and exchange route information such as traffic updates with the server and other clients. +With gRPC you can define your service once in a .proto file and implement clients and servers in any of gRPC's supported languages, which in turn can be run in environments ranging from servers inside Google to your own tablet - all the complexity of communication between different languages and environments is handled for you by gRPC. You also get all the advantages of working with protocol buffers, including efficient serialization, a simple IDL, and easy interface updating. -With gRPC we can define our service once in a .proto file and implement clients and servers in any of gRPC's supported languages, which in turn can be run in environments ranging from servers inside Google to your own tablet - all the complexity of communication between different languages and environments is handled for you by gRPC. We also get all the advantages of working with protocol buffers, including efficient serialization, a simple IDL, and easy interface updating. + ## Example code and setup The example code for our tutorial is in [grpc/grpc-common/php/route_guide](https://github.com/grpc/grpc-common/tree/master/php/route_guide). To download the example, clone the `grpc-common` repository by running the following command: @@ -27,14 +37,17 @@ Then change your current directory to `grpc-common/php/route_guide`: $ cd grpc-common/php/route_guide ``` -You also should have the relevant tools installed to generate the client interface code - if you don't already, follow the setup instructions in [the PHP quick start guide](https://github.com/grpc/grpc-common/tree/master/php). +Our example is a simple route mapping application that lets clients get information about features on their route, create a summary of their route, and exchange route information such as traffic updates with the server and other clients. + +You also should have the relevant tools installed to generate the client interface code (and a server in another language, for testing). You can obtain the latter by following [these setup instructions](https://github.com/grpc/homebrew-grpc). -Please note that currently we only support gRPC clients implemented in PHP. See the tutorials for our other supported languages (e.g. [Node.js](https://github.com/grpc/grpc-common/tree/master/node/route_guide)) to see how gRPC servers are implemented. +The next sections guide you step-by-step through how this proto service is defined, how to generate a client library from it, and how to create a client stub that uses that library. + ## Defining the service -Our first step (as you'll know from [Getting started](https://github.com/grpc/grpc-common)) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`grpc-common/protos/route_guide.proto`](https://github.com/grpc/grpc-common/blob/master/protos/route_guide.proto). +First let's look at how the service we're using is defined. A gRPC *service* and its method *request* and *response* types using [protocol buffers](https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file for our example in [`grpc-common/protos/route_guide.proto`](https://github.com/grpc/grpc-common/blob/master/protos/route_guide.proto). To define a service, you specify a named `service` in your .proto file: @@ -44,15 +57,15 @@ service RouteGuide { } ``` -Then you define `rpc` methods inside your service definition, specifying their request and response types. gRPC lets you define four kinds of service method, all of which are used in the `RouteGuide` service: +Then you define `rpc` methods inside your service definition, specifying their request and response types. Protocol buffers let you define four kinds of service method, all of which are used in the `RouteGuide` service: -- A *simple RPC* where the client sends a request to the server using the stub and waits for a response to come back, just like a normal function call. +- A *simple RPC* where the client sends a request to the server and receives a response later, just like a normal remote procedure call. ```protobuf // Obtains the feature at a given position. rpc GetFeature(Point) returns (Feature) {} ``` -- A *server-side streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from the returned stream until there are no more messages. As you can see in our example, you specify a server-side streaming method by placing the `stream` keyword before the *response* type. +- A *response-streaming RPC* where the client sends a request to the server and gets back a stream of response messages. You specify a response-streaming method by placing the `stream` keyword before the *response* type. ```protobuf // Obtains the Features available within the given Rectangle. Results are // streamed rather than returned at once (e.g. in a response message with a @@ -61,14 +74,14 @@ Then you define `rpc` methods inside your service definition, specifying their r rpc ListFeatures(Rectangle) returns (stream Feature) {} ``` -- A *client-side streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client has finished writing the messages, it waits for the server to read them all and return its response. You specify a server-side streaming method by placing the `stream` keyword before the *request* type. +- A *request-streaming RPC* where the client sends a sequence of messages to the server. Once the client has finished writing the messages, it waits for the server to read them all and return its response. You specify a request-streaming method by placing the `stream` keyword before the *request* type. ```protobuf // Accepts a stream of Points on a route being traversed, returning a // RouteSummary when traversal is completed. rpc RecordRoute(stream Point) returns (RouteSummary) {} ``` -- A *bidirectional streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients and servers can read and write in whatever order they like: for example, the server could wait to receive all the client messages before writing its responses, or it could alternately read a message then write a message, or some other combination of reads and writes. The order of messages in each stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response. +- A *bidirectional streaming RPC* where both sides send a sequence of messages to the other. The two streams operate independently, so clients and servers can read and write in whatever order they like: for example, the server could wait to receive all the client messages before writing its responses, or it could alternately read a message then write a message, or some other combination of reads and writes. The order of messages in each stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response. ```protobuf // Accepts a stream of RouteNotes sent while a route is being traversed, // while receiving other RouteNotes (e.g. from other users). @@ -88,9 +101,10 @@ message Point { ``` -## Generating client stub from proto files + +## Generating client code -The PHP client stub implementation of the proto files can be generated by the [`protoc-gen-php`](https://github.com/datto/protobuf-php) tool. +The PHP client stub implementation of the proto files can be generated by the [`protoc-gen-php`](https://github.com/datto/protobuf-php) tool. To install the tool: ```sh $ cd grpc-common/php @@ -116,17 +130,19 @@ To load the generated client stub file, simply `require` it in your PHP applicat require dirname(__FILE__) . '/route_guide.php'; ``` -Once you've done this, the client classes are in the `examples\` namespace (e.g. `examples\RouteGuideClient`). +The file contains: +- All the protocol buffer code to populate, serialize, and retrieve our request and response message types. +- A class called `examples\RouteGuideClient` that lets clients call the methods defined in the `RouteGuide` service. ## Creating the client -In this section, we'll look at creating a PHP client for our `RouteGuide` service. You can see our complete example client code in [grpc-common/php/route_guide/route_guide_client.php](https://github.com/grpc/grpc-common/blob/master/php/route_guide/route_guide_client.php). Again, please consult other languages (e.g. [Node.js](https://github.com/grpc/grpc-common/blob/master/node/route_guide/) to see how to start the route guide example server. +In this section, we'll look at creating a PHP client for our `RouteGuide` service. You can see our complete example client code in [grpc-common/php/route_guide/route_guide_client.php](https://github.com/grpc/grpc-common/blob/master/php/route_guide/route_guide_client.php). -### Creating a stub +### Constructing a client object -To call service methods, we first need to create a *stub*. To do this, we just need to call the RouteGuide stub constructor, specifying the server address and port. +To call service methods, we first need to create a client object, an instance of the generated `RouteGuideClient` class. The constructor of the class expects the server address and port we want to connect to: ```php $client = new examples\RouteGuideClient(new Grpc\BaseStub('localhost:50051', [])); @@ -141,10 +157,10 @@ Now let's look at how we call our service methods. Calling the simple RPC `GetFeature` is nearly as straightforward as calling a local asynchronous method. ```php -$point = new examples\Point(); -$point->setLatitude(409146138); -$point->setLongitude(-746188906); -list($feature, $status) = $client->GetFeature($point)->wait(); + $point = new examples\Point(); + $point->setLatitude(409146138); + $point->setLongitude(-746188906); + list($feature, $status) = $client->GetFeature($point)->wait(); ``` As you can see, we create and populate a request object, i.e. an `examples\Point` object. Then, we call the method on the stub, passing it the request object. If there is no error, then we can read the response information from the server from our response object, i.e. an `examples\Feature` object. @@ -198,7 +214,7 @@ The client-side streaming method `RecordRoute` is similar, except there we pass $client->RecordRoute($points_iter($db))->wait(); ``` -Finally, let's look at our bidirectional streaming RPC `routeChat()`. In this case, we just pass a context to the method and get back a `Duplex` stream object, which we can use to both write and read messages. +Finally, let's look at our bidirectional streaming RPC `routeChat()`. In this case, we just pass a context to the method and get back a `BidiStreamingCall` stream object, which we can use to both write and read messages. ```php $call = $client->RouteChat(); @@ -224,9 +240,20 @@ To read messages from the server: Each side will always get the other's messages in the order they were written, both the client and server can read and write in any order — the streams operate completely independently. + ## Try it out! -Run the client (in a different terminal): +To try the sample app, we need a gRPC server running locally. Let's compile and run, for example, the Node.js server in this repository: + +```shell +$ cd ../../node +$ npm install +$ cd route_guide +$ nodejs ./route_guide_server.js --db_path=route_guide_db.json +``` + +Run the PHP client (in a different terminal): + ```shell $ ./run_route_guide_client.sh ``` From fd7627691f13b1c62e97014253b3ac011e5e4b94 Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Wed, 17 Jun 2015 16:31:39 -0700 Subject: [PATCH 21/26] Move to new Status API --- cpp/helloworld/greeter_async_client.cc | 2 +- cpp/helloworld/greeter_client.cc | 2 +- cpp/route_guide/route_guide_client.cc | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cpp/helloworld/greeter_async_client.cc b/cpp/helloworld/greeter_async_client.cc index b88ba0e74ad..561b880ecb6 100644 --- a/cpp/helloworld/greeter_async_client.cc +++ b/cpp/helloworld/greeter_async_client.cc @@ -79,7 +79,7 @@ class GreeterClient { GPR_ASSERT(ok); GPR_ASSERT(got_tag == (void*)1); - if (status.IsOk()) { + if (status.ok()) { return reply.message(); } else { return "Rpc failed"; diff --git a/cpp/helloworld/greeter_client.cc b/cpp/helloworld/greeter_client.cc index c0aec1696a4..44e4447f1f9 100644 --- a/cpp/helloworld/greeter_client.cc +++ b/cpp/helloworld/greeter_client.cc @@ -64,7 +64,7 @@ class GreeterClient { ClientContext context; Status status = stub_->SayHello(&context, request, &reply); - if (status.IsOk()) { + if (status.ok()) { return reply.message(); } else { return "Rpc failed"; diff --git a/cpp/route_guide/route_guide_client.cc b/cpp/route_guide/route_guide_client.cc index 91e1cebfc7a..734ea9fb8ad 100644 --- a/cpp/route_guide/route_guide_client.cc +++ b/cpp/route_guide/route_guide_client.cc @@ -124,7 +124,7 @@ class RouteGuideClient { << feature.location().longitude()/kCoordFactor_ << std::endl; } Status status = reader->Finish(); - if (status.IsOk()) { + if (status.ok()) { std::cout << "ListFeatures rpc succeeded." << std::endl; } else { std::cout << "ListFeatures rpc failed." << std::endl; @@ -160,7 +160,7 @@ class RouteGuideClient { } writer->WritesDone(); Status status = writer->Finish(); - if (status.IsOk()) { + if (status.ok()) { std::cout << "Finished trip with " << stats.point_count() << " points\n" << "Passed " << stats.feature_count() << " features\n" << "Travelled " << stats.distance() << " meters\n" @@ -200,7 +200,7 @@ class RouteGuideClient { } writer.join(); Status status = stream->Finish(); - if (!status.IsOk()) { + if (!status.ok()) { std::cout << "RouteChat rpc failed." << std::endl; } } @@ -210,7 +210,7 @@ class RouteGuideClient { bool GetOneFeature(const Point& point, Feature* feature) { ClientContext context; Status status = stub_->GetFeature(&context, point, feature); - if (!status.IsOk()) { + if (!status.ok()) { std::cout << "GetFeature rpc failed." << std::endl; return false; } From 5bcf4671e479ce73e47bcc1c8aafc21a2208498d Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Thu, 18 Jun 2015 08:23:17 -0700 Subject: [PATCH 22/26] update PHP route guide README as per feedback --- php/route_guide/README.md | 41 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/php/route_guide/README.md b/php/route_guide/README.md index 931dd0c68a1..084661a5eba 100644 --- a/php/route_guide/README.md +++ b/php/route_guide/README.md @@ -8,14 +8,16 @@ This tutorial provides a basic PHP programmer's introduction to working with gRP It assumes a passing familiarity with [protocol buffers](https://developers.google.com/protocol-buffers/docs/overview). Note that the example in this tutorial uses the proto2 version of the protocol buffers language. +Also note that currently you can only create clients in PHP for gRPC services - you can find out how to create gRPC servers in our other tutorials, e.g. [Node.js](https://github.com/grpc/grpc-common/tree/master/node/route_guide). + This isn't a comprehensive guide to using gRPC in PHP: more reference documentation is coming soon. - [Why use gRPC?](#why-grpc) - [Example code and setup](#setup) +- [Try it out!](#try) - [Defining the service](#proto) - [Generating client code](#protoc) - [Creating the client](#client) -- [Try it out!](#try) @@ -41,6 +43,25 @@ Our example is a simple route mapping application that lets clients get informat You also should have the relevant tools installed to generate the client interface code (and a server in another language, for testing). You can obtain the latter by following [these setup instructions](https://github.com/grpc/homebrew-grpc). + + +## Try it out! + +To try the sample app, we need a gRPC server running locally. Let's compile and run, for example, the Node.js server in this repository: + +```shell +$ cd ../../node +$ npm install +$ cd route_guide +$ nodejs ./route_guide_server.js --db_path=route_guide_db.json +``` + +Run the PHP client (in a different terminal): + +```shell +$ ./run_route_guide_client.sh +``` + The next sections guide you step-by-step through how this proto service is defined, how to generate a client library from it, and how to create a client stub that uses that library. @@ -239,21 +260,3 @@ To read messages from the server: ``` Each side will always get the other's messages in the order they were written, both the client and server can read and write in any order — the streams operate completely independently. - - -## Try it out! - -To try the sample app, we need a gRPC server running locally. Let's compile and run, for example, the Node.js server in this repository: - -```shell -$ cd ../../node -$ npm install -$ cd route_guide -$ nodejs ./route_guide_server.js --db_path=route_guide_db.json -``` - -Run the PHP client (in a different terminal): - -```shell -$ ./run_route_guide_client.sh -``` From 40dc223f07ec31e0b9acf1796b574109cf965c3b Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Tue, 23 Jun 2015 17:35:04 -0700 Subject: [PATCH 23/26] Add PHP Google Auth example --- grpc-auth-support.md | 21 +++++++++++ php/composer.json | 1 + php/greeter_client_with_auth.php | 57 +++++++++++++++++++++++++++++ php/run_greeter_client_with_auth.sh | 37 +++++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 php/greeter_client_with_auth.php create mode 100755 php/run_greeter_client_with_auth.sh diff --git a/grpc-auth-support.md b/grpc-auth-support.md index 9b97203276b..aff952a0503 100644 --- a/grpc-auth-support.md +++ b/grpc-auth-support.md @@ -174,3 +174,24 @@ if (authorization.IsCreateScopedRequired) var client = new Greeter.GreeterClient(channel, new StubConfiguration(OAuth2InterceptorFactory.Create(credential))); ``` + +###Authenticating with Google (PHP) +```php +// Base case - No encryption/authorization +$client = new helloworld\GreeterClient( + new Grpc\BaseStub('localhost:50051', [])); +... + +// Authenticating with Google +// the environment variable "GOOGLE_APPLICATION_CREDENTIALS" needs to be set +$scope = "https://www.googleapis.com/auth/grpc-testing"; +$auth = Google\Auth\ApplicationDefaultCredentials::getCredentials($scope); +$opts = [ + 'credentials' => Grpc\Credentials::createSsl(file_get_contents('ca.pem')); + 'update_metadata' => $auth->getUpdateMetadataFunc(), +]; + +$client = new helloworld\GreeterClient( + new Grpc\BaseStub('localhost:50051', $opts)); + +``` diff --git a/php/composer.json b/php/composer.json index d1c4bd2a183..f0ce3a2aff4 100644 --- a/php/composer.json +++ b/php/composer.json @@ -11,6 +11,7 @@ "require": { "php": ">=5.5.0", "datto/protobuf-php": "dev-master", + "google/auth": "dev-master", "grpc/grpc": "dev-master" } } diff --git a/php/greeter_client_with_auth.php b/php/greeter_client_with_auth.php new file mode 100644 index 00000000000..39e28fcb80b --- /dev/null +++ b/php/greeter_client_with_auth.php @@ -0,0 +1,57 @@ + Grpc\Credentials::createSsl( + // file_get_contents(getenv('SSL_CERT_FILE'))), + 'update_metadata' => $auth->getUpdateMetadataFunc(), + ]; + $client = new helloworld\GreeterClient( + new Grpc\BaseStub('localhost:50051', $opts)); + + $request = new helloworld\HelloRequest(); + $request->setName($name); + list($reply, $status) = $client->SayHello($request)->wait(); + $message = $reply->getMessage(); + return $message; +} + +$name = !empty($argv[1]) ? $argv[1] : 'world'; +print(greet($name)."\n"); diff --git a/php/run_greeter_client_with_auth.sh b/php/run_greeter_client_with_auth.sh new file mode 100755 index 00000000000..b367096b9b3 --- /dev/null +++ b/php/run_greeter_client_with_auth.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# Copyright 2015, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +set -e +cd $(dirname $0) +command -v brew >/dev/null 2>&1 && \ + extension_dir="-d extension_dir="`brew --prefix`/opt/grpc-php +# path to project credentials .json file +export GOOGLE_APPLICATION_CREDENTIALS='' +php $extension_dir -d extension=grpc.so greeter_client_with_auth.php $1 From 20f68f6a63713ab2a9d59732cbc6c8a956c8735e Mon Sep 17 00:00:00 2001 From: Misha Brukman Date: Wed, 24 Jun 2015 09:44:39 -0400 Subject: [PATCH 24/26] Add syntax highlighting for C++ code samples. --- grpc-auth-support.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grpc-auth-support.md b/grpc-auth-support.md index 6a5ef0fa3d0..78dfd9ade2a 100644 --- a/grpc-auth-support.md +++ b/grpc-auth-support.md @@ -31,7 +31,7 @@ Tokens to each request being made on the channel. This is the simplest authentication scenario, where a client just wants to authenticate the server and encrypt all data. -``` +```cpp SslCredentialsOptions ssl_opts; // Options to override SSL params, empty by default // Create the credentials object by providing service account key in constructor std::unique_ptr creds = CredentialsFactory::SslCredentials(ssl_opts); @@ -52,7 +52,7 @@ passed to the factory method. gRPC applications can use a simple API to create a credential that works in various deployment scenarios. -``` +```cpp std::unique_ptr creds = CredentialsFactory::GoogleDefaultCredentials(); // Create a channel, stub and make RPC calls (same as in the previous example) std::shared_ptr channel = CreateChannel(server_name, creds, channel_args); From 05514b042497a4584ec092f40af09d811f904da5 Mon Sep 17 00:00:00 2001 From: Misha Brukman Date: Wed, 24 Jun 2015 09:45:20 -0400 Subject: [PATCH 25/26] Fix comments: code blocks ignore MarkDown. --- grpc-auth-support.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grpc-auth-support.md b/grpc-auth-support.md index 78dfd9ade2a..7f538d1a841 100644 --- a/grpc-auth-support.md +++ b/grpc-auth-support.md @@ -108,7 +108,7 @@ stub = Helloworld::Greeter::Stub.new('localhost:50051') ... # Authenticating with Google -require 'googleauth' # from [googleauth](http://www.rubydoc.info/gems/googleauth/0.1.0) +require 'googleauth' # from http://www.rubydoc.info/gems/googleauth/0.1.0 ... creds = GRPC::Core::Credentials.new(load_certs) # load_certs typically loads a CA roots file scope = 'https://www.googleapis.com/auth/grpc-testing' From 865deaeee9ff5c89864dd89c360b0e2c2b1e2c7c Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Wed, 24 Jun 2015 11:24:17 -0700 Subject: [PATCH 26/26] remove with_auth example because no ssl --- php/greeter_client_with_auth.php | 57 ----------------------------- php/run_greeter_client_with_auth.sh | 37 ------------------- 2 files changed, 94 deletions(-) delete mode 100644 php/greeter_client_with_auth.php delete mode 100755 php/run_greeter_client_with_auth.sh diff --git a/php/greeter_client_with_auth.php b/php/greeter_client_with_auth.php deleted file mode 100644 index 39e28fcb80b..00000000000 --- a/php/greeter_client_with_auth.php +++ /dev/null @@ -1,57 +0,0 @@ - Grpc\Credentials::createSsl( - // file_get_contents(getenv('SSL_CERT_FILE'))), - 'update_metadata' => $auth->getUpdateMetadataFunc(), - ]; - $client = new helloworld\GreeterClient( - new Grpc\BaseStub('localhost:50051', $opts)); - - $request = new helloworld\HelloRequest(); - $request->setName($name); - list($reply, $status) = $client->SayHello($request)->wait(); - $message = $reply->getMessage(); - return $message; -} - -$name = !empty($argv[1]) ? $argv[1] : 'world'; -print(greet($name)."\n"); diff --git a/php/run_greeter_client_with_auth.sh b/php/run_greeter_client_with_auth.sh deleted file mode 100755 index b367096b9b3..00000000000 --- a/php/run_greeter_client_with_auth.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash -# Copyright 2015, Google Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google Inc. nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -set -e -cd $(dirname $0) -command -v brew >/dev/null 2>&1 && \ - extension_dir="-d extension_dir="`brew --prefix`/opt/grpc-php -# path to project credentials .json file -export GOOGLE_APPLICATION_CREDENTIALS='' -php $extension_dir -d extension=grpc.so greeter_client_with_auth.php $1