|
|
@ -151,24 +151,25 @@ class RouteGuideImpl final : public RouteGuide::Service { |
|
|
|
|
|
|
|
|
|
|
|
Status RouteChat(ServerContext* context, |
|
|
|
Status RouteChat(ServerContext* context, |
|
|
|
ServerReaderWriter<RouteNote, RouteNote>* stream) override { |
|
|
|
ServerReaderWriter<RouteNote, RouteNote>* stream) override { |
|
|
|
std::vector<RouteNote> received_notes; |
|
|
|
|
|
|
|
RouteNote note; |
|
|
|
RouteNote note; |
|
|
|
while (stream->Read(¬e)) { |
|
|
|
while (stream->Read(¬e)) { |
|
|
|
for (const RouteNote& n : received_notes) { |
|
|
|
std::unique_lock<std::mutex> lock(mu_); |
|
|
|
|
|
|
|
for (const RouteNote& n : received_notes_) { |
|
|
|
if (n.location().latitude() == note.location().latitude() && |
|
|
|
if (n.location().latitude() == note.location().latitude() && |
|
|
|
n.location().longitude() == note.location().longitude()) { |
|
|
|
n.location().longitude() == note.location().longitude()) { |
|
|
|
stream->Write(n); |
|
|
|
stream->Write(n); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
received_notes.push_back(note); |
|
|
|
received_notes_.push_back(note); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return Status::OK; |
|
|
|
return Status::OK; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
|
|
|
|
|
|
|
|
std::vector<Feature> feature_list_; |
|
|
|
std::vector<Feature> feature_list_; |
|
|
|
|
|
|
|
std::mutex mu_; |
|
|
|
|
|
|
|
std::vector<RouteNote> received_notes_; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
void RunServer(const std::string& db_path) { |
|
|
|
void RunServer(const std::string& db_path) { |
|
|
|