diff --git a/common/cpp/CMakeLists.txt b/common/cpp/CMakeLists.txt index 8a24c3accfb2236713ced19c03304653d9ab1a72..6786909571b5f11a6c6d5280713d41bacc17ad18 100644 --- a/common/cpp/CMakeLists.txt +++ b/common/cpp/CMakeLists.txt @@ -1,5 +1,10 @@ set(TARGET_NAME common) -set(SOURCE_FILES include/common/os.h include/common/networking.h) +set(SOURCE_FILES + include/common/os.h + include/common/networking.h + include/system_wrappers/io.h + include/system_wrappers/system_io.h src/system_io.cpp + ) ################################ @@ -8,10 +13,3 @@ set(SOURCE_FILES include/common/os.h include/common/networking.h) add_library(${TARGET_NAME} SHARED ${SOURCE_FILES}) target_include_directories(${TARGET_NAME} PUBLIC include) set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX) - -################################ -# Testing -################################ -set(TEST_SOURCE_FILES unittests/test_common.cpp) -set(TEST_LIBRARIES common) -gtest(${TARGET_NAME} ${TEST_SOURCE_FILES} ${TEST_LIBRARIES}) diff --git a/common/cpp/include/common/networking.h b/common/cpp/include/common/networking.h index fb0fdadb6c72e00a5d96c6e4a6b1c5494d135ac5..b3cd443c0335c619403043e60610ab4a7734d404 100644 --- a/common/cpp/include/common/networking.h +++ b/common/cpp/include/common/networking.h @@ -4,41 +4,40 @@ #include <cstdint> #include "os.h" -namespace HIDRA2 -{ - enum OP_CODE : uint8_t { - OP_CODE__HELLO, - }; - - enum ERROR_CODE : uint16_t { - ERR__NO_ERROR, - ERR__UNSUPPORTED_VERSION, - ERR__INTERNAL_SERVER_ERROR = 65535, - }; - - struct NetworkRequest { - OP_CODE op_code; - uint64_t request_id; - char data[]; - }; - - struct NetworkResponse { - OP_CODE op_code; - uint64_t request_id; - ERROR_CODE error_code; - char data[]; - }; - - struct OP_HelloRequest { - uint32_t client_version; - - OS_TYPE os : 4; - bool is_x64 : 1; - }; - - struct OP_HelloResponse { - uint32_t server_version; - }; +namespace hidra2 { +enum OP_CODE : uint8_t { + OP_CODE__HELLO, +}; + +enum ERROR_CODE : uint16_t { + ERR__NO_ERROR, + ERR__UNSUPPORTED_VERSION, + ERR__INTERNAL_SERVER_ERROR = 65535, +}; + +struct NetworkRequest { + OP_CODE op_code; + uint64_t request_id; + char data[]; +}; + +struct NetworkResponse { + OP_CODE op_code; + uint64_t request_id; + ERROR_CODE error_code; + char data[]; +}; + +struct OP_HelloRequest { + uint32_t client_version; + + OS_TYPE os : 4; + bool is_x64 : 1; +}; + +struct OP_HelloResponse { + uint32_t server_version; +}; } #endif //HIDRA2__COMMON_NETWORKING_H diff --git a/common/cpp/include/common/os.h b/common/cpp/include/common/os.h index 984756e0ade21ae2609f3dd84a9c773b617108b2..ddd8c2a3e814b87031b4b48cefbf8f2e2b64de96 100644 --- a/common/cpp/include/common/os.h +++ b/common/cpp/include/common/os.h @@ -3,15 +3,14 @@ #include <cstdint> -namespace HIDRA2 -{ - enum OS_TYPE : uint8_t { - OS_UNKOWN, - OS_LINUX, - OS_WINDOWS, +namespace hidra2 { +enum OS_TYPE : uint8_t { + OS_UNKOWN, + OS_LINUX, + OS_WINDOWS, - OS_INVALID = 16, /* Never use more then 4 bit */ - }; + OS_INVALID = 16, /* Never use more then 4 bit */ +}; } #endif //HIDRA2__COMMON_OS_H diff --git a/common/cpp/include/system_wrappers/io.h b/common/cpp/include/system_wrappers/io.h new file mode 100644 index 0000000000000000000000000000000000000000..d3206d00bfe9bf4c107faf66da32bd393f146632 --- /dev/null +++ b/common/cpp/include/system_wrappers/io.h @@ -0,0 +1,16 @@ +#ifndef HIDRA2_SYSTEM_WRAPPERS__IO_H +#define HIDRA2_SYSTEM_WRAPPERS__IO_H + +namespace hidra2 { + +class IO { + public: + virtual int open(const char *__file, int __oflag) = 0; + virtual int close(int __fd) = 0; + virtual ssize_t read(int __fd, void *buf, size_t count) = 0; + virtual ssize_t write(int __fd, const void *__buf, size_t __n) = 0; +}; + +} + +#endif //HIDRA2_SYSTEM_WRAPPERS__IO_H diff --git a/common/cpp/include/system_wrappers/system_io.h b/common/cpp/include/system_wrappers/system_io.h new file mode 100644 index 0000000000000000000000000000000000000000..41a2d3fdd1ad11e1cb3a1c0e217a0dc9b5d35be1 --- /dev/null +++ b/common/cpp/include/system_wrappers/system_io.h @@ -0,0 +1,16 @@ +#ifndef HIDRA2_SYSTEM_WRAPPERS__SYSTEM_IO_H +#define HIDRA2_SYSTEM_WRAPPERS__SYSTEM_IO_H + +#include "io.h" + +namespace hidra2 { +class SystemIO : public IO { + public: + int open(const char *__file, int __oflag) final; + int close(int __fd) final; + ssize_t read(int __fd, void *buf, size_t count) final; + ssize_t write(int __fd, const void *__buf, size_t __n) final; +}; +} + +#endif //HIDRA2_SYSTEM_WRAPPERS__SYSTEM_IO_H diff --git a/common/cpp/src/system_io.cpp b/common/cpp/src/system_io.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4d9166497f70fd1c9edfa11aabf22a9bd29fbd8c --- /dev/null +++ b/common/cpp/src/system_io.cpp @@ -0,0 +1,19 @@ +#include <fcntl.h> +#include <unistd.h> +#include <system_wrappers/system_io.h> + +int hidra2::SystemIO::open(const char *__file, int __oflag) { + return ::open(__file, __oflag); +} + +int hidra2::SystemIO::close(int __fd) { + return ::close(__fd); +} + +ssize_t hidra2::SystemIO::read(int __fd, void *buf, size_t count) { + return ::read(__fd, buf, count); +} + +ssize_t hidra2::SystemIO::write(int __fd, const void *__buf, size_t __n) { + return ::write(__fd, __buf, __n); +} diff --git a/common/cpp/unittests/test_common.cpp b/common/cpp/unittests/test_common.cpp deleted file mode 100644 index 5f7937f18df83b24f063f6df6cb2d3aaf7a10624..0000000000000000000000000000000000000000 --- a/common/cpp/unittests/test_common.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include <gtest/gtest.h> - -TEST(EMPTY, REMOVEME) -{ - EXPECT_EQ(1, 1); -} diff --git a/producer/api/include/producer/producer.h b/producer/api/include/producer/producer.h index efcfb311d2dafdc8c546b9ffcac92f8892e6b0d5..674836c52d330d3c662efe3204ca33027a1d25de 100644 --- a/producer/api/include/producer/producer.h +++ b/producer/api/include/producer/producer.h @@ -3,21 +3,19 @@ #include <string> -namespace HIDRA2 -{ - class Producer - { - private: - static unsigned long kinit_count_; - Producer(); - public: - static const uint32_t VERSION; +namespace hidra2 { +class Producer { + private: + static unsigned long kinit_count_; + Producer(); + public: + static const uint32_t VERSION; - Producer(const Producer&) = delete; - Producer& operator=(const Producer&) = delete; + Producer(const Producer&) = delete; + Producer& operator=(const Producer&) = delete; - static Producer* CreateProducer(std::string receiver_address); - }; + static Producer* CreateProducer(std::string receiver_address); +}; } #endif //HIDRA2__PRODUCER_PRODUCER_H diff --git a/producer/api/src/producer/producer.cpp b/producer/api/src/producer/producer.cpp index dd530f97a5a69336a4b8df76ed8ea94eb87f8ab6..15a6fca30e57b034984ae3494c1ab9a4471c0341 100644 --- a/producer/api/src/producer/producer.cpp +++ b/producer/api/src/producer/producer.cpp @@ -1,14 +1,12 @@ #include <producer/producer.h> -unsigned long HIDRA2::Producer::kinit_count_ = 0; -const uint32_t HIDRA2::Producer::VERSION = 1; +unsigned long hidra2::Producer::kinit_count_ = 0; +const uint32_t hidra2::Producer::VERSION = 1; -HIDRA2::Producer::Producer() -{ +hidra2::Producer::Producer() { kinit_count_++; } -HIDRA2::Producer *HIDRA2::Producer::CreateProducer(std::string receiver_address) -{ +hidra2::Producer *hidra2::Producer::CreateProducer(std::string receiver_address) { return new Producer(); } diff --git a/producer/api/unittests/test_producer.cpp b/producer/api/unittests/test_producer.cpp index edb6d762f83611ffc79cb92cf7cbccbfa61d047d..ea06e427054fb2d85c69b4c3714ec00e83d89026 100644 --- a/producer/api/unittests/test_producer.cpp +++ b/producer/api/unittests/test_producer.cpp @@ -1,16 +1,13 @@ #include <gtest/gtest.h> #include <producer/producer.h> -namespace -{ - TEST(VERSION, VersionAboveZero) - { - EXPECT_GE(HIDRA2::Producer::VERSION, 0); - } +namespace { +TEST(VERSION, VersionAboveZero) { + EXPECT_GE(hidra2::Producer::VERSION, 0); +} - TEST(CreateProducer, PointerIsNotNullptr) - { - HIDRA2::Producer* prod = HIDRA2::Producer::CreateProducer("127.0.0.1"); - EXPECT_NE(prod, nullptr); - } +TEST(CreateProducer, PointerIsNotNullptr) { + hidra2::Producer* prod = hidra2::Producer::CreateProducer("127.0.0.1"); + EXPECT_NE(prod, nullptr); +} } diff --git a/producer/inotify-event-detector-cpp/src/main.cpp b/producer/inotify-event-detector-cpp/src/main.cpp index 0f7c8b6cf909fbb77eed4d6dfb8d0e67c1962d12..62d77f036cc0be9f6da7bd1728fbe931c97e95db 100644 --- a/producer/inotify-event-detector-cpp/src/main.cpp +++ b/producer/inotify-event-detector-cpp/src/main.cpp @@ -1,11 +1,10 @@ #include <producer/producer.h> #include <iostream> -int main (int argc, char* argv[]) -{ - std::cout << "Running producer version: " << HIDRA2::Producer::VERSION << std::endl; +int main (int argc, char* argv[]) { + std::cout << "Running producer version: " << hidra2::Producer::VERSION << std::endl; - HIDRA2::Producer* producer = HIDRA2::Producer::CreateProducer("127.0.0.1"); + hidra2::Producer* producer = hidra2::Producer::CreateProducer("127.0.0.1"); if(!producer) { std::cerr << "Fail to create producer" << std::endl; return 1; diff --git a/producer/inotify-event-detector-cpp/unittests/test_inotify_client.cpp b/producer/inotify-event-detector-cpp/unittests/test_inotify_client.cpp index 5f7937f18df83b24f063f6df6cb2d3aaf7a10624..1e1b911ef88017e2c98dc5915b52b210f2e18fbf 100644 --- a/producer/inotify-event-detector-cpp/unittests/test_inotify_client.cpp +++ b/producer/inotify-event-detector-cpp/unittests/test_inotify_client.cpp @@ -1,6 +1,5 @@ #include <gtest/gtest.h> -TEST(EMPTY, REMOVEME) -{ +TEST(EMPTY, REMOVEME) { EXPECT_EQ(1, 1); }