Finish of a dummy client/server pair

pull/3109/head
Yang Gao 10 years ago
parent ae803c3969
commit 5621545e4c
  1. 79
      cpp/route_guide/Makefile
  2. 1736
      cpp/route_guide/route_guide.pb.cc
  3. 929
      cpp/route_guide/route_guide.pb.h
  4. 99
      cpp/route_guide/route_guide_client.cc
  5. 37
      cpp/route_guide/route_guide_server.cc

@ -29,19 +29,82 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
CXX=g++
CPPFLAGS=-I/usr/local/include -pthread
CXXFLAGS=-std=c++11
LDFLAGS=-L/usr/local/lib -lgrpc -lgrpc++ -lprotobuf -lpthread -ldl
CXX = g++
CPPFLAGS = -I/usr/local/include -pthread
CXXFLAGS = -std=c++11
LDFLAGS = -L/usr/local/lib -lgpr -lgrpc -lgrpc++ -lprotobuf -lpthread -ldl
PROTOC = protoc
GRPC_CPP_PLUGIN = grpc_cpp_plugin
GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`
all: route_guide_client route_guide_server
PROTOS_PATH = ../../protos
vpath %.proto $(PROTOS_PATH)
all: system-check route_guide_client route_guide_server
route_guide_client: route_guide.pb.o route_guide_client.o
$(CXX) $(CPPFLAGS) $^ $(LDFLAGS) -o $@
$(CXX) $^ $(LDFLAGS) -o $@
route_guide_server: route_guide.pb.o route_guide_server.o
$(CXX) $(CPPFLAGS) $^ $(LDFLAGS) -o $@
$(CXX) $^ $(LDFLAGS) -o $@
%.pb.cc: %.proto
$(PROTOC) -I $(PROTOS_PATH) --cpp_out=. --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
clean:
rm -f *.o route_guide_client route_guide_server
rm -f *.o *.pb.cc *.pb.h route_guide_client route_guide_server
# The following is to test your system and ensure a smoother experience.
# They are by no means necessary to actually compile a grpc-enabled software.
PROTOC_CMD = which $(PROTOC)
PROTOC_CHECK_CMD = $(PROTOC) --version | grep -q libprotoc.3
PLUGIN_CHECK_CMD = which $(GRPC_CPP_PLUGIN)
HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false)
ifeq ($(HAS_PROTOC),true)
HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
endif
HAS_PLUGIN = $(shell $(PLUGIN_CHECK_CMD) > /dev/null && echo true || echo false)
SYSTEM_OK = false
ifeq ($(HAS_VALID_PROTOC),true)
ifeq ($(HAS_PLUGIN),true)
SYSTEM_OK = true
endif
endif
system-check:
ifneq ($(HAS_VALID_PROTOC),true)
@echo " DEPENDENCY ERROR"
@echo
@echo "You don't have protoc 3.0.0 installed in your path."
@echo "Please install Google protocol buffers 3.0.0 and its compiler."
@echo "You can find it here:"
@echo
@echo " https://github.com/google/protobuf/releases/tag/v3.0.0-alpha-1"
@echo
@echo "Here is what I get when trying to evaluate your version of protoc:"
@echo
-$(PROTOC) --version
@echo
@echo
endif
ifneq ($(HAS_PLUGIN),true)
@echo " DEPENDENCY ERROR"
@echo
@echo "You don't have the grpc c++ protobuf plugin installed in your path."
@echo "Please install grpc. You can find it here:"
@echo
@echo " https://github.com/grpc/grpc"
@echo
@echo "Here is what I get when trying to detect if you have the plugin:"
@echo
-which $(GRPC_CPP_PLUGIN)
@echo
@echo
endif
ifneq ($(SYSTEM_OK),true)
@false
endif

File diff suppressed because it is too large Load Diff

@ -1,929 +0,0 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: route_guide.proto
#ifndef PROTOBUF_route_5fguide_2eproto__INCLUDED
#define PROTOBUF_route_5fguide_2eproto__INCLUDED
#include <string>
#include <google/protobuf/stubs/common.h>
#if GOOGLE_PROTOBUF_VERSION < 3000000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 3000000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
#include <google/protobuf/arena.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/metadata.h>
#include <google/protobuf/message.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/unknown_field_set.h>
#include <grpc++/impl/internal_stub.h>
#include <grpc++/impl/service_type.h>
#include <grpc++/status.h>
namespace grpc {
class CompletionQueue;
class ChannelInterface;
class RpcService;
class ServerContext;
template <class OutMessage> class ClientAsyncResponseReader;
template <class OutMessage> class ServerAsyncResponseWriter;
template <class OutMessage> class ClientWriter;
template <class InMessage> class ServerReader;
template <class OutMessage> class ClientAsyncWriter;
template <class OutMessage, class InMessage> class ServerAsyncReader;
template <class InMessage> class ClientReader;
template <class OutMessage> class ServerWriter;
template <class OutMessage> class ClientAsyncReader;
template <class InMessage> class ServerAsyncWriter;
template <class OutMessage, class InMessage>
class ClientReaderWriter;
template <class OutMessage, class InMessage>
class ServerReaderWriter;
template <class OutMessage, class InMessage>
class ClientAsyncReaderWriter;
template <class OutMessage, class InMessage>
class ServerAsyncReaderWriter;
} // namespace grpc
// @@protoc_insertion_point(includes)
namespace examples {
// Internal implementation detail -- do not call these.
void protobuf_AddDesc_route_5fguide_2eproto();
void protobuf_AssignDesc_route_5fguide_2eproto();
void protobuf_ShutdownFile_route_5fguide_2eproto();
class Point;
class Rectangle;
class Feature;
class RouteNote;
class RouteSummary;
// ===================================================================
class Point : public ::google::protobuf::Message {
public:
Point();
virtual ~Point();
Point(const Point& from);
inline Point& operator=(const Point& from) {
CopyFrom(from);
return *this;
}
static const ::google::protobuf::Descriptor* descriptor();
static const Point& default_instance();
void Swap(Point* other);
// implements Message ----------------------------------------------
inline Point* New() const { return New(NULL); }
Point* New(::google::protobuf::Arena* arena) const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
void CopyFrom(const Point& from);
void MergeFrom(const Point& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
void InternalSwap(Point* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
return _internal_metadata_.arena();
}
inline void* MaybeArenaPtr() const {
return _internal_metadata_.raw_arena_ptr();
}
public:
::google::protobuf::Metadata GetMetadata() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// optional int32 latitude = 1;
inline void clear_latitude();
static const int kLatitudeFieldNumber = 1;
inline ::google::protobuf::int32 latitude() const;
inline void set_latitude(::google::protobuf::int32 value);
// optional int32 longitude = 2;
inline void clear_longitude();
static const int kLongitudeFieldNumber = 2;
inline ::google::protobuf::int32 longitude() const;
inline void set_longitude(::google::protobuf::int32 value);
// @@protoc_insertion_point(class_scope:examples.Point)
private:
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
bool _is_default_instance_;
::google::protobuf::int32 latitude_;
::google::protobuf::int32 longitude_;
mutable int _cached_size_;
friend void protobuf_AddDesc_route_5fguide_2eproto();
friend void protobuf_AssignDesc_route_5fguide_2eproto();
friend void protobuf_ShutdownFile_route_5fguide_2eproto();
void InitAsDefaultInstance();
static Point* default_instance_;
};
// -------------------------------------------------------------------
class Rectangle : public ::google::protobuf::Message {
public:
Rectangle();
virtual ~Rectangle();
Rectangle(const Rectangle& from);
inline Rectangle& operator=(const Rectangle& from) {
CopyFrom(from);
return *this;
}
static const ::google::protobuf::Descriptor* descriptor();
static const Rectangle& default_instance();
void Swap(Rectangle* other);
// implements Message ----------------------------------------------
inline Rectangle* New() const { return New(NULL); }
Rectangle* New(::google::protobuf::Arena* arena) const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
void CopyFrom(const Rectangle& from);
void MergeFrom(const Rectangle& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
void InternalSwap(Rectangle* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
return _internal_metadata_.arena();
}
inline void* MaybeArenaPtr() const {
return _internal_metadata_.raw_arena_ptr();
}
public:
::google::protobuf::Metadata GetMetadata() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// optional .examples.Point lo = 1;
inline bool has_lo() const;
inline void clear_lo();
static const int kLoFieldNumber = 1;
inline const ::examples::Point& lo() const;
inline ::examples::Point* mutable_lo();
inline ::examples::Point* release_lo();
inline void set_allocated_lo(::examples::Point* lo);
// optional .examples.Point hi = 2;
inline bool has_hi() const;
inline void clear_hi();
static const int kHiFieldNumber = 2;
inline const ::examples::Point& hi() const;
inline ::examples::Point* mutable_hi();
inline ::examples::Point* release_hi();
inline void set_allocated_hi(::examples::Point* hi);
// @@protoc_insertion_point(class_scope:examples.Rectangle)
private:
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
bool _is_default_instance_;
::examples::Point* lo_;
::examples::Point* hi_;
mutable int _cached_size_;
friend void protobuf_AddDesc_route_5fguide_2eproto();
friend void protobuf_AssignDesc_route_5fguide_2eproto();
friend void protobuf_ShutdownFile_route_5fguide_2eproto();
void InitAsDefaultInstance();
static Rectangle* default_instance_;
};
// -------------------------------------------------------------------
class Feature : public ::google::protobuf::Message {
public:
Feature();
virtual ~Feature();
Feature(const Feature& from);
inline Feature& operator=(const Feature& from) {
CopyFrom(from);
return *this;
}
static const ::google::protobuf::Descriptor* descriptor();
static const Feature& default_instance();
void Swap(Feature* other);
// implements Message ----------------------------------------------
inline Feature* New() const { return New(NULL); }
Feature* New(::google::protobuf::Arena* arena) const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
void CopyFrom(const Feature& from);
void MergeFrom(const Feature& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
void InternalSwap(Feature* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
return _internal_metadata_.arena();
}
inline void* MaybeArenaPtr() const {
return _internal_metadata_.raw_arena_ptr();
}
public:
::google::protobuf::Metadata GetMetadata() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// optional string name = 1;
inline void clear_name();
static const int kNameFieldNumber = 1;
inline const ::std::string& name() const;
inline void set_name(const ::std::string& value);
inline void set_name(const char* value);
inline void set_name(const char* value, size_t size);
inline ::std::string* mutable_name();
inline ::std::string* release_name();
inline void set_allocated_name(::std::string* name);
// optional .examples.Point location = 2;
inline bool has_location() const;
inline void clear_location();
static const int kLocationFieldNumber = 2;
inline const ::examples::Point& location() const;
inline ::examples::Point* mutable_location();
inline ::examples::Point* release_location();
inline void set_allocated_location(::examples::Point* location);
// @@protoc_insertion_point(class_scope:examples.Feature)
private:
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
bool _is_default_instance_;
::google::protobuf::internal::ArenaStringPtr name_;
::examples::Point* location_;
mutable int _cached_size_;
friend void protobuf_AddDesc_route_5fguide_2eproto();
friend void protobuf_AssignDesc_route_5fguide_2eproto();
friend void protobuf_ShutdownFile_route_5fguide_2eproto();
void InitAsDefaultInstance();
static Feature* default_instance_;
};
// -------------------------------------------------------------------
class RouteNote : public ::google::protobuf::Message {
public:
RouteNote();
virtual ~RouteNote();
RouteNote(const RouteNote& from);
inline RouteNote& operator=(const RouteNote& from) {
CopyFrom(from);
return *this;
}
static const ::google::protobuf::Descriptor* descriptor();
static const RouteNote& default_instance();
void Swap(RouteNote* other);
// implements Message ----------------------------------------------
inline RouteNote* New() const { return New(NULL); }
RouteNote* New(::google::protobuf::Arena* arena) const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
void CopyFrom(const RouteNote& from);
void MergeFrom(const RouteNote& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
void InternalSwap(RouteNote* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
return _internal_metadata_.arena();
}
inline void* MaybeArenaPtr() const {
return _internal_metadata_.raw_arena_ptr();
}
public:
::google::protobuf::Metadata GetMetadata() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// optional .examples.Point location = 1;
inline bool has_location() const;
inline void clear_location();
static const int kLocationFieldNumber = 1;
inline const ::examples::Point& location() const;
inline ::examples::Point* mutable_location();
inline ::examples::Point* release_location();
inline void set_allocated_location(::examples::Point* location);
// optional string message = 2;
inline void clear_message();
static const int kMessageFieldNumber = 2;
inline const ::std::string& message() const;
inline void set_message(const ::std::string& value);
inline void set_message(const char* value);
inline void set_message(const char* value, size_t size);
inline ::std::string* mutable_message();
inline ::std::string* release_message();
inline void set_allocated_message(::std::string* message);
// @@protoc_insertion_point(class_scope:examples.RouteNote)
private:
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
bool _is_default_instance_;
::examples::Point* location_;
::google::protobuf::internal::ArenaStringPtr message_;
mutable int _cached_size_;
friend void protobuf_AddDesc_route_5fguide_2eproto();
friend void protobuf_AssignDesc_route_5fguide_2eproto();
friend void protobuf_ShutdownFile_route_5fguide_2eproto();
void InitAsDefaultInstance();
static RouteNote* default_instance_;
};
// -------------------------------------------------------------------
class RouteSummary : public ::google::protobuf::Message {
public:
RouteSummary();
virtual ~RouteSummary();
RouteSummary(const RouteSummary& from);
inline RouteSummary& operator=(const RouteSummary& from) {
CopyFrom(from);
return *this;
}
static const ::google::protobuf::Descriptor* descriptor();
static const RouteSummary& default_instance();
void Swap(RouteSummary* other);
// implements Message ----------------------------------------------
inline RouteSummary* New() const { return New(NULL); }
RouteSummary* New(::google::protobuf::Arena* arena) const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
void CopyFrom(const RouteSummary& from);
void MergeFrom(const RouteSummary& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
void InternalSwap(RouteSummary* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
return _internal_metadata_.arena();
}
inline void* MaybeArenaPtr() const {
return _internal_metadata_.raw_arena_ptr();
}
public:
::google::protobuf::Metadata GetMetadata() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// optional int32 point_count = 1;
inline void clear_point_count();
static const int kPointCountFieldNumber = 1;
inline ::google::protobuf::int32 point_count() const;
inline void set_point_count(::google::protobuf::int32 value);
// optional int32 feature_count = 2;
inline void clear_feature_count();
static const int kFeatureCountFieldNumber = 2;
inline ::google::protobuf::int32 feature_count() const;
inline void set_feature_count(::google::protobuf::int32 value);
// optional int32 distance = 3;
inline void clear_distance();
static const int kDistanceFieldNumber = 3;
inline ::google::protobuf::int32 distance() const;
inline void set_distance(::google::protobuf::int32 value);
// optional int32 elapsed_time = 4;
inline void clear_elapsed_time();
static const int kElapsedTimeFieldNumber = 4;
inline ::google::protobuf::int32 elapsed_time() const;
inline void set_elapsed_time(::google::protobuf::int32 value);
// @@protoc_insertion_point(class_scope:examples.RouteSummary)
private:
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
bool _is_default_instance_;
::google::protobuf::int32 point_count_;
::google::protobuf::int32 feature_count_;
::google::protobuf::int32 distance_;
::google::protobuf::int32 elapsed_time_;
mutable int _cached_size_;
friend void protobuf_AddDesc_route_5fguide_2eproto();
friend void protobuf_AssignDesc_route_5fguide_2eproto();
friend void protobuf_ShutdownFile_route_5fguide_2eproto();
void InitAsDefaultInstance();
static RouteSummary* default_instance_;
};
// ===================================================================
// ===================================================================
// Point
// optional int32 latitude = 1;
inline void Point::clear_latitude() {
latitude_ = 0;
}
inline ::google::protobuf::int32 Point::latitude() const {
// @@protoc_insertion_point(field_get:examples.Point.latitude)
return latitude_;
}
inline void Point::set_latitude(::google::protobuf::int32 value) {
latitude_ = value;
// @@protoc_insertion_point(field_set:examples.Point.latitude)
}
// optional int32 longitude = 2;
inline void Point::clear_longitude() {
longitude_ = 0;
}
inline ::google::protobuf::int32 Point::longitude() const {
// @@protoc_insertion_point(field_get:examples.Point.longitude)
return longitude_;
}
inline void Point::set_longitude(::google::protobuf::int32 value) {
longitude_ = value;
// @@protoc_insertion_point(field_set:examples.Point.longitude)
}
// -------------------------------------------------------------------
// Rectangle
// optional .examples.Point lo = 1;
inline bool Rectangle::has_lo() const {
return !_is_default_instance_ && lo_ != NULL;
}
inline void Rectangle::clear_lo() {
if (lo_ != NULL) delete lo_;
lo_ = NULL;
}
inline const ::examples::Point& Rectangle::lo() const {
// @@protoc_insertion_point(field_get:examples.Rectangle.lo)
return lo_ != NULL ? *lo_ : *default_instance_->lo_;
}
inline ::examples::Point* Rectangle::mutable_lo() {
if (lo_ == NULL) {
lo_ = new ::examples::Point;
}
// @@protoc_insertion_point(field_mutable:examples.Rectangle.lo)
return lo_;
}
inline ::examples::Point* Rectangle::release_lo() {
::examples::Point* temp = lo_;
lo_ = NULL;
return temp;
}
inline void Rectangle::set_allocated_lo(::examples::Point* lo) {
delete lo_;
lo_ = lo;
if (lo) {
} else {
}
// @@protoc_insertion_point(field_set_allocated:examples.Rectangle.lo)
}
// optional .examples.Point hi = 2;
inline bool Rectangle::has_hi() const {
return !_is_default_instance_ && hi_ != NULL;
}
inline void Rectangle::clear_hi() {
if (hi_ != NULL) delete hi_;
hi_ = NULL;
}
inline const ::examples::Point& Rectangle::hi() const {
// @@protoc_insertion_point(field_get:examples.Rectangle.hi)
return hi_ != NULL ? *hi_ : *default_instance_->hi_;
}
inline ::examples::Point* Rectangle::mutable_hi() {
if (hi_ == NULL) {
hi_ = new ::examples::Point;
}
// @@protoc_insertion_point(field_mutable:examples.Rectangle.hi)
return hi_;
}
inline ::examples::Point* Rectangle::release_hi() {
::examples::Point* temp = hi_;
hi_ = NULL;
return temp;
}
inline void Rectangle::set_allocated_hi(::examples::Point* hi) {
delete hi_;
hi_ = hi;
if (hi) {
} else {
}
// @@protoc_insertion_point(field_set_allocated:examples.Rectangle.hi)
}
// -------------------------------------------------------------------
// Feature
// optional string name = 1;
inline void Feature::clear_name() {
name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& Feature::name() const {
// @@protoc_insertion_point(field_get:examples.Feature.name)
return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline void Feature::set_name(const ::std::string& value) {
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:examples.Feature.name)
}
inline void Feature::set_name(const char* value) {
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
// @@protoc_insertion_point(field_set_char:examples.Feature.name)
}
inline void Feature::set_name(const char* value, size_t size) {
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
::std::string(reinterpret_cast<const char*>(value), size));
// @@protoc_insertion_point(field_set_pointer:examples.Feature.name)
}
inline ::std::string* Feature::mutable_name() {
// @@protoc_insertion_point(field_mutable:examples.Feature.name)
return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline ::std::string* Feature::release_name() {
return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline void Feature::set_allocated_name(::std::string* name) {
if (name != NULL) {
} else {
}
name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name);
// @@protoc_insertion_point(field_set_allocated:examples.Feature.name)
}
// optional .examples.Point location = 2;
inline bool Feature::has_location() const {
return !_is_default_instance_ && location_ != NULL;
}
inline void Feature::clear_location() {
if (location_ != NULL) delete location_;
location_ = NULL;
}
inline const ::examples::Point& Feature::location() const {
// @@protoc_insertion_point(field_get:examples.Feature.location)
return location_ != NULL ? *location_ : *default_instance_->location_;
}
inline ::examples::Point* Feature::mutable_location() {
if (location_ == NULL) {
location_ = new ::examples::Point;
}
// @@protoc_insertion_point(field_mutable:examples.Feature.location)
return location_;
}
inline ::examples::Point* Feature::release_location() {
::examples::Point* temp = location_;
location_ = NULL;
return temp;
}
inline void Feature::set_allocated_location(::examples::Point* location) {
delete location_;
location_ = location;
if (location) {
} else {
}
// @@protoc_insertion_point(field_set_allocated:examples.Feature.location)
}
// -------------------------------------------------------------------
// RouteNote
// optional .examples.Point location = 1;
inline bool RouteNote::has_location() const {
return !_is_default_instance_ && location_ != NULL;
}
inline void RouteNote::clear_location() {
if (location_ != NULL) delete location_;
location_ = NULL;
}
inline const ::examples::Point& RouteNote::location() const {
// @@protoc_insertion_point(field_get:examples.RouteNote.location)
return location_ != NULL ? *location_ : *default_instance_->location_;
}
inline ::examples::Point* RouteNote::mutable_location() {
if (location_ == NULL) {
location_ = new ::examples::Point;
}
// @@protoc_insertion_point(field_mutable:examples.RouteNote.location)
return location_;
}
inline ::examples::Point* RouteNote::release_location() {
::examples::Point* temp = location_;
location_ = NULL;
return temp;
}
inline void RouteNote::set_allocated_location(::examples::Point* location) {
delete location_;
location_ = location;
if (location) {
} else {
}
// @@protoc_insertion_point(field_set_allocated:examples.RouteNote.location)
}
// optional string message = 2;
inline void RouteNote::clear_message() {
message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& RouteNote::message() const {
// @@protoc_insertion_point(field_get:examples.RouteNote.message)
return message_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline void RouteNote::set_message(const ::std::string& value) {
message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:examples.RouteNote.message)
}
inline void RouteNote::set_message(const char* value) {
message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
// @@protoc_insertion_point(field_set_char:examples.RouteNote.message)
}
inline void RouteNote::set_message(const char* value, size_t size) {
message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
::std::string(reinterpret_cast<const char*>(value), size));
// @@protoc_insertion_point(field_set_pointer:examples.RouteNote.message)
}
inline ::std::string* RouteNote::mutable_message() {
// @@protoc_insertion_point(field_mutable:examples.RouteNote.message)
return message_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline ::std::string* RouteNote::release_message() {
return message_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline void RouteNote::set_allocated_message(::std::string* message) {
if (message != NULL) {
} else {
}
message_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), message);
// @@protoc_insertion_point(field_set_allocated:examples.RouteNote.message)
}
// -------------------------------------------------------------------
// RouteSummary
// optional int32 point_count = 1;
inline void RouteSummary::clear_point_count() {
point_count_ = 0;
}
inline ::google::protobuf::int32 RouteSummary::point_count() const {
// @@protoc_insertion_point(field_get:examples.RouteSummary.point_count)
return point_count_;
}
inline void RouteSummary::set_point_count(::google::protobuf::int32 value) {
point_count_ = value;
// @@protoc_insertion_point(field_set:examples.RouteSummary.point_count)
}
// optional int32 feature_count = 2;
inline void RouteSummary::clear_feature_count() {
feature_count_ = 0;
}
inline ::google::protobuf::int32 RouteSummary::feature_count() const {
// @@protoc_insertion_point(field_get:examples.RouteSummary.feature_count)
return feature_count_;
}
inline void RouteSummary::set_feature_count(::google::protobuf::int32 value) {
feature_count_ = value;
// @@protoc_insertion_point(field_set:examples.RouteSummary.feature_count)
}
// optional int32 distance = 3;
inline void RouteSummary::clear_distance() {
distance_ = 0;
}
inline ::google::protobuf::int32 RouteSummary::distance() const {
// @@protoc_insertion_point(field_get:examples.RouteSummary.distance)
return distance_;
}
inline void RouteSummary::set_distance(::google::protobuf::int32 value) {
distance_ = value;
// @@protoc_insertion_point(field_set:examples.RouteSummary.distance)
}
// optional int32 elapsed_time = 4;
inline void RouteSummary::clear_elapsed_time() {
elapsed_time_ = 0;
}
inline ::google::protobuf::int32 RouteSummary::elapsed_time() const {
// @@protoc_insertion_point(field_get:examples.RouteSummary.elapsed_time)
return elapsed_time_;
}
inline void RouteSummary::set_elapsed_time(::google::protobuf::int32 value) {
elapsed_time_ = value;
// @@protoc_insertion_point(field_set:examples.RouteSummary.elapsed_time)
}
class RouteGuide final {
public:
class Stub final : public ::grpc::InternalStub {
public:
::grpc::Status GetFeature(::grpc::ClientContext* context, const ::examples::Point& request, ::examples::Feature* response);
::grpc::ClientAsyncResponseReader< ::examples::Feature>* GetFeature(::grpc::ClientContext* context, const ::examples::Point& request, ::grpc::CompletionQueue* cq, void* tag);
::grpc::ClientReader< ::examples::Feature>* ListFeatures(::grpc::ClientContext* context, const ::examples::Rectangle& request);
::grpc::ClientAsyncReader< ::examples::Feature>* ListFeatures(::grpc::ClientContext* context, const ::examples::Rectangle& request, ::grpc::CompletionQueue* cq, void* tag);
::grpc::ClientWriter< ::examples::Point>* RecordRoute(::grpc::ClientContext* context, ::examples::RouteSummary* response);
::grpc::ClientAsyncWriter< ::examples::Point>* RecordRoute(::grpc::ClientContext* context, ::examples::RouteSummary* response, ::grpc::CompletionQueue* cq, void* tag);
::grpc::ClientReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* RouteChat(::grpc::ClientContext* context);
::grpc::ClientAsyncReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* RouteChat(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag);
};
static Stub* NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel);
class Service : public ::grpc::SynchronousService {
public:
Service() : service_(nullptr) {}
virtual ~Service();
virtual ::grpc::Status GetFeature(::grpc::ServerContext* context, const ::examples::Point* request, ::examples::Feature* response);
virtual ::grpc::Status ListFeatures(::grpc::ServerContext* context, const ::examples::Rectangle* request, ::grpc::ServerWriter< ::examples::Feature>* writer);
virtual ::grpc::Status RecordRoute(::grpc::ServerContext* context, ::grpc::ServerReader< ::examples::Point>* reader, ::examples::RouteSummary* response);
virtual ::grpc::Status RouteChat(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* stream);
::grpc::RpcService* service() override final;
private:
::grpc::RpcService* service_;
};
class AsyncService final : public ::grpc::AsynchronousService {
public:
explicit AsyncService(::grpc::CompletionQueue* cq);
~AsyncService() {};
void RequestGetFeature(::grpc::ServerContext* context, ::examples::Point* request, ::grpc::ServerAsyncResponseWriter< ::examples::Feature>* response, ::grpc::CompletionQueue* cq, void *tag);
void RequestListFeatures(::grpc::ServerContext* context, ::examples::Rectangle* request, ::grpc::ServerAsyncWriter< ::examples::Feature>* writer, ::grpc::CompletionQueue* cq, void *tag);
void RequestRecordRoute(::grpc::ServerContext* context, ::grpc::ServerAsyncReader< ::examples::RouteSummary, ::examples::Point>* reader, ::grpc::CompletionQueue* cq, void *tag);
void RequestRouteChat(::grpc::ServerContext* context, ::grpc::ServerAsyncReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* stream, ::grpc::CompletionQueue* cq, void *tag);
};
};
// @@protoc_insertion_point(namespace_scope)
} // namespace examples
#ifndef SWIG
namespace google {
namespace protobuf {
} // namespace protobuf
} // namespace google
#endif // SWIG
// @@protoc_insertion_point(global_scope)
#endif // PROTOBUF_route_5fguide_2eproto__INCLUDED

@ -41,51 +41,110 @@
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
#include <grpc++/status.h>
#include "helloworld.pb.h"
#include <grpc++/stream.h>
#include "route_guide.pb.h"
using grpc::ChannelArguments;
using grpc::ChannelInterface;
using grpc::ClientContext;
using grpc::ClientReader;
using grpc::ClientReaderWriter;
using grpc::ClientWriter;
using grpc::Status;
using helloworld::HelloRequest;
using helloworld::HelloReply;
using helloworld::Greeter;
using examples::Point;
using examples::Feature;
using examples::Rectangle;
using examples::RouteSummary;
using examples::RouteNote;
using examples::RouteGuide;
class GreeterClient {
class RouteGuideClient {
public:
GreeterClient(std::shared_ptr<ChannelInterface> channel)
: stub_(Greeter::NewStub(channel)) {}
RouteGuideClient(std::shared_ptr<ChannelInterface> channel)
: stub_(RouteGuide::NewStub(channel)) {}
std::string SayHello(const std::string& user) {
HelloRequest request;
request.set_name(user);
HelloReply reply;
void GetFeature() {
Point point;
Feature feature;
ClientContext context;
Status status = stub_->sayHello(&context, request, &reply);
Status status = stub_->GetFeature(&context, point, &feature);
if (status.IsOk()) {
return reply.message();
std::cout << "GetFeature rpc succeeded." << std::endl;
} else {
return "Rpc failed";
std::cout << "GetFeature rpc failed." << std::endl;
}
}
void ListFeatures() {
Rectangle rect;
Feature feature;
ClientContext context;
std::unique_ptr<ClientReader<Feature> > reader(
stub_->ListFeatures(&context, rect));
while (reader->Read(&feature)) {
std::cout << "Received feature" << std::endl;
}
Status status = reader->Finish();
if (status.IsOk()) {
std::cout << "ListFeatures rpc succeeded." << std::endl;
} else {
std::cout << "ListFeatures rpc failed." << std::endl;
}
}
void RecordRoute() {
Point point;
RouteSummary summary;
ClientContext context;
std::unique_ptr<ClientWriter<Point> > writer(
stub_->RecordRoute(&context, &summary));
writer->WritesDone();
Status status = writer->Finish();
if (status.IsOk()) {
std::cout << "RecordRoute rpc succeeded." << std::endl;
} else {
std::cout << "RecordRoute rpc failed." << std::endl;
}
}
void RouteChat() {
RouteNote server_note;
ClientContext context;
std::unique_ptr<ClientReaderWriter<RouteNote, RouteNote> > stream(
stub_->RouteChat(&context));
stream->WritesDone();
while (stream->Read(&server_note)) {
}
Status status = stream->Finish();
if (status.IsOk()) {
std::cout << "RouteChat rpc succeeded." << std::endl;
} else {
std::cout << "RouteChat rpc failed." << std::endl;
}
}
void Shutdown() { stub_.reset(); }
private:
std::unique_ptr<Greeter::Stub> stub_;
std::unique_ptr<RouteGuide::Stub> stub_;
};
int main(int argc, char** argv) {
grpc_init();
GreeterClient greeter(
RouteGuideClient guide(
grpc::CreateChannel("localhost:50051", ChannelArguments()));
std::string user("world");
std::string reply = greeter.SayHello(user);
std::cout << "Greeter received: " << reply << std::endl;
greeter.Shutdown();
guide.GetFeature();
guide.ListFeatures();
guide.RecordRoute();
guide.RouteChat();
guide.Shutdown();
grpc_shutdown();
}

@ -41,28 +41,45 @@
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
#include <grpc++/status.h>
#include "helloworld.pb.h"
#include <grpc++/stream.h>
#include "route_guide.pb.h"
using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::ServerReader;
using grpc::ServerReaderWriter;
using grpc::ServerWriter;
using grpc::Status;
using helloworld::HelloRequest;
using helloworld::HelloReply;
using helloworld::Greeter;
using examples::Point;
using examples::Feature;
using examples::Rectangle;
using examples::RouteSummary;
using examples::RouteNote;
using examples::RouteGuide;
class GreeterServiceImpl final : public Greeter::Service {
Status sayHello(ServerContext* context, const HelloRequest* request,
HelloReply* reply) override {
std::string prefix("Hello ");
reply->set_message(prefix + request->name());
class RouteGuideImpl final : public RouteGuide::Service {
Status GetFeature(ServerContext* context, const Point* point,
Feature* feature) override {
return Status::OK;
}
Status ListFeatures(ServerContext* context, const Rectangle* rectangle,
ServerWriter<Feature>* writer) override {
return Status::OK;
}
Status RecordRoute(ServerContext* context, ServerReader<Point>* reader,
RouteSummary* summary) override {
return Status::OK;
}
Status RouteChat(ServerContext* context,
ServerReaderWriter<RouteNote, RouteNote>* stream) override {
return Status::OK;
}
};
void RunServer() {
std::string server_address("0.0.0.0:50051");
GreeterServiceImpl service;
RouteGuideImpl service;
ServerBuilder builder;
builder.AddPort(server_address);

Loading…
Cancel
Save