Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3531139
D3515.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D3515.diff
View Options
diff --git a/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientWriteReactorBase.h b/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientWriteReactorBase.h
new file mode 100644
--- /dev/null
+++ b/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientWriteReactorBase.h
@@ -0,0 +1,78 @@
+#include <grpcpp/grpcpp.h>
+
+namespace comm {
+namespace network {
+namespace reactor {
+
+template <class Request, class Response>
+class ClientWriteReactorBase : public grpc::ClientWriteReactor<Request> {
+ grpc::Status status;
+ bool done = false;
+ bool initialized = 0;
+ Request request;
+
+public:
+ Response response;
+ grpc::ClientContext context;
+
+ void nextWrite();
+ void OnWriteDone(bool ok) override;
+ void terminate(const grpc::Status &status);
+ bool isDone();
+ void OnDone(const grpc::Status &status) override;
+
+ virtual std::unique_ptr<grpc::Status> prepareRequest(Request &request) = 0;
+ virtual void doneCallback() {
+ }
+};
+
+template <class Request, class Response>
+void ClientWriteReactorBase<Request, Response>::nextWrite() {
+ this->request = Request();
+ std::unique_ptr<grpc::Status> status = this->prepareRequest(this->request);
+ if (status != nullptr) {
+ this->terminate(*status);
+ return;
+ }
+ this->StartWrite(&this->request);
+ if (!this->initialized) {
+ this->StartCall();
+ this->initialized = true;
+ }
+}
+
+template <class Request, class Response>
+void ClientWriteReactorBase<Request, Response>::OnWriteDone(bool ok) {
+ if (!ok) {
+ this->terminate(grpc::Status(grpc::StatusCode::UNKNOWN, "write error"));
+ return;
+ }
+ this->nextWrite();
+}
+
+template <class Request, class Response>
+void ClientWriteReactorBase<Request, Response>::terminate(
+ const grpc::Status &status) {
+ if (this->done) {
+ return;
+ }
+ this->status = status;
+ this->done = true;
+ this->StartWritesDone();
+ this->doneCallback();
+}
+
+template <class Request, class Response>
+bool ClientWriteReactorBase<Request, Response>::isDone() {
+ return this->done;
+}
+
+template <class Request, class Response>
+void ClientWriteReactorBase<Request, Response>::OnDone(
+ const grpc::Status &status) {
+ this->terminate(status);
+}
+
+} // namespace reactor
+} // namespace network
+} // namespace comm
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 26, 6:12 AM (12 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2704053
Default Alt Text
D3515.diff (2 KB)
Attached To
Mode
D3515: [services] Backup - Add client reactor base classes - write reactor
Attached
Detach File
Event Timeline
Log In to Comment