Merge branch 'master' of github.com:grpc/grpc into core_creds_plugin

pull/3217/head
Julien Boeuf 9 years ago
commit a7072cbbf7
  1. 12
      BUILD
  2. 2
      Makefile
  3. 4
      build.json
  4. 16
      examples/README.md
  5. 11
      examples/cpp/README.md
  6. 18
      examples/cpp/cpptutorial.md
  7. 14
      examples/cpp/helloworld/README.md
  8. 5
      examples/cpp/helloworld/greeter_async_client.cc
  9. 2
      examples/cpp/helloworld/greeter_async_server.cc
  10. 6
      examples/cpp/helloworld/greeter_client.cc
  11. 2
      examples/cpp/helloworld/greeter_server.cc
  12. 4
      examples/cpp/route_guide/helper.cc
  13. 4
      examples/cpp/route_guide/helper.h
  14. 24
      examples/cpp/route_guide/route_guide_client.cc
  15. 20
      examples/cpp/route_guide/route_guide_server.cc
  16. 2
      examples/csharp/README.md
  17. 8
      examples/csharp/route_guide/README.md
  18. 3
      examples/node/greeter_client.js
  19. 14
      examples/node/greeter_server.js
  20. 2
      examples/node/package.json
  21. 10
      examples/node/route_guide/README.md
  22. 3
      examples/node/route_guide/route_guide_client.js
  23. 20
      examples/node/route_guide/route_guide_server.js
  24. 6
      examples/objective-c/auth_sample/README.md
  25. 4
      examples/objective-c/helloworld/README.md
  26. 8
      examples/objective-c/route_guide/README.md
  27. 28
      examples/php/route_guide/README.md
  28. 142
      examples/php/route_guide/route_guide.php
  29. 2
      examples/php/route_guide/route_guide.proto
  30. 16
      examples/php/route_guide/route_guide_client.php
  31. 2
      examples/protos/route_guide.proto
  32. 6
      examples/python/helloworld/README.md
  33. 10
      examples/python/route_guide/README.md
  34. 4
      examples/ruby/README.md
  35. 10
      examples/ruby/route_guide/README.md
  36. 7
      gRPC.podspec
  37. 105
      include/grpc/census.h
  38. 36
      src/core/census/aggregation.h
  39. 32
      src/core/census/grpc_filter.c
  40. 27
      src/core/census/rpc_metric_id.h
  41. 13
      src/csharp/Grpc.Core/Grpc.Core.nuspec
  42. 2
      src/node/README.md
  43. 10
      src/node/index.js
  44. 4
      src/node/interop/interop_client.js
  45. 2
      src/node/package.json
  46. 98
      src/node/src/client.js
  47. 35
      src/node/test/surface_test.js
  48. 2
      src/objective-c/generated_libraries/RouteGuideClient/route_guide.proto
  49. 2
      src/objective-c/tests/LocalClearTextTests.m
  50. 1
      src/ruby/.rspec
  51. 2
      src/ruby/grpc.gemspec
  52. 12
      src/ruby/lib/grpc/generic/rpc_server.rb
  53. 2
      src/ruby/lib/grpc/version.rb
  54. 3
      src/ruby/spec/client_server_spec.rb
  55. 1
      src/ruby/spec/pb/health/checker_spec.rb
  56. 4
      tools/doxygen/Doxyfile.core.internal
  57. 14
      tools/run_tests/sources_and_headers.json
  58. 5
      vsprojects/grpc/grpc.vcxproj
  59. 8
      vsprojects/grpc/grpc.vcxproj.filters
  60. 5
      vsprojects/grpc_unsecure/grpc_unsecure.vcxproj
  61. 8
      vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters

12
BUILD

@ -245,8 +245,9 @@ cc_library(
"src/core/transport/stream_op.h", "src/core/transport/stream_op.h",
"src/core/transport/transport.h", "src/core/transport/transport.h",
"src/core/transport/transport_impl.h", "src/core/transport/transport_impl.h",
"src/core/census/aggregation.h",
"src/core/census/context.h", "src/core/census/context.h",
"src/core/census/rpc_stat_id.h", "src/core/census/rpc_metric_id.h",
"src/core/httpcli/httpcli_security_connector.c", "src/core/httpcli/httpcli_security_connector.c",
"src/core/security/base64.c", "src/core/security/base64.c",
"src/core/security/client_auth_filter.c", "src/core/security/client_auth_filter.c",
@ -387,7 +388,6 @@ cc_library(
"src/core/census/context.c", "src/core/census/context.c",
"src/core/census/initialize.c", "src/core/census/initialize.c",
"src/core/census/operation.c", "src/core/census/operation.c",
"src/core/census/record_stat.c",
"src/core/census/tracing.c", "src/core/census/tracing.c",
], ],
hdrs = [ hdrs = [
@ -515,8 +515,9 @@ cc_library(
"src/core/transport/stream_op.h", "src/core/transport/stream_op.h",
"src/core/transport/transport.h", "src/core/transport/transport.h",
"src/core/transport/transport_impl.h", "src/core/transport/transport_impl.h",
"src/core/census/aggregation.h",
"src/core/census/context.h", "src/core/census/context.h",
"src/core/census/rpc_stat_id.h", "src/core/census/rpc_metric_id.h",
"src/core/surface/init_unsecure.c", "src/core/surface/init_unsecure.c",
"src/core/census/grpc_context.c", "src/core/census/grpc_context.c",
"src/core/census/grpc_filter.c", "src/core/census/grpc_filter.c",
@ -637,7 +638,6 @@ cc_library(
"src/core/census/context.c", "src/core/census/context.c",
"src/core/census/initialize.c", "src/core/census/initialize.c",
"src/core/census/operation.c", "src/core/census/operation.c",
"src/core/census/record_stat.c",
"src/core/census/tracing.c", "src/core/census/tracing.c",
], ],
hdrs = [ hdrs = [
@ -1151,7 +1151,6 @@ objc_library(
"src/core/census/context.c", "src/core/census/context.c",
"src/core/census/initialize.c", "src/core/census/initialize.c",
"src/core/census/operation.c", "src/core/census/operation.c",
"src/core/census/record_stat.c",
"src/core/census/tracing.c", "src/core/census/tracing.c",
], ],
hdrs = [ hdrs = [
@ -1276,8 +1275,9 @@ objc_library(
"src/core/transport/stream_op.h", "src/core/transport/stream_op.h",
"src/core/transport/transport.h", "src/core/transport/transport.h",
"src/core/transport/transport_impl.h", "src/core/transport/transport_impl.h",
"src/core/census/aggregation.h",
"src/core/census/context.h", "src/core/census/context.h",
"src/core/census/rpc_stat_id.h", "src/core/census/rpc_metric_id.h",
], ],
includes = [ includes = [
"include", "include",

@ -4150,7 +4150,6 @@ LIBGRPC_SRC = \
src/core/census/context.c \ src/core/census/context.c \
src/core/census/initialize.c \ src/core/census/initialize.c \
src/core/census/operation.c \ src/core/census/operation.c \
src/core/census/record_stat.c \
src/core/census/tracing.c \ src/core/census/tracing.c \
PUBLIC_HEADERS_C += \ PUBLIC_HEADERS_C += \
@ -4426,7 +4425,6 @@ LIBGRPC_UNSECURE_SRC = \
src/core/census/context.c \ src/core/census/context.c \
src/core/census/initialize.c \ src/core/census/initialize.c \
src/core/census/operation.c \ src/core/census/operation.c \
src/core/census/record_stat.c \
src/core/census/tracing.c \ src/core/census/tracing.c \
PUBLIC_HEADERS_C += \ PUBLIC_HEADERS_C += \

@ -18,14 +18,14 @@
"include/grpc/census.h" "include/grpc/census.h"
], ],
"headers": [ "headers": [
"src/core/census/aggregation.h",
"src/core/census/context.h", "src/core/census/context.h",
"src/core/census/rpc_stat_id.h" "src/core/census/rpc_metric_id.h"
], ],
"src": [ "src": [
"src/core/census/context.c", "src/core/census/context.c",
"src/core/census/initialize.c", "src/core/census/initialize.c",
"src/core/census/operation.c", "src/core/census/operation.c",
"src/core/census/record_stat.c",
"src/core/census/tracing.c" "src/core/census/tracing.c"
] ]
}, },

@ -10,16 +10,16 @@ Hello World example. You'll find more tutorials and reference docs in this repos
<a name="quickstart"></a> <a name="quickstart"></a>
## Quick start ## Quick start
You can find quick start guides for each language, including installation instructions, examples, and tutorials here: You can find quick start guides for each language, including installation instructions, examples, and tutorials here:
* [C++](examples/cpp) * [C++](cpp)
* [Java](https://github.com/grpc/grpc-java/tree/master/examples) * [Java](https://github.com/grpc/grpc-java/tree/master/examples)
* [Go](https://github.com/grpc/grpc-go/tree/master/examples) * [Go](https://github.com/grpc/grpc-go/tree/master/examples)
* [Ruby](examples/ruby) * [Ruby](ruby)
* [Node.js](examples/node) * [Node.js](node)
* [Android Java](examples/java/android) * [Android Java](https://github.com/grpc/grpc-java/tree/master/examples/android)
* [Python](examples/python/helloworld) * [Python](python/helloworld)
* [C#](examples/csharp) * [C#](csharp)
* [Objective-C](examples/objective-c/route_guide) * [Objective-C](objective-c/route_guide)
* [PHP](examples/php) * [PHP](php)
## What's in this repository? ## What's in this repository?

@ -2,12 +2,11 @@
## Installation ## Installation
To install gRPC on your system, follow the instructions here: To install gRPC on your system, follow the instructions [here](../../INSTALL).
[https://github.com/grpc/grpc/blob/master/INSTALL](https://github.com/grpc/grpc/blob/master/INSTALL).
## Hello C++ gRPC! ## Hello C++ gRPC!
Here's how to build and run the C++ implementation of the [Hello World](examples/protos/helloworld.proto) example used in [Getting started](https://github.com/grpc/grpc/tree/master/examples). Here's how to build and run the C++ implementation of the [Hello World](../protos/helloworld.proto) example used in [Getting started](..).
The example code for this and our other examples lives in the `examples` The example code for this and our other examples lives in the `examples`
directory. Clone this repository to your local machine by running the directory. Clone this repository to your local machine by running the
@ -41,9 +40,9 @@ $ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto
### Client and server implementations ### Client and server implementations
The client implementation is at [greeter_client.cc](examples/cpp/helloworld/greeter_client.cc). The client implementation is at [greeter_client.cc](helloworld/greeter_client.cc).
The server implementation is at [greeter_server.cc](examples/cpp/helloworld/greeter_server.cc). The server implementation is at [greeter_server.cc](helloworld/greeter_server.cc).
### Try it! ### Try it!
Build client and server: Build client and server:
@ -62,4 +61,4 @@ If things go smoothly, you will see the "Greeter received: Hello world" in the c
## Tutorial ## Tutorial
You can find a more detailed tutorial in [gRPC Basics: C++](examples/cpp/cpptutorial.md) You can find a more detailed tutorial in [gRPC Basics: C++](cpptutorial.md)

@ -6,7 +6,7 @@ This tutorial provides a basic C++ programmer's introduction to working with gRP
- Generate server and client code using the protocol buffer compiler. - Generate server and client code using the protocol buffer compiler.
- Use the C++ gRPC API to write a simple client and server for your service. - Use the C++ gRPC API to write a simple client and server for your service.
It assumes that you have read the [Getting started](https://github.com/grpc/grpc/tree/master/examples) guide and are familiar with [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). Note that the example in this tutorial uses the proto3 version of the protocol buffers language, which is currently in alpha release: you can find out more in the [proto3 language guide](https://developers.google.com/protocol-buffers/docs/proto3) and see the [release notes](https://github.com/google/protobuf/releases) for the new version in the protocol buffers Github repository. It assumes that you have read the [Getting started](..) guide and are familiar with [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). Note that the example in this tutorial uses the proto3 version of the protocol buffers language, which is currently in alpha release: you can find out more in the [proto3 language guide](https://developers.google.com/protocol-buffers/docs/proto3) and see the [release notes](https://github.com/google/protobuf/releases) for the new version in the protocol buffers Github repository.
This isn't a comprehensive guide to using gRPC in C++: more reference documentation is coming soon. This isn't a comprehensive guide to using gRPC in C++: more reference documentation is coming soon.
@ -18,7 +18,7 @@ With gRPC we can define our service once in a .proto file and implement clients
## Example code and setup ## Example code and setup
The example code for our tutorial is in [examples/cpp/route_guide](examples/cpp/route_guide). To download the example, clone this repository by running the following command: The example code for our tutorial is in [examples/cpp/route_guide](route_guide). To download the example, clone this repository by running the following command:
```shell ```shell
$ git clone https://github.com/grpc/grpc.git $ git clone https://github.com/grpc/grpc.git
``` ```
@ -28,12 +28,12 @@ Then change your current directory to `examples/cpp/route_guide`:
$ cd examples/cpp/route_guide $ cd examples/cpp/route_guide
``` ```
You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the C++ quick start guide](examples/cpp). You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [gRPC in 3 minutes](README.md).
## Defining the service ## Defining the service
Our first step (as you'll know from [Getting started](examples/) 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 [`examples/protos/route_guide.proto`](examples/protos/route_guide.proto). Our first step (as you'll know from [Getting started](..) 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 [`examples/protos/route_guide.proto`](../protos/route_guide.proto).
To define a service, you specify a named `service` in your .proto file: To define a service, you specify a named `service` in your .proto file:
@ -91,7 +91,7 @@ message Point {
Next we need to generate the gRPC client and server interfaces from our .proto service definition. We do this using the protocol buffer compiler `protoc` with a special gRPC C++ plugin. Next we need to generate the gRPC client and server interfaces from our .proto service definition. We do this using the protocol buffer compiler `protoc` with a special gRPC C++ plugin.
For simplicity, we've provided a [makefile](examples/cpp/route_guide/Makefile) that runs `protoc` for you with the appropriate plugin, input, and output (if you want to run this yourself, make sure you've installed protoc and followed the gRPC code [installation instructions](https://github.com/grpc/grpc/blob/master/INSTALL) first): For simplicity, we've provided a [makefile](route_guide/Makefile) that runs `protoc` for you with the appropriate plugin, input, and output (if you want to run this yourself, make sure you've installed protoc and followed the gRPC code [installation instructions](../../INSTALL) first):
```shell ```shell
$ make route_guide.grpc.pb.cc route_guide.pb.cc $ make route_guide.grpc.pb.cc route_guide.pb.cc
@ -126,7 +126,7 @@ There are two parts to making our `RouteGuide` service do its job:
- Implementing the service interface generated from our service definition: doing the actual "work" of our service. - Implementing the service interface generated from our service definition: doing the actual "work" of our service.
- Running a gRPC server to listen for requests from clients and return the service responses. - Running a gRPC server to listen for requests from clients and return the service responses.
You can find our example `RouteGuide` server in [examples/cpp/route_guide/route_guide_server.cc](examples/cpp/route_guide/route_guide_server.cc). Let's take a closer look at how it works. You can find our example `RouteGuide` server in [route_guide/route_guide_server.cc](route_guide/route_guide_server.cc). Let's take a closer look at how it works.
### Implementing RouteGuide ### Implementing RouteGuide
@ -236,16 +236,16 @@ As you can see, we build and start our server using a `ServerBuilder`. To do thi
<a name="client"></a> <a name="client"></a>
## Creating the client ## Creating the client
In this section, we'll look at creating a C++ client for our `RouteGuide` service. You can see our complete example client code in [examples/cpp/route_guide/route_guide_client.cc](examples/cpp/route_guide/route_guide_client.cc). In this section, we'll look at creating a C++ client for our `RouteGuide` service. You can see our complete example client code in [route_guide/route_guide_client.cc](route_guide/route_guide_client.cc).
### Creating a stub ### Creating a stub
To call service methods, we first need to create a *stub*. To call service methods, we first need to create a *stub*.
First we need to create a gRPC *channel* for our stub, specifying the server address and port we want to connect to and any special channel arguments - in our case we'll use the default `ChannelArguments` and no SSL: First we need to create a gRPC *channel* for our stub, specifying the server address and port we want to connect to without SSL:
```cpp ```cpp
grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials(), ChannelArguments()); grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials());
``` ```
Now we can use the channel to create our stub using the `NewStub` method provided in the `RouteGuide` class we generated from our .proto. Now we can use the channel to create our stub using the `NewStub` method provided in the `RouteGuide` class we generated from our .proto.

@ -2,7 +2,7 @@
### Install gRPC ### Install gRPC
Make sure you have installed gRPC on your system. Follow the instructions here: Make sure you have installed gRPC on your system. Follow the instructions here:
[https://github.com/grpc/grpc/blob/master/INSTALL](https://github.com/grpc/grpc/blob/master/INSTALL). [https://github.com/grpc/grpc/blob/master/INSTALL](../../../INSTALL).
### Get the tutorial source code ### Get the tutorial source code
@ -34,7 +34,7 @@ types as protocol buffer message types. Both the client and the
server use interface code generated from the service definition. server use interface code generated from the service definition.
Here's our example service definition, defined using protocol buffers IDL in Here's our example service definition, defined using protocol buffers IDL in
[helloworld.proto](examples/protos/helloworld.proto). The `Greeting` [helloworld.proto](../../protos/helloworld.proto). The `Greeting`
service has one method, `hello`, that lets the server receive a single service has one method, `hello`, that lets the server receive a single
`HelloRequest` `HelloRequest`
message from the remote client containing the user's name, then send back message from the remote client containing the user's name, then send back
@ -94,7 +94,7 @@ $ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto
arguments as follows arguments as follows
``` ```
auto channel = CreateChannel("localhost:50051", InsecureCredentials(), ChannelArguments()); auto channel = CreateChannel("localhost:50051", InsecureCredentials());
``` ```
- Create a stub. A stub implements the rpc methods of a service and in the - Create a stub. A stub implements the rpc methods of a service and in the
@ -124,7 +124,7 @@ $ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto
} }
``` ```
For a working example, refer to [greeter_client.cc](examples/cpp/helloworld/greeter_client.cc). For a working example, refer to [greeter_client.cc](greeter_client.cc).
### Writing a server ### Writing a server
@ -152,7 +152,7 @@ For a working example, refer to [greeter_client.cc](examples/cpp/helloworld/gree
std::unique_ptr<Server> server(builder.BuildAndStart()); std::unique_ptr<Server> server(builder.BuildAndStart());
``` ```
For a working example, refer to [greeter_server.cc](examples/cpp/helloworld/greeter_server.cc). For a working example, refer to [greeter_server.cc](greeter_server.cc).
### Writing asynchronous client and server ### Writing asynchronous client and server
@ -194,7 +194,7 @@ The channel and stub creation code is the same as the sync client.
} }
``` ```
For a working example, refer to [greeter_async_client.cc](examples/cpp/helloworld/greeter_async_client.cc). For a working example, refer to [greeter_async_client.cc](greeter_async_client.cc).
#### Async server #### Async server
@ -253,7 +253,7 @@ maintain the state of each rpc and use the address of it as the unique tag. For
simplicity the server only uses one completion queue for all events, and runs a simplicity the server only uses one completion queue for all events, and runs a
main loop in `HandleRpcs` to query the queue. main loop in `HandleRpcs` to query the queue.
For a working example, refer to [greeter_async_server.cc](examples/cpp/helloworld/greeter_async_server.cc). For a working example, refer to [greeter_async_server.cc](greeter_async_server.cc).

@ -41,11 +41,10 @@
#include <grpc++/client_context.h> #include <grpc++/client_context.h>
#include <grpc++/completion_queue.h> #include <grpc++/completion_queue.h>
#include <grpc++/create_channel.h> #include <grpc++/create_channel.h>
#include <grpc++/credentials.h> #include <grpc++/security/credentials.h>
#include "helloworld.grpc.pb.h" #include "helloworld.grpc.pb.h"
using grpc::Channel; using grpc::Channel;
using grpc::ChannelArguments;
using grpc::ClientAsyncResponseReader; using grpc::ClientAsyncResponseReader;
using grpc::ClientContext; using grpc::ClientContext;
using grpc::CompletionQueue; using grpc::CompletionQueue;
@ -89,7 +88,7 @@ class GreeterClient {
int main(int argc, char** argv) { int main(int argc, char** argv) {
GreeterClient greeter(grpc::CreateChannel( GreeterClient greeter(grpc::CreateChannel(
"localhost:50051", grpc::InsecureCredentials(), ChannelArguments())); "localhost:50051", grpc::InsecureCredentials()));
std::string user("world"); std::string user("world");
std::string reply = greeter.SayHello(user); std::string reply = greeter.SayHello(user);
std::cout << "Greeter received: " << reply << std::endl; std::cout << "Greeter received: " << reply << std::endl;

@ -39,10 +39,10 @@
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc++/completion_queue.h> #include <grpc++/completion_queue.h>
#include <grpc++/security/server_credentials.h>
#include <grpc++/server.h> #include <grpc++/server.h>
#include <grpc++/server_builder.h> #include <grpc++/server_builder.h>
#include <grpc++/server_context.h> #include <grpc++/server_context.h>
#include <grpc++/server_credentials.h>
#include "helloworld.grpc.pb.h" #include "helloworld.grpc.pb.h"
using grpc::Server; using grpc::Server;

@ -39,11 +39,10 @@
#include <grpc++/channel.h> #include <grpc++/channel.h>
#include <grpc++/client_context.h> #include <grpc++/client_context.h>
#include <grpc++/create_channel.h> #include <grpc++/create_channel.h>
#include <grpc++/credentials.h> #include <grpc++/security/credentials.h>
#include "helloworld.grpc.pb.h" #include "helloworld.grpc.pb.h"
using grpc::Channel; using grpc::Channel;
using grpc::ChannelArguments;
using grpc::ClientContext; using grpc::ClientContext;
using grpc::Status; using grpc::Status;
using helloworld::HelloRequest; using helloworld::HelloRequest;
@ -75,8 +74,7 @@ class GreeterClient {
int main(int argc, char** argv) { int main(int argc, char** argv) {
GreeterClient greeter( GreeterClient greeter(
grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials(), grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials()));
ChannelArguments()));
std::string user("world"); std::string user("world");
std::string reply = greeter.SayHello(user); std::string reply = greeter.SayHello(user);
std::cout << "Greeter received: " << reply << std::endl; std::cout << "Greeter received: " << reply << std::endl;

@ -36,10 +36,10 @@
#include <string> #include <string>
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include <grpc++/security/server_credentials.h>
#include <grpc++/server.h> #include <grpc++/server.h>
#include <grpc++/server_builder.h> #include <grpc++/server_builder.h>
#include <grpc++/server_context.h> #include <grpc++/server_context.h>
#include <grpc++/server_credentials.h>
#include "helloworld.grpc.pb.h" #include "helloworld.grpc.pb.h"
using grpc::Server; using grpc::Server;

@ -40,7 +40,7 @@
#include <vector> #include <vector>
#include "route_guide.grpc.pb.h" #include "route_guide.grpc.pb.h"
namespace examples { namespace routeguide {
std::string GetDbFileContent(int argc, char** argv) { std::string GetDbFileContent(int argc, char** argv) {
std::string db_path; std::string db_path;
@ -174,5 +174,5 @@ void ParseDb(const std::string& db, std::vector<Feature>* feature_list) {
} }
} // namespace examples } // namespace routeguide

@ -37,14 +37,14 @@
#include <string> #include <string>
#include <vector> #include <vector>
namespace examples { namespace routeguide {
class Feature; class Feature;
std::string GetDbFileContent(int argc, char** argv); std::string GetDbFileContent(int argc, char** argv);
void ParseDb(const std::string& db, std::vector<Feature>* feature_list); void ParseDb(const std::string& db, std::vector<Feature>* feature_list);
} // namespace examples } // namespace routeguide
#endif // GRPC_COMMON_CPP_ROUTE_GUIDE_HELPER_H_ #endif // GRPC_COMMON_CPP_ROUTE_GUIDE_HELPER_H_

@ -42,23 +42,22 @@
#include <grpc++/channel.h> #include <grpc++/channel.h>
#include <grpc++/client_context.h> #include <grpc++/client_context.h>
#include <grpc++/create_channel.h> #include <grpc++/create_channel.h>
#include <grpc++/credentials.h> #include <grpc++/security/credentials.h>
#include "helper.h" #include "helper.h"
#include "route_guide.grpc.pb.h" #include "route_guide.grpc.pb.h"
using grpc::Channel; using grpc::Channel;
using grpc::ChannelArguments;
using grpc::ClientContext; using grpc::ClientContext;
using grpc::ClientReader; using grpc::ClientReader;
using grpc::ClientReaderWriter; using grpc::ClientReaderWriter;
using grpc::ClientWriter; using grpc::ClientWriter;
using grpc::Status; using grpc::Status;
using examples::Point; using routeguide::Point;
using examples::Feature; using routeguide::Feature;
using examples::Rectangle; using routeguide::Rectangle;
using examples::RouteSummary; using routeguide::RouteSummary;
using examples::RouteNote; using routeguide::RouteNote;
using examples::RouteGuide; using routeguide::RouteGuide;
Point MakePoint(long latitude, long longitude) { Point MakePoint(long latitude, long longitude) {
Point p; Point p;
@ -87,7 +86,7 @@ class RouteGuideClient {
public: public:
RouteGuideClient(std::shared_ptr<Channel> channel, const std::string& db) RouteGuideClient(std::shared_ptr<Channel> channel, const std::string& db)
: stub_(RouteGuide::NewStub(channel)) { : stub_(RouteGuide::NewStub(channel)) {
examples::ParseDb(db, &feature_list_); routeguide::ParseDb(db, &feature_list_);
} }
void GetFeature() { void GetFeature() {
@ -100,7 +99,7 @@ class RouteGuideClient {
} }
void ListFeatures() { void ListFeatures() {
examples::Rectangle rect; routeguide::Rectangle rect;
Feature feature; Feature feature;
ClientContext context; ClientContext context;
@ -233,10 +232,9 @@ class RouteGuideClient {
int main(int argc, char** argv) { int main(int argc, char** argv) {
// Expect only arg: --db_path=path/to/route_guide_db.json. // Expect only arg: --db_path=path/to/route_guide_db.json.
std::string db = examples::GetDbFileContent(argc, argv); std::string db = routeguide::GetDbFileContent(argc, argv);
RouteGuideClient guide( RouteGuideClient guide(
grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials(), grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials()),
ChannelArguments()),
db); db);
std::cout << "-------------- GetFeature --------------" << std::endl; std::cout << "-------------- GetFeature --------------" << std::endl;

@ -42,7 +42,7 @@
#include <grpc++/server.h> #include <grpc++/server.h>
#include <grpc++/server_builder.h> #include <grpc++/server_builder.h>
#include <grpc++/server_context.h> #include <grpc++/server_context.h>
#include <grpc++/server_credentials.h> #include <grpc++/security/server_credentials.h>
#include "helper.h" #include "helper.h"
#include "route_guide.grpc.pb.h" #include "route_guide.grpc.pb.h"
@ -53,12 +53,12 @@ using grpc::ServerReader;
using grpc::ServerReaderWriter; using grpc::ServerReaderWriter;
using grpc::ServerWriter; using grpc::ServerWriter;
using grpc::Status; using grpc::Status;
using examples::Point; using routeguide::Point;
using examples::Feature; using routeguide::Feature;
using examples::Rectangle; using routeguide::Rectangle;
using examples::RouteSummary; using routeguide::RouteSummary;
using examples::RouteNote; using routeguide::RouteNote;
using examples::RouteGuide; using routeguide::RouteGuide;
using std::chrono::system_clock; using std::chrono::system_clock;
@ -99,7 +99,7 @@ std::string GetFeatureName(const Point& point,
class RouteGuideImpl final : public RouteGuide::Service { class RouteGuideImpl final : public RouteGuide::Service {
public: public:
explicit RouteGuideImpl(const std::string& db) { explicit RouteGuideImpl(const std::string& db) {
examples::ParseDb(db, &feature_list_); routeguide::ParseDb(db, &feature_list_);
} }
Status GetFeature(ServerContext* context, const Point* point, Status GetFeature(ServerContext* context, const Point* point,
@ -110,7 +110,7 @@ class RouteGuideImpl final : public RouteGuide::Service {
} }
Status ListFeatures(ServerContext* context, Status ListFeatures(ServerContext* context,
const examples::Rectangle* rectangle, const routeguide::Rectangle* rectangle,
ServerWriter<Feature>* writer) override { ServerWriter<Feature>* writer) override {
auto lo = rectangle->lo(); auto lo = rectangle->lo();
auto hi = rectangle->hi(); auto hi = rectangle->hi();
@ -195,7 +195,7 @@ void RunServer(const std::string& db_path) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
// Expect only arg: --db_path=path/to/route_guide_db.json. // Expect only arg: --db_path=path/to/route_guide_db.json.
std::string db = examples::GetDbFileContent(argc, argv); std::string db = routeguide::GetDbFileContent(argc, argv);
RunServer(db); RunServer(db);
return 0; return 0;

@ -69,4 +69,4 @@ On Linux or Mac, use `mono GreeterServer.exe` and `mono GreeterClient.exe` to ru
Tutorial Tutorial
-------- --------
You can find a more detailed tutorial in [gRPC Basics: C#](examples/csharp/route_guide/README.md) You can find a more detailed tutorial in [gRPC Basics: C#](route_guide/README.md)

@ -18,7 +18,7 @@ With gRPC we can define our service once in a .proto file and implement clients
## Example code and setup ## Example code and setup
The example code for our tutorial is in [examples/csharp/route_guide](examples/csharp/route_guide). To download the example, clone this repository by running the following command: The example code for our tutorial is in [examples/csharp/route_guide](.). To download the example, clone this repository by running the following command:
```shell ```shell
$ git clone https://github.com/grpc/grpc.git $ git clone https://github.com/grpc/grpc.git
``` ```
@ -34,7 +34,7 @@ able to generate the server and client interface code and run the examples. Foll
## Defining the service ## Defining the service
Our first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) 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 [`examples/csharp/route_guide/RouteGuide/protos/route_guide.proto`](examples/csharp/route_guide/RouteGuide/protos/route_guide.proto). Our first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) 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 [`RouteGuide/protos/route_guide.proto`](RouteGuide/protos/route_guide.proto).
To define a service, you specify a named `service` in your .proto file: To define a service, you specify a named `service` in your .proto file:
@ -127,7 +127,7 @@ There are two parts to making our `RouteGuide` service do its job:
- Implementing the service interface generated from our service definition: doing the actual "work" of our service. - Implementing the service interface generated from our service definition: doing the actual "work" of our service.
- Running a gRPC server to listen for requests from clients and return the service responses. - Running a gRPC server to listen for requests from clients and return the service responses.
You can find our example `RouteGuide` server in [examples/csharp/route_guide/RouteGuideServer/RouteGuideImpl.cs](examples/csharp/route_guide/RouteGuideServer/RouteGuideServerImpl.cs). Let's take a closer look at how it works. You can find our example `RouteGuide` server in [RouteGuideServer/RouteGuideImpl.cs](RouteGuideServer/RouteGuideServerImpl.cs). Let's take a closer look at how it works.
### Implementing RouteGuide ### Implementing RouteGuide
@ -288,7 +288,7 @@ As you can see, we build and start our server using `Grpc.Core.Server` class. To
<a name="client"></a> <a name="client"></a>
## Creating the client ## Creating the client
In this section, we'll look at creating a C# client for our `RouteGuide` service. You can see our complete example client code in [examples/csharp/route_guide/RouteGuideClient/Program.cs](examples/csharp/route_guide/RouteGuideClient/Program.cs). In this section, we'll look at creating a C# client for our `RouteGuide` service. You can see our complete example client code in [RouteGuideClient/Program.cs](RouteGuideClient/Program.cs).
### Creating a stub ### Creating a stub

@ -37,7 +37,8 @@ var grpc = require('grpc');
var hello_proto = grpc.load(PROTO_PATH).helloworld; var hello_proto = grpc.load(PROTO_PATH).helloworld;
function main() { function main() {
var client = new hello_proto.Greeter('localhost:50051'); var client = new hello_proto.Greeter('localhost:50051',
grpc.Credentials.createInsecure());
var user; var user;
if (process.argv.length >= 3) { if (process.argv.length >= 3) {
user = process.argv[2]; user = process.argv[2];

@ -36,8 +36,6 @@ var PROTO_PATH = __dirname + '/helloworld.proto';
var grpc = require('grpc'); var grpc = require('grpc');
var hello_proto = grpc.load(PROTO_PATH).helloworld; var hello_proto = grpc.load(PROTO_PATH).helloworld;
var Server = grpc.buildServer([hello_proto.Greeter.service]);
/** /**
* Implements the SayHello RPC method. * Implements the SayHello RPC method.
*/ */
@ -50,14 +48,10 @@ function sayHello(call, callback) {
* sample server port * sample server port
*/ */
function main() { function main() {
var server = new Server({ var server = new grpc.Server();
"helloworld.Greeter": { server.addProtoService(hello_proto.Greeter.service, {sayHello: sayHello});
sayHello: sayHello server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
} server.start();
});
server.bind('0.0.0.0:50051');
server.listen();
} }
main(); main();

@ -3,7 +3,7 @@
"version": "0.5.0", "version": "0.5.0",
"dependencies": { "dependencies": {
"async": "^0.9.0", "async": "^0.9.0",
"grpc": "~0.9.0", "grpc": "~0.11.0",
"minimist": "^1.1.0", "minimist": "^1.1.0",
"underscore": "^1.8.2" "underscore": "^1.8.2"
} }

@ -17,7 +17,7 @@ With gRPC we can define our service once in a .proto file and implement clients
## Example code and setup ## Example code and setup
The example code for our tutorial is in [examples/node/route_guide](examples/node/route_guide). To download the example, clone this repository by running the following command: The example code for our tutorial is in [examples/node/route_guide](.). To download the example, clone this repository by running the following command:
```shell ```shell
$ git clone https://github.com/grpc/grpc.git $ git clone https://github.com/grpc/grpc.git
``` ```
@ -27,12 +27,12 @@ Then change your current directory to `examples/node/route_guide`:
$ cd examples/node/route_guide $ cd examples/node/route_guide
``` ```
You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Node.js quick start guide](examples/node). You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Node.js quick start guide](..).
## Defining the service ## Defining the service
Our first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) 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 [`examples/protos/route_guide.proto`](examples/protos/route_guide.proto). Our first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) 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 [`examples/protos/route_guide.proto`](../../route_guide.proto).
To define a service, you specify a named `service` in your .proto file: To define a service, you specify a named `service` in your .proto file:
@ -110,7 +110,7 @@ There are two parts to making our `RouteGuide` service do its job:
- Implementing the service interface generated from our service definition: doing the actual "work" of our service. - Implementing the service interface generated from our service definition: doing the actual "work" of our service.
- Running a gRPC server to listen for requests from clients and return the service responses. - Running a gRPC server to listen for requests from clients and return the service responses.
You can find our example `RouteGuide` server in [examples/node/route_guide/route_guide_server.js](examples/node/route_guide/route_guide_server.js). Let's take a closer look at how it works. You can find our example `RouteGuide` server in [route_guide_server.js](route_guide_server.js). Let's take a closer look at how it works.
### Implementing RouteGuide ### Implementing RouteGuide
@ -244,7 +244,7 @@ As you can see, we build and start our server with the following steps:
<a name="client"></a> <a name="client"></a>
## Creating the client ## Creating the client
In this section, we'll look at creating a Node.js client for our `RouteGuide` service. You can see our complete example client code in [examples/node/route_guide/route_guide_client.js](examples/node/route_guide/route_guide_client.js). In this section, we'll look at creating a Node.js client for our `RouteGuide` service. You can see our complete example client code in [route_guide_client.js](route_guide_client.js).
### Creating a stub ### Creating a stub

@ -34,7 +34,8 @@ var path = require('path');
var _ = require('underscore'); var _ = require('underscore');
var grpc = require('grpc'); var grpc = require('grpc');
var examples = grpc.load(__dirname + '/route_guide.proto').examples; var examples = grpc.load(__dirname + '/route_guide.proto').examples;
var client = new examples.RouteGuide('localhost:50051'); var client = new examples.RouteGuide('localhost:50051',
grpc.Credentials.createInsecure());
var COORD_FACTOR = 1e7; var COORD_FACTOR = 1e7;

@ -34,8 +34,6 @@ var _ = require('underscore');
var grpc = require('grpc'); var grpc = require('grpc');
var examples = grpc.load(__dirname + '/route_guide.proto').examples; var examples = grpc.load(__dirname + '/route_guide.proto').examples;
var Server = grpc.buildServer([examples.RouteGuide.service]);
var COORD_FACTOR = 1e7; var COORD_FACTOR = 1e7;
/** /**
@ -222,27 +220,27 @@ function routeChat(call) {
* @return {Server} The new server object * @return {Server} The new server object
*/ */
function getServer() { function getServer() {
return new Server({ var server = new grpc.Server();
'examples.RouteGuide' : { server.addProtoService(examples.RouteGuide.service, {
getFeature: getFeature, getFeature: getFeature,
listFeatures: listFeatures, listFeatures: listFeatures,
recordRoute: recordRoute, recordRoute: recordRoute,
routeChat: routeChat routeChat: routeChat
}
}); });
return server;
} }
if (require.main === module) { if (require.main === module) {
// If this is run as a script, start a server on an unused port // If this is run as a script, start a server on an unused port
var routeServer = getServer(); var routeServer = getServer();
routeServer.bind('0.0.0.0:50051'); routeServer.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
var argv = parseArgs(process.argv, { var argv = parseArgs(process.argv, {
string: 'db_path' string: 'db_path'
}); });
fs.readFile(path.resolve(argv.db_path), function(err, data) { fs.readFile(path.resolve(argv.db_path), function(err, data) {
if (err) throw err; if (err) throw err;
feature_list = JSON.parse(data); feature_list = JSON.parse(data);
routeServer.listen(); routeServer.start();
}); });
} }

@ -9,8 +9,8 @@ headers.
- Read response metadata from a call, which is equivalent to HTTP response headers and trailers. - Read response metadata from a call, which is equivalent to HTTP response headers and trailers.
It assumes you know the basics on how to make gRPC API calls using the Objective-C client library, It assumes you know the basics on how to make gRPC API calls using the Objective-C client library,
as shown in the [Hello World](examples/objective-c/helloworld) as shown in the [Hello World](../helloworld)
or [Route Guide](examples/objective-c/route_guide) tutorials, or [Route Guide](../route_guide) tutorials,
and are familiar with OAuth2 concepts like _access token_. and are familiar with OAuth2 concepts like _access token_.
- [Example code and setup](#setup) - [Example code and setup](#setup)
@ -22,7 +22,7 @@ and are familiar with OAuth2 concepts like _access token_.
<a name="setup"></a> <a name="setup"></a>
## Example code and setup ## Example code and setup
The example code for our tutorial is in [examples/objective-c/auth_sample](examples/objective-c/auth_sample). The example code for our tutorial is in [examples/objective-c/auth_sample](.).
To download the example, clone this repository by running the following command: To download the example, clone this repository by running the following command:
```shell ```shell
$ git clone https://github.com/grpc/grpc.git $ git clone https://github.com/grpc/grpc.git

@ -8,7 +8,7 @@ testing). You can obtain the latter by following [these setup instructions](http
## Hello Objective-C gRPC! ## Hello Objective-C gRPC!
Here's how to build and run the Objective-C implementation of the [Hello World](examples/protos/helloworld.proto) Here's how to build and run the Objective-C implementation of the [Hello World](../../protos/helloworld.proto)
example used in [Getting started](https://github.com/grpc/grpc/tree/master/examples). example used in [Getting started](https://github.com/grpc/grpc/tree/master/examples).
The example code for this and our other examples lives in the `examples` directory. Clone The example code for this and our other examples lives in the `examples` directory. Clone
@ -53,4 +53,4 @@ responds with a `HLWHelloResponse`, which contains a string that is then output
## Tutorial ## Tutorial
You can find a more detailed tutorial in [gRPC Basics: Objective-C](examples/objective-c/route_guide/README.md). You can find a more detailed tutorial in [gRPC Basics: Objective-C](../route_guide/README.md).

@ -43,7 +43,7 @@ code is limited by the dynamic nature of the language.
<a name="setup"></a> <a name="setup"></a>
## Example code and setup ## Example code and setup
The example code for our tutorial is in [examples/objective-c/route_guide](examples/objective-c/route_guide). The example code for our tutorial is in [examples/objective-c/route_guide](.).
To download the example, clone this repository by running the following command: To download the example, clone this repository by running the following command:
```shell ```shell
$ git clone https://github.com/grpc/grpc.git $ git clone https://github.com/grpc/grpc.git
@ -97,7 +97,7 @@ a client library from it, and how to create an app that uses that library.
First let's look at how the service we're using is defined. A gRPC *service* and its method 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). *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 [`examples/protos/route_guide.proto`](examples/protos/route_guide.proto). You can see the complete .proto file for our example in [`examples/protos/route_guide.proto`](../../protos/route_guide.proto).
To define a service, you specify a named `service` in your .proto file: To define a service, you specify a named `service` in your .proto file:
@ -177,7 +177,7 @@ option objc_class_prefix = "RTG";
Next we need to generate the gRPC client interfaces from our .proto service definition. We do this Next we need to generate the gRPC client interfaces from our .proto service definition. We do this
using the protocol buffer compiler (`protoc`) with a special gRPC Objective-C plugin. using the protocol buffer compiler (`protoc`) with a special gRPC Objective-C plugin.
For simplicity, we've provided a [Podspec file](examples/objective-c/route_guide/RouteGuide.podspec) For simplicity, we've provided a [Podspec file](RouteGuide.podspec)
that runs `protoc` for you with the appropriate plugin, input, and output, and describes how to that runs `protoc` for you with the appropriate plugin, input, and output, and describes how to
compile the generated files. You just need to run in this directory (`examples/objective-c/route_guide`): compile the generated files. You just need to run in this directory (`examples/objective-c/route_guide`):
@ -211,7 +211,7 @@ definition; just replace the name (matching the file name), version, and other m
## Creating the client ## Creating the client
In this section, we'll look at creating an Objective-C client for our `RouteGuide` service. You can In this section, we'll look at creating an Objective-C client for our `RouteGuide` service. You can
see our complete example client code in [examples/objective-c/route_guide/ViewControllers.m](examples/objective-c/route_guide/ViewControllers.m). see our complete example client code in [ViewControllers.m](ViewControllers.m).
(Note: In your apps, for maintainability and readability reasons, you shouldn't put all of your view (Note: In your apps, for maintainability and readability reasons, you shouldn't put all of your view
controllers in a single file; it's done here only to simplify the learning process). controllers in a single file; it's done here only to simplify the learning process).

@ -8,7 +8,7 @@ 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. 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](examples/node/route_guide). 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](../node/route_guide).
This isn't a comprehensive guide to using gRPC in PHP: more reference documentation is coming soon. This isn't a comprehensive guide to using gRPC in PHP: more reference documentation is coming soon.
@ -29,7 +29,7 @@ With gRPC you can define your service once in a .proto file and implement client
<a name="setup"></a> <a name="setup"></a>
## Example code and setup ## Example code and setup
The example code for our tutorial is in [examples/php/route_guide](examples/php/route_guide). To download the example, clone this repository by running the following command: The example code for our tutorial is in [examples/php/route_guide](.). To download the example, clone this repository by running the following command:
```shell ```shell
$ git clone https://github.com/grpc/grpc.git $ git clone https://github.com/grpc/grpc.git
``` ```
@ -68,7 +68,7 @@ The next sections guide you step-by-step through how this proto service is defin
<a name="proto"></a> <a name="proto"></a>
## Defining the service ## Defining the service
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 [`examples/protos/route_guide.proto`](examples/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 [`route_guide.proto`](route_guide.proto).
To define a service, you specify a named `service` in your .proto file: To define a service, you specify a named `service` in your .proto file:
@ -153,20 +153,20 @@ require dirname(__FILE__) . '/route_guide.php';
The file contains: The file contains:
- All the protocol buffer code to populate, serialize, and retrieve our request and response message types. - 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. - A class called `routeguide\RouteGuideClient` that lets clients call the methods defined in the `RouteGuide` service.
<a name="client"></a> <a name="client"></a>
## Creating the client ## 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 [examples/php/route_guide/route_guide_client.php](examples/php/route_guide/route_guide_client.php). In this section, we'll look at creating a PHP client for our `RouteGuide` service. You can see our complete example client code in [route_guide_client.php](route_guide_client.php).
### Constructing a client object ### Constructing a client object
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: 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 ```php
$client = new examples\RouteGuideClient(new Grpc\BaseStub('localhost:50051', [])); $client = new routeguide\RouteGuideClient(new Grpc\BaseStub('localhost:50051', []));
``` ```
### Calling service methods ### Calling service methods
@ -178,13 +178,13 @@ 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. Calling the simple RPC `GetFeature` is nearly as straightforward as calling a local asynchronous method.
```php ```php
$point = new examples\Point(); $point = new routeguide\Point();
$point->setLatitude(409146138); $point->setLatitude(409146138);
$point->setLongitude(-746188906); $point->setLongitude(-746188906);
list($feature, $status) = $client->GetFeature($point)->wait(); 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. As you can see, we create and populate a request object, i.e. an `routeguide\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 `routeguide\Feature` object.
```php ```php
print sprintf("Found %s \n at %f, %f\n", $feature->getName(), print sprintf("Found %s \n at %f, %f\n", $feature->getName(),
@ -197,15 +197,15 @@ As you can see, we create and populate a request object, i.e. an `examples\Point
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: 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 ```php
$lo_point = new examples\Point(); $lo_point = new routeguide\Point();
$hi_point = new examples\Point(); $hi_point = new routeguide\Point();
$lo_point->setLatitude(400000000); $lo_point->setLatitude(400000000);
$lo_point->setLongitude(-750000000); $lo_point->setLongitude(-750000000);
$hi_point->setLatitude(420000000); $hi_point->setLatitude(420000000);
$hi_point->setLongitude(-730000000); $hi_point->setLongitude(-730000000);
$rectangle = new examples\Rectangle(); $rectangle = new routeguide\Rectangle();
$rectangle->setLo($lo_point); $rectangle->setLo($lo_point);
$rectangle->setHi($hi_point); $rectangle->setHi($hi_point);
@ -219,12 +219,12 @@ Now let's look at our streaming methods. Here's where we call the server-side st
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 `$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`. The client-side streaming method `RecordRoute` is similar, except there we pass the method an iterator and get back a `routeguide\RouteSummary`.
```php ```php
$points_iter = function($db) { $points_iter = function($db) {
for ($i = 0; $i < $num_points; $i++) { for ($i = 0; $i < $num_points; $i++) {
$point = new examples\Point(); $point = new routeguide\Point();
$point->setLatitude($lat); $point->setLatitude($lat);
$point->setLongitude($long); $point->setLongitude($long);
yield $point; yield $point;
@ -245,7 +245,7 @@ To write messages from the client:
```php ```php
foreach ($notes as $n) { foreach ($notes as $n) {
$route_note = new examples\RouteNote(); $route_note = new routerguide\RouteNote();
$call->write($route_note); $call->write($route_note);
} }
$call->writesDone(); $call->writesDone();

@ -1,9 +1,9 @@
<?php <?php
// DO NOT EDIT! Generated by Protobuf-PHP protoc plugin 1.0 // DO NOT EDIT! Generated by Protobuf-PHP protoc plugin 1.0
// Source: route_guide.proto // Source: route_guide.proto
// Date: 2015-06-12 00:32:41 // Date: 2015-08-31 21:11:45
namespace examples { namespace routeguide {
class Point extends \DrSlump\Protobuf\Message { class Point extends \DrSlump\Protobuf\Message {
@ -19,7 +19,7 @@ namespace examples {
public static function descriptor() public static function descriptor()
{ {
$descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'examples.Point'); $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.Point');
// OPTIONAL INT32 latitude = 1 // OPTIONAL INT32 latitude = 1
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
@ -58,7 +58,7 @@ namespace examples {
/** /**
* Clear <latitude> value * Clear <latitude> value
* *
* @return \examples\Point * @return \routeguide\Point
*/ */
public function clearLatitude(){ public function clearLatitude(){
return $this->_clear(1); return $this->_clear(1);
@ -77,7 +77,7 @@ namespace examples {
* Set <latitude> value * Set <latitude> value
* *
* @param int $value * @param int $value
* @return \examples\Point * @return \routeguide\Point
*/ */
public function setLatitude( $value){ public function setLatitude( $value){
return $this->_set(1, $value); return $this->_set(1, $value);
@ -95,7 +95,7 @@ namespace examples {
/** /**
* Clear <longitude> value * Clear <longitude> value
* *
* @return \examples\Point * @return \routeguide\Point
*/ */
public function clearLongitude(){ public function clearLongitude(){
return $this->_clear(2); return $this->_clear(2);
@ -114,7 +114,7 @@ namespace examples {
* Set <longitude> value * Set <longitude> value
* *
* @param int $value * @param int $value
* @return \examples\Point * @return \routeguide\Point
*/ */
public function setLongitude( $value){ public function setLongitude( $value){
return $this->_set(2, $value); return $this->_set(2, $value);
@ -122,14 +122,14 @@ namespace examples {
} }
} }
namespace examples { namespace routeguide {
class Rectangle extends \DrSlump\Protobuf\Message { class Rectangle extends \DrSlump\Protobuf\Message {
/** @var \examples\Point */ /** @var \routeguide\Point */
public $lo = null; public $lo = null;
/** @var \examples\Point */ /** @var \routeguide\Point */
public $hi = null; public $hi = null;
@ -138,7 +138,7 @@ namespace examples {
public static function descriptor() public static function descriptor()
{ {
$descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'examples.Rectangle'); $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.Rectangle');
// OPTIONAL MESSAGE lo = 1 // OPTIONAL MESSAGE lo = 1
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
@ -146,7 +146,7 @@ namespace examples {
$f->name = "lo"; $f->name = "lo";
$f->type = \DrSlump\Protobuf::TYPE_MESSAGE; $f->type = \DrSlump\Protobuf::TYPE_MESSAGE;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$f->reference = '\examples\Point'; $f->reference = '\routeguide\Point';
$descriptor->addField($f); $descriptor->addField($f);
// OPTIONAL MESSAGE hi = 2 // OPTIONAL MESSAGE hi = 2
@ -155,7 +155,7 @@ namespace examples {
$f->name = "hi"; $f->name = "hi";
$f->type = \DrSlump\Protobuf::TYPE_MESSAGE; $f->type = \DrSlump\Protobuf::TYPE_MESSAGE;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$f->reference = '\examples\Point'; $f->reference = '\routeguide\Point';
$descriptor->addField($f); $descriptor->addField($f);
foreach (self::$__extensions as $cb) { foreach (self::$__extensions as $cb) {
@ -177,7 +177,7 @@ namespace examples {
/** /**
* Clear <lo> value * Clear <lo> value
* *
* @return \examples\Rectangle * @return \routeguide\Rectangle
*/ */
public function clearLo(){ public function clearLo(){
return $this->_clear(1); return $this->_clear(1);
@ -186,7 +186,7 @@ namespace examples {
/** /**
* Get <lo> value * Get <lo> value
* *
* @return \examples\Point * @return \routeguide\Point
*/ */
public function getLo(){ public function getLo(){
return $this->_get(1); return $this->_get(1);
@ -195,10 +195,10 @@ namespace examples {
/** /**
* Set <lo> value * Set <lo> value
* *
* @param \examples\Point $value * @param \routeguide\Point $value
* @return \examples\Rectangle * @return \routeguide\Rectangle
*/ */
public function setLo(\examples\Point $value){ public function setLo(\routeguide\Point $value){
return $this->_set(1, $value); return $this->_set(1, $value);
} }
@ -214,7 +214,7 @@ namespace examples {
/** /**
* Clear <hi> value * Clear <hi> value
* *
* @return \examples\Rectangle * @return \routeguide\Rectangle
*/ */
public function clearHi(){ public function clearHi(){
return $this->_clear(2); return $this->_clear(2);
@ -223,7 +223,7 @@ namespace examples {
/** /**
* Get <hi> value * Get <hi> value
* *
* @return \examples\Point * @return \routeguide\Point
*/ */
public function getHi(){ public function getHi(){
return $this->_get(2); return $this->_get(2);
@ -232,23 +232,23 @@ namespace examples {
/** /**
* Set <hi> value * Set <hi> value
* *
* @param \examples\Point $value * @param \routeguide\Point $value
* @return \examples\Rectangle * @return \routeguide\Rectangle
*/ */
public function setHi(\examples\Point $value){ public function setHi(\routeguide\Point $value){
return $this->_set(2, $value); return $this->_set(2, $value);
} }
} }
} }
namespace examples { namespace routeguide {
class Feature extends \DrSlump\Protobuf\Message { class Feature extends \DrSlump\Protobuf\Message {
/** @var string */ /** @var string */
public $name = null; public $name = null;
/** @var \examples\Point */ /** @var \routeguide\Point */
public $location = null; public $location = null;
@ -257,7 +257,7 @@ namespace examples {
public static function descriptor() public static function descriptor()
{ {
$descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'examples.Feature'); $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.Feature');
// OPTIONAL STRING name = 1 // OPTIONAL STRING name = 1
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
@ -273,7 +273,7 @@ namespace examples {
$f->name = "location"; $f->name = "location";
$f->type = \DrSlump\Protobuf::TYPE_MESSAGE; $f->type = \DrSlump\Protobuf::TYPE_MESSAGE;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$f->reference = '\examples\Point'; $f->reference = '\routeguide\Point';
$descriptor->addField($f); $descriptor->addField($f);
foreach (self::$__extensions as $cb) { foreach (self::$__extensions as $cb) {
@ -295,7 +295,7 @@ namespace examples {
/** /**
* Clear <name> value * Clear <name> value
* *
* @return \examples\Feature * @return \routeguide\Feature
*/ */
public function clearName(){ public function clearName(){
return $this->_clear(1); return $this->_clear(1);
@ -314,7 +314,7 @@ namespace examples {
* Set <name> value * Set <name> value
* *
* @param string $value * @param string $value
* @return \examples\Feature * @return \routeguide\Feature
*/ */
public function setName( $value){ public function setName( $value){
return $this->_set(1, $value); return $this->_set(1, $value);
@ -332,7 +332,7 @@ namespace examples {
/** /**
* Clear <location> value * Clear <location> value
* *
* @return \examples\Feature * @return \routeguide\Feature
*/ */
public function clearLocation(){ public function clearLocation(){
return $this->_clear(2); return $this->_clear(2);
@ -341,7 +341,7 @@ namespace examples {
/** /**
* Get <location> value * Get <location> value
* *
* @return \examples\Point * @return \routeguide\Point
*/ */
public function getLocation(){ public function getLocation(){
return $this->_get(2); return $this->_get(2);
@ -350,20 +350,20 @@ namespace examples {
/** /**
* Set <location> value * Set <location> value
* *
* @param \examples\Point $value * @param \routeguide\Point $value
* @return \examples\Feature * @return \routeguide\Feature
*/ */
public function setLocation(\examples\Point $value){ public function setLocation(\routeguide\Point $value){
return $this->_set(2, $value); return $this->_set(2, $value);
} }
} }
} }
namespace examples { namespace routeguide {
class RouteNote extends \DrSlump\Protobuf\Message { class RouteNote extends \DrSlump\Protobuf\Message {
/** @var \examples\Point */ /** @var \routeguide\Point */
public $location = null; public $location = null;
/** @var string */ /** @var string */
@ -375,7 +375,7 @@ namespace examples {
public static function descriptor() public static function descriptor()
{ {
$descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'examples.RouteNote'); $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.RouteNote');
// OPTIONAL MESSAGE location = 1 // OPTIONAL MESSAGE location = 1
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
@ -383,7 +383,7 @@ namespace examples {
$f->name = "location"; $f->name = "location";
$f->type = \DrSlump\Protobuf::TYPE_MESSAGE; $f->type = \DrSlump\Protobuf::TYPE_MESSAGE;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$f->reference = '\examples\Point'; $f->reference = '\routeguide\Point';
$descriptor->addField($f); $descriptor->addField($f);
// OPTIONAL STRING message = 2 // OPTIONAL STRING message = 2
@ -413,7 +413,7 @@ namespace examples {
/** /**
* Clear <location> value * Clear <location> value
* *
* @return \examples\RouteNote * @return \routeguide\RouteNote
*/ */
public function clearLocation(){ public function clearLocation(){
return $this->_clear(1); return $this->_clear(1);
@ -422,7 +422,7 @@ namespace examples {
/** /**
* Get <location> value * Get <location> value
* *
* @return \examples\Point * @return \routeguide\Point
*/ */
public function getLocation(){ public function getLocation(){
return $this->_get(1); return $this->_get(1);
@ -431,10 +431,10 @@ namespace examples {
/** /**
* Set <location> value * Set <location> value
* *
* @param \examples\Point $value * @param \routeguide\Point $value
* @return \examples\RouteNote * @return \routeguide\RouteNote
*/ */
public function setLocation(\examples\Point $value){ public function setLocation(\routeguide\Point $value){
return $this->_set(1, $value); return $this->_set(1, $value);
} }
@ -450,7 +450,7 @@ namespace examples {
/** /**
* Clear <message> value * Clear <message> value
* *
* @return \examples\RouteNote * @return \routeguide\RouteNote
*/ */
public function clearMessage(){ public function clearMessage(){
return $this->_clear(2); return $this->_clear(2);
@ -469,7 +469,7 @@ namespace examples {
* Set <message> value * Set <message> value
* *
* @param string $value * @param string $value
* @return \examples\RouteNote * @return \routeguide\RouteNote
*/ */
public function setMessage( $value){ public function setMessage( $value){
return $this->_set(2, $value); return $this->_set(2, $value);
@ -477,7 +477,7 @@ namespace examples {
} }
} }
namespace examples { namespace routeguide {
class RouteSummary extends \DrSlump\Protobuf\Message { class RouteSummary extends \DrSlump\Protobuf\Message {
@ -499,7 +499,7 @@ namespace examples {
public static function descriptor() public static function descriptor()
{ {
$descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'examples.RouteSummary'); $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.RouteSummary');
// OPTIONAL INT32 point_count = 1 // OPTIONAL INT32 point_count = 1
$f = new \DrSlump\Protobuf\Field(); $f = new \DrSlump\Protobuf\Field();
@ -556,7 +556,7 @@ namespace examples {
/** /**
* Clear <point_count> value * Clear <point_count> value
* *
* @return \examples\RouteSummary * @return \routeguide\RouteSummary
*/ */
public function clearPointCount(){ public function clearPointCount(){
return $this->_clear(1); return $this->_clear(1);
@ -575,7 +575,7 @@ namespace examples {
* Set <point_count> value * Set <point_count> value
* *
* @param int $value * @param int $value
* @return \examples\RouteSummary * @return \routeguide\RouteSummary
*/ */
public function setPointCount( $value){ public function setPointCount( $value){
return $this->_set(1, $value); return $this->_set(1, $value);
@ -593,7 +593,7 @@ namespace examples {
/** /**
* Clear <feature_count> value * Clear <feature_count> value
* *
* @return \examples\RouteSummary * @return \routeguide\RouteSummary
*/ */
public function clearFeatureCount(){ public function clearFeatureCount(){
return $this->_clear(2); return $this->_clear(2);
@ -612,7 +612,7 @@ namespace examples {
* Set <feature_count> value * Set <feature_count> value
* *
* @param int $value * @param int $value
* @return \examples\RouteSummary * @return \routeguide\RouteSummary
*/ */
public function setFeatureCount( $value){ public function setFeatureCount( $value){
return $this->_set(2, $value); return $this->_set(2, $value);
@ -630,7 +630,7 @@ namespace examples {
/** /**
* Clear <distance> value * Clear <distance> value
* *
* @return \examples\RouteSummary * @return \routeguide\RouteSummary
*/ */
public function clearDistance(){ public function clearDistance(){
return $this->_clear(3); return $this->_clear(3);
@ -649,7 +649,7 @@ namespace examples {
* Set <distance> value * Set <distance> value
* *
* @param int $value * @param int $value
* @return \examples\RouteSummary * @return \routeguide\RouteSummary
*/ */
public function setDistance( $value){ public function setDistance( $value){
return $this->_set(3, $value); return $this->_set(3, $value);
@ -667,7 +667,7 @@ namespace examples {
/** /**
* Clear <elapsed_time> value * Clear <elapsed_time> value
* *
* @return \examples\RouteSummary * @return \routeguide\RouteSummary
*/ */
public function clearElapsedTime(){ public function clearElapsedTime(){
return $this->_clear(4); return $this->_clear(4);
@ -686,7 +686,7 @@ namespace examples {
* Set <elapsed_time> value * Set <elapsed_time> value
* *
* @param int $value * @param int $value
* @return \examples\RouteSummary * @return \routeguide\RouteSummary
*/ */
public function setElapsedTime( $value){ public function setElapsedTime( $value){
return $this->_set(4, $value); return $this->_set(4, $value);
@ -694,38 +694,36 @@ namespace examples {
} }
} }
namespace examples { namespace routeguide {
class RouteGuideClient{ class RouteGuideClient extends \Grpc\BaseStub {
private $rpc_impl; public function __construct($hostname, $opts) {
parent::__construct($hostname, $opts);
public function __construct($rpc_impl) {
$this->rpc_impl = $rpc_impl;
} }
/** /**
* @param examples\Point $input * @param routeguide\Point $input
*/ */
public function GetFeature(\examples\Point $argument, $metadata = array()) { public function GetFeature(\routeguide\Point $argument, $metadata = array(), $options = array()) {
return $this->rpc_impl->_simpleRequest('/examples.RouteGuide/GetFeature', $argument, '\examples\Feature::deserialize', $metadata); return $this->_simpleRequest('/routeguide.RouteGuide/GetFeature', $argument, '\routeguide\Feature::deserialize', $metadata, $options);
} }
/** /**
* @param examples\Rectangle $input * @param routeguide\Rectangle $input
*/ */
public function ListFeatures($argument, $metadata = array()) { public function ListFeatures($argument, $metadata = array(), $options = array()) {
return $this->rpc_impl->_serverStreamRequest('/examples.RouteGuide/ListFeatures', $argument, '\examples\Feature::deserialize', $metadata); return $this->_serverStreamRequest('/routeguide.RouteGuide/ListFeatures', $argument, '\routeguide\Feature::deserialize', $metadata, $options);
} }
/** /**
* @param examples\Point $input * @param routeguide\Point $input
*/ */
public function RecordRoute($arguments, $metadata = array()) { public function RecordRoute($metadata = array()) {
return $this->rpc_impl->_clientStreamRequest('/examples.RouteGuide/RecordRoute', $arguments, '\examples\RouteSummary::deserialize', $metadata); return $this->_clientStreamRequest('/routeguide.RouteGuide/RecordRoute', '\routeguide\RouteSummary::deserialize', $metadata);
} }
/** /**
* @param examples\RouteNote $input * @param routeguide\RouteNote $input
*/ */
public function RouteChat($metadata = array()) { public function RouteChat($metadata = array()) {
return $this->rpc_impl->_bidiRequest('/examples.RouteGuide/RouteChat', '\examples\RouteNote::deserialize', $metadata); return $this->_bidiRequest('/routeguide.RouteGuide/RouteChat', '\routeguide\RouteNote::deserialize', $metadata);
} }
} }
} }

@ -31,7 +31,7 @@ syntax = "proto2";
option java_package = "io.grpc.examples"; option java_package = "io.grpc.examples";
package examples; package routeguide;
// Interface exported by the server. // Interface exported by the server.
service RouteGuide { service RouteGuide {

@ -37,7 +37,7 @@ require dirname(__FILE__) . '/route_guide.php';
define('COORD_FACTOR', 1e7); define('COORD_FACTOR', 1e7);
$client = new examples\RouteGuideClient( $client = new routeguide\RouteGuideClient(
new Grpc\BaseStub('localhost:50051', [])); new Grpc\BaseStub('localhost:50051', []));
function printFeature($feature) { function printFeature($feature) {
@ -60,7 +60,7 @@ function runGetFeature() {
print "Running GetFeature...\n"; print "Running GetFeature...\n";
global $client; global $client;
$point = new examples\Point(); $point = new routeguide\Point();
$points = array( $points = array(
array(409146138, -746188906), array(409146138, -746188906),
array(0, 0), array(0, 0),
@ -84,15 +84,15 @@ function runListFeatures() {
print "Running ListFeatures...\n"; print "Running ListFeatures...\n";
global $client; global $client;
$lo_point = new examples\Point(); $lo_point = new routeguide\Point();
$hi_point = new examples\Point(); $hi_point = new routeguide\Point();
$lo_point->setLatitude(400000000); $lo_point->setLatitude(400000000);
$lo_point->setLongitude(-750000000); $lo_point->setLongitude(-750000000);
$hi_point->setLatitude(420000000); $hi_point->setLatitude(420000000);
$hi_point->setLongitude(-730000000); $hi_point->setLongitude(-730000000);
$rectangle = new examples\Rectangle(); $rectangle = new routeguide\Rectangle();
$rectangle->setLo($lo_point); $rectangle->setLo($lo_point);
$rectangle->setHi($hi_point); $rectangle->setHi($hi_point);
@ -118,7 +118,7 @@ function runRecordRoute() {
$num_points_in_db = count($db); $num_points_in_db = count($db);
$num_points = 10; $num_points = 10;
for ($i = 0; $i < $num_points; $i++) { for ($i = 0; $i < $num_points; $i++) {
$point = new examples\Point(); $point = new routeguide\Point();
$index = rand(0, $num_points_in_db - 1); $index = rand(0, $num_points_in_db - 1);
$lat = $db[$index]['location']['latitude']; $lat = $db[$index]['location']['latitude'];
$long = $db[$index]['location']['longitude']; $long = $db[$index]['location']['longitude'];
@ -163,11 +163,11 @@ function runRouteChat() {
); );
foreach ($notes as $n) { foreach ($notes as $n) {
$point = new examples\Point(); $point = new routeguide\Point();
$point->setLatitude($lat = $n[0]); $point->setLatitude($lat = $n[0]);
$point->setLongitude($long = $n[1]); $point->setLongitude($long = $n[1]);
$route_note = new examples\RouteNote(); $route_note = new routeguide\RouteNote();
$route_note->setLocation($point); $route_note->setLocation($point);
$route_note->setMessage($message = $n[2]); $route_note->setMessage($message = $n[2]);

@ -32,7 +32,7 @@ syntax = "proto3";
option java_package = "ex.grpc"; option java_package = "ex.grpc";
option objc_class_prefix = "RTG"; option objc_class_prefix = "RTG";
package examples; package routeguide;
// Interface exported by the server. // Interface exported by the server.
service RouteGuide { service RouteGuide {

@ -1,6 +1,6 @@
# gRPC Python Hello World # gRPC Python Hello World
This is a quick introduction with a simple example and installation instructions: for a more complete tutorial see [gRPC Basics: Python](examples/python/route_guide). This is a quick introduction with a simple example and installation instructions: for a more complete tutorial see [gRPC Basics: Python](../route_guide).
### Install gRPC ### Install gRPC
Make sure you have built gRPC Python from source on your system. Follow the instructions here: Make sure you have built gRPC Python from source on your system. Follow the instructions here:
@ -96,7 +96,7 @@ been generated for you (helloworld_pb2.py).
### The client ### The client
Client-side code can be found in [greeter_client.py](examples/python/helloworld/greeter_client.py). Client-side code can be found in [greeter_client.py](greeter_client.py).
You can run the client using: You can run the client using:
@ -107,7 +107,7 @@ $ ./run_client.sh
### The server ### The server
Server side code can be found in [greeter_server.py](examples/python/helloworld/greeter_server.py). Server side code can be found in [greeter_server.py](greeter_server.py).
You can run the server using: You can run the server using:

@ -19,7 +19,7 @@ With gRPC you can define your service once in a .proto file and implement client
## Example code and setup ## Example code and setup
The example code for this tutorial is in [examples/python/route_guide](examples/python/route_guide). To download the example, clone this repository by running the following command: The example code for this tutorial is in [examples/python/route_guide](.). To download the example, clone this repository by running the following command:
```shell ```shell
$ git clone https://github.com/grpc/grpc.git $ git clone https://github.com/grpc/grpc.git
``` ```
@ -29,11 +29,11 @@ Then change your current directory to `examples/python/route_guide`:
$ cd examples/python/route_guide $ cd examples/python/route_guide
``` ```
You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Python quick start guide](examples/python). You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Python quick start guide](../python).
## Defining the service ## Defining the service
Your first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) 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 [`examples/protos/route_guide.proto`](examples/protos/route_guide.proto). Your first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) 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 [`examples/protos/route_guide.proto`](../../protos/route_guide.proto).
To define a service, you specify a named `service` in your .proto file: To define a service, you specify a named `service` in your .proto file:
@ -115,7 +115,7 @@ Creating and running a `RouteGuide` server breaks down into two work items:
- Implementing the servicer interface generated from our service definition with functions that perform the actual "work" of the service. - Implementing the servicer interface generated from our service definition with functions that perform the actual "work" of the service.
- Running a gRPC server to listen for requests from clients and transmit responses. - Running a gRPC server to listen for requests from clients and transmit responses.
You can find the example `RouteGuide` server in [examples/python/route_guide/route_guide_server.py](examples/python/route_guide/route_guide_server.py). You can find the example `RouteGuide` server in [route_guide_server.py](route_guide_server.py).
### Implementing RouteGuide ### Implementing RouteGuide
@ -222,7 +222,7 @@ Because `start()` does not block you may need to sleep-loop if there is nothing
<a name="client"></a> <a name="client"></a>
## Creating the client ## Creating the client
You can see the complete example client code in [examples/python/route_guide/route_guide_client.py](examples/python/route_guide/route_guide_client.py). You can see the complete example client code in [route_guide_client.py](route_guide_client.py).
### Creating a stub ### Creating a stub

@ -55,7 +55,7 @@ Try it!
Tutorial Tutorial
-------- --------
You can find a more detailed tutorial in [gRPC Basics: Ruby](examples/ruby/route_guide/README.md) You can find a more detailed tutorial in [gRPC Basics: Ruby](route_guide/README.md)
[helloworld.proto]:examples/protos/helloworld.proto [helloworld.proto]:../protos/helloworld.proto
[RVM]:https://www.rvm.io/ [RVM]:https://www.rvm.io/

@ -18,7 +18,7 @@ With gRPC we can define our service once in a .proto file and implement clients
## Example code and setup ## Example code and setup
The example code for our tutorial is in [examples/ruby/route_guide](examples/ruby/route_guide). To download the example, clone this repository by running the following command: The example code for our tutorial is in [examples/ruby/route_guide](.). To download the example, clone this repository by running the following command:
```shell ```shell
$ git clone https://github.com/grpc/grpc.git $ git clone https://github.com/grpc/grpc.git
``` ```
@ -28,12 +28,12 @@ Then change your current directory to `examples/ruby/route_guide`:
$ cd examples/ruby/route_guide $ cd examples/ruby/route_guide
``` ```
You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Ruby quick start guide](examples/ruby). You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Ruby quick start guide](..).
## Defining the service ## Defining the service
Our first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) 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 [`examples/protos/route_guide.proto`](examples/protos/route_guide.proto). Our first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) 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 [`examples/protos/route_guide.proto`](../../route_guide.proto).
To define a service, you specify a named `service` in your .proto file: To define a service, you specify a named `service` in your .proto file:
@ -116,7 +116,7 @@ There are two parts to making our `RouteGuide` service do its job:
- Implementing the service interface generated from our service definition: doing the actual "work" of our service. - Implementing the service interface generated from our service definition: doing the actual "work" of our service.
- Running a gRPC server to listen for requests from clients and return the service responses. - Running a gRPC server to listen for requests from clients and return the service responses.
You can find our example `RouteGuide` server in [examples/ruby/route_guide/route_guide_server.rb](examples/ruby/route_guide/route_guide_server.rb). Let's take a closer look at how it works. You can find our example `RouteGuide` server in [route_guide_server.rb](route_guide_server.rb). Let's take a closer look at how it works.
### Implementing RouteGuide ### Implementing RouteGuide
@ -199,7 +199,7 @@ As you can see, we build and start our server using a `GRPC::RpcServer`. To do t
<a name="client"></a> <a name="client"></a>
## Creating the client ## Creating the client
In this section, we'll look at creating a Ruby client for our `RouteGuide` service. You can see our complete example client code in [examples/ruby/route_guide/route_guide_client.rb](examples/ruby/route_guide/route_guide_client.rb). In this section, we'll look at creating a Ruby client for our `RouteGuide` service. You can see our complete example client code in [route_guide_client.rb](route_guide_client.rb).
### Creating a stub ### Creating a stub

@ -247,8 +247,9 @@ Pod::Spec.new do |s|
'src/core/transport/stream_op.h', 'src/core/transport/stream_op.h',
'src/core/transport/transport.h', 'src/core/transport/transport.h',
'src/core/transport/transport_impl.h', 'src/core/transport/transport_impl.h',
'src/core/census/aggregation.h',
'src/core/census/context.h', 'src/core/census/context.h',
'src/core/census/rpc_stat_id.h', 'src/core/census/rpc_metric_id.h',
'grpc/grpc_security.h', 'grpc/grpc_security.h',
'grpc/byte_buffer.h', 'grpc/byte_buffer.h',
'grpc/byte_buffer_reader.h', 'grpc/byte_buffer_reader.h',
@ -396,7 +397,6 @@ Pod::Spec.new do |s|
'src/core/census/context.c', 'src/core/census/context.c',
'src/core/census/initialize.c', 'src/core/census/initialize.c',
'src/core/census/operation.c', 'src/core/census/operation.c',
'src/core/census/record_stat.c',
'src/core/census/tracing.c' 'src/core/census/tracing.c'
ss.private_header_files = 'src/core/support/env.h', ss.private_header_files = 'src/core/support/env.h',
@ -521,8 +521,9 @@ Pod::Spec.new do |s|
'src/core/transport/stream_op.h', 'src/core/transport/stream_op.h',
'src/core/transport/transport.h', 'src/core/transport/transport.h',
'src/core/transport/transport_impl.h', 'src/core/transport/transport_impl.h',
'src/core/census/aggregation.h',
'src/core/census/context.h', 'src/core/census/context.h',
'src/core/census/rpc_stat_id.h' 'src/core/census/rpc_metric_id.h'
ss.header_mappings_dir = '.' ss.header_mappings_dir = '.'

@ -379,16 +379,107 @@ int census_tag_set_next(census_tag_set_iterator *it, census_tag_const *tag);
invalidated, and should not be used once close is called. */ invalidated, and should not be used once close is called. */
void census_tag_set_close(census_tag_set_iterator *it); void census_tag_set_close(census_tag_set_iterator *it);
/* A census statistic to be recorded comprises two parts: an ID for the /* Core stats collection API's. The following concepts are used:
* particular statistic and the value to be recorded against it. */ * Aggregation: A collection of values. Census supports the following
aggregation types:
Sum - a single summation type. Typically used for keeping (e.g.)
counts of events.
Distribution - statistical distribution information, used for
recording average, standard deviation etc.
Histogram - a histogram of measurements falling in defined bucket
boundaries.
Window - a count of events that happen in reolling time window.
New aggregation types can be added by the user, if desired (see
census_register_aggregation()).
* Metric: Each measurement is for a single metric. Examples include RPC
latency, CPU seconds consumed, and bytes transmitted.
* View: A view is a combination of a metric, a tag set (in which the tag
values are regular expressions) and a set of aggregations. When a
measurement for a metric matches the view tags, it is recorded (for each
unique set of tags) against each aggregation. Each metric can have an
arbitrary number of views by which it will be broken down.
*/
/* A single value to be recorded comprises two parts: an ID for the particular
* metric and the value to be recorded against it. */
typedef struct { typedef struct {
int id; gpr_uint32 metric_id;
double value; double value;
} census_stat; } census_value;
/* Record new usage values against the given context. */
void census_record_values(census_context *context, census_value *values,
size_t nvalues);
/** Type representing a particular aggregation */
typedef struct census_aggregation_ops census_aggregation_ops;
/* Predefined aggregation types, for use with census_view_create(). */
extern census_aggregation_ops census_agg_sum;
extern census_aggregation_ops census_agg_distribution;
extern census_aggregation_ops census_agg_histogram;
extern census_aggregation_ops census_agg_window;
/** Information needed to instantiate a new aggregation. Used in view
construction via census_define_view(). */
typedef struct {
const census_aggregation_ops *ops;
const void
*create_arg; /* Argument to be used for aggregation initialization. */
} census_aggregation;
/** A census view type. Opaque. */
typedef struct census_view census_view;
/** Create a new view.
@param metric_id Metric with which this view is associated.
@param tags tags that define the view
@param aggregations aggregations to associate with the view
@param naggregations number of aggregations
@return A new census view
*/
census_view *census_view_create(gpr_uint32 metric_id,
const census_tag_set *tags,
const census_aggregation *aggregations,
size_t naggregations);
/** Destroy a previously created view. */
void census_view_delete(census_view *view);
/** Metric ID associated with a view */
size_t census_view_metric(const census_view *view);
/** Number of aggregations associated with view. */
size_t census_view_naggregations(const census_view *view);
/** Get tags associated with view. */
const census_tag_set *census_view_tags(const census_view *view);
/** Get aggregation descriptors associated with a view. */
const census_aggregation *census_view_aggregrations(const census_view *view);
/** Holds all the aggregation data for a particular view instantiation. Forms
part of the data returned by census_view_data(). */
typedef struct {
const census_tag_set *tags; /* Tags for this set of aggregations. */
const void **data; /* One data set for every aggregation in the view. */
} census_view_aggregation_data;
/** Census view data as returned by census_view_get_data(). */
typedef struct {
size_t n_tag_sets; /* Number of unique tag sets that matched view. */
const census_view_aggregation_data *data; /* n_tag_sets entries */
} census_view_data;
/** Get data from aggregations associated with a view.
@param view View from which to get data.
@return Full set of data for all aggregations for the view.
*/
const census_view_data *census_view_get_data(const census_view *view);
/* Record new stats against the given context. */ /** Reset all view data to zero for the specified view */
void census_record_stat(census_context *context, census_stat *stats, void census_view_reset(census_view *view);
size_t nstats);
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -31,8 +31,36 @@
* *
*/ */
#include <grpc/census.h> #include <stddef.h>
#include "src/core/census/rpc_stat_id.h"
void census_record_stat(census_context *context, census_stat *stats, #ifndef GRPC_INTERNAL_CORE_CENSUS_AGGREGATION_H
size_t nstats) {} #define GRPC_INTERNAL_CORE_CENSUS_AGGREGATION_H
/** Structure used to describe an aggregation type. */
struct census_aggregation_ops {
/* Create a new aggregation. The pointer returned can be used in future calls
to clone(), free(), record(), data() and reset(). */
void *(*create)(const void *create_arg);
/* Make a copy of an aggregation created by create() */
void *(*clone)(const void *aggregation);
/* Destroy an aggregation created by create() */
void (*free)(void *aggregation);
/* Record a new value against aggregation. */
void (*record)(void *aggregation, double value);
/* Return current aggregation data. The caller must cast this object into
the correct type for the aggregation result. The object returned can be
freed by using free_data(). */
void *(*data)(const void *aggregation);
/* free data returned by data() */
void (*free_data)(void *data);
/* Reset an aggregation to default (zero) values. */
void (*reset)(void *aggregation);
/* Merge 'from' aggregation into 'to'. Both aggregations must be compatible */
void (*merge)(void *to, const void *from);
/* Fill buffer with printable string version of aggregation contents. For
debugging only. Returns the number of bytes added to buffer (a value == n
implies the buffer was of insufficient size). */
size_t (*print)(const void *aggregation, char *buffer, size_t n);
};
#endif /* GRPC_INTERNAL_CORE_CENSUS_AGGREGATION_H */

@ -36,7 +36,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "src/core/census/rpc_stat_id.h" #include "include/grpc/census.h"
#include "src/core/channel/channel_stack.h" #include "src/core/channel/channel_stack.h"
#include "src/core/channel/noop_filter.h" #include "src/core/channel/noop_filter.h"
#include "src/core/statistics/census_interface.h" #include "src/core/statistics/census_interface.h"
@ -173,25 +173,15 @@ static void destroy_channel_elem(grpc_channel_element* elem) {
} }
const grpc_channel_filter grpc_client_census_filter = { const grpc_channel_filter grpc_client_census_filter = {
client_start_transport_op, client_start_transport_op, grpc_channel_next_op,
grpc_channel_next_op, sizeof(call_data), client_init_call_elem,
sizeof(call_data), client_destroy_call_elem, sizeof(channel_data),
client_init_call_elem, init_channel_elem, destroy_channel_elem,
client_destroy_call_elem, grpc_call_next_get_peer, "census-client"};
sizeof(channel_data),
init_channel_elem,
destroy_channel_elem,
grpc_call_next_get_peer,
"census-client"};
const grpc_channel_filter grpc_server_census_filter = { const grpc_channel_filter grpc_server_census_filter = {
server_start_transport_op, server_start_transport_op, grpc_channel_next_op,
grpc_channel_next_op, sizeof(call_data), server_init_call_elem,
sizeof(call_data), server_destroy_call_elem, sizeof(channel_data),
server_init_call_elem, init_channel_elem, destroy_channel_elem,
server_destroy_call_elem, grpc_call_next_get_peer, "census-server"};
sizeof(channel_data),
init_channel_elem,
destroy_channel_elem,
grpc_call_next_get_peer,
"census-server"};

@ -31,16 +31,21 @@
* *
*/ */
#ifndef CENSUS_RPC_STAT_ID_H #ifndef CENSUS_RPC_METRIC_ID_H
#define CENSUS_RPC_STAT_ID_H #define CENSUS_RPC_METRIC_ID_H
/* Stats ID's used for RPC measurements. */ /* Metric ID's used for RPC measurements. */
#define CENSUS_INVALID_STAT_ID 0 /* ID 0 is always invalid */ /* Count of client requests sent. */
#define CENSUS_RPC_CLIENT_REQUESTS 1 /* Count of client requests sent. */ #define CENSUS_METRIC_RPC_CLIENT_REQUESTS ((gpr_uint32)0)
#define CENSUS_RPC_SERVER_REQUESTS 2 /* Count of server requests sent. */ /* Count of server requests sent. */
#define CENSUS_RPC_CLIENT_ERRORS 3 /* Client error counts. */ #define CENSUS_METRIC_RPC_SERVER_REQUESTS ((gpr_uint32)1)
#define CENSUS_RPC_SERVER_ERRORS 4 /* Server error counts. */ /* Client error counts. */
#define CENSUS_RPC_CLIENT_LATENCY 5 /* Client side request latency. */ #define CENSUS_METRIC_RPC_CLIENT_ERRORS ((gpr_uint32)2)
#define CENSUS_RPC_SERVER_LATENCY 6 /* Server side request latency. */ /* Server error counts. */
#define CENSUS_METRIC_RPC_SERVER_ERRORS ((gpr_uint32)3)
/* Client side request latency. */
#define CENSUS_METRIC_RPC_CLIENT_LATENCY ((gpr_uint32)4)
/* Server side request latency. */
#define CENSUS_METRIC_RPC_SERVER_LATENCY ((gpr_uint32)5)
#endif /* CENSUS_RPC_STAT_ID_H */ #endif /* CENSUS_RPC_METRIC_ID_H */

@ -14,15 +14,16 @@
<releaseNotes>Release $version$ of gRPC C#</releaseNotes> <releaseNotes>Release $version$ of gRPC C#</releaseNotes>
<copyright>Copyright 2015, Google Inc.</copyright> <copyright>Copyright 2015, Google Inc.</copyright>
<tags>gRPC RPC Protocol HTTP/2</tags> <tags>gRPC RPC Protocol HTTP/2</tags>
<dependencies> <dependencies>
<dependency id="Ix-Async" version="1.2.3" /> <dependency id="Ix-Async" version="1.2.3" />
<dependency id="grpc.native.csharp_ext" version="$GrpcNativeCsharpExtVersion$" /> <dependency id="grpc.native.csharp_ext" version="$GrpcNativeCsharpExtVersion$" />
</dependencies> </dependencies>
</metadata> </metadata>
<files> <files>
<file src="..\..\..\etc\roots.pem" target="tools" />
<file src="bin/ReleaseSigned/Grpc.Core.dll" target="lib/net45" /> <file src="bin/ReleaseSigned/Grpc.Core.dll" target="lib/net45" />
<file src="bin/ReleaseSigned/Grpc.Core.pdb" target="lib/net45" /> <file src="bin/ReleaseSigned/Grpc.Core.pdb" target="lib/net45" />
<file src="bin/ReleaseSigned/Grpc.Core.xml" target="lib/net45" /> <file src="bin/ReleaseSigned/Grpc.Core.xml" target="lib/net45" />
<file src="**\*.cs" target="src" /> <file src="**\*.cs" target="src" />
</files> </files>
</package> </package>

@ -1,7 +1,7 @@
# Node.js gRPC Library # Node.js gRPC Library
## Status ## Status
Alpha : Ready for early adopters Beta
## PREREQUISITES ## PREREQUISITES
- `node`: This requires `node` to be installed. If you instead have the `nodejs` executable on Debian, you should install the [`nodejs-legacy`](https://packages.debian.org/sid/nodejs-legacy) package. - `node`: This requires `node` to be installed. If you instead have the `nodejs` executable on Debian, you should install the [`nodejs-legacy`](https://packages.debian.org/sid/nodejs-legacy) package.

@ -164,3 +164,13 @@ exports.ServerCredentials = grpc.ServerCredentials;
* @see module:src/client.makeClientConstructor * @see module:src/client.makeClientConstructor
*/ */
exports.makeGenericClientConstructor = client.makeClientConstructor; exports.makeGenericClientConstructor = client.makeClientConstructor;
/**
* @see module:src/client.getClientChannel
*/
exports.getClientChannel = client.getClientChannel;
/**
* @see module:src/client.waitForClientReady
*/
exports.waitForClientReady = client.waitForClientReady;

@ -285,7 +285,7 @@ function authTest(expected_user, scope, client, done) {
if (credential.createScopedRequired() && scope) { if (credential.createScopedRequired() && scope) {
credential = credential.createScoped(scope); credential = credential.createScoped(scope);
} }
client.updateMetadata = grpc.getGoogleAuthDelegate(credential); client.$updateMetadata = grpc.getGoogleAuthDelegate(credential);
var arg = { var arg = {
response_type: 'COMPRESSABLE', response_type: 'COMPRESSABLE',
response_size: 314159, response_size: 314159,
@ -338,7 +338,7 @@ function oauth2Test(expected_user, scope, per_rpc, client, done) {
if (per_rpc) { if (per_rpc) {
updateMetadata('', {}, makeTestCall); updateMetadata('', {}, makeTestCall);
} else { } else {
client.updateMetadata = updateMetadata; client.$updateMetadata = updateMetadata;
makeTestCall(null, {}); makeTestCall(null, {});
} }
}); });

@ -1,6 +1,6 @@
{ {
"name": "grpc", "name": "grpc",
"version": "0.10.0", "version": "0.11.0",
"author": "Google Inc.", "author": "Google Inc.",
"description": "gRPC Library for Node", "description": "gRPC Library for Node",
"homepage": "http://www.grpc.io/", "homepage": "http://www.grpc.io/",

@ -32,7 +32,7 @@
*/ */
/** /**
* Server module * Client module
* @module * @module
*/ */
@ -270,7 +270,7 @@ function makeUnaryRequestFunction(method, serialize, deserialize) {
function makeUnaryRequest(argument, callback, metadata, options) { function makeUnaryRequest(argument, callback, metadata, options) {
/* jshint validthis: true */ /* jshint validthis: true */
var emitter = new EventEmitter(); var emitter = new EventEmitter();
var call = getCall(this.channel, method, options); var call = getCall(this.$channel, method, options);
if (metadata === null || metadata === undefined) { if (metadata === null || metadata === undefined) {
metadata = new Metadata(); metadata = new Metadata();
} else { } else {
@ -282,7 +282,7 @@ function makeUnaryRequestFunction(method, serialize, deserialize) {
emitter.getPeer = function getPeer() { emitter.getPeer = function getPeer() {
return call.getPeer(); return call.getPeer();
}; };
this.updateMetadata(this.auth_uri, metadata, function(error, metadata) { this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) {
if (error) { if (error) {
call.cancel(); call.cancel();
callback(error); callback(error);
@ -364,14 +364,14 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) {
*/ */
function makeClientStreamRequest(callback, metadata, options) { function makeClientStreamRequest(callback, metadata, options) {
/* jshint validthis: true */ /* jshint validthis: true */
var call = getCall(this.channel, method, options); var call = getCall(this.$channel, method, options);
if (metadata === null || metadata === undefined) { if (metadata === null || metadata === undefined) {
metadata = new Metadata(); metadata = new Metadata();
} else { } else {
metadata = metadata.clone(); metadata = metadata.clone();
} }
var stream = new ClientWritableStream(call, serialize); var stream = new ClientWritableStream(call, serialize);
this.updateMetadata(this.auth_uri, metadata, function(error, metadata) { this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) {
if (error) { if (error) {
call.cancel(); call.cancel();
callback(error); callback(error);
@ -455,14 +455,14 @@ function makeServerStreamRequestFunction(method, serialize, deserialize) {
*/ */
function makeServerStreamRequest(argument, metadata, options) { function makeServerStreamRequest(argument, metadata, options) {
/* jshint validthis: true */ /* jshint validthis: true */
var call = getCall(this.channel, method, options); var call = getCall(this.$channel, method, options);
if (metadata === null || metadata === undefined) { if (metadata === null || metadata === undefined) {
metadata = new Metadata(); metadata = new Metadata();
} else { } else {
metadata = metadata.clone(); metadata = metadata.clone();
} }
var stream = new ClientReadableStream(call, deserialize); var stream = new ClientReadableStream(call, deserialize);
this.updateMetadata(this.auth_uri, metadata, function(error, metadata) { this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) {
if (error) { if (error) {
call.cancel(); call.cancel();
stream.emit('error', error); stream.emit('error', error);
@ -533,14 +533,14 @@ function makeBidiStreamRequestFunction(method, serialize, deserialize) {
*/ */
function makeBidiStreamRequest(metadata, options) { function makeBidiStreamRequest(metadata, options) {
/* jshint validthis: true */ /* jshint validthis: true */
var call = getCall(this.channel, method, options); var call = getCall(this.$channel, method, options);
if (metadata === null || metadata === undefined) { if (metadata === null || metadata === undefined) {
metadata = new Metadata(); metadata = new Metadata();
} else { } else {
metadata = metadata.clone(); metadata = metadata.clone();
} }
var stream = new ClientDuplexStream(call, serialize, deserialize); var stream = new ClientDuplexStream(call, serialize, deserialize);
this.updateMetadata(this.auth_uri, metadata, function(error, metadata) { this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) {
if (error) { if (error) {
call.cancel(); call.cancel();
stream.emit('error', error); stream.emit('error', error);
@ -631,45 +631,21 @@ exports.makeClientConstructor = function(methods, serviceName) {
options = {}; options = {};
} }
options['grpc.primary_user_agent'] = 'grpc-node/' + version; options['grpc.primary_user_agent'] = 'grpc-node/' + version;
this.channel = new grpc.Channel(address, credentials, options); /* Private fields use $ as a prefix instead of _ because it is an invalid
* prefix of a method name */
this.$channel = new grpc.Channel(address, credentials, options);
// Remove the optional DNS scheme, trailing port, and trailing backslash // Remove the optional DNS scheme, trailing port, and trailing backslash
address = address.replace(/^(dns:\/{3})?([^:\/]+)(:\d+)?\/?$/, '$2'); address = address.replace(/^(dns:\/{3})?([^:\/]+)(:\d+)?\/?$/, '$2');
this.server_address = address; this.$server_address = address;
this.auth_uri = 'https://' + this.server_address + '/' + serviceName; this.$auth_uri = 'https://' + this.server_address + '/' + serviceName;
this.updateMetadata = updateMetadata; this.$updateMetadata = updateMetadata;
} }
/**
* Wait for the client to be ready. The callback will be called when the
* client has successfully connected to the server, and it will be called
* with an error if the attempt to connect to the server has unrecoverablly
* failed or if the deadline expires. This function will make the channel
* start connecting if it has not already done so.
* @param {(Date|Number)} deadline When to stop waiting for a connection. Pass
* Infinity to wait forever.
* @param {function(Error)} callback The callback to call when done attempting
* to connect.
*/
Client.prototype.$waitForReady = function(deadline, callback) {
var self = this;
var checkState = function(err) {
if (err) {
callback(new Error('Failed to connect before the deadline'));
}
var new_state = self.channel.getConnectivityState(true);
if (new_state === grpc.connectivityState.READY) {
callback();
} else if (new_state === grpc.connectivityState.FATAL_FAILURE) {
callback(new Error('Failed to connect to server'));
} else {
self.channel.watchConnectivityState(new_state, deadline, checkState);
}
};
checkState();
};
_.each(methods, function(attrs, name) { _.each(methods, function(attrs, name) {
var method_type; var method_type;
if (_.startsWith(name, '$')) {
throw new Error('Method names cannot start with $');
}
if (attrs.requestStream) { if (attrs.requestStream) {
if (attrs.responseStream) { if (attrs.responseStream) {
method_type = 'bidi'; method_type = 'bidi';
@ -694,6 +670,44 @@ exports.makeClientConstructor = function(methods, serviceName) {
return Client; return Client;
}; };
/**
* Return the underlying channel object for the specified client
* @param {Client} client
* @return {Channel} The channel
*/
exports.getClientChannel = function(client) {
return client.$channel;
};
/**
* Wait for the client to be ready. The callback will be called when the
* client has successfully connected to the server, and it will be called
* with an error if the attempt to connect to the server has unrecoverablly
* failed or if the deadline expires. This function will make the channel
* start connecting if it has not already done so.
* @param {Client} client The client to wait on
* @param {(Date|Number)} deadline When to stop waiting for a connection. Pass
* Infinity to wait forever.
* @param {function(Error)} callback The callback to call when done attempting
* to connect.
*/
exports.waitForClientReady = function(client, deadline, callback) {
var checkState = function(err) {
if (err) {
callback(new Error('Failed to connect before the deadline'));
}
var new_state = client.$channel.getConnectivityState(true);
if (new_state === grpc.connectivityState.READY) {
callback();
} else if (new_state === grpc.connectivityState.FATAL_FAILURE) {
callback(new Error('Failed to connect to server'));
} else {
client.$channel.watchConnectivityState(new_state, deadline, checkState);
}
};
checkState();
};
/** /**
* Creates a constructor for clients for the given service * Creates a constructor for clients for the given service
* @param {ProtoBuf.Reflect.Service} service The service to generate a client * @param {ProtoBuf.Reflect.Service} service The service to generate a client

@ -133,7 +133,25 @@ describe('Server.prototype.addProtoService', function() {
}); });
}); });
}); });
describe('Client#$waitForReady', function() { describe('Client constructor building', function() {
var illegal_service_attrs = {
$method : {
path: '/illegal/$method',
requestStream: false,
responseStream: false,
requestSerialize: _.identity,
requestDeserialize: _.identity,
responseSerialize: _.identity,
responseDeserialize: _.identity
}
};
it('Should reject method names starting with $', function() {
assert.throws(function() {
grpc.makeGenericClientConstructor(illegal_service_attrs);
}, /\$/);
});
});
describe('waitForClientReady', function() {
var server; var server;
var port; var port;
var Client; var Client;
@ -151,13 +169,13 @@ describe('Client#$waitForReady', function() {
server.forceShutdown(); server.forceShutdown();
}); });
it('should complete when called alone', function(done) { it('should complete when called alone', function(done) {
client.$waitForReady(Infinity, function(error) { grpc.waitForClientReady(client, Infinity, function(error) {
assert.ifError(error); assert.ifError(error);
done(); done();
}); });
}); });
it('should complete when a call is initiated', function(done) { it('should complete when a call is initiated', function(done) {
client.$waitForReady(Infinity, function(error) { grpc.waitForClientReady(client, Infinity, function(error) {
assert.ifError(error); assert.ifError(error);
done(); done();
}); });
@ -166,19 +184,19 @@ describe('Client#$waitForReady', function() {
}); });
it('should complete if called more than once', function(done) { it('should complete if called more than once', function(done) {
done = multiDone(done, 2); done = multiDone(done, 2);
client.$waitForReady(Infinity, function(error) { grpc.waitForClientReady(client, Infinity, function(error) {
assert.ifError(error); assert.ifError(error);
done(); done();
}); });
client.$waitForReady(Infinity, function(error) { grpc.waitForClientReady(client, Infinity, function(error) {
assert.ifError(error); assert.ifError(error);
done(); done();
}); });
}); });
it('should complete if called when already ready', function(done) { it('should complete if called when already ready', function(done) {
client.$waitForReady(Infinity, function(error) { grpc.waitForClientReady(client, Infinity, function(error) {
assert.ifError(error); assert.ifError(error);
client.$waitForReady(Infinity, function(error) { grpc.waitForClientReady(client, Infinity, function(error) {
assert.ifError(error); assert.ifError(error);
done(); done();
}); });
@ -426,7 +444,8 @@ describe('Other conditions', function() {
server.forceShutdown(); server.forceShutdown();
}); });
it('channel.getTarget should be available', function() { it('channel.getTarget should be available', function() {
assert.strictEqual(typeof client.channel.getTarget(), 'string'); assert.strictEqual(typeof grpc.getClientChannel(client).getTarget(),
'string');
}); });
describe('Server recieving bad input', function() { describe('Server recieving bad input', function() {
var misbehavingClient; var misbehavingClient;

@ -29,7 +29,7 @@
syntax = "proto3"; syntax = "proto3";
package examples; package routeguide;
option objc_class_prefix = "RGD"; option objc_class_prefix = "RGD";

@ -47,7 +47,7 @@
// instructions at https://github.com/grpc/homebrew-grpc // instructions at https://github.com/grpc/homebrew-grpc
static NSString * const kRouteGuideHost = @"http://localhost:50051"; static NSString * const kRouteGuideHost = @"http://localhost:50051";
static NSString * const kPackage = @"examples"; static NSString * const kPackage = @"routeguide";
static NSString * const kService = @"RouteGuide"; static NSString * const kService = @"RouteGuide";
@interface LocalClearTextTests : XCTestCase @interface LocalClearTextTests : XCTestCase

@ -1,5 +1,6 @@
-I. -I.
-Ipb -Ipb
--backtrace
--require spec_helper --require spec_helper
--format documentation --format documentation
--color --color

@ -14,7 +14,7 @@ Gem::Specification.new do |s|
s.license = 'BSD-3-Clause' s.license = 'BSD-3-Clause'
s.required_ruby_version = '>= 2.0.0' s.required_ruby_version = '>= 2.0.0'
s.requirements << 'libgrpc ~> 0.10.0 needs to be installed' s.requirements << 'libgrpc ~> 0.11.0 needs to be installed'
s.files = %w( Rakefile ) s.files = %w( Rakefile )
s.files += Dir.glob('lib/**/*') s.files += Dir.glob('lib/**/*')

@ -417,18 +417,18 @@ module GRPC
begin begin
an_rpc = @server.request_call(@cq, loop_tag, INFINITE_FUTURE) an_rpc = @server.request_call(@cq, loop_tag, INFINITE_FUTURE)
c = new_active_server_call(an_rpc) c = new_active_server_call(an_rpc)
unless c.nil?
mth = an_rpc.method.to_sym
@pool.schedule(c) do |call|
rpc_descs[mth].run_server_method(call, rpc_handlers[mth])
end
end
rescue Core::CallError, RuntimeError => e rescue Core::CallError, RuntimeError => e
# these might happen for various reasonse. The correct behaviour of # these might happen for various reasonse. The correct behaviour of
# the server is to log them and continue, if it's not shutting down. # the server is to log them and continue, if it's not shutting down.
GRPC.logger.warn("server call failed: #{e}") unless stopped? GRPC.logger.warn("server call failed: #{e}") unless stopped?
next next
end end
unless c.nil?
mth = an_rpc.method.to_sym
@pool.schedule(c) do |call|
rpc_descs[mth].run_server_method(call, rpc_handlers[mth])
end
end
end end
@running = false @running = false
GRPC.logger.info("stopped: #{self}") GRPC.logger.info("stopped: #{self}")

@ -29,5 +29,5 @@
# GRPC contains the General RPC module. # GRPC contains the General RPC module.
module GRPC module GRPC
VERSION = '0.10.0' VERSION = '0.11.0'
end end

@ -28,7 +28,6 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
require 'grpc' require 'grpc'
require 'spec_helper'
include GRPC::Core include GRPC::Core
@ -41,7 +40,7 @@ shared_context 'setup: tags' do
end end
def deadline def deadline
Time.now + 2 Time.now + 5
end end
def server_allows_client_to_proceed def server_allows_client_to_proceed

@ -179,7 +179,6 @@ describe Grpc::Health::Checker do
describe 'running on RpcServer' do describe 'running on RpcServer' do
RpcServer = GRPC::RpcServer RpcServer = GRPC::RpcServer
StatusCodes = GRPC::Core::StatusCodes
CheckerStub = Grpc::Health::Checker.rpc_stub_class CheckerStub = Grpc::Health::Checker.rpc_stub_class
before(:each) do before(:each) do

@ -881,8 +881,9 @@ src/core/transport/metadata.h \
src/core/transport/stream_op.h \ src/core/transport/stream_op.h \
src/core/transport/transport.h \ src/core/transport/transport.h \
src/core/transport/transport_impl.h \ src/core/transport/transport_impl.h \
src/core/census/aggregation.h \
src/core/census/context.h \ src/core/census/context.h \
src/core/census/rpc_stat_id.h \ src/core/census/rpc_metric_id.h \
src/core/httpcli/httpcli_security_connector.c \ src/core/httpcli/httpcli_security_connector.c \
src/core/security/base64.c \ src/core/security/base64.c \
src/core/security/client_auth_filter.c \ src/core/security/client_auth_filter.c \
@ -1023,7 +1024,6 @@ src/core/transport/transport_op_string.c \
src/core/census/context.c \ src/core/census/context.c \
src/core/census/initialize.c \ src/core/census/initialize.c \
src/core/census/operation.c \ src/core/census/operation.c \
src/core/census/record_stat.c \
src/core/census/tracing.c \ src/core/census/tracing.c \
include/grpc/support/alloc.h \ include/grpc/support/alloc.h \
include/grpc/support/atm.h \ include/grpc/support/atm.h \

@ -12229,9 +12229,10 @@
"include/grpc/grpc.h", "include/grpc/grpc.h",
"include/grpc/grpc_security.h", "include/grpc/grpc_security.h",
"include/grpc/status.h", "include/grpc/status.h",
"src/core/census/aggregation.h",
"src/core/census/context.h", "src/core/census/context.h",
"src/core/census/grpc_filter.h", "src/core/census/grpc_filter.h",
"src/core/census/rpc_stat_id.h", "src/core/census/rpc_metric_id.h",
"src/core/channel/channel_args.h", "src/core/channel/channel_args.h",
"src/core/channel/channel_stack.h", "src/core/channel/channel_stack.h",
"src/core/channel/client_channel.h", "src/core/channel/client_channel.h",
@ -12356,6 +12357,7 @@
"include/grpc/grpc.h", "include/grpc/grpc.h",
"include/grpc/grpc_security.h", "include/grpc/grpc_security.h",
"include/grpc/status.h", "include/grpc/status.h",
"src/core/census/aggregation.h",
"src/core/census/context.c", "src/core/census/context.c",
"src/core/census/context.h", "src/core/census/context.h",
"src/core/census/grpc_context.c", "src/core/census/grpc_context.c",
@ -12363,8 +12365,7 @@
"src/core/census/grpc_filter.h", "src/core/census/grpc_filter.h",
"src/core/census/initialize.c", "src/core/census/initialize.c",
"src/core/census/operation.c", "src/core/census/operation.c",
"src/core/census/record_stat.c", "src/core/census/rpc_metric_id.h",
"src/core/census/rpc_stat_id.h",
"src/core/census/tracing.c", "src/core/census/tracing.c",
"src/core/channel/channel_args.c", "src/core/channel/channel_args.c",
"src/core/channel/channel_args.h", "src/core/channel/channel_args.h",
@ -12708,9 +12709,10 @@
"include/grpc/compression.h", "include/grpc/compression.h",
"include/grpc/grpc.h", "include/grpc/grpc.h",
"include/grpc/status.h", "include/grpc/status.h",
"src/core/census/aggregation.h",
"src/core/census/context.h", "src/core/census/context.h",
"src/core/census/grpc_filter.h", "src/core/census/grpc_filter.h",
"src/core/census/rpc_stat_id.h", "src/core/census/rpc_metric_id.h",
"src/core/channel/channel_args.h", "src/core/channel/channel_args.h",
"src/core/channel/channel_stack.h", "src/core/channel/channel_stack.h",
"src/core/channel/client_channel.h", "src/core/channel/client_channel.h",
@ -12821,6 +12823,7 @@
"include/grpc/compression.h", "include/grpc/compression.h",
"include/grpc/grpc.h", "include/grpc/grpc.h",
"include/grpc/status.h", "include/grpc/status.h",
"src/core/census/aggregation.h",
"src/core/census/context.c", "src/core/census/context.c",
"src/core/census/context.h", "src/core/census/context.h",
"src/core/census/grpc_context.c", "src/core/census/grpc_context.c",
@ -12828,8 +12831,7 @@
"src/core/census/grpc_filter.h", "src/core/census/grpc_filter.h",
"src/core/census/initialize.c", "src/core/census/initialize.c",
"src/core/census/operation.c", "src/core/census/operation.c",
"src/core/census/record_stat.c", "src/core/census/rpc_metric_id.h",
"src/core/census/rpc_stat_id.h",
"src/core/census/tracing.c", "src/core/census/tracing.c",
"src/core/channel/channel_args.c", "src/core/channel/channel_args.c",
"src/core/channel/channel_args.h", "src/core/channel/channel_args.h",

@ -343,8 +343,9 @@
<ClInclude Include="..\..\src\core\transport\stream_op.h" /> <ClInclude Include="..\..\src\core\transport\stream_op.h" />
<ClInclude Include="..\..\src\core\transport\transport.h" /> <ClInclude Include="..\..\src\core\transport\transport.h" />
<ClInclude Include="..\..\src\core\transport\transport_impl.h" /> <ClInclude Include="..\..\src\core\transport\transport_impl.h" />
<ClInclude Include="..\..\src\core\census\aggregation.h" />
<ClInclude Include="..\..\src\core\census\context.h" /> <ClInclude Include="..\..\src\core\census\context.h" />
<ClInclude Include="..\..\src\core\census\rpc_stat_id.h" /> <ClInclude Include="..\..\src\core\census\rpc_metric_id.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\src\core\httpcli\httpcli_security_connector.c"> <ClCompile Include="..\..\src\core\httpcli\httpcli_security_connector.c">
@ -627,8 +628,6 @@
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\core\census\operation.c"> <ClCompile Include="..\..\src\core\census\operation.c">
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\core\census\record_stat.c">
</ClCompile>
<ClCompile Include="..\..\src\core\census\tracing.c"> <ClCompile Include="..\..\src\core\census\tracing.c">
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>

@ -421,9 +421,6 @@
<ClCompile Include="..\..\src\core\census\operation.c"> <ClCompile Include="..\..\src\core\census\operation.c">
<Filter>src\core\census</Filter> <Filter>src\core\census</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\core\census\record_stat.c">
<Filter>src\core\census</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\census\tracing.c"> <ClCompile Include="..\..\src\core\census\tracing.c">
<Filter>src\core\census</Filter> <Filter>src\core\census</Filter>
</ClCompile> </ClCompile>
@ -794,10 +791,13 @@
<ClInclude Include="..\..\src\core\transport\transport_impl.h"> <ClInclude Include="..\..\src\core\transport\transport_impl.h">
<Filter>src\core\transport</Filter> <Filter>src\core\transport</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\core\census\aggregation.h">
<Filter>src\core\census</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\census\context.h"> <ClInclude Include="..\..\src\core\census\context.h">
<Filter>src\core\census</Filter> <Filter>src\core\census</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\core\census\rpc_stat_id.h"> <ClInclude Include="..\..\src\core\census\rpc_metric_id.h">
<Filter>src\core\census</Filter> <Filter>src\core\census</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>

@ -326,8 +326,9 @@
<ClInclude Include="..\..\src\core\transport\stream_op.h" /> <ClInclude Include="..\..\src\core\transport\stream_op.h" />
<ClInclude Include="..\..\src\core\transport\transport.h" /> <ClInclude Include="..\..\src\core\transport\transport.h" />
<ClInclude Include="..\..\src\core\transport\transport_impl.h" /> <ClInclude Include="..\..\src\core\transport\transport_impl.h" />
<ClInclude Include="..\..\src\core\census\aggregation.h" />
<ClInclude Include="..\..\src\core\census\context.h" /> <ClInclude Include="..\..\src\core\census\context.h" />
<ClInclude Include="..\..\src\core\census\rpc_stat_id.h" /> <ClInclude Include="..\..\src\core\census\rpc_metric_id.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\src\core\surface\init_unsecure.c"> <ClCompile Include="..\..\src\core\surface\init_unsecure.c">
@ -570,8 +571,6 @@
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\core\census\operation.c"> <ClCompile Include="..\..\src\core\census\operation.c">
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\core\census\record_stat.c">
</ClCompile>
<ClCompile Include="..\..\src\core\census\tracing.c"> <ClCompile Include="..\..\src\core\census\tracing.c">
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>

@ -361,9 +361,6 @@
<ClCompile Include="..\..\src\core\census\operation.c"> <ClCompile Include="..\..\src\core\census\operation.c">
<Filter>src\core\census</Filter> <Filter>src\core\census</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\core\census\record_stat.c">
<Filter>src\core\census</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\census\tracing.c"> <ClCompile Include="..\..\src\core\census\tracing.c">
<Filter>src\core\census</Filter> <Filter>src\core\census</Filter>
</ClCompile> </ClCompile>
@ -692,10 +689,13 @@
<ClInclude Include="..\..\src\core\transport\transport_impl.h"> <ClInclude Include="..\..\src\core\transport\transport_impl.h">
<Filter>src\core\transport</Filter> <Filter>src\core\transport</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\core\census\aggregation.h">
<Filter>src\core\census</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\census\context.h"> <ClInclude Include="..\..\src\core\census\context.h">
<Filter>src\core\census</Filter> <Filter>src\core\census</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\core\census\rpc_stat_id.h"> <ClInclude Include="..\..\src\core\census\rpc_metric_id.h">
<Filter>src\core\census</Filter> <Filter>src\core\census</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>

Loading…
Cancel
Save