diff --git a/services/backup/src/Reactors/server/AddAttachmentReactor.h b/services/backup/src/Reactors/server/AddAttachmentReactor.h new file mode 100644 --- /dev/null +++ b/services/backup/src/Reactors/server/AddAttachmentReactor.h @@ -0,0 +1,65 @@ +#pragma once + +#include "DatabaseEntitiesTools.h" +#include "ServerReadReactorBase.h" +#include "ServiceBlobClient.h" + +#include "../_generated/backup.grpc.pb.h" +#include "../_generated/backup.pb.h" + +#include +#include + +namespace comm { +namespace network { +namespace reactor { + +class AddAttachmentReactor : public ServerReadReactorBase< + backup::AddAttachmentRequest, + google::protobuf::Empty> { + enum class State { + USER_ID = 1, + BACKUP_ID = 2, + LOG_ID = 3, + DATA_HASH = 4, + DATA_CHUNK = 5, + }; + + enum class ParentType { + UNKNOWN = 0, + BACKUP = 1, + LOG = 2, + }; + + State state = State::USER_ID; + ParentType parentType = ParentType::UNKNOWN; + std::string userID; + std::shared_ptr backupItem; + std::shared_ptr logItem; + std::string logID; + std::string holder; + std::string hash; + std::mutex reactorStateMutex; + + std::condition_variable blobPutDoneCV; + std::mutex blobPutDoneCVMutex; + + std::shared_ptr putReactor; + ServiceBlobClient blobClient; + + void initializePutReactor(); + void storeInDatabase(); + +public: + using ServerReadReactorBase< + backup::AddAttachmentRequest, + google::protobuf::Empty>::ServerReadReactorBase; + + std::unique_ptr + readRequest(backup::AddAttachmentRequest request) override; + void terminateCallback() override; +}; + +} // namespace reactor +} // namespace network +} // namespace comm diff --git a/services/backup/src/Reactors/server/AddAttachmentReactor.cpp b/services/backup/src/Reactors/server/AddAttachmentReactor.cpp new file mode 100644 --- /dev/null +++ b/services/backup/src/Reactors/server/AddAttachmentReactor.cpp @@ -0,0 +1,45 @@ +#include "AddAttachmentReactor.h" + +#include "Constants.h" +#include "DatabaseManager.h" +#include "GlobalTools.h" +#include "Tools.h" + +#include + +namespace comm { +namespace network { +namespace reactor { + +void AddAttachmentReactor::initializePutReactor() { +} + +void AddAttachmentReactor::storeInDatabase() { +} + +std::unique_ptr +AddAttachmentReactor::readRequest(backup::AddAttachmentRequest request) { + // we make sure that the blob client's state is flushed to the main memory + // as there may be multiple threads from the pool taking over here + const std::lock_guard lock(this->reactorStateMutex); + switch (this->state) { + case State::USER_ID: { + }; + case State::BACKUP_ID: { + }; + case State::LOG_ID: { + }; + case State::DATA_HASH: { + }; + case State::DATA_CHUNK: { + }; + } + throw std::runtime_error("send attachment - invalid state"); +} + +void AddAttachmentReactor::terminateCallback() { +} + +} // namespace reactor +} // namespace network +} // namespace comm