Page MenuHomePhabricator

D3514.id10891.diff
No OneTemporary

D3514.id10891.diff

diff --git a/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientReadReactorBase.h b/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientReadReactorBase.h
new file mode 100644
--- /dev/null
+++ b/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientReadReactorBase.h
@@ -0,0 +1,78 @@
+#include <grpcpp/grpcpp.h>
+
+namespace comm {
+namespace network {
+namespace reactor {
+
+template <class Request, class Response>
+class ClientReadReactorBase : public grpc::ClientReadReactor<Response> {
+ Response response;
+ grpc::Status status;
+ bool done = false;
+ bool initialized = false;
+
+ void terminate(const grpc::Status &status);
+
+public:
+ Request request;
+ grpc::ClientContext context;
+
+ void start();
+ void OnReadDone(bool ok) override;
+ void OnDone(const grpc::Status &status) override;
+ bool isDone();
+
+ virtual std::unique_ptr<grpc::Status>
+ readResponse(const Response &response) = 0;
+ virtual void doneCallback() {
+ }
+};
+
+template <class Request, class Response>
+void ClientReadReactorBase<Request, Response>::terminate(
+ const grpc::Status &status) {
+ if (this->done) {
+ return;
+ }
+ this->status = status;
+ this->done = true;
+ this->doneCallback();
+}
+
+template <class Request, class Response>
+void ClientReadReactorBase<Request, Response>::start() {
+ this->StartRead(&this->response);
+ if (!this->initialized) {
+ this->StartCall();
+ this->initialized = true;
+ }
+}
+
+template <class Request, class Response>
+void ClientReadReactorBase<Request, Response>::OnReadDone(bool ok) {
+ if (!ok) {
+ this->terminate(grpc::Status(grpc::StatusCode::UNKNOWN, "read error"));
+ return;
+ }
+ std::unique_ptr<grpc::Status> status = this->readResponse(this->response);
+ if (status != nullptr) {
+ this->terminate(*status);
+ return;
+ }
+ this->StartRead(&this->response);
+}
+
+template <class Request, class Response>
+void ClientReadReactorBase<Request, Response>::OnDone(
+ const grpc::Status &status) {
+ this->terminate(status);
+}
+
+template <class Request, class Response>
+bool ClientReadReactorBase<Request, Response>::isDone() {
+ return this->done;
+}
+
+} // namespace reactor
+} // namespace network
+} // namespace comm

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 26, 6:01 PM (12 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2704079
Default Alt Text
D3514.id10891.diff (2 KB)

Event Timeline