Page MenuHomePhabricator

D3512.id10639.diff
No OneTemporary

D3512.id10639.diff

diff --git a/services/backup/docker-server/contents/server/src/BackupServiceImpl.cpp b/services/backup/docker-server/contents/server/src/BackupServiceImpl.cpp
--- a/services/backup/docker-server/contents/server/src/BackupServiceImpl.cpp
+++ b/services/backup/docker-server/contents/server/src/BackupServiceImpl.cpp
@@ -39,12 +39,13 @@
grpc::ServerReadReactor<backup::SendLogRequest> *BackupServiceImpl::SendLog(
grpc::CallbackServerContext *context,
google::protobuf::Empty *response) {
- class SendLogReactor
- : public reactor::
- ReadReactorBase<backup::SendLogRequest, google::protobuf::Empty> {
+ class SendLogReactor : public reactor::ServerReadReactorBase<
+ backup::SendLogRequest,
+ google::protobuf::Empty> {
public:
- using ReadReactorBase<backup::SendLogRequest, google::protobuf::Empty>::
- ReadReactorBase;
+ using ServerReadReactorBase<
+ backup::SendLogRequest,
+ google::protobuf::Empty>::ServerReadReactorBase;
std::unique_ptr<grpc::Status>
readRequest(backup::SendLogRequest request) override {
// TODO handle request
diff --git a/services/backup/docker-server/contents/server/src/Reactors/server/base-reactors/ServerReadReactorBase.h b/services/backup/docker-server/contents/server/src/Reactors/server/base-reactors/ServerReadReactorBase.h
--- a/services/backup/docker-server/contents/server/src/Reactors/server/base-reactors/ServerReadReactorBase.h
+++ b/services/backup/docker-server/contents/server/src/Reactors/server/base-reactors/ServerReadReactorBase.h
@@ -1,59 +1,75 @@
#pragma once
#include <grpcpp/grpcpp.h>
+
#include <iostream>
#include <memory>
#include <string>
namespace comm {
namespace network {
+namespace reactor {
template <class Request, class Response>
-class ReadReactorBase : public grpc::ServerReadReactor<Request> {
+class ServerReadReactorBase : public grpc::ServerReadReactor<Request> {
Request request;
+ void terminate(grpc::Status status);
+
protected:
Response *response;
+ grpc::Status status;
public:
- ReadReactorBase(Response *response);
+ ServerReadReactorBase(Response *response);
void OnDone() override;
void OnReadDone(bool ok) override;
virtual std::unique_ptr<grpc::Status> readRequest(Request request) = 0;
+ virtual void initialize(){};
+ virtual void doneCallback(){};
};
template <class Request, class Response>
-ReadReactorBase<Request, Response>::ReadReactorBase(Response *response)
+void ServerReadReactorBase<Request, Response>::terminate(grpc::Status status) {
+ this->status = status;
+ this->Finish(status);
+}
+
+template <class Request, class Response>
+ServerReadReactorBase<Request, Response>::ServerReadReactorBase(
+ Response *response)
: response(response) {
+ this->initialize();
this->StartRead(&this->request);
}
template <class Request, class Response>
-void ReadReactorBase<Request, Response>::OnDone() {
+void ServerReadReactorBase<Request, Response>::OnDone() {
+ this->doneCallback();
delete this;
}
template <class Request, class Response>
-void ReadReactorBase<Request, Response>::OnReadDone(bool ok) {
+void ServerReadReactorBase<Request, Response>::OnReadDone(bool ok) {
if (!ok) {
- this->Finish(
- grpc::Status(grpc::StatusCode::INTERNAL, "OnReadDone: reading error"));
+ this->terminate(grpc::Status(grpc::StatusCode::INTERNAL, "reading error"));
return;
}
try {
std::unique_ptr<grpc::Status> status = this->readRequest(this->request);
if (status != nullptr) {
- this->Finish(*status);
+ this->terminate(*status);
return;
}
} catch (std::runtime_error &e) {
- this->Finish(grpc::Status(grpc::StatusCode::INTERNAL, e.what()));
+ this->terminate(grpc::Status(grpc::StatusCode::INTERNAL, e.what()));
return;
}
this->StartRead(&this->request);
}
+} // namespace reactor
} // namespace network
} // namespace comm

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 1, 1:16 AM (15 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2603122
Default Alt Text
D3512.id10639.diff (3 KB)

Event Timeline