From e84649b6b12c483706f2634f5e72d64e0fc776de Mon Sep 17 00:00:00 2001 From: Sergey Yakubov <sergey.yakubov@desy.de> Date: Thu, 5 Apr 2018 09:58:47 +0200 Subject: [PATCH] some refactoring --- common/cpp/include/system/io.h | 106 ++++++++ common/cpp/include/system/io_error.h | 142 +++++++++++ .../{system_wrappers => system}/io_factory.h | 0 .../{system_wrappers => system}/system_io.h | 6 +- common/cpp/include/system_wrappers/io.h | 238 ------------------ common/cpp/include/unittests/MockIO.h | 2 +- common/cpp/src/json_parser/rapid_json.cpp | 2 +- common/cpp/src/json_parser/rapid_json.h | 2 +- common/cpp/src/system_io/io_factory.cpp | 4 +- common/cpp/src/system_io/system_io.cpp | 3 +- common/cpp/src/system_io/system_io_linux.cpp | 5 +- .../cpp/src/system_io/system_io_windows.cpp | 2 +- .../dummy_data_producer.cpp | 4 +- producer/api/include/hidra2_producer.h | 6 + producer/api/src/producer_impl.cpp | 8 +- producer/api/src/producer_impl.h | 4 +- producer/api/unittests/test_producer.cpp | 4 +- producer/api/unittests/test_producer_impl.cpp | 2 +- receiver/src/connection.cpp | 2 +- receiver/src/connection.h | 2 +- receiver/src/receiver.cpp | 2 +- receiver/src/request.cpp | 2 +- receiver/src/request.h | 2 +- receiver/src/request_handler_file_write.cpp | 2 +- receiver/src/request_handler_file_write.h | 2 +- .../ip_tcp_network/ip_tcp_network.cpp | 2 +- .../ip_tcp_network_speedtest.cpp | 2 +- .../read_file_content/read_file_content.cpp | 2 +- .../read_folder_content.cpp | 2 +- .../read_string_from_file.cpp | 2 +- .../resolve_hostname_to_ip.cpp | 2 +- .../write_data_to_file/write_data_to_file.cpp | 2 +- worker/api/cpp/src/folder_data_broker.cpp | 2 +- worker/api/cpp/src/folder_data_broker.h | 2 +- worker/api/cpp/src/server_data_broker.cpp | 2 +- worker/api/cpp/src/server_data_broker.h | 2 +- .../api/cpp/unittests/test_folder_broker.cpp | 4 +- .../api/cpp/unittests/test_server_broker.cpp | 4 +- .../folder_to_db/src/folder_db_importer.cpp | 2 +- .../folder_to_db/src/folder_db_importer.h | 2 +- .../unittests/test_folder_to_db.cpp | 4 +- 41 files changed, 306 insertions(+), 286 deletions(-) create mode 100644 common/cpp/include/system/io.h create mode 100644 common/cpp/include/system/io_error.h rename common/cpp/include/{system_wrappers => system}/io_factory.h (100%) rename common/cpp/include/{system_wrappers => system}/system_io.h (97%) delete mode 100644 common/cpp/include/system_wrappers/io.h create mode 100644 producer/api/include/hidra2_producer.h diff --git a/common/cpp/include/system/io.h b/common/cpp/include/system/io.h new file mode 100644 index 000000000..925d53099 --- /dev/null +++ b/common/cpp/include/system/io.h @@ -0,0 +1,106 @@ +#ifndef HIDRA2_SYSTEM__IO_H +#define HIDRA2_SYSTEM__IO_H + +#include <cinttypes> + +#include <string> +#include <vector> +#include <chrono> +#include <thread> + +#include "common/data_structs.h" +#include "io_error.h" + +namespace hidra2 { + +//Need to be "enum" since multiple flags are allowed +enum FileOpenMode { + IO_OPEN_MODE_READ = 1 << 0, + IO_OPEN_MODE_WRITE = 1 << 1, + IO_OPEN_MODE_RW = IO_OPEN_MODE_READ | IO_OPEN_MODE_WRITE, + IO_OPEN_MODE_CREATE = 1 << 2, + IO_OPEN_MODE_CREATE_AND_FAIL_IF_EXISTS = 1 << 3, + /** + * Will set the length of a file to 0 + * Only works if file is open with READ and WRITE mode + */ + IO_OPEN_MODE_SET_LENGTH_0 = 1 << 4, +}; + +enum class AddressFamilies { + INET, +}; + +enum class SocketTypes { + STREAM, +}; + +enum class SocketProtocols { + IP, +}; + +using FileDescriptor = int; +using SocketDescriptor = int; + +class IO { + public: + + /* + * Special + */ + virtual std::unique_ptr<std::thread> NewThread (std::function<void()> function) const = 0; + + /* + * Network + */ + virtual SocketDescriptor CreateSocket(AddressFamilies address_family, SocketTypes socket_type, + SocketProtocols socket_protocol, Error* err) const = 0; + virtual void Listen(SocketDescriptor socket_fd, int backlog, Error* err) const = 0; + virtual void InetBind(SocketDescriptor socket_fd, const std::string& address, Error* err) const = 0; + virtual SocketDescriptor CreateAndBindIPTCPSocketListener(const std::string& address, int backlog, + Error* err) const = 0; + virtual std::unique_ptr<std::tuple<std::string, SocketDescriptor>> InetAcceptConnection(SocketDescriptor socket_fd, + Error* err) const = 0; + virtual std::string ResolveHostnameToIp(const std::string& hostname, Error* err) const = 0; + virtual void InetConnect(SocketDescriptor socket_fd, const std::string& address, Error* err) const = 0; + virtual SocketDescriptor CreateAndConnectIPTCPSocket(const std::string& address, Error* err) const = 0; + virtual size_t Receive(SocketDescriptor socket_fd, void* buf, size_t length, Error* err) const = 0; + virtual size_t ReceiveWithTimeout(SocketDescriptor socket_fd, + void* buf, + size_t length, + long timeout_in_usec, + Error* err) const = 0; + virtual size_t Send(SocketDescriptor socket_fd, const void* buf, size_t length, Error* err) const = 0; + + virtual void Skip(SocketDescriptor socket_fd, size_t length, Error* err) const = 0; + /** + * @param err Since CloseSocket if often used in an error case, it's able to accept err as nullptr. + */ + virtual void CloseSocket(SocketDescriptor socket_fd, Error* err) const = 0; + + /* + * Filesystem + */ + virtual FileDescriptor Open (const std::string& filename, int open_flags, Error* err) const = 0; + /** + * @param err Since Close if often used in an error case, it's able to accept err as nullptr. + */ + virtual void Close (FileDescriptor fd, Error* err) const = 0; + + virtual size_t Read (FileDescriptor fd, void* buf, size_t length, Error* err) const = 0; + virtual size_t Write (FileDescriptor fd, const void* buf, size_t length, Error* err) const = 0; + + virtual Error WriteDataToFile (const std::string& fname, const FileData& data, size_t length) const = 0; + + virtual void CreateNewDirectory (const std::string& directory_name, Error* err) const = 0; + virtual FileData GetDataFromFile (const std::string& fname, uint64_t fsize, Error* err) const = 0; + virtual void CollectFileInformationRecursively(const std::string& path, std::vector<FileInfo>* files, + Error* err) const = 0; + virtual std::vector<FileInfo> FilesInFolder (const std::string& folder, Error* err) const = 0; + virtual std::string ReadFileToString (const std::string& fname, Error* err) const = 0; + +}; + +} + +#endif //HIDRA2_SYSTEM__IO_H diff --git a/common/cpp/include/system/io_error.h b/common/cpp/include/system/io_error.h new file mode 100644 index 000000000..40c9d4dd7 --- /dev/null +++ b/common/cpp/include/system/io_error.h @@ -0,0 +1,142 @@ +#ifndef HIDRA2_SYSTEM__IO_ERROR_H +#define HIDRA2_SYSTEM__IO_ERROR_H + +#include "common/error.h" + +namespace hidra2 { + + +enum class IOErrorType { + kUnknownIOError, + kBadFileNumber, + kResourceTemporarilyUnavailable, + kFileNotFound, + kReadError, + kPermissionDenied, + kUnsupportedAddressFamily, + kInvalidAddressFormat, + kAddressAlreadyInUse, + kConnectionRefused, + kConnectionResetByPeer, + kTimeout, + kFileAlreadyExists, + kNoSpaceLeft, + kSocketOperationOnNonSocket, + kInvalidMemoryAddress, + kUnableToResolveHostname, + kSocketOperationUnknownAtLevel, + kSocketOperationValueOutOfBound, + kAddressNotValid + +}; + +class IOError : public SimpleError { + private: + IOErrorType io_error_type_; + public: + IOError(const std::string& error, IOErrorType io_error_type) : SimpleError(error, ErrorType::kIOError) { + io_error_type_ = io_error_type; + } + + IOErrorType GetIOErrorType() const noexcept { + return io_error_type_; + } +}; + +class IOErrorTemplate : public SimpleErrorTemplate { + protected: + IOErrorType io_error_type_; + public: + IOErrorTemplate(const std::string& error, IOErrorType io_error_type) : SimpleErrorTemplate(error, ErrorType::kIOError) { + io_error_type_ = io_error_type; + } + + inline IOErrorType GetIOErrorType() const noexcept { + return io_error_type_; + } + + inline Error Generate() const noexcept override { + return Error(new IOError(error_, io_error_type_)); + } + + inline bool operator == (const Error& rhs) const override { + return SimpleErrorTemplate::operator==(rhs) + && GetIOErrorType() == ((IOError*)rhs.get())->GetIOErrorType(); + } +}; + +static inline std::ostream& operator<<(std::ostream& os, const IOErrorTemplate& err) { + return os << err.Text(); +} + + +namespace IOErrorTemplates { +auto const kUnknownIOError = IOErrorTemplate { + "Unknown Error", IOErrorType::kUnknownIOError +}; + +auto const kFileNotFound = IOErrorTemplate { + "No such file or directory", IOErrorType::kFileNotFound +}; +auto const kReadError = IOErrorTemplate { + "Read error", IOErrorType::kReadError +}; +auto const kBadFileNumber = IOErrorTemplate { + "Bad file number", IOErrorType::kBadFileNumber +}; +auto const kResourceTemporarilyUnavailable = IOErrorTemplate { + "Resource temporarily unavailable", IOErrorType::kResourceTemporarilyUnavailable +}; +auto const kPermissionDenied = IOErrorTemplate { + "Permission denied", IOErrorType::kPermissionDenied +}; +auto const kUnsupportedAddressFamily = IOErrorTemplate { + "Unsupported address family", IOErrorType::kUnsupportedAddressFamily +}; +auto const kInvalidAddressFormat = IOErrorTemplate { + "Invalid address format", IOErrorType::kInvalidAddressFormat +}; +auto const kAddressAlreadyInUse = IOErrorTemplate { + "Address already in use", IOErrorType::kAddressAlreadyInUse +}; +auto const kConnectionRefused = IOErrorTemplate { + "Connection refused", IOErrorType::kConnectionRefused +}; +auto const kConnectionResetByPeer = IOErrorTemplate { + "kConnectionResetByPeer", IOErrorType::kConnectionResetByPeer +}; +auto const kTimeout = IOErrorTemplate { + "kTimeout", IOErrorType::kTimeout +}; +auto const kFileAlreadyExists = IOErrorTemplate { + "kFileAlreadyExists", IOErrorType::kFileAlreadyExists +}; +auto const kNoSpaceLeft = IOErrorTemplate { + "kNoSpaceLeft", IOErrorType::kNoSpaceLeft +}; +auto const kSocketOperationOnNonSocket = IOErrorTemplate { + "kSocketOperationOnNonSocket", IOErrorType::kSocketOperationOnNonSocket +}; +auto const kInvalidMemoryAddress = IOErrorTemplate { + "kInvalidMemoryAddress", IOErrorType::kInvalidMemoryAddress +}; +auto const kUnableToResolveHostname = IOErrorTemplate { + "kUnableToResolveHostname", IOErrorType::kUnableToResolveHostname +}; +auto const kSocketOperationUnknownAtLevel = IOErrorTemplate { + "kSocketOperationUnknownAtLevel", IOErrorType::kSocketOperationUnknownAtLevel +}; + +auto const kSocketOperationValueOutOfBound = IOErrorTemplate { + "kSocketOperationValueOutOfBound", IOErrorType::kSocketOperationValueOutOfBound +}; + +auto const kAddressNotValid = IOErrorTemplate { + "Address not valid", IOErrorType::kAddressNotValid +}; + +} + +} + +#endif //HIDRA2_SYSTEM__IO_ERROR_H diff --git a/common/cpp/include/system_wrappers/io_factory.h b/common/cpp/include/system/io_factory.h similarity index 100% rename from common/cpp/include/system_wrappers/io_factory.h rename to common/cpp/include/system/io_factory.h diff --git a/common/cpp/include/system_wrappers/system_io.h b/common/cpp/include/system/system_io.h similarity index 97% rename from common/cpp/include/system_wrappers/system_io.h rename to common/cpp/include/system/system_io.h index 2a1703d7f..3aac18edd 100644 --- a/common/cpp/include/system_wrappers/system_io.h +++ b/common/cpp/include/system/system_io.h @@ -1,5 +1,5 @@ -#ifndef HIDRA2_SYSTEM_WRAPPERS__SYSTEM_IO_H -#define HIDRA2_SYSTEM_WRAPPERS__SYSTEM_IO_H +#ifndef HIDRA2_SYSTEM__SYSTEM_IO_H +#define HIDRA2_SYSTEM__SYSTEM_IO_H #include "io.h" @@ -108,4 +108,4 @@ class SystemIO final : public IO { }; } -#endif //HIDRA2_SYSTEM_WRAPPERS__SYSTEM_IO_H +#endif //HIDRA2_SYSTEM__SYSTEM_IO_H diff --git a/common/cpp/include/system_wrappers/io.h b/common/cpp/include/system_wrappers/io.h deleted file mode 100644 index 76fe9f1c7..000000000 --- a/common/cpp/include/system_wrappers/io.h +++ /dev/null @@ -1,238 +0,0 @@ -#ifndef HIDRA2_SYSTEM_WRAPPERS__IO_H -#define HIDRA2_SYSTEM_WRAPPERS__IO_H - -#include <cinttypes> - -#include <string> -#include <vector> -#include <chrono> -#include <thread> - -#include "common/data_structs.h" -#include "common/error.h" - -namespace hidra2 { - - -enum class IOErrorType { - kUnknownIOError, - kBadFileNumber, - kResourceTemporarilyUnavailable, - kFileNotFound, - kReadError, - kPermissionDenied, - kUnsupportedAddressFamily, - kInvalidAddressFormat, - kAddressAlreadyInUse, - kConnectionRefused, - kConnectionResetByPeer, - kTimeout, - kFileAlreadyExists, - kNoSpaceLeft, - kSocketOperationOnNonSocket, - kInvalidMemoryAddress, - kUnableToResolveHostname, - kSocketOperationUnknownAtLevel, - kSocketOperationValueOutOfBound, - kAddressNotValid - -}; - -class IOError : public SimpleError { - private: - IOErrorType io_error_type_; - public: - IOError(const std::string& error, IOErrorType io_error_type) : SimpleError(error, ErrorType::kIOError) { - io_error_type_ = io_error_type; - } - - IOErrorType GetIOErrorType() const noexcept { - return io_error_type_; - } -}; - -class IOErrorTemplate : public SimpleErrorTemplate { - protected: - IOErrorType io_error_type_; - public: - IOErrorTemplate(const std::string& error, IOErrorType io_error_type) : SimpleErrorTemplate(error, ErrorType::kIOError) { - io_error_type_ = io_error_type; - } - - inline IOErrorType GetIOErrorType() const noexcept { - return io_error_type_; - } - - inline Error Generate() const noexcept override { - return Error(new IOError(error_, io_error_type_)); - } - - inline bool operator == (const Error& rhs) const override { - return SimpleErrorTemplate::operator==(rhs) - && GetIOErrorType() == ((IOError*)rhs.get())->GetIOErrorType(); - } -}; - -static inline std::ostream& operator<<(std::ostream& os, const IOErrorTemplate& err) { - return os << err.Text(); -} - - -namespace IOErrorTemplates { -auto const kUnknownIOError = IOErrorTemplate { - "Unknown Error", IOErrorType::kUnknownIOError -}; - -auto const kFileNotFound = IOErrorTemplate { - "No such file or directory", IOErrorType::kFileNotFound -}; -auto const kReadError = IOErrorTemplate { - "Read error", IOErrorType::kReadError -}; -auto const kBadFileNumber = IOErrorTemplate { - "Bad file number", IOErrorType::kBadFileNumber -}; -auto const kResourceTemporarilyUnavailable = IOErrorTemplate { - "Resource temporarily unavailable", IOErrorType::kResourceTemporarilyUnavailable -}; -auto const kPermissionDenied = IOErrorTemplate { - "Permission denied", IOErrorType::kPermissionDenied -}; -auto const kUnsupportedAddressFamily = IOErrorTemplate { - "Unsupported address family", IOErrorType::kUnsupportedAddressFamily -}; -auto const kInvalidAddressFormat = IOErrorTemplate { - "Invalid address format", IOErrorType::kInvalidAddressFormat -}; -auto const kAddressAlreadyInUse = IOErrorTemplate { - "Address already in use", IOErrorType::kAddressAlreadyInUse -}; -auto const kConnectionRefused = IOErrorTemplate { - "Connection refused", IOErrorType::kConnectionRefused -}; -auto const kConnectionResetByPeer = IOErrorTemplate { - "kConnectionResetByPeer", IOErrorType::kConnectionResetByPeer -}; -auto const kTimeout = IOErrorTemplate { - "kTimeout", IOErrorType::kTimeout -}; -auto const kFileAlreadyExists = IOErrorTemplate { - "kFileAlreadyExists", IOErrorType::kFileAlreadyExists -}; -auto const kNoSpaceLeft = IOErrorTemplate { - "kNoSpaceLeft", IOErrorType::kNoSpaceLeft -}; -auto const kSocketOperationOnNonSocket = IOErrorTemplate { - "kSocketOperationOnNonSocket", IOErrorType::kSocketOperationOnNonSocket -}; -auto const kInvalidMemoryAddress = IOErrorTemplate { - "kInvalidMemoryAddress", IOErrorType::kInvalidMemoryAddress -}; -auto const kUnableToResolveHostname = IOErrorTemplate { - "kUnableToResolveHostname", IOErrorType::kUnableToResolveHostname -}; -auto const kSocketOperationUnknownAtLevel = IOErrorTemplate { - "kSocketOperationUnknownAtLevel", IOErrorType::kSocketOperationUnknownAtLevel -}; - -auto const kSocketOperationValueOutOfBound = IOErrorTemplate { - "kSocketOperationValueOutOfBound", IOErrorType::kSocketOperationValueOutOfBound -}; - -auto const kAddressNotValid = IOErrorTemplate { - "Address not valid", IOErrorType::kAddressNotValid -}; - -} - -//Need to be "enum" since multiple flags are allowed -enum FileOpenMode { - IO_OPEN_MODE_READ = 1 << 0, - IO_OPEN_MODE_WRITE = 1 << 1, - IO_OPEN_MODE_RW = IO_OPEN_MODE_READ | IO_OPEN_MODE_WRITE, - IO_OPEN_MODE_CREATE = 1 << 2, - IO_OPEN_MODE_CREATE_AND_FAIL_IF_EXISTS = 1 << 3, - /** - * Will set the length of a file to 0 - * Only works if file is open with READ and WRITE mode - */ - IO_OPEN_MODE_SET_LENGTH_0 = 1 << 4, -}; - -enum class AddressFamilies { - INET, -}; - -enum class SocketTypes { - STREAM, -}; - -enum class SocketProtocols { - IP, -}; - -typedef int FileDescriptor; -typedef int SocketDescriptor; - -class IO { - public: - - /* - * Special - */ - virtual std::unique_ptr<std::thread> NewThread (std::function<void()> function) const = 0; - - /* - * Network - */ - virtual SocketDescriptor CreateSocket(AddressFamilies address_family, SocketTypes socket_type, - SocketProtocols socket_protocol, Error* err) const = 0; - virtual void Listen(SocketDescriptor socket_fd, int backlog, Error* err) const = 0; - virtual void InetBind(SocketDescriptor socket_fd, const std::string& address, Error* err) const = 0; - virtual SocketDescriptor CreateAndBindIPTCPSocketListener(const std::string& address, int backlog, - Error* err) const = 0; - virtual std::unique_ptr<std::tuple<std::string, SocketDescriptor>> InetAcceptConnection(SocketDescriptor socket_fd, - Error* err) const = 0; - virtual std::string ResolveHostnameToIp(const std::string& hostname, Error* err) const = 0; - virtual void InetConnect(SocketDescriptor socket_fd, const std::string& address, Error* err) const = 0; - virtual SocketDescriptor CreateAndConnectIPTCPSocket(const std::string& address, Error* err) const = 0; - virtual size_t Receive(SocketDescriptor socket_fd, void* buf, size_t length, Error* err) const = 0; - virtual size_t ReceiveWithTimeout(SocketDescriptor socket_fd, - void* buf, - size_t length, - long timeout_in_usec, - Error* err) const = 0; - virtual size_t Send(SocketDescriptor socket_fd, const void* buf, size_t length, Error* err) const = 0; - - virtual void Skip(SocketDescriptor socket_fd, size_t length, Error* err) const = 0; - /** - * @param err Since CloseSocket if often used in an error case, it's able to accept err as nullptr. - */ - virtual void CloseSocket(SocketDescriptor socket_fd, Error* err) const = 0; - - /* - * Filesystem - */ - virtual FileDescriptor Open (const std::string& filename, int open_flags, Error* err) const = 0; - /** - * @param err Since Close if often used in an error case, it's able to accept err as nullptr. - */ - virtual void Close (FileDescriptor fd, Error* err) const = 0; - - virtual size_t Read (FileDescriptor fd, void* buf, size_t length, Error* err) const = 0; - virtual size_t Write (FileDescriptor fd, const void* buf, size_t length, Error* err) const = 0; - - virtual Error WriteDataToFile (const std::string& fname, const FileData& data, size_t length) const = 0; - - virtual void CreateNewDirectory (const std::string& directory_name, Error* err) const = 0; - virtual FileData GetDataFromFile (const std::string& fname, uint64_t fsize, Error* err) const = 0; - virtual void CollectFileInformationRecursively(const std::string& path, std::vector<FileInfo>* files, - Error* err) const = 0; - virtual std::vector<FileInfo> FilesInFolder (const std::string& folder, Error* err) const = 0; - virtual std::string ReadFileToString (const std::string& fname, Error* err) const = 0; - -}; - -} - -#endif //HIDRA2_SYSTEM_WRAPPERS__IO_H diff --git a/common/cpp/include/unittests/MockIO.h b/common/cpp/include/unittests/MockIO.h index 262245a8b..909662886 100644 --- a/common/cpp/include/unittests/MockIO.h +++ b/common/cpp/include/unittests/MockIO.h @@ -4,7 +4,7 @@ #include <gtest/gtest.h> #include <gmock/gmock.h> -#include "system_wrappers/io.h" +#include "system/io.h" namespace hidra2 { class MockIO : public IO { public: diff --git a/common/cpp/src/json_parser/rapid_json.cpp b/common/cpp/src/json_parser/rapid_json.cpp index 6d5d65b75..09b62116b 100644 --- a/common/cpp/src/json_parser/rapid_json.cpp +++ b/common/cpp/src/json_parser/rapid_json.cpp @@ -3,7 +3,7 @@ using namespace rapidjson; -#include "system_wrappers/io_factory.h" +#include "system/io_factory.h" namespace hidra2 { diff --git a/common/cpp/src/json_parser/rapid_json.h b/common/cpp/src/json_parser/rapid_json.h index 6f55934c2..661d695fc 100644 --- a/common/cpp/src/json_parser/rapid_json.h +++ b/common/cpp/src/json_parser/rapid_json.h @@ -3,7 +3,7 @@ #include "rapidjson/document.h" #include "common/error.h" -#include "system_wrappers/io.h" +#include "system/io.h" namespace hidra2 { diff --git a/common/cpp/src/system_io/io_factory.cpp b/common/cpp/src/system_io/io_factory.cpp index 116f87e9b..b30384adb 100644 --- a/common/cpp/src/system_io/io_factory.cpp +++ b/common/cpp/src/system_io/io_factory.cpp @@ -1,5 +1,5 @@ -#include "system_wrappers/system_io.h" -#include "system_wrappers/io_factory.h" +#include "system/system_io.h" +#include "system/io_factory.h" namespace hidra2 { diff --git a/common/cpp/src/system_io/system_io.cpp b/common/cpp/src/system_io/system_io.cpp index d91eda9a4..a6086681e 100644 --- a/common/cpp/src/system_io/system_io.cpp +++ b/common/cpp/src/system_io/system_io.cpp @@ -6,7 +6,6 @@ #include <cstring> #include <algorithm> -#include <system_wrappers/system_io.h> #if defined(__linux__) || defined (__APPLE__) #include <sys/socket.h> @@ -19,6 +18,8 @@ #include <sys/select.h> #endif +#include "system/system_io.h" + namespace hidra2 { diff --git a/common/cpp/src/system_io/system_io_linux.cpp b/common/cpp/src/system_io/system_io_linux.cpp index 4bbb6cac0..004947186 100644 --- a/common/cpp/src/system_io/system_io_linux.cpp +++ b/common/cpp/src/system_io/system_io_linux.cpp @@ -1,4 +1,3 @@ -#include "system_wrappers/system_io.h" #include <cstring> @@ -12,11 +11,13 @@ #include <zconf.h> #include <netdb.h> +#include "system/system_io.h" + + using std::string; using std::vector; using std::chrono::system_clock; - namespace hidra2 { /** diff --git a/common/cpp/src/system_io/system_io_windows.cpp b/common/cpp/src/system_io/system_io_windows.cpp index 19f9e377e..de3771551 100644 --- a/common/cpp/src/system_io/system_io_windows.cpp +++ b/common/cpp/src/system_io/system_io_windows.cpp @@ -1,4 +1,4 @@ -#include "system_wrappers/system_io.h" +#include "system/system_io.h" #include <cstring> #include <sys/stat.h> diff --git a/examples/producer/dummy-data-producer/dummy_data_producer.cpp b/examples/producer/dummy-data-producer/dummy_data_producer.cpp index be419bf09..a9476d524 100644 --- a/examples/producer/dummy-data-producer/dummy_data_producer.cpp +++ b/examples/producer/dummy-data-producer/dummy_data_producer.cpp @@ -1,10 +1,10 @@ - -#include <producer/producer.h> #include <iostream> #include <chrono> #include <vector> #include <tuple> +#include "hidra2_producer.h" + using std::chrono::high_resolution_clock; typedef std::tuple<std::string, size_t, uint64_t> ArgumentTuple; diff --git a/producer/api/include/hidra2_producer.h b/producer/api/include/hidra2_producer.h new file mode 100644 index 000000000..34f852058 --- /dev/null +++ b/producer/api/include/hidra2_producer.h @@ -0,0 +1,6 @@ +#ifndef HIDRA2_HIDRA2_PRODUCER_H +#define HIDRA2_HIDRA2_PRODUCER_H + +#include "producer/producer.h" + +#endif //HIDRA2_HIDRA2_PRODUCER_H diff --git a/producer/api/src/producer_impl.cpp b/producer/api/src/producer_impl.cpp index 69f785c66..8ca887112 100644 --- a/producer/api/src/producer_impl.cpp +++ b/producer/api/src/producer_impl.cpp @@ -2,7 +2,7 @@ #include <cstring> #include "producer_impl.h" -#include "system_wrappers/io_factory.h" +#include "system/io_factory.h" namespace hidra2 { @@ -20,7 +20,7 @@ ProducerStatus ProducerImpl::GetStatus() const { return status_; } -Error ProducerImpl::InitializeSocketToReceiver_(const std::string& receiver_address) { +Error ProducerImpl::InitializeSocketToReceiver(const std::string& receiver_address) { Error err; FileDescriptor fd = io__->CreateAndConnectIPTCPSocket(receiver_address, &err); if(err != nullptr) { @@ -32,11 +32,11 @@ Error ProducerImpl::InitializeSocketToReceiver_(const std::string& receiver_addr } Error ProducerImpl::ConnectToReceiver(const std::string& receiver_address) { - if(client_fd_ != -1 && status_ != ProducerStatus::kDisconnected) { + if(status_ != ProducerStatus::kDisconnected) { return ProducerErrorTemplates::kAlreadyConnected.Generate(); } - auto error = InitializeSocketToReceiver_(receiver_address); + auto error = InitializeSocketToReceiver(receiver_address); if(error) { status_ = ProducerStatus::kDisconnected; return error; diff --git a/producer/api/src/producer_impl.h b/producer/api/src/producer_impl.h index bc1fc280a..30642ab1a 100644 --- a/producer/api/src/producer_impl.h +++ b/producer/api/src/producer_impl.h @@ -3,7 +3,7 @@ #include <string> #include <common/networking.h> -#include <system_wrappers/io.h> +#include <system/io.h> #include "producer/producer.h" namespace hidra2 { @@ -16,7 +16,7 @@ class ProducerImpl : public Producer { ProducerStatus status_ = ProducerStatus::kDisconnected; - Error InitializeSocketToReceiver_(const std::string& receiver_address); + Error InitializeSocketToReceiver(const std::string& receiver_address); GenericNetworkRequestHeader GenerateNextSendRequest(uint64_t file_id, size_t file_size); Error SendHeaderAndData(const GenericNetworkRequestHeader& header, const void* data, size_t file_size); Error ReceiveResponce(); diff --git a/producer/api/unittests/test_producer.cpp b/producer/api/unittests/test_producer.cpp index 8345d264b..91b1f691a 100644 --- a/producer/api/unittests/test_producer.cpp +++ b/producer/api/unittests/test_producer.cpp @@ -1,13 +1,15 @@ #include <gtest/gtest.h> -#include <producer/producer.h> #include <unittests/MockIO.h> +#include "producer/producer.h" +#include "../src/producer_impl.h" using ::testing::Ne; namespace { TEST(CreateProducer, PointerIsNotNullptr) { std::unique_ptr<hidra2::Producer> producer = hidra2::Producer::Create(); + ASSERT_THAT(dynamic_cast<hidra2::ProducerImpl*>(producer.get()), Ne(nullptr)); ASSERT_THAT(producer.get(), Ne(nullptr)); } diff --git a/producer/api/unittests/test_producer_impl.cpp b/producer/api/unittests/test_producer_impl.cpp index 2bb141400..3fdbe4688 100644 --- a/producer/api/unittests/test_producer_impl.cpp +++ b/producer/api/unittests/test_producer_impl.cpp @@ -3,7 +3,7 @@ #include <unittests/MockIO.h> #include "common/error.h" -#include "system_wrappers/io.h" +#include "system/io.h" #include "producer/producer.h" #include "../src/producer_impl.h" diff --git a/receiver/src/connection.cpp b/receiver/src/connection.cpp index 7567d319e..e734f417a 100644 --- a/receiver/src/connection.cpp +++ b/receiver/src/connection.cpp @@ -2,7 +2,7 @@ #include <assert.h> #include "connection.h" #include "receiver_error.h" -#include "system_wrappers/io_factory.h" +#include "system/io_factory.h" namespace hidra2 { diff --git a/receiver/src/connection.h b/receiver/src/connection.h index 23e66b199..c03d85c03 100644 --- a/receiver/src/connection.h +++ b/receiver/src/connection.h @@ -12,7 +12,7 @@ #include <vector> #include "common/networking.h" -#include "system_wrappers/io.h" +#include "system/io.h" #include "request.h" namespace hidra2 { diff --git a/receiver/src/receiver.cpp b/receiver/src/receiver.cpp index d384ac936..01978c842 100644 --- a/receiver/src/receiver.cpp +++ b/receiver/src/receiver.cpp @@ -3,7 +3,7 @@ #include "receiver.h" #include "receiver_error.h" #include "connection.h" -#include <system_wrappers/io_factory.h> +#include <system/io_factory.h> namespace hidra2 { diff --git a/receiver/src/request.cpp b/receiver/src/request.cpp index 8d4b90d2e..ac86cac6c 100644 --- a/receiver/src/request.cpp +++ b/receiver/src/request.cpp @@ -1,5 +1,5 @@ #include "request.h" -#include "system_wrappers/io_factory.h" +#include "system/io_factory.h" namespace hidra2 { diff --git a/receiver/src/request.h b/receiver/src/request.h index dd45a8c74..6c8845d58 100644 --- a/receiver/src/request.h +++ b/receiver/src/request.h @@ -3,7 +3,7 @@ #include "receiver_error.h" #include "common/networking.h" -#include "system_wrappers/io.h" +#include "system/io.h" #include "request_handler.h" #include "request_handler_file_write.h" diff --git a/receiver/src/request_handler_file_write.cpp b/receiver/src/request_handler_file_write.cpp index 346416db6..6af753677 100644 --- a/receiver/src/request_handler_file_write.cpp +++ b/receiver/src/request_handler_file_write.cpp @@ -1,5 +1,5 @@ #include "request_handler_file_write.h" -#include "system_wrappers/io_factory.h" +#include "system/io_factory.h" #include "request.h" namespace hidra2 { diff --git a/receiver/src/request_handler_file_write.h b/receiver/src/request_handler_file_write.h index fb56d4e25..c38daaabc 100644 --- a/receiver/src/request_handler_file_write.h +++ b/receiver/src/request_handler_file_write.h @@ -3,7 +3,7 @@ #include "request_handler.h" -#include "system_wrappers/io.h" +#include "system/io.h" namespace hidra2 { diff --git a/tests/system_io/ip_tcp_network/ip_tcp_network.cpp b/tests/system_io/ip_tcp_network/ip_tcp_network.cpp index 9d077e9d2..8f5b9c1af 100644 --- a/tests/system_io/ip_tcp_network/ip_tcp_network.cpp +++ b/tests/system_io/ip_tcp_network/ip_tcp_network.cpp @@ -1,5 +1,5 @@ #include <iostream> -#include <system_wrappers/system_io.h> +#include <system/system_io.h> #include <chrono> #include <thread> #include <future> diff --git a/tests/system_io/ip_tcp_network_speedtest/ip_tcp_network_speedtest.cpp b/tests/system_io/ip_tcp_network_speedtest/ip_tcp_network_speedtest.cpp index 324748033..1b234f469 100644 --- a/tests/system_io/ip_tcp_network_speedtest/ip_tcp_network_speedtest.cpp +++ b/tests/system_io/ip_tcp_network_speedtest/ip_tcp_network_speedtest.cpp @@ -1,5 +1,5 @@ #include <iostream> -#include <system_wrappers/system_io.h> +#include <system/system_io.h> #include <future> #include <iomanip> diff --git a/tests/system_io/read_file_content/read_file_content.cpp b/tests/system_io/read_file_content/read_file_content.cpp index 065e94328..538fd0b23 100644 --- a/tests/system_io/read_file_content/read_file_content.cpp +++ b/tests/system_io/read_file_content/read_file_content.cpp @@ -1,5 +1,5 @@ #include <iostream> -#include <system_wrappers/system_io.h> +#include <system/system_io.h> #include "testing.h" diff --git a/tests/system_io/read_folder_content/read_folder_content.cpp b/tests/system_io/read_folder_content/read_folder_content.cpp index ffc4588ee..5f753075f 100644 --- a/tests/system_io/read_folder_content/read_folder_content.cpp +++ b/tests/system_io/read_folder_content/read_folder_content.cpp @@ -1,6 +1,6 @@ #include <iostream> -#include "system_wrappers/io_factory.h" +#include "system/io_factory.h" #include "testing.h" using hidra2::IO; diff --git a/tests/system_io/read_string_from_file/read_string_from_file.cpp b/tests/system_io/read_string_from_file/read_string_from_file.cpp index 6a41e2e76..371403f41 100644 --- a/tests/system_io/read_string_from_file/read_string_from_file.cpp +++ b/tests/system_io/read_string_from_file/read_string_from_file.cpp @@ -1,5 +1,5 @@ #include <iostream> -#include <system_wrappers/system_io.h> +#include <system/system_io.h> #include "testing.h" diff --git a/tests/system_io/resolve_hostname_to_ip/resolve_hostname_to_ip.cpp b/tests/system_io/resolve_hostname_to_ip/resolve_hostname_to_ip.cpp index e031b3f4e..d4f693e42 100644 --- a/tests/system_io/resolve_hostname_to_ip/resolve_hostname_to_ip.cpp +++ b/tests/system_io/resolve_hostname_to_ip/resolve_hostname_to_ip.cpp @@ -1,5 +1,5 @@ #include <iostream> -#include <system_wrappers/system_io.h> +#include <system/system_io.h> #include "testing.h" diff --git a/tests/system_io/write_data_to_file/write_data_to_file.cpp b/tests/system_io/write_data_to_file/write_data_to_file.cpp index de329c7b5..b50085b8e 100644 --- a/tests/system_io/write_data_to_file/write_data_to_file.cpp +++ b/tests/system_io/write_data_to_file/write_data_to_file.cpp @@ -1,5 +1,5 @@ #include <iostream> -#include <system_wrappers/system_io.h> +#include <system/system_io.h> #include "testing.h" diff --git a/worker/api/cpp/src/folder_data_broker.cpp b/worker/api/cpp/src/folder_data_broker.cpp index 851fbce7d..5fbdf6775 100644 --- a/worker/api/cpp/src/folder_data_broker.cpp +++ b/worker/api/cpp/src/folder_data_broker.cpp @@ -1,6 +1,6 @@ #include "folder_data_broker.h" -#include "system_wrappers/io_factory.h" +#include "system/io_factory.h" namespace hidra2 { diff --git a/worker/api/cpp/src/folder_data_broker.h b/worker/api/cpp/src/folder_data_broker.h index 4ffe1b211..4fbec5df6 100644 --- a/worker/api/cpp/src/folder_data_broker.h +++ b/worker/api/cpp/src/folder_data_broker.h @@ -6,7 +6,7 @@ #include <string> #include <mutex> -#include "system_wrappers/io.h" +#include "system/io.h" namespace hidra2 { diff --git a/worker/api/cpp/src/server_data_broker.cpp b/worker/api/cpp/src/server_data_broker.cpp index fca1ce551..733b4865e 100644 --- a/worker/api/cpp/src/server_data_broker.cpp +++ b/worker/api/cpp/src/server_data_broker.cpp @@ -1,5 +1,5 @@ #include "server_data_broker.h" -#include "system_wrappers/io_factory.h" +#include "system/io_factory.h" #include "curl_http_client.h" namespace hidra2 { diff --git a/worker/api/cpp/src/server_data_broker.h b/worker/api/cpp/src/server_data_broker.h index d77fff8bf..d90b9f557 100644 --- a/worker/api/cpp/src/server_data_broker.h +++ b/worker/api/cpp/src/server_data_broker.h @@ -2,7 +2,7 @@ #define HIDRA2_SERVER_DATA_BROKER_H #include "worker/data_broker.h" -#include "system_wrappers/io.h" +#include "system/io.h" #include "http_client.h" diff --git a/worker/api/cpp/unittests/test_folder_broker.cpp b/worker/api/cpp/unittests/test_folder_broker.cpp index a70c4845b..d6dec1c04 100644 --- a/worker/api/cpp/unittests/test_folder_broker.cpp +++ b/worker/api/cpp/unittests/test_folder_broker.cpp @@ -3,8 +3,8 @@ #include "gtest/gtest.h" #include "worker/data_broker.h" -#include "system_wrappers/io.h" -#include "system_wrappers/system_io.h" +#include "system/io.h" +#include "system/system_io.h" #include "../src/folder_data_broker.h" using hidra2::DataBrokerFactory; diff --git a/worker/api/cpp/unittests/test_server_broker.cpp b/worker/api/cpp/unittests/test_server_broker.cpp index f9dd28e49..453423f51 100644 --- a/worker/api/cpp/unittests/test_server_broker.cpp +++ b/worker/api/cpp/unittests/test_server_broker.cpp @@ -2,8 +2,8 @@ #include "gtest/gtest.h" #include "worker/data_broker.h" -#include "system_wrappers/io.h" -#include "system_wrappers/system_io.h" +#include "system/io.h" +#include "system/system_io.h" #include "../src/server_data_broker.h" #include "../src/curl_http_client.h" #include "unittests/MockIO.h" diff --git a/worker/tools/folder_to_db/src/folder_db_importer.cpp b/worker/tools/folder_to_db/src/folder_db_importer.cpp index eb2494f94..15998cb13 100644 --- a/worker/tools/folder_to_db/src/folder_db_importer.cpp +++ b/worker/tools/folder_to_db/src/folder_db_importer.cpp @@ -3,7 +3,7 @@ #include <future> #include <algorithm> -#include "system_wrappers/io_factory.h" +#include "system/io_factory.h" #include "database/database.h" diff --git a/worker/tools/folder_to_db/src/folder_db_importer.h b/worker/tools/folder_to_db/src/folder_db_importer.h index aecadd203..b1d0ee04c 100644 --- a/worker/tools/folder_to_db/src/folder_db_importer.h +++ b/worker/tools/folder_to_db/src/folder_db_importer.h @@ -6,7 +6,7 @@ #include <future> -#include "system_wrappers/io.h" +#include "system/io.h" #include "database/database.h" #include "common/error.h" namespace hidra2 { diff --git a/worker/tools/folder_to_db/unittests/test_folder_to_db.cpp b/worker/tools/folder_to_db/unittests/test_folder_to_db.cpp index 196ff2a7c..4c43d081d 100644 --- a/worker/tools/folder_to_db/unittests/test_folder_to_db.cpp +++ b/worker/tools/folder_to_db/unittests/test_folder_to_db.cpp @@ -2,8 +2,8 @@ #include "gtest/gtest.h" #include <thread> -#include "system_wrappers/io.h" -#include "system_wrappers/system_io.h" +#include "system/io.h" +#include "system/system_io.h" #include "database/database.h" -- GitLab