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

Merge branch 'f-files' into f-consolidation

parents 7bc40ea8 ea446318
No related branches found
No related tags found
1 merge request!12F consolidation
Showing
with 686 additions and 403 deletions
...@@ -42,13 +42,11 @@ set(libcaosdb_INCL ...@@ -42,13 +42,11 @@ set(libcaosdb_INCL
${CMAKE_CURRENT_SOURCE_DIR}/caosdb/utility.h ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/utility.h
${CMAKE_CURRENT_SOURCE_DIR}/caosdb/value.h ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/value.h
${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/register_file_upload_handler.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/upload_request_handler.h
${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/UploadRequestHandler.h ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/download_request_handler.h
${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/DownloadRequestHandler.h ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/file_writer.h
${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/FileWriter.h ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/file_reader.h
${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/FileReader.h ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/file_error.h
${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/FileLock.h
${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/FileError.h
) )
# pass variable to parent scope # pass variable to parent scope
......
#include "caosdb/entity.h" // for FileDescriptor
#include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for FileTransmissionS...
#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 caosdb::transaction {
using caosdb::StatusCode;
using caosdb::entity::FileDescriptor;
using caosdb::entity::v1alpha1::FileTransmissionService;
class FileExchangeClient final {
public:
FileExchangeClient(
const std::shared_ptr<FileTransmissionService::Stub> &service)
: stub_(service) {}
~FileExchangeClient();
FileExchangeClient(const FileExchangeClient &) = delete;
FileExchangeClient &operator=(const FileExchangeClient &) = delete;
FileExchangeClient(FileExchangeClient &&) = delete;
FileExchangeClient &operator=(FileExchangeClient &&) = delete;
StatusCode upload(const FileDescriptor &file_descriptor);
StatusCode download(const FileDescriptor &file_descriptor);
void Cancel();
private:
int processMessages();
grpc::CompletionQueue cq_;
std::shared_ptr<FileTransmissionService::Stub> stub_;
std::unique_ptr<HandlerInterface> handler_;
};
} // namespace caosdb::transaction
#pragma once
#include <stdexcept>
#include <string>
namespace caosdb::transaction {
class FileLockError : public std::runtime_error {
public:
FileLockError(const std::string &message) : std::runtime_error(message) {}
};
class FileIOError : public std::runtime_error {
public:
FileIOError(const std::string &message) : std::runtime_error(message) {}
};
class FileNotManagedError : public std::runtime_error {
public:
FileNotManagedError(const std::string &message)
: std::runtime_error(message) {}
};
} // namespace caosdb::transaction
#pragma once
#include <mutex>
#include <shared_mutex>
namespace caosdb::transaction {
using FileMutex = std::shared_timed_mutex;
using FileReadLock = std::shared_lock<FileMutex>;
using FileWriteLock = std::unique_lock<FileMutex>;
} // namespace caosdb::transaction
#pragma once
#include "caosdb/file_transmission/FileLock.h" // for FileMutex, FileReadLock
#include <boost/filesystem/fstream.hpp> // for ifstream
#include <boost/filesystem/operations.hpp> // for exists
#include <boost/filesystem/path.hpp> // for path
#include <fstream> // for ifstream, size_t
#include <memory> // for shared_ptr
#include <string> // for string
namespace caosdb::transaction {
using boost::filesystem::exists;
using boost::filesystem::ifstream;
using boost::filesystem::path;
class FileReader final {
public:
FileReader(boost::filesystem::path filename);
FileReader(boost::filesystem::path filename,
std::shared_ptr<FileMutex> mutexPtr);
~FileReader() = default;
FileReader(const FileReader &) = delete;
FileReader &operator=(const FileReader &) = delete;
FileReader(FileReader &&) = default;
FileReader &operator=(FileReader &&) = default;
unsigned long long fileSize() const { return size_; }
std::size_t read(std::string &buffer);
private:
void openFile();
std::ifstream stream_;
boost::filesystem::path filename_;
unsigned long long size_;
std::shared_ptr<FileMutex> mutexPtr_;
FileReadLock lock_;
};
} // namespace caosdb::transaction
#pragma once
#include "caosdb/file_transmission/FileLock.h" // for FileMutex, FileWriteLock
#include <boost/filesystem/path.hpp> // for path
#include <fstream> // for ofstream
#include <memory> // for shared_ptr
#include <string> // for string
namespace caosdb::transaction {
class FileWriter final {
public:
FileWriter(boost::filesystem::path filename);
FileWriter(boost::filesystem::path filename,
std::shared_ptr<FileMutex> mutexPtr);
~FileWriter() = default;
FileWriter(const FileWriter &) = delete;
FileWriter &operator=(const FileWriter &) = delete;
FileWriter(FileWriter &&) = default;
FileWriter &operator=(FileWriter &&) = default;
void write(const std::string &buffer);
private:
void openFile();
std::ofstream stream_;
boost::filesystem::path filename_;
std::shared_ptr<FileMutex> mutexPtr_;
FileWriteLock lock_;
};
} // 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_FILE_TRANSMISSION_DOWNLOAD_REQUEST_HANDLER_H
#define CAOSDB_FILE_TRANSMISSION_DOWNLOAD_REQUEST_HANDLER_H
#include "caosdb/entity.h" // for FileDescriptor #include "caosdb/entity.h" // for FileDescriptor
#include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for FileTransmissionS... #include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for FileTransmissionS...
#include "caosdb/entity/v1alpha1/main.pb.h" // for FileDownloadResponse #include "caosdb/entity/v1alpha1/main.pb.h" // for FileDownloadResponse
#include "caosdb/file_transmission/FileWriter.h" // for FileWriter #include "caosdb/file_transmission/file_writer.h" // for FileWriter
#include "caosdb/handler_interface.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/async_stream.h> // for ClientAsyncReader
#include <grpcpp/impl/codegen/client_context.h> // for ClientContext #include <grpcpp/impl/codegen/client_context.h> // for ClientContext
#include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue #include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue
...@@ -31,10 +81,6 @@ public: ...@@ -31,10 +81,6 @@ public:
DownloadRequestHandler(DownloadRequestHandler &&) = delete; DownloadRequestHandler(DownloadRequestHandler &&) = delete;
DownloadRequestHandler &operator=(DownloadRequestHandler &&) = delete; DownloadRequestHandler &operator=(DownloadRequestHandler &&) = delete;
TransactionStatus GetStatus() override {
return TransactionStatus::EXECUTING();
}
void Start() override { OnNext(true); } void Start() override { OnNext(true); }
bool OnNext(bool ok) override; bool OnNext(bool ok) override;
...@@ -71,3 +117,5 @@ protected: ...@@ -71,3 +117,5 @@ protected:
}; };
} // namespace caosdb::transaction } // namespace caosdb::transaction
#endif
/*
* 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_FILE_TRANSMISSION_FILE_ERROR_H
#define CAOSDB_FILE_TRANSMISSION_FILE_ERROR_H
#include <stdexcept>
#include <string>
namespace caosdb::transaction {
class FileIOError : public std::runtime_error {
public:
FileIOError(const std::string &message) : std::runtime_error(message) {}
};
} // namespace caosdb::transaction
#endif
/*
* 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_FILE_TRANSMISSION_FILE_READER_H
#define CAOSDB_FILE_TRANSMISSION_FILE_READER_H
#include <boost/filesystem/fstream.hpp> // for ifstream
#include <boost/filesystem/operations.hpp> // for exists
#include <boost/filesystem/path.hpp> // for path
#include <fstream> // for ifstream, size_t
#include <string> // for string
namespace caosdb::transaction {
using boost::filesystem::exists;
using boost::filesystem::ifstream;
using boost::filesystem::path;
class FileReader final {
public:
FileReader(boost::filesystem::path filename);
~FileReader() = default;
FileReader(const FileReader &) = delete;
FileReader &operator=(const FileReader &) = delete;
FileReader(FileReader &&) = default;
FileReader &operator=(FileReader &&) = default;
unsigned long long fileSize() const { return size_; }
std::size_t read(std::string &buffer);
private:
void openFile();
std::ifstream stream_;
boost::filesystem::path filename_;
unsigned long long size_;
};
} // namespace caosdb::transaction
#endif
/*
* 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_FILE_TRANSMISSION_FILE_WRITER_H
#define CAOSDB_FILE_TRANSMISSION_FILE_WRITER_H
#include <boost/filesystem/path.hpp> // for path
#include <fstream> // for ofstream
#include <string> // for string
namespace caosdb::transaction {
class FileWriter final {
public:
FileWriter(boost::filesystem::path filename);
~FileWriter() = default;
FileWriter(const FileWriter &) = delete;
FileWriter &operator=(const FileWriter &) = delete;
FileWriter(FileWriter &&) = default;
FileWriter &operator=(FileWriter &&) = default;
void write(const std::string &buffer);
private:
void openFile();
std::ofstream stream_;
boost::filesystem::path filename_;
};
} // namespace caosdb::transaction
#endif
#pragma once /*
* 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_FILE_TRANSMISSION_REGISTER_FILE_UPLOAD_H
#define CAOSDB_FILE_TRANSMISSION_REGISTER_FILE_UPLOAD_H
#include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for FileTransmissionS... #include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for FileTransmissionS...
#include "caosdb/entity/v1alpha1/main.pb.h" // for FileDownloadResponse #include "caosdb/entity/v1alpha1/main.pb.h" // for FileDownloadResponse
#include "caosdb/handler_interface.h" // for HandlerTag, Handl... #include "caosdb/handler_interface.h" // for HandlerTag, Handl...
...@@ -30,7 +80,6 @@ public: ...@@ -30,7 +80,6 @@ public:
protected: protected:
void handleNewCallState() override; void handleNewCallState() override;
void handleReceivingFileState() override;
HandlerTag tag_; HandlerTag tag_;
...@@ -44,3 +93,5 @@ protected: ...@@ -44,3 +93,5 @@ protected:
}; };
} // namespace caosdb::transaction } // namespace caosdb::transaction
#endif
/*
* 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_FILE_TRANSMISSION_UPLOAD_REQUEST_HANDLER_H
#define CAOSDB_FILE_TRANSMISSION_UPLOAD_REQUEST_HANDLER_H
#include "caosdb/entity.h" // for FileDescriptor #include "caosdb/entity.h" // for FileDescriptor
#include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for FileTransmissionS... #include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for FileTransmissionS...
#include "caosdb/entity/v1alpha1/main.pb.h" // for FileUploadRequest #include "caosdb/entity/v1alpha1/main.pb.h" // for FileUploadRequest
#include "caosdb/file_transmission/FileReader.h" // for FileReader #include "caosdb/file_transmission/file_reader.h" // for FileReader
#include "caosdb/handler_interface.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 <cstdint> // for uint64_t
#include <grpcpp/impl/codegen/async_stream.h> // for ClientAsyncWriter #include <grpcpp/impl/codegen/async_stream.h> // for ClientAsyncWriter
#include <grpcpp/impl/codegen/client_context.h> // for ClientContext #include <grpcpp/impl/codegen/client_context.h> // for ClientContext
...@@ -32,10 +82,6 @@ public: ...@@ -32,10 +82,6 @@ public:
UploadRequestHandler(UploadRequestHandler &&) = delete; UploadRequestHandler(UploadRequestHandler &&) = delete;
UploadRequestHandler &operator=(UploadRequestHandler &&) = delete; UploadRequestHandler &operator=(UploadRequestHandler &&) = delete;
TransactionStatus GetStatus() override {
return TransactionStatus::EXECUTING();
}
void Start() override { OnNext(true); } void Start() override { OnNext(true); }
bool OnNext(bool ok) override; bool OnNext(bool ok) override;
...@@ -79,3 +125,5 @@ protected: ...@@ -79,3 +125,5 @@ protected:
}; };
} // namespace caosdb::transaction } // namespace caosdb::transaction
#endif
...@@ -59,6 +59,8 @@ const static std::string logger_name = "caosdb::transaction"; ...@@ -59,6 +59,8 @@ const static std::string logger_name = "caosdb::transaction";
class HandlerInterface { class HandlerInterface {
public: public:
HandlerInterface() : transaction_status(TransactionStatus::READY()) {}
virtual ~HandlerInterface() = default; virtual ~HandlerInterface() = default;
virtual void Start() = 0; virtual void Start() = 0;
...@@ -67,7 +69,10 @@ public: ...@@ -67,7 +69,10 @@ public:
virtual void Cancel() = 0; virtual void Cancel() = 0;
virtual TransactionStatus GetStatus() = 0; inline TransactionStatus GetStatus() { return this->transaction_status; }
protected:
TransactionStatus transaction_status;
}; };
using HandlerPtr = std::unique_ptr<HandlerInterface>; using HandlerPtr = std::unique_ptr<HandlerInterface>;
......
...@@ -30,7 +30,6 @@ public: ...@@ -30,7 +30,6 @@ public:
protected: protected:
virtual void handleNewCallState() override; virtual void handleNewCallState() override;
virtual void handleReceivingFileState() override;
HandlerTag tag_; HandlerTag tag_;
......
#pragma once /*
* 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_UNARY_RPC_HANDLER_H
#define CAOSDB_UNARY_RPC_HANDLER_H
#include "caosdb/handler_interface.h" // for HandlerTag, Handl... #include "caosdb/handler_interface.h" // for HandlerTag, Handl...
#include "caosdb/transaction_status.h" // for TransactionStatus #include "caosdb/transaction_status.h" // for TransactionStatus
#include <grpcpp/impl/codegen/client_context.h> // for ClientContext #include <grpcpp/impl/codegen/client_context.h> // for ClientContext
...@@ -10,8 +60,8 @@ namespace caosdb::transaction { ...@@ -10,8 +60,8 @@ namespace caosdb::transaction {
class UnaryRpcHandler : public HandlerInterface { class UnaryRpcHandler : public HandlerInterface {
public: public:
inline UnaryRpcHandler(grpc::CompletionQueue *completion_queue) inline UnaryRpcHandler(grpc::CompletionQueue *completion_queue)
: state_(CallState::NewCall), completion_queue(completion_queue), : HandlerInterface(), state_(CallState::NewCall),
transaction_status(TransactionStatus::EXECUTING()) {} completion_queue(completion_queue) {}
void Start() override { void Start() override {
transaction_status = TransactionStatus::EXECUTING(); transaction_status = TransactionStatus::EXECUTING();
...@@ -22,20 +72,18 @@ public: ...@@ -22,20 +72,18 @@ public:
void Cancel() override; void Cancel() override;
TransactionStatus GetStatus() override { return transaction_status; }
protected: protected:
virtual void handleNewCallState() = 0; virtual void handleNewCallState() = 0;
virtual void handleReceivingFileState() = 0;
void handleCallCompleteState(); void handleCallCompleteState();
enum class CallState { NewCall, ReceivingFile, CallComplete }; enum class CallState { NewCall, CallComplete };
CallState state_; CallState state_;
grpc::CompletionQueue *completion_queue; grpc::CompletionQueue *completion_queue;
grpc::ClientContext call_context; grpc::ClientContext call_context;
grpc::Status status_; grpc::Status status_;
TransactionStatus transaction_status;
}; };
} // namespace caosdb::transaction } // namespace caosdb::transaction
#endif
...@@ -31,11 +31,10 @@ set(libcaosdb_SRC ...@@ -31,11 +31,10 @@ set(libcaosdb_SRC
${CMAKE_CURRENT_SOURCE_DIR}/caosdb/transaction_handler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/transaction_handler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/caosdb/unary_rpc_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/register_file_upload_handler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/Client.cpp ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/upload_request_handler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/UploadRequestHandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/download_request_handler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/DownloadRequestHandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/file_writer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/FileWriter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/file_reader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/FileReader.cpp
) )
# pass variable to parent scope # pass variable to parent scope
......
#include "caosdb/file_transmission/Client.h"
#include "caosdb/file_transmission/DownloadRequestHandler.h" // for DownloadReq...
#include "caosdb/file_transmission/UploadRequestHandler.h" // for UploadReque...
#include "caosdb/logging.h" // for CAOSDB_LOG_...
#include "caosdb/status_code.h" // for StatusCode
#include <boost/log/core/record.hpp> // for record
#include <boost/log/sources/record_ostream.hpp> // for basic_recor...
#include <boost/preprocessor/seq/limits/enum_256.hpp> // for BOOST_PP_SE...
#include <boost/preprocessor/seq/limits/size_256.hpp> // for BOOST_PP_SE...
#include <exception> // IWYU pragma: keep
// IWYU pragma: no_include <bits/exception.h>
#include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQ...
namespace caosdb::transaction {
using caosdb::StatusCode;
FileExchangeClient::~FileExchangeClient() {
this->Cancel();
cq_.Shutdown();
// drain the queue
void *ignoredTag = nullptr;
bool ok = false;
while (cq_.Next(&ignoredTag, &ok)) {
;
}
}
StatusCode FileExchangeClient::upload(const FileDescriptor &file_descriptor) {
handler_ = std::make_unique<UploadRequestHandler>(&handler_, stub_.get(),
&cq_, file_descriptor);
int status = this->processMessages();
if (status > 0) {
return StatusCode::FILE_UPLOAD_ERROR;
}
return StatusCode::SUCCESS;
}
StatusCode FileExchangeClient::download(const FileDescriptor &file_descriptor) {
handler_ = std::make_unique<DownloadRequestHandler>(&handler_, stub_.get(),
&cq_, file_descriptor);
int status = this->processMessages();
if (status > 0) {
return StatusCode::FILE_DOWNLOAD_ERROR;
}
return StatusCode::SUCCESS;
}
void FileExchangeClient::Cancel() {
if (handler_) {
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);
if (!res) {
// TODO(tf): comment
handler_.reset();
break;
}
} else {
CAOSDB_LOG_ERROR(logger_name)
<< "Invalid tag delivered by notification queue.";
}
} else {
CAOSDB_LOG_ERROR(logger_name)
<< "Notification queue has been shut down unexpectedly.";
return 1;
}
}
} catch (std::exception &e) {
CAOSDB_LOG_ERROR(logger_name) << "Caught exception: " << e.what();
return 1;
} catch (...) {
CAOSDB_LOG_ERROR(logger_name) << "Caught unknown exception.";
return 1;
}
return 0;
}
} // namespace caosdb::transaction
#include "caosdb/file_transmission/FileReader.h"
#include "caosdb/file_transmission/FileError.h" // for FileIOError, FileLockError
#include <boost/filesystem/path.hpp> // for path
#include <mutex> // for try_to_lock
#include <utility> // for move
namespace caosdb::transaction {
FileReader::FileReader(boost::filesystem::path filename)
: filename_(std::move(filename)), size_(0) {
this->openFile();
}
FileReader::FileReader(boost::filesystem::path filename,
std::shared_ptr<FileMutex> mutexPtr)
: filename_(std::move(filename)), size_(0), mutexPtr_(std::move(mutexPtr)) {
this->openFile();
}
void FileReader::openFile() {
if (mutexPtr_) {
lock_ = FileReadLock(*mutexPtr_, std::try_to_lock);
if (!lock_) {
throw FileLockError("Can't lock file for reading: " + filename_.string());
}
}
stream_.open(filename_, std::ios::binary | std::ios::ate);
if (!stream_) {
throw FileIOError("Can't open file for reading: " + filename_.string());
}
auto size = stream_.tellg();
stream_.seekg(0);
if (size > 0) {
size_ = static_cast<decltype(size_)>(size);
}
}
std::size_t FileReader::read(std::string &buffer) {
std::size_t bytesRead = 0;
if (!stream_.eof()) {
auto bufferSize = buffer.size();
if (bufferSize > 0) {
if (!stream_.read(&buffer[0], bufferSize)) {
throw FileIOError("Can't read file: " + filename_.string());
}
bytesRead = static_cast<std::size_t>(stream_.gcount());
}
}
return bytesRead;
}
} // namespace caosdb::transaction
#include "caosdb/file_transmission/FileWriter.h"
#include "caosdb/file_transmission/FileError.h" // for FileIOError, FileLockError
#include <boost/filesystem/path.hpp> // for path
#include <mutex> // for try_to_lock
#include <utility> // for move
namespace caosdb::transaction {
FileWriter::FileWriter(boost::filesystem::path filename)
: filename_(std::move(filename)) {
this->openFile();
}
FileWriter::FileWriter(boost::filesystem::path filename,
std::shared_ptr<FileMutex> mutexPtr)
: filename_(std::move(filename)), mutexPtr_(std::move(mutexPtr)) {
this->openFile();
}
void FileWriter::openFile() {
if (mutexPtr_) {
lock_ = FileWriteLock(*mutexPtr_, std::try_to_lock);
if (!lock_) {
throw FileLockError("Can't lock file for writing: " + filename_.string());
}
}
stream_.open(filename_, std::ios::binary | std::ios::trunc);
if (!stream_) {
throw FileIOError("Can't open file for writing: " + filename_.string());
}
}
void FileWriter::write(const std::string &buffer) {
auto bufferSize = buffer.size();
if (bufferSize > 0) {
if (!stream_.write(buffer.data(), bufferSize)) {
throw FileIOError("Can't write file: " + filename_.string());
}
}
}
} // namespace caosdb::transaction
#include "caosdb/file_transmission/DownloadRequestHandler.h" /*
#include "caosdb/exceptions.h" // for Exception * 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.
*/
#include "caosdb/file_transmission/download_request_handler.h"
#include "caosdb/logging.h" // for CAOSDB_LOG_TRACE #include "caosdb/logging.h" // for CAOSDB_LOG_TRACE
#include "caosdb/protobuf_helper.h" // for get_arena #include "caosdb/protobuf_helper.h" // for get_arena
#include "caosdb/status_code.h" // for GENERIC_RPC_E... #include "caosdb/status_code.h" // for GENERIC_RPC_E...
#include "caosdb/transaction_status.h" // for TransactionStatus
#include <boost/filesystem/path.hpp> // for operator<<, path #include <boost/filesystem/path.hpp> // for operator<<, path
#include <boost/log/core/record.hpp> // for record #include <boost/log/core/record.hpp> // for record
#include <boost/log/detail/attachable_sstream_buf.hpp> // for basic_ostring... #include <boost/log/detail/attachable_sstream_buf.hpp> // for basic_ostring...
...@@ -24,9 +72,6 @@ ...@@ -24,9 +72,6 @@
namespace caosdb::transaction { namespace caosdb::transaction {
using caosdb::StatusCode; using caosdb::StatusCode;
using caosdb::exceptions::AuthenticationError;
using caosdb::exceptions::ConnectionError;
using caosdb::exceptions::Exception;
using caosdb::utility::get_arena; using caosdb::utility::get_arena;
using google::protobuf::Arena; using google::protobuf::Arena;
...@@ -50,7 +95,7 @@ bool DownloadRequestHandler::OnNext(bool ok) { ...@@ -50,7 +95,7 @@ bool DownloadRequestHandler::OnNext(bool ok) {
this->handleReceivingFileState(); this->handleReceivingFileState();
} else if (state_ == CallState::CallComplete) { } else if (state_ == CallState::CallComplete) {
this->handleCallCompleteState(); this->handleCallCompleteState();
return false; // TODO(tf): comment return false;
} }
} else { } else {
state_ = CallState::CallComplete; state_ = CallState::CallComplete;
...@@ -58,19 +103,20 @@ bool DownloadRequestHandler::OnNext(bool ok) { ...@@ -58,19 +103,20 @@ bool DownloadRequestHandler::OnNext(bool ok) {
} }
return true; return true;
} catch (Exception &e) {
throw;
} catch (std::exception &e) { } catch (std::exception &e) {
CAOSDB_LOG_ERROR(logger_name) << "Download processing error: " << e.what(); CAOSDB_LOG_ERROR(logger_name)
throw; << "DownloadRequestHandler caught an exception: " << e.what();
transaction_status = TransactionStatus::GENERIC_ERROR(e.what());
state_ = CallState::CallComplete;
} catch (...) { } catch (...) {
CAOSDB_LOG_ERROR(logger_name) CAOSDB_LOG_ERROR(logger_name)
<< "Download processing error: unknown exception caught"; << "Transaction error: unknown exception caught";
throw; transaction_status = TransactionStatus::GENERIC_ERROR(
"DownloadRequestHandler caught an unknown exception");
state_ = CallState::CallComplete;
} }
if (state_ == CallState::NewCall) { if (state_ == CallState::NewCall) {
// TODO(tf): comment
return false; return false;
} }
...@@ -93,6 +139,7 @@ void DownloadRequestHandler::handleNewCallState() { ...@@ -93,6 +139,7 @@ void DownloadRequestHandler::handleNewCallState() {
rpc_ = stub_->PrepareAsyncFileDownload(&ctx_, *request_, cq_); rpc_ = stub_->PrepareAsyncFileDownload(&ctx_, *request_, cq_);
transaction_status = TransactionStatus::EXECUTING();
state_ = CallState::SendingRequest; state_ = CallState::SendingRequest;
rpc_->StartCall(tag_); rpc_->StartCall(tag_);
CAOSDB_LOG_TRACE(logger_name) CAOSDB_LOG_TRACE(logger_name)
...@@ -133,22 +180,26 @@ void DownloadRequestHandler::handleReceivingFileState() { ...@@ -133,22 +180,26 @@ void DownloadRequestHandler::handleReceivingFileState() {
void DownloadRequestHandler::handleCallCompleteState() { void DownloadRequestHandler::handleCallCompleteState() {
CAOSDB_LOG_TRACE(logger_name) CAOSDB_LOG_TRACE(logger_name)
<< "Enter DownloadRequestHandler::handleCallCompleteState"; << "Enter DownloadRequestHandler::handleCallCompleteState";
switch (status_.error_code()) { switch (status_.error_code()) {
case grpc::OK: case grpc::OK: {
CAOSDB_LOG_INFO(logger_name) << "[" << file_descriptor_.local_path CAOSDB_LOG_INFO(logger_name)
<< "]: download complete: " << bytesReceived_ << "DownloadRequestHandler finished successfully ("
<< " bytes received" << std::endl; << file_descriptor_.local_path << "): Download complete, "
break; << bytesReceived_ << " bytes received.";
} break;
case grpc::UNAUTHENTICATED: default: {
throw AuthenticationError(status_.error_message()); auto code(static_cast<StatusCode>(status_.error_code()));
case grpc::UNAVAILABLE: std::string description(get_status_description(code) +
throw ConnectionError(status_.error_message()); " Original message: " + status_.error_message());
default: transaction_status = TransactionStatus(code, description);
throw Exception(StatusCode::GENERIC_RPC_ERROR, CAOSDB_LOG_ERROR(logger_name)
"GRPC error code " + std::to_string(status_.error_code()) + << "DownloadRequestHandler finished with an error ("
" - " + status_.error_message()); << file_descriptor_.local_path << "): Download aborted with code " << code
<< " - " << description;
} break;
} }
CAOSDB_LOG_TRACE(logger_name) CAOSDB_LOG_TRACE(logger_name)
<< "Leave DownloadRequestHandler::handleCallCompleteState"; << "Leave DownloadRequestHandler::handleCallCompleteState";
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment