diff --git a/services/backup/docker-server/contents/server/src/BackupServiceImpl.cpp b/services/backup/docker-server/contents/server/src/BackupServiceImpl.cpp index d7fa77ada..a7650bf1c 100644 --- a/services/backup/docker-server/contents/server/src/BackupServiceImpl.cpp +++ b/services/backup/docker-server/contents/server/src/BackupServiceImpl.cpp @@ -1,48 +1,120 @@ #include "BackupServiceImpl.h" +#include "BidiReactorBase.h" +#include "ReadReactorBase.h" + #include namespace comm { namespace network { BackupServiceImpl::BackupServiceImpl() { Aws::InitAPI({}); } BackupServiceImpl::~BackupServiceImpl() { Aws::ShutdownAPI({}); } -grpc::Status BackupServiceImpl::CreateNewBackup( - grpc::ServerContext *context, - grpc::ServerReaderWriter< - backup::CreateNewBackupResponse, - backup::CreateNewBackupRequest> *stream) { - return grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "not implemented yet"); +grpc::ServerBidiReactor< + backup::CreateNewBackupRequest, + backup::CreateNewBackupResponse> * +BackupServiceImpl::CreateNewBackup(grpc::CallbackServerContext *context) { + class CreateNewBackupReactor : public BidiReactorBase< + backup::CreateNewBackupRequest, + backup::CreateNewBackupResponse> { + auth::AuthenticationManager authenticationManager; + + public: + std::unique_ptr handleRequest( + backup::CreateNewBackupRequest request, + backup::CreateNewBackupResponse *response) override { + if (this->authenticationManager.getState() != + auth::AuthenticationState::SUCCESS && + !request.has_authenticationrequestdata()) { + return std::make_unique( + grpc::StatusCode::INTERNAL, + "authentication has not been finished properly"); + } + if (this->authenticationManager.getState() == + auth::AuthenticationState::FAIL) { + return std::make_unique( + grpc::StatusCode::INTERNAL, "authentication failure"); + } + if (this->authenticationManager.getState() != + auth::AuthenticationState::SUCCESS) { + backup::FullAuthenticationResponseData *authResponse = + this->authenticationManager.processRequest( + request.authenticationrequestdata()); + response->set_allocated_authenticationresponsedata(authResponse); + return nullptr; + } + // TODO handle request + return std::make_unique( + grpc::StatusCode::UNIMPLEMENTED, "unimplemented"); + } + }; + + return new CreateNewBackupReactor(); } -grpc::Status BackupServiceImpl::SendLog( - grpc::ServerContext *context, - grpc::ServerReader *reader, +grpc::ServerReadReactor *BackupServiceImpl::SendLog( + grpc::CallbackServerContext *context, google::protobuf::Empty *response) { - return grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "not implemented yet"); + class SendLogReactor : public ReadReactorBase< + backup::SendLogRequest, + google::protobuf::Empty> { + public: + using ReadReactorBase:: + ReadReactorBase; + std::unique_ptr + readRequest(backup::SendLogRequest request) override { + // TODO handle request + return std::make_unique( + grpc::StatusCode::UNIMPLEMENTED, "unimplemented"); + } + }; + + return new SendLogReactor(response); } -grpc::Status BackupServiceImpl::RecoverBackupKey( - grpc::ServerContext *context, - grpc::ServerReaderWriter< - backup::RecoverBackupKeyResponse, - backup::RecoverBackupKeyRequest> *stream) { - return grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "not implemented yet"); +grpc::ServerBidiReactor< + backup::RecoverBackupKeyRequest, + backup::RecoverBackupKeyResponse> * +BackupServiceImpl::RecoverBackupKey(grpc::CallbackServerContext *context) { + class RecoverBackupKeyReactor : public BidiReactorBase< + backup::RecoverBackupKeyRequest, + backup::RecoverBackupKeyResponse> { + public: + std::unique_ptr handleRequest( + backup::RecoverBackupKeyRequest request, + backup::RecoverBackupKeyResponse *response) override { + // TODO handle request + return std::make_unique( + grpc::StatusCode::UNIMPLEMENTED, "unimplemented"); + } + }; + + return new RecoverBackupKeyReactor(); } -grpc::Status BackupServiceImpl::PullBackup( - grpc::ServerContext *context, - grpc::ServerReaderWriter< - backup::PullBackupResponse, - backup::PullBackupRequest> *stream) { - return grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "not implemented yet"); +grpc::ServerBidiReactor * +BackupServiceImpl::PullBackup(grpc::CallbackServerContext *context) { + class PullBackupReactor : public BidiReactorBase< + backup::PullBackupRequest, + backup::PullBackupResponse> { + public: + std::unique_ptr handleRequest( + backup::PullBackupRequest request, + backup::PullBackupResponse *response) override { + // TODO handle request + return std::make_unique( + grpc::StatusCode::UNIMPLEMENTED, "unimplemented"); + } + }; + + return new PullBackupReactor(); } } // namespace network } // namespace comm diff --git a/services/backup/docker-server/contents/server/src/BackupServiceImpl.h b/services/backup/docker-server/contents/server/src/BackupServiceImpl.h index 3be780b8d..caa197aa1 100644 --- a/services/backup/docker-server/contents/server/src/BackupServiceImpl.h +++ b/services/backup/docker-server/contents/server/src/BackupServiceImpl.h @@ -1,39 +1,36 @@ #pragma once #include "../_generated/backup.grpc.pb.h" #include "../_generated/backup.pb.h" #include namespace comm { namespace network { -class BackupServiceImpl final : public backup::BackupService::Service { +class BackupServiceImpl final : public backup::BackupService::CallbackService { public: BackupServiceImpl(); virtual ~BackupServiceImpl(); - grpc::Status CreateNewBackup( - grpc::ServerContext *context, - grpc::ServerReaderWriter< - backup::CreateNewBackupResponse, - backup::CreateNewBackupRequest> *stream) override; - grpc::Status SendLog( - grpc::ServerContext *context, - grpc::ServerReader *reader, + grpc::ServerBidiReactor< + backup::CreateNewBackupRequest, + backup::CreateNewBackupResponse> * + CreateNewBackup(grpc::CallbackServerContext *context) override; + + grpc::ServerReadReactor *SendLog( + grpc::CallbackServerContext *context, google::protobuf::Empty *response) override; - grpc::Status RecoverBackupKey( - grpc::ServerContext *context, - grpc::ServerReaderWriter< - backup::RecoverBackupKeyResponse, - backup::RecoverBackupKeyRequest> *stream) override; - grpc::Status PullBackup( - grpc::ServerContext *context, - grpc::ServerReaderWriter< - backup::PullBackupResponse, - backup::PullBackupRequest> *stream) override; + + grpc::ServerBidiReactor< + backup::RecoverBackupKeyRequest, + backup::RecoverBackupKeyResponse> * + RecoverBackupKey(grpc::CallbackServerContext *context) override; + + grpc::ServerBidiReactor + *PullBackup(grpc::CallbackServerContext *context) override; }; } // namespace network } // namespace comm