Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3377835
D3512.id10639.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D3512.id10639.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 28, 7:44 AM (20 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2593279
Default Alt Text
D3512.id10639.diff (3 KB)
Attached To
Mode
D3512: [services] Backup - Add server reactor base classes - read reactor
Attached
Detach File
Event Timeline
Log In to Comment