Merge pull request #177 from nicolasnoble/plugin-rework

Updating examples to reflect the new state of things.
pull/3109/head
Yang Gao 10 years ago
commit 3f07f660ec
  1. 5
      cpp/README.md
  2. 11
      cpp/cpptutorial.md
  3. 7
      cpp/helloworld/Makefile
  4. 5
      cpp/helloworld/README.md
  5. 2
      cpp/helloworld/greeter_client.cc
  6. 2
      cpp/helloworld/greeter_server.cc
  7. 9
      cpp/route_guide/Makefile
  8. 2
      cpp/route_guide/helper.cc
  9. 2
      cpp/route_guide/route_guide_client.cc
  10. 2
      cpp/route_guide/route_guide_server.cc

@ -30,12 +30,13 @@ $ cd grpc-common/cpp/helloworld/
To generate the client and server side interfaces: To generate the client and server side interfaces:
```sh ```sh
$ make helloworld.pb.cc $ make helloworld.grpc.pb.cc helloworld.pb.cc
``` ```
Which internally invokes the proto-compiler as: Which internally invokes the proto-compiler as:
```sh ```sh
$ protoc -I ../../protos/ --cpp_out=. --grpc_out=. --plugin=protoc-gen-grpc=grpc_cpp_plugin ../../protos/helloworld.proto $ protoc -I ../../protos/ --grpc_out=. --plugin=protoc-gen-grpc=grpc_cpp_plugin ../../protos/helloworld.proto
$ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto
``` ```
### Client and server implementations ### Client and server implementations

@ -94,18 +94,21 @@ Next we need to generate the gRPC client and server interfaces from our .proto s
For simplicity, we've provided a [makefile](https://github.com/grpc/grpc-common/blob/master/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](https://github.com/grpc/grpc-common/blob/master/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):
```shell ```shell
$ make route_guide.pb.cc $ make route_guide.grpc.pb.cc route_guide.pb.cc
``` ```
which actually runs: which actually runs:
```shell ```shell
$ protoc -I ../../protos --cpp_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ../../protos/route_guide.proto $ protoc -I ../../protos --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ../../protos/route_guide.proto
$ protoc -I ../../protos --cpp_out=. ../../protos/route_guide.proto
``` ```
Running this command generates the following files in your current directory: Running this command generates the following files in your current directory:
- `route_guide.pb.h`, the header which declares your generated classes - `route_guide.pb.h`, the header which declares your generated message classes
- `route_guide.pb.cc`, which contains the implementation of your classes - `route_guide.pb.cc`, which contains the implementation of your message classes
- `route_guide.grpc.pb.h`, the header which declares your generated service classes
- `route_guide.grpc.pb.cc`, which contains the implementation of your service classes
These contain: These contain:
- 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

@ -43,14 +43,17 @@ vpath %.proto $(PROTOS_PATH)
all: system-check greeter_client greeter_server all: system-check greeter_client greeter_server
greeter_client: helloworld.pb.o greeter_client.o greeter_client: helloworld.grpc.pb.o helloworld.pb.o greeter_client.o
$(CXX) $^ $(LDFLAGS) -o $@ $(CXX) $^ $(LDFLAGS) -o $@
greeter_server: helloworld.pb.o greeter_server.o greeter_server: helloworld.pb.o greeter_server.o
$(CXX) $^ $(LDFLAGS) -o $@ $(CXX) $^ $(LDFLAGS) -o $@
%.grpc.pb.cc: %.proto
$(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
%.pb.cc: %.proto %.pb.cc: %.proto
$(PROTOC) -I $(PROTOS_PATH) --cpp_out=. --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $< $(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $<
clean: clean:
rm -f *.o *.pb.cc *.pb.h greeter_client greeter_server rm -f *.o *.pb.cc *.pb.h greeter_client greeter_server

@ -78,12 +78,13 @@ defined in our `Greeting` service.
To generate the client and server side interfaces: To generate the client and server side interfaces:
```sh ```sh
$ make helloworld.pb.cc $ make helloworld.grpc.pb.cc helloworld.pb.cc
``` ```
Which internally invokes the proto-compiler as: Which internally invokes the proto-compiler as:
```sh ```sh
$protoc -I ../../protos/ --cpp_out=. --grpc_out=. --plugin=protoc-gen-grpc=grpc_cpp_plugin helloworld.proto $ protoc -I ../../protos/ --grpc_out=. --plugin=protoc-gen-grpc=grpc_cpp_plugin ../../protos/helloworld.proto
$ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto
``` ```
### Writing a client ### Writing a client

@ -42,7 +42,7 @@
#include <grpc++/create_channel.h> #include <grpc++/create_channel.h>
#include <grpc++/credentials.h> #include <grpc++/credentials.h>
#include <grpc++/status.h> #include <grpc++/status.h>
#include "helloworld.pb.h" #include "helloworld.grpc.pb.h"
using grpc::ChannelArguments; using grpc::ChannelArguments;
using grpc::ChannelInterface; using grpc::ChannelInterface;

@ -41,7 +41,7 @@
#include <grpc++/server_context.h> #include <grpc++/server_context.h>
#include <grpc++/server_credentials.h> #include <grpc++/server_credentials.h>
#include <grpc++/status.h> #include <grpc++/status.h>
#include "helloworld.pb.h" #include "helloworld.grpc.pb.h"
using grpc::Server; using grpc::Server;
using grpc::ServerBuilder; using grpc::ServerBuilder;

@ -43,14 +43,17 @@ vpath %.proto $(PROTOS_PATH)
all: system-check route_guide_client route_guide_server all: system-check route_guide_client route_guide_server
route_guide_client: route_guide.pb.o route_guide_client.o helper.o route_guide_client: route_guide.grpc.pb.o route_guide.pb.o route_guide_client.o helper.o
$(CXX) $^ $(LDFLAGS) -o $@ $(CXX) $^ $(LDFLAGS) -o $@
route_guide_server: route_guide.pb.o route_guide_server.o helper.o route_guide_server: route_guide.grpc.pb.o route_guide.pb.o route_guide_server.o helper.o
$(CXX) $^ $(LDFLAGS) -o $@ $(CXX) $^ $(LDFLAGS) -o $@
%.grpc.pb.cc: %.proto
$(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
%.pb.cc: %.proto %.pb.cc: %.proto
$(PROTOC) -I $(PROTOS_PATH) --cpp_out=. --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $< $(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $<
clean: clean:
rm -f *.o *.pb.cc *.pb.h route_guide_client route_guide_server rm -f *.o *.pb.cc *.pb.h route_guide_client route_guide_server

@ -38,7 +38,7 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
#include "route_guide.pb.h" #include "route_guide.grpc.pb.h"
namespace examples { namespace examples {

@ -47,7 +47,7 @@
#include <grpc++/status.h> #include <grpc++/status.h>
#include <grpc++/stream.h> #include <grpc++/stream.h>
#include "helper.h" #include "helper.h"
#include "route_guide.pb.h" #include "route_guide.grpc.pb.h"
using grpc::ChannelArguments; using grpc::ChannelArguments;
using grpc::ChannelInterface; using grpc::ChannelInterface;

@ -46,7 +46,7 @@
#include <grpc++/status.h> #include <grpc++/status.h>
#include <grpc++/stream.h> #include <grpc++/stream.h>
#include "helper.h" #include "helper.h"
#include "route_guide.pb.h" #include "route_guide.grpc.pb.h"
using grpc::Server; using grpc::Server;
using grpc::ServerBuilder; using grpc::ServerBuilder;

Loading…
Cancel
Save