Skip to content
Snippets Groups Projects
Verified Commit 4b921fdb authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: files

parent 4e053068
No related branches found
No related tags found
1 merge request!11F files
Pipeline #11998 passed
Pipeline: caosdb-cppinttest

#12038

    Showing
    with 377 additions and 122 deletions
    ......@@ -27,6 +27,7 @@ set(libcaosdb_INCL
    ${CMAKE_CURRENT_BINARY_DIR}/caosdb/constants.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/entity.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/exceptions.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/handler_interface.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/info.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/log_level.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/logging.h
    ......@@ -34,12 +35,14 @@ set(libcaosdb_INCL
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/protobuf_helper.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/status_code.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/transaction.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/transaction_handler.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/transaction_status.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/unary_rpc_handler.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/utility.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/register_file_upload_handler.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/Client.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/UploadRequestHandler.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/DownloadRequestHandler.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/HandlerInterface.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/FileWriter.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/FileReader.h
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/FileLock.h
    ......
    #include "caosdb/entity.h" // for FileDescriptor
    #include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for FileTransmissionS...
    #include "caosdb/file_transmission/HandlerInterface.h" // for HandlerInterface
    #include "caosdb/handler_interface.h" // for HandlerInterface
    #include "caosdb/status_code.h" // for StatusCode
    #include "caosdb/transaction_status.h" // for StatusCode
    #include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue
    #include <memory> // for shared_ptr, uniqu...
    namespace FileExchange {
    namespace caosdb::transaction {
    using caosdb::StatusCode;
    using caosdb::entity::FileDescriptor;
    using caosdb::entity::v1alpha1::FileTransmissionService;
    ......@@ -26,7 +27,7 @@ public:
    StatusCode upload(const FileDescriptor &file_descriptor);
    StatusCode download(const FileDescriptor &file_descriptor);
    void cancel();
    void Cancel();
    private:
    int processMessages();
    ......@@ -37,4 +38,4 @@ private:
    std::unique_ptr<HandlerInterface> handler_;
    };
    } // namespace FileExchange
    } // namespace caosdb::transaction
    ......@@ -2,18 +2,21 @@
    #include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for FileTransmissionS...
    #include "caosdb/entity/v1alpha1/main.pb.h" // for FileDownloadResponse
    #include "caosdb/file_transmission/FileWriter.h" // for FileWriter
    #include "caosdb/file_transmission/HandlerInterface.h" // for HandlerTag, Handl...
    #include "caosdb/handler_interface.h" // for HandlerTag, Handl...
    #include "caosdb/transaction_status.h" // for TransactionStatus
    #include <grpcpp/impl/codegen/async_stream.h> // for ClientAsyncReader
    #include <grpcpp/impl/codegen/client_context.h> // for ClientContext
    #include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue
    #include <grpcpp/impl/codegen/status.h> // for Status
    #include <memory> // for unique_ptr
    namespace FileExchange {
    namespace caosdb::transaction {
    using caosdb::entity::FileDescriptor;
    using caosdb::entity::v1alpha1::FileDownloadRequest;
    using caosdb::entity::v1alpha1::FileDownloadResponse;
    using caosdb::entity::v1alpha1::FileTransmissionService;
    using caosdb::transaction::HandlerInterface;
    using caosdb::transaction::HandlerTag;
    class DownloadRequestHandler final : public HandlerInterface {
    public:
    ......@@ -28,9 +31,15 @@ public:
    DownloadRequestHandler(DownloadRequestHandler &&) = delete;
    DownloadRequestHandler &operator=(DownloadRequestHandler &&) = delete;
    bool onNext(bool ok) override;
    TransactionStatus GetStatus() override {
    return TransactionStatus::EXECUTING();
    }
    void cancel() override;
    void Start() override { OnNext(true); }
    bool OnNext(bool ok) override;
    void Cancel() override;
    protected:
    enum class CallState { NewCall, SendingRequest, ReceivingFile, CallComplete };
    ......@@ -61,4 +70,4 @@ protected:
    unsigned long long bytesReceived_;
    };
    } // namespace FileExchange
    } // namespace caosdb::transaction
    ......@@ -3,7 +3,7 @@
    #include <stdexcept>
    #include <string>
    namespace FileExchange {
    namespace caosdb::transaction {
    class FileLockError : public std::runtime_error {
    public:
    ......@@ -21,4 +21,4 @@ public:
    : std::runtime_error(message) {}
    };
    } // namespace FileExchange
    } // namespace caosdb::transaction
    ......@@ -3,10 +3,10 @@
    #include <mutex>
    #include <shared_mutex>
    namespace FileExchange {
    namespace caosdb::transaction {
    using FileMutex = std::shared_timed_mutex;
    using FileReadLock = std::shared_lock<FileMutex>;
    using FileWriteLock = std::unique_lock<FileMutex>;
    } // namespace FileExchange
    } // namespace caosdb::transaction
    ......@@ -8,7 +8,7 @@
    #include <memory> // for shared_ptr
    #include <string> // for string
    namespace FileExchange {
    namespace caosdb::transaction {
    using boost::filesystem::exists;
    using boost::filesystem::ifstream;
    using boost::filesystem::path;
    ......@@ -42,4 +42,4 @@ private:
    FileReadLock lock_;
    };
    } // namespace FileExchange
    } // namespace caosdb::transaction
    ......@@ -6,7 +6,7 @@
    #include <memory> // for shared_ptr
    #include <string> // for string
    namespace FileExchange {
    namespace caosdb::transaction {
    class FileWriter final {
    public:
    ......@@ -34,4 +34,4 @@ private:
    FileWriteLock lock_;
    };
    } // namespace FileExchange
    } // namespace caosdb::transaction
    #pragma once
    #include <memory>
    #include <string>
    namespace FileExchange {
    const std::string logger_name("caosdb::transaction::file_transmission");
    class HandlerInterface {
    public:
    virtual ~HandlerInterface() = default;
    virtual bool onNext(bool ok) = 0;
    virtual void cancel() = 0;
    };
    using HandlerPtr = std::unique_ptr<HandlerInterface>;
    using HandlerTag = HandlerPtr *;
    } // namespace FileExchange
    MIT License
    Copyright (c) 2019 NeiRo21
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.
    ......@@ -2,7 +2,8 @@
    #include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for FileTransmissionS...
    #include "caosdb/entity/v1alpha1/main.pb.h" // for FileUploadRequest
    #include "caosdb/file_transmission/FileReader.h" // for FileReader
    #include "caosdb/file_transmission/HandlerInterface.h" // for HandlerTag, Handl...
    #include "caosdb/handler_interface.h" // for HandlerTag, Handl...
    #include "caosdb/transaction_status.h" // for TransactionStatus
    #include <cstdint> // for uint64_t
    #include <grpcpp/impl/codegen/async_stream.h> // for ClientAsyncWriter
    #include <grpcpp/impl/codegen/client_context.h> // for ClientContext
    ......@@ -10,11 +11,13 @@
    #include <grpcpp/impl/codegen/status.h> // for Status
    #include <memory> // for unique_ptr
    namespace FileExchange {
    namespace caosdb::transaction {
    using caosdb::entity::FileDescriptor;
    using caosdb::entity::v1alpha1::FileTransmissionService;
    using caosdb::entity::v1alpha1::FileUploadRequest;
    using caosdb::entity::v1alpha1::FileUploadResponse;
    using caosdb::transaction::HandlerInterface;
    using caosdb::transaction::HandlerTag;
    class UploadRequestHandler final : public HandlerInterface {
    public:
    ......@@ -29,9 +32,15 @@ public:
    UploadRequestHandler(UploadRequestHandler &&) = delete;
    UploadRequestHandler &operator=(UploadRequestHandler &&) = delete;
    bool onNext(bool ok) override;
    TransactionStatus GetStatus() override {
    return TransactionStatus::EXECUTING();
    }
    void cancel() override;
    void Start() override { OnNext(true); }
    bool OnNext(bool ok) override;
    void Cancel() override;
    protected:
    enum class CallState {
    ......@@ -69,4 +78,4 @@ protected:
    uint64_t bytesToSend_;
    };
    } // namespace FileExchange
    } // namespace caosdb::transaction
    #pragma once
    #include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for FileTransmissionS...
    #include "caosdb/entity/v1alpha1/main.pb.h" // for FileDownloadResponse
    #include "caosdb/handler_interface.h" // for HandlerTag, Handl...
    #include "caosdb/unary_rpc_handler.h"
    #include <grpcpp/impl/codegen/async_unary_call.h> // for ClientAsyncRespons...
    #include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue
    #include <memory> // for unique_ptr
    namespace caosdb::transaction {
    using caosdb::entity::v1alpha1::FileTransmissionService;
    using caosdb::entity::v1alpha1::RegisterFileUploadRequest;
    using caosdb::entity::v1alpha1::RegisterFileUploadResponse;
    class RegisterFileUploadHandler final : public UnaryRpcHandler {
    public:
    RegisterFileUploadHandler(HandlerTag tag, FileTransmissionService::Stub *stub,
    grpc::CompletionQueue *completion_queue,
    RegisterFileUploadRequest *request,
    RegisterFileUploadResponse *response);
    ~RegisterFileUploadHandler();
    RegisterFileUploadHandler(const RegisterFileUploadHandler &) = delete;
    RegisterFileUploadHandler &
    operator=(const RegisterFileUploadHandler &) = delete;
    RegisterFileUploadHandler(RegisterFileUploadHandler &&) = delete;
    RegisterFileUploadHandler &operator=(RegisterFileUploadHandler &&) = delete;
    protected:
    void handleNewCallState() override;
    void handleReceivingFileState() override;
    HandlerTag tag_;
    FileTransmissionService::Stub *stub_;
    std::unique_ptr<grpc::ClientAsyncResponseReader<RegisterFileUploadResponse>>
    rpc_;
    RegisterFileUploadRequest *request_;
    RegisterFileUploadResponse *response_;
    };
    } // namespace caosdb::transaction
    /*
    * This file is a part of the CaosDB Project.
    * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
    * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
    *
    * This program is free software: you can redistribute it and/or modify
    * it under the terms of the GNU Affero General Public License as
    * published by the Free Software Foundation, either version 3 of the
    * License, or (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    * GNU Affero General Public License for more details.
    *
    * You should have received a copy of the GNU Affero General Public License
    * along with this program. If not, see <https://www.gnu.org/licenses/>.
    *
    *********************************************************************************
    *
    * This is derived work which is heavily based on
    * https://github.com/NeiRo21/grpcpp-bidi-streaming, Commit
    * cd9cb78e5d6d72806c2ec4c703e5e856b223dc96, Aug 10, 2020
    *
    * The orginal work is licensed as
    *
    * > MIT License
    * >
    * > Copyright (c) 2019 NeiRo21
    * >
    * > Permission is hereby granted, free of charge, to any person obtaining a
    * > copy of this software and associated documentation files (the "Software"),
    * > to deal in the Software without restriction, including without limitation
    * > the rights to use, copy, modify, merge, publish, distribute, sublicense,
    * > and/or sell copies of the Software, and to permit persons to whom the
    * > Software is furnished to do so, subject to the following conditions:
    * >
    * > The above copyright notice and this permission notice shall be included in
    * > all copies or substantial portions of the Software.
    * >
    * > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    * > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    * > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    * > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    * > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    * > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    * > DEALINGS IN THE SOFTWARE.
    */
    #ifndef CAOSDB_HANDLER_INTERFACE_H
    #define CAOSDB_HANDLER_INTERFACE_H
    #include "caosdb/transaction_status.h" // for TransactionStatus
    #include <memory>
    #include <string>
    namespace caosdb::transaction {
    const static std::string logger_name = "caosdb::transaction";
    class HandlerInterface {
    public:
    virtual ~HandlerInterface() = default;
    virtual void Start() = 0;
    virtual bool OnNext(bool ok) = 0;
    virtual void Cancel() = 0;
    virtual TransactionStatus GetStatus() = 0;
    };
    using HandlerPtr = std::unique_ptr<HandlerInterface>;
    using HandlerTag = HandlerPtr *;
    } // namespace caosdb::transaction
    #endif
    ......@@ -41,6 +41,7 @@ enum StatusCode {
    INITIAL = -2,
    EXECUTING = -1,
    SUCCESS = 0,
    // TODO(tf) Map other GRPC errors
    AUTHENTICATION_ERROR = 16,
    CONNECTION_ERROR = 14,
    GENERIC_RPC_ERROR = 20,
    ......
    ......@@ -24,17 +24,22 @@
    #include "caosdb/entity.h" // for Entity, FileDe...
    #include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for EntityTransact...
    #include "caosdb/entity/v1alpha1/main.pb.h" // for MultiTransacti...
    #include "caosdb/handler_interface.h" // for HandlerInterface
    #include "caosdb/transaction_handler.h" // for EntityTransactionHandler
    #include "caosdb/logging.h" // for CAOSDB_LOG_ERR...
    #include "caosdb/protobuf_helper.h" // for get_arena
    #include "caosdb/status_code.h" // for StatusCode
    #include "caosdb/transaction_status.h" // for StatusCode
    #include <boost/log/core/record.hpp> // for record
    #include <boost/log/sources/record_ostream.hpp> // for basic_record_o...
    #include <boost/preprocessor/seq/limits/enum_256.hpp> // for BOOST_PP_SEQ_E...
    #include <boost/preprocessor/seq/limits/size_256.hpp> // for BOOST_PP_SEQ_S...
    // IWYU pragma: no_include <ext/alloc_traits.h>
    #include <google/protobuf/arena.h> // for Arena
    #include <google/protobuf/util/json_util.h> // for MessageToJsonS...
    #include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue
    #include <iterator> // for iterator, next
    #include <map> // for map
    // IWYU pragma: no_include <ext/alloc_traits.h>
    #include <memory> // for unique_ptr
    #include <string> // for string
    #include <utility> // for move
    ......@@ -177,11 +182,11 @@ using caosdb::entity::v1alpha1::RegisterFileUploadResponse;
    using caosdb::transaction::TransactionStatus;
    using TransactionResponseCase =
    caosdb::entity::v1alpha1::TransactionResponse::TransactionResponseCase;
    using caosdb::utility::get_arena;
    using google::protobuf::Arena;
    class Transaction;
    static const std::string logger_name = "caosdb::transaction";
    /**
    * Abstract base class for the results of a Transaction.
    */
    ......@@ -265,6 +270,13 @@ public:
    Transaction(std::shared_ptr<EntityTransactionService::Stub> entity_service,
    std::shared_ptr<FileTransmissionService::Stub> file_service);
    ~Transaction();
    Transaction(const Transaction &) = delete;
    Transaction &operator=(const Transaction &) = delete;
    Transaction(Transaction &&) = delete;
    Transaction &operator=(Transaction &&) = delete;
    /**
    * Add an entity id to this transaction for retrieval and also download the
    * file.
    ......@@ -410,11 +422,45 @@ public:
    return out;
    }
    /**
    * Return the vector which holds all the files which are to be uploaded.
    */
    inline auto GetUploadFiles() const -> const std::vector<FileDescriptor> & {
    return upload_files;
    }
    protected:
    /**
    * Await and process the current handler's results.
    */
    auto ProcessCalls() -> TransactionStatus;
    /**
    * Cancels any active handler and drains the completion_queue.
    *
    * Can stay protected until ExecuteAsynchronously() is actually asynchronous.
    * Then it is also intended for aborting an execution after it has already
    * started.
    */
    auto Cancel() -> void;
    /**
    * Return the Arena where this transaction may create Message instances.
    *
    * Currently, this implementation is only a call to
    * caosdb::utility::get_arena(), but in the future we might want to have a
    * smarter memory management.
    */
    inline auto GetArena() const -> Arena * { return get_arena(); }
    private:
    grpc::CompletionQueue completion_queue;
    std::unique_ptr<HandlerInterface> handler_;
    std::vector<FileDescriptor> upload_files;
    std::map<std::string, FileDescriptor> download_files;
    private:
    auto RegisterUploadFile(RegisterFileUploadResponse *response) -> void;
    // auto RegisterUploadFile(RegisterFileUploadResponse *response) -> void;
    auto UploadFile(FileUploadResponse *response,
    const FileDescriptor &file_descriptor,
    const std::string &registration_id) -> void;
    ......
    #pragma once
    #include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for FileTransmissionS...
    #include "caosdb/entity/v1alpha1/main.pb.h" // for FileDownloadResponse
    #include "caosdb/handler_interface.h" // for HandlerTag
    #include "caosdb/unary_rpc_handler.h" // for HandlerTag, Handl...
    #include <grpcpp/impl/codegen/async_unary_call.h> // for ClientAsyncRespons...
    #include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue
    #include <memory> // for unique_ptr
    namespace caosdb::transaction {
    using caosdb::entity::v1alpha1::EntityTransactionService;
    using caosdb::entity::v1alpha1::MultiTransactionRequest;
    using caosdb::entity::v1alpha1::MultiTransactionResponse;
    class EntityTransactionHandler final : public UnaryRpcHandler {
    public:
    EntityTransactionHandler(HandlerTag tag, EntityTransactionService::Stub *stub,
    grpc::CompletionQueue *completion_queue,
    MultiTransactionRequest *request,
    MultiTransactionResponse *response);
    ~EntityTransactionHandler() override = default;
    EntityTransactionHandler(const EntityTransactionHandler &) = delete;
    EntityTransactionHandler &
    operator=(const EntityTransactionHandler &) = delete;
    EntityTransactionHandler(EntityTransactionHandler &&) = delete;
    EntityTransactionHandler &operator=(EntityTransactionHandler &&) = delete;
    protected:
    virtual void handleNewCallState() override;
    virtual void handleReceivingFileState() override;
    HandlerTag tag_;
    EntityTransactionService::Stub *stub_;
    std::unique_ptr<grpc::ClientAsyncResponseReader<MultiTransactionResponse>>
    rpc_;
    MultiTransactionRequest *request_;
    MultiTransactionResponse *response_;
    };
    } // namespace caosdb::transaction
    ......@@ -170,6 +170,19 @@ public:
    " Original error: " + details);
    }
    /**
    * Factory for a GENERIC_ERROR status.
    *
    * This status means that the transaction failed due to errors which
    * supposedly do not have a special handling.
    */
    inline static auto GENERIC_ERROR(const std::string &details) {
    return TransactionStatus(
    StatusCode::GENERIC_ERROR,
    caosdb::get_status_description(StatusCode::GENERIC_ERROR) +
    "Original error: " + details);
    }
    inline auto ThrowExceptionIfError() const -> void {
    TransactionStatus::ThrowExceptionIfError(this->code, this->description);
    }
    ......@@ -192,7 +205,7 @@ public:
    case StatusCode::TRANSACTION_TYPE_ERROR:
    throw TransactionTypeError(description);
    default:
    throw Exception(StatusCode::GENERIC_ERROR, description);
    throw Exception(code, description);
    }
    }
    ......@@ -227,6 +240,9 @@ public:
    */
    inline auto GetCode() const -> StatusCode { return this->code; }
    TransactionStatus(StatusCode code, const std::string &description)
    : code(code), description(description){};
    private:
    /**
    * The code is an identifier of errors.
    ......@@ -237,9 +253,6 @@ private:
    * Description of the error
    */
    std::string description;
    TransactionStatus(StatusCode code, const std::string &description)
    : code(code), description(description){};
    };
    } // namespace caosdb::transaction
    ......
    #pragma once
    #include "caosdb/handler_interface.h" // for HandlerTag, Handl...
    #include "caosdb/transaction_status.h" // for TransactionStatus
    #include <grpcpp/impl/codegen/client_context.h> // for ClientContext
    #include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue
    #include <grpcpp/impl/codegen/status.h> // for Status
    namespace caosdb::transaction {
    class UnaryRpcHandler : public HandlerInterface {
    public:
    inline UnaryRpcHandler(grpc::CompletionQueue *completion_queue)
    : state_(CallState::NewCall), completion_queue(completion_queue),
    transaction_status(TransactionStatus::EXECUTING()) {}
    void Start() override {
    transaction_status = TransactionStatus::EXECUTING();
    OnNext(true);
    }
    bool OnNext(bool ok) override;
    void Cancel() override;
    TransactionStatus GetStatus() override { return transaction_status; }
    protected:
    virtual void handleNewCallState() = 0;
    virtual void handleReceivingFileState() = 0;
    void handleCallCompleteState();
    enum class CallState { NewCall, ReceivingFile, CallComplete };
    CallState state_;
    grpc::CompletionQueue *completion_queue;
    grpc::ClientContext call_context;
    grpc::Status status_;
    TransactionStatus transaction_status;
    };
    } // namespace caosdb::transaction
    Subproject commit af178772ef43ded290168f33852ef3d85583b20a
    Subproject commit 485173a714d9ff7c2388945b0a4cad35980cda69
    ......@@ -28,6 +28,9 @@ set(libcaosdb_SRC
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/configuration.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/protobuf_helper.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/transaction.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/transaction_handler.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/unary_rpc_handler.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/register_file_upload_handler.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/Client.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/UploadRequestHandler.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/DownloadRequestHandler.cpp
    ......
    ......@@ -11,11 +11,11 @@
    // IWYU pragma: no_include <bits/exception.h>
    #include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQ...
    namespace FileExchange {
    namespace caosdb::transaction {
    using caosdb::StatusCode;
    FileExchangeClient::~FileExchangeClient() {
    this->cancel();
    this->Cancel();
    cq_.Shutdown();
    ......@@ -49,21 +49,22 @@ StatusCode FileExchangeClient::download(const FileDescriptor &file_descriptor) {
    return StatusCode::SUCCESS;
    }
    void FileExchangeClient::cancel() {
    void FileExchangeClient::Cancel() {
    if (handler_) {
    handler_->cancel();
    handler_->Cancel();
    }
    }
    int FileExchangeClient::processMessages() {
    try {
    handler_->Start();
    void *tag = nullptr;
    bool ok = false;
    while (true) {
    if (cq_.Next(&tag, &ok)) {
    if (tag != nullptr) {
    // TODO(tf): assert
    auto res = handler_->onNext(ok);
    auto res = handler_->OnNext(ok);
    if (!res) {
    // TODO(tf): comment
    handler_.reset();
    ......@@ -89,4 +90,4 @@ int FileExchangeClient::processMessages() {
    return 0;
    }
    } // namespace FileExchange
    } // namespace caosdb::transaction
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment