diff --git a/BasaltPresenter/Presenter/CMakeLists.txt b/BasaltPresenter/Presenter/CMakeLists.txt index 604a0c3..bf97147 100644 --- a/BasaltPresenter/Presenter/CMakeLists.txt +++ b/BasaltPresenter/Presenter/CMakeLists.txt @@ -3,14 +3,14 @@ target_sources(BasaltPresenter PRIVATE main.cpp dll_loader.cpp - command_client.cpp + cmd_client.cpp ) target_sources(BasaltPresenter PUBLIC FILE_SET HEADERS FILES dll_loader.hpp - command_client.hpp + cmd_client.hpp ) target_include_directories(BasaltPresenter PUBLIC diff --git a/BasaltPresenter/Presenter/command_client.cpp b/BasaltPresenter/Presenter/cmd_client.cpp similarity index 97% rename from BasaltPresenter/Presenter/command_client.cpp rename to BasaltPresenter/Presenter/cmd_client.cpp index d2ffbf0..9b265ae 100644 --- a/BasaltPresenter/Presenter/command_client.cpp +++ b/BasaltPresenter/Presenter/cmd_client.cpp @@ -1,8 +1,8 @@ -#include "command_client.hpp" +#include "cmd_client.hpp" #include #include -namespace Basalt::Presenter { +namespace basalt::presenter::cmd_client { CommandClient::CommandClient() : m_PipeOperator(BSTEXT("ed0e3f1f-d214-4880-9562-640bce15e72e")), m_Status(ClientStatus::Ready) {} diff --git a/BasaltPresenter/Presenter/command_client.hpp b/BasaltPresenter/Presenter/cmd_client.hpp similarity index 72% rename from BasaltPresenter/Presenter/command_client.hpp rename to BasaltPresenter/Presenter/cmd_client.hpp index 122d4ee..f991780 100644 --- a/BasaltPresenter/Presenter/command_client.hpp +++ b/BasaltPresenter/Presenter/cmd_client.hpp @@ -2,16 +2,17 @@ #include #include -namespace Basalt::Presenter { +namespace basalt::presenter::cmd_client { // Protocol codes enum class ProtocolCode : std::uint8_t { - HANDSHAKE_REQUEST = 0x61, //< Trainer -> Presenter - HANDSHAKE_RESPONSE = 0x62, //< Presenter -> Trainer - DATA_READY = 0x01, //< Presenter -> Trainer - DATA_RECEIVED = 0x02, //< Trainer -> Presenter - STOP_REQUEST = 0x71, //< Both directions - STOP = 0x71 //< Both directions (same code) + HANDSHAKE_REQUEST = 0x61, ///< Trainer -> Presenter + HANDSHAKE_RESPONSE = 0x62, ///< Presenter -> Trainer + DATA_READY = 0x01, ///< Presenter -> Trainer + DATA_RECEIVED = 0x02, ///< Trainer -> Presenter + ACTIVELY_STOP = 0x21, ///< Presenter-->Trainer + STOP_REQUEST = 0X71, ///< Presenter<--Trainer + STOP_RESPONSE = 0x72, //< Presenter-->Trainer }; // Pixel kind values diff --git a/BasaltPresenter/Presenter/dll_loader.cpp b/BasaltPresenter/Presenter/dll_loader.cpp index 3a1b89c..5c4c9a1 100644 --- a/BasaltPresenter/Presenter/dll_loader.cpp +++ b/BasaltPresenter/Presenter/dll_loader.cpp @@ -8,9 +8,9 @@ #include #endif -using ::Basalt::Shared::Char::BSStringView; +using ::basalt::shared::char_types::BSStringView; -namespace Basalt::Presenter { +namespace basalt::presenter::dll_loader { static std::filesystem::path get_executable() { #if defined(BASALT_OS_WINDOWS) diff --git a/BasaltPresenter/Presenter/dll_loader.hpp b/BasaltPresenter/Presenter/dll_loader.hpp index c09ac3e..fd21d50 100644 --- a/BasaltPresenter/Presenter/dll_loader.hpp +++ b/BasaltPresenter/Presenter/dll_loader.hpp @@ -1,5 +1,4 @@ #include -#include #if defined(BASALT_OS_WINDOWS) #include @@ -7,7 +6,7 @@ #include #endif -namespace Basalt::Presenter { +namespace basalt::presenter::dll_loader { enum class DllKind { Engine, ///< Render engine @@ -25,7 +24,7 @@ namespace Basalt::Presenter { #endif public: - DllLoader(DllKind kind, const Shared::Char::BSStringView& filename); + DllLoader(DllKind kind, const shared::char_types::BSStringView& filename); ~DllLoader(); private: diff --git a/BasaltPresenter/Shared/CMakeLists.txt b/BasaltPresenter/Shared/CMakeLists.txt index fb53207..d97b7f6 100644 --- a/BasaltPresenter/Shared/CMakeLists.txt +++ b/BasaltPresenter/Shared/CMakeLists.txt @@ -3,8 +3,11 @@ target_sources(BasaltShared PRIVATE # Sources basalt/pipe_operator.cpp - basalt/kernel.cpp basalt/math.cpp + basalt/engine.cpp + basalt/deliver.cpp + basalt/object_loader.cpp + basalt/anime_loader.cpp ) target_sources(BasaltShared @@ -15,8 +18,12 @@ FILES basalt/char_types.hpp basalt/export_macro.hpp basalt/pipe_operator.hpp - basalt/kernel.hpp basalt/math.hpp + basalt/guid.hpp + basalt/engine.hpp + basalt/deliver.hpp + basalt/object_loader.hpp + basalt/anime_loader.hpp ) target_include_directories(BasaltShared PUBLIC diff --git a/BasaltPresenter/Shared/basalt/anime_loader.cpp b/BasaltPresenter/Shared/basalt/anime_loader.cpp new file mode 100644 index 0000000..00eb5ac --- /dev/null +++ b/BasaltPresenter/Shared/basalt/anime_loader.cpp @@ -0,0 +1,13 @@ +#include "anime_loader.hpp" + +namespace basalt::shared::anime_loader { + + IAnimeLoader::IAnimeLoader() { + + } + + IAnimeLoader::~IAnimeLoader() { + + } + +} diff --git a/BasaltPresenter/Shared/basalt/anime_loader.hpp b/BasaltPresenter/Shared/basalt/anime_loader.hpp new file mode 100644 index 0000000..cf4dd74 --- /dev/null +++ b/BasaltPresenter/Shared/basalt/anime_loader.hpp @@ -0,0 +1,13 @@ +#pragma once + +namespace basalt::shared::anime_loader { + + class IAnimeLoader { + public: + IAnimeLoader(); + virtual ~IAnimeLoader(); + + protected: + }; + +} // namespace basalt::shared::anime_loader diff --git a/BasaltPresenter/Shared/basalt/char_types.hpp b/BasaltPresenter/Shared/basalt/char_types.hpp index 6fb445e..a2b421f 100644 --- a/BasaltPresenter/Shared/basalt/char_types.hpp +++ b/BasaltPresenter/Shared/basalt/char_types.hpp @@ -12,9 +12,9 @@ #define BSTEXT(x) x #endif -namespace Basalt::Shared::Char { +namespace basalt::shared::char_types { using BSString = std::basic_string; using BSStringView = std::basic_string_view; -}; // namespace Basalt::Shared::Char +}; // namespace basalt::shared::char_types diff --git a/BasaltPresenter/Shared/basalt/deliver.cpp b/BasaltPresenter/Shared/basalt/deliver.cpp new file mode 100644 index 0000000..302b7aa --- /dev/null +++ b/BasaltPresenter/Shared/basalt/deliver.cpp @@ -0,0 +1,29 @@ +#include "deliver.hpp" +#include + +namespace basalt::shared::deliver { + + IDeliver::IDeliver() {} + + IDeliver::~IDeliver() {} + + guid::Guid IDeliver::GetGuid() const { + throw std::logic_error("unimplemented function"); + } + + void IDeliver::Startup(DeliverConfig &&config) { + if (this->status != DeliverStatus::Ready) throw std::runtime_error("unexpected deliver status"); + this->config = std::move(config); + this->status = DeliverStatus::Running; + } + + void IDeliver::Transmit() { + if (this->status != DeliverStatus::Running) throw std::runtime_error("unexpected deliver status"); + } + + void IDeliver::Shutdown() { + if (this->status != DeliverStatus::Running) throw std::runtime_error("unexpected deliver status"); + this->status = DeliverStatus::Stop; + } + +} diff --git a/BasaltPresenter/Shared/basalt/deliver.hpp b/BasaltPresenter/Shared/basalt/deliver.hpp new file mode 100644 index 0000000..1309050 --- /dev/null +++ b/BasaltPresenter/Shared/basalt/deliver.hpp @@ -0,0 +1,33 @@ +#pragma once +#include "guid.hpp" + +namespace basalt::shared::deliver { + + struct DeliverConfig { + guid::Guid engine; ///< The GUID of render engine. + }; + + enum class DeliverStatus { + Ready, ///< Engine was allocated but not initialized. + Running, ///< Engine has been initialized and running. + Stop, ///< Engine is shutdown. + }; + + class IDeliver { + public: + IDeliver(); + virtual ~IDeliver(); + + public: + virtual guid::Guid GetGuid() const; + virtual void Startup(DeliverConfig&& config); + virtual void Transmit(); + virtual void Shutdown(); + + protected: + DeliverConfig config; + DeliverStatus status; + }; + +} + diff --git a/BasaltPresenter/Shared/basalt/engine.cpp b/BasaltPresenter/Shared/basalt/engine.cpp new file mode 100644 index 0000000..7703c79 --- /dev/null +++ b/BasaltPresenter/Shared/basalt/engine.cpp @@ -0,0 +1,34 @@ +#include "engine.hpp" +#include + +namespace basalt::shared::engine { + + IEngine::IEngine() : config(), status(EngineStatus::Ready) {} + + IEngine::~IEngine() { + if (this->status != EngineStatus::Stop) { + this->Shutdown(); + } + } + + guid::Guid IEngine::GetGuid() const { + throw std::logic_error("unimplemented function"); + } + + void IEngine::Startup(EngineConfig &&config) { + if (this->status != EngineStatus::Ready) throw std::runtime_error("unexpected engine status"); + this->config = std::move(config); + this->status = EngineStatus::Running; + } + + bool IEngine::Tick() { + if (this->status != EngineStatus::Running) throw std::runtime_error("unexpected engine status"); + return false; + } + + void IEngine::Shutdown() { + if (this->status != EngineStatus::Running) throw std::runtime_error("unexpected engine status"); + this->status = EngineStatus::Stop; + } + +} diff --git a/BasaltPresenter/Shared/basalt/engine.hpp b/BasaltPresenter/Shared/basalt/engine.hpp new file mode 100644 index 0000000..6924a61 --- /dev/null +++ b/BasaltPresenter/Shared/basalt/engine.hpp @@ -0,0 +1,41 @@ +#pragma once +#include "guid.hpp" +#include +#include + +namespace basalt::shared::engine { + + struct EngineConfig { + bool headless; ///< Whether enable headless mode (No Window created). + std::uint32_t width; ///< Window width. + std::uint32_t height; ///< Window height. + guid::Guid deliver; ///< The GUID of deliver. + }; + + enum class EngineStatus { + Ready, ///< Engine was allocated but not initialized. + Running, ///< Engine has been initialized and running. + Stop, ///< Engine is shutdown. + }; + + class IEngine { + public: + IEngine(); + virtual ~IEngine(); + + public: + virtual guid::Guid GetGuid() const; + virtual void Startup(EngineConfig&& config); + /** + * @brief + * @return True for active exit. + */ + virtual bool Tick(); + virtual void Shutdown(); + + protected: + EngineConfig config; + EngineStatus status; + }; + +} // namespace basalt::shared::engine diff --git a/BasaltPresenter/Shared/basalt/guid.hpp b/BasaltPresenter/Shared/basalt/guid.hpp new file mode 100644 index 0000000..34a3232 --- /dev/null +++ b/BasaltPresenter/Shared/basalt/guid.hpp @@ -0,0 +1,50 @@ +#pragma once +#include +#include + +namespace basalt::shared::guid { + + struct Guid { + std::uint32_t d1, d2; + + constexpr Guid(std::uint32_t gd1 = 0, std::uint32_t gd2 = 0) : d1(gd1), d2(gd2) {} + Guid(const Guid& rhs) : d1(rhs.d1), d2(rhs.d2) {} + Guid(Guid&& rhs) noexcept : d1(rhs.d1), d2(rhs.d2) {} + Guid& operator=(const Guid& rhs) { + this->d1 = rhs.d1; + this->d2 = rhs.d2; + return *this; + } + Guid& operator=(Guid&& rhs) noexcept { + this->d1 = rhs.d1; + this->d2 = rhs.d2; + return *this; + } + + auto operator<=>(const Guid& rhs) const { + if (auto cmp = this->d1 <=> rhs.d1; cmp != 0) return cmp; + return this->d2 <=> rhs.d2; + } + bool operator==(const Guid& rhs) const { return ((this->d1 == rhs.d1) && (this->d2 == rhs.d2)); } + }; + + constexpr Guid DIRECTX8_ENGINE{0x0, 0x1}; + constexpr Guid DIRECTX9_ENGINE{0x0, 0x2}; + constexpr Guid DIRECTX11_ENGINE{0x0, 0x3}; + constexpr Guid DIRECTX12_ENGINE{0x0, 0x4}; + constexpr Guid OPENGL_ENGINE{0x0, 0x5}; + constexpr Guid VULKAN_ENGINE{0x0, 0x6}; + + constexpr Guid CUDA_DELIVER{0x1, 0x1}; + constexpr Guid ROCM_DELIVER{0x1, 0x2}; + constexpr Guid PIPE_DELIVER{0x1, 0x3}; + constexpr Guid TCP_DELIVER{0x1, 0x4}; + constexpr Guid MMAP_DELIVER{0x1, 0x5}; + + constexpr Guid TINYOBJLOADER_OBJECT_LOADER{0x2, 0x1}; + constexpr Guid CGLTF_OBJECT_LOADER{0x2, 0x2}; + constexpr Guid ASSIMP_OBJECT_LOADER{0x2, 0x3}; + + constexpr Guid HOMEBREW_ANIME_LOADER{0x3, 0x1}; + +} diff --git a/BasaltPresenter/Shared/basalt/kernel.cpp b/BasaltPresenter/Shared/basalt/kernel.cpp deleted file mode 100644 index ec99349..0000000 --- a/BasaltPresenter/Shared/basalt/kernel.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include "kernel.hpp" -#include - -namespace Basalt::Shared::Kernel { - -#pragma region Engine - - IEngine::IEngine() : config(), status(EngineStatus::Ready) {} - - IEngine::~IEngine() { - if (this->status != EngineStatus::Stop) { - this->Shutdown(); - } - } - - Guid IEngine::GetGuid() const { - throw std::logic_error("unimplemented function"); - } - - void IEngine::Startup(EngineConfig &&config) { - if (this->status != EngineStatus::Ready) throw std::runtime_error("unexpected engine status"); - this->config = std::move(config); - this->status = EngineStatus::Running; - } - - bool IEngine::Tick() { - if (this->status != EngineStatus::Running) throw std::runtime_error("unexpected engine status"); - return false; - } - - void IEngine::Shutdown() { - if (this->status != EngineStatus::Running) throw std::runtime_error("unexpected engine status"); - this->status = EngineStatus::Stop; - } - -#pragma endregion - -#pragma region Deliver - - IDeliver::IDeliver() {} - - IDeliver::~IDeliver() {} - - Guid IDeliver::GetGuid() const { - throw std::logic_error("unimplemented function"); - } - - void IDeliver::Startup(DeliverConfig &&config) { - if (this->status != DeliverStatus::Ready) throw std::runtime_error("unexpected deliver status"); - this->config = std::move(config); - this->status = DeliverStatus::Running; - } - - void IDeliver::Transmit() { - if (this->status != DeliverStatus::Running) throw std::runtime_error("unexpected deliver status"); - } - - void IDeliver::Shutdown() { - if (this->status != DeliverStatus::Running) throw std::runtime_error("unexpected deliver status"); - this->status = DeliverStatus::Stop; - } - -#pragma endregion - -} // namespace Basalt::Shared::Kernel diff --git a/BasaltPresenter/Shared/basalt/kernel.hpp b/BasaltPresenter/Shared/basalt/kernel.hpp deleted file mode 100644 index 21e893f..0000000 --- a/BasaltPresenter/Shared/basalt/kernel.hpp +++ /dev/null @@ -1,123 +0,0 @@ -#pragma once -#include "char_types.hpp" -#include -#include - -namespace Basalt::Shared::Kernel { - -#pragma region Guid & Predefined Guid - - struct Guid { - std::uint32_t d1, d2; - - constexpr Guid(std::uint32_t gd1 = 0, std::uint32_t gd2 = 0) : d1(gd1), d2(gd2) {} - Guid(const Guid& rhs) : d1(rhs.d1), d2(rhs.d2) {} - Guid(Guid&& rhs) noexcept : d1(rhs.d1), d2(rhs.d2) {} - Guid& operator=(const Guid& rhs) { - this->d1 = rhs.d1; - this->d2 = rhs.d2; - return *this; - } - Guid& operator=(Guid&& rhs) noexcept { - this->d1 = rhs.d1; - this->d2 = rhs.d2; - return *this; - } - - auto operator<=>(const Guid& rhs) const { - if (auto cmp = this->d1 <=> rhs.d1; cmp != 0) return cmp; - return this->d2 <=> rhs.d2; - } - bool operator==(const Guid& rhs) const { return ((this->d1 == rhs.d1) && (this->d2 == rhs.d2)); } - }; - - constexpr Guid DIRECTX8_ENGINE{0x0, 0x1}; - constexpr Guid DIRECTX9_ENGINE{0x0, 0x2}; - constexpr Guid DIRECTX11_ENGINE{0x0, 0x3}; - constexpr Guid DIRECTX12_ENGINE{0x0, 0x4}; - constexpr Guid OPENGL_ENGINE{0x0, 0x5}; - constexpr Guid VULKAN_ENGINE{0x0, 0x6}; - - constexpr Guid CUDA_DELIVER{0x1, 0x1}; - constexpr Guid ROCM_DELIVER{0x1, 0x2}; - constexpr Guid PIPE_DELIVER{0x1, 0x3}; - constexpr Guid TCP_DELIVER{0x1, 0x4}; - constexpr Guid MMAP_DELIVER{0x1, 0x5}; - - constexpr Guid TINYOBJLOADER_OBJECT_LOADER{0x2, 0x1}; - constexpr Guid CGLTF_OBJECT_LOADER{0x2, 0x2}; - constexpr Guid ASSIMP_OBJECT_LOADER{0x2, 0x3}; - - constexpr Guid HOMEBREW_ANIME_LOADER{0x3, 0x1}; - -#pragma endregion - -#pragma region Engine - - struct EngineConfig { - bool headless; ///< Whether enable headless mode (No Window created). - std::basic_string title; ///< Window title. - std::uint32_t width; ///< Window width. - std::uint32_t height; ///< Window height. - Guid deliver; ///< The GUID of deliver. - }; - - enum class EngineStatus { - Ready, ///< Engine was allocated but not initialized. - Running, ///< Engine has been initialized and running. - Stop, ///< Engine is shutdown. - }; - - class IEngine { - public: - IEngine(); - virtual ~IEngine(); - - public: - virtual Guid GetGuid() const; - virtual void Startup(EngineConfig&& config); - /** - * @brief - * @return True for active exit. - */ - virtual bool Tick(); - virtual void Shutdown(); - - protected: - EngineConfig config; - EngineStatus status; - }; - -#pragma endregion - -#pragma region Deliver - - struct DeliverConfig { - Guid engine; ///< The GUID of render engine. - }; - - enum class DeliverStatus { - Ready, ///< Engine was allocated but not initialized. - Running, ///< Engine has been initialized and running. - Stop, ///< Engine is shutdown. - }; - - class IDeliver { - public: - IDeliver(); - virtual ~IDeliver(); - - public: - virtual Guid GetGuid() const; - virtual void Startup(DeliverConfig&& config); - virtual void Transmit(); - virtual void Shutdown(); - - protected: - DeliverConfig config; - DeliverStatus status; - }; - -#pragma endregion - -} // namespace Basalt::Shared::Kernel diff --git a/BasaltPresenter/Shared/basalt/math.cpp b/BasaltPresenter/Shared/basalt/math.cpp index 8b66f4b..872c124 100644 --- a/BasaltPresenter/Shared/basalt/math.cpp +++ b/BasaltPresenter/Shared/basalt/math.cpp @@ -1,5 +1,82 @@ #include "math.hpp" +#include // Include for std::out_of_range namespace Basalt::Shared::Math { -} +#pragma region Vector3 + + FloatPoint& Vector3::operator[](size_t index) { + switch (index) { + case 0: + return x; + case 1: + return y; + case 2: + return z; + default: + throw std::out_of_range("Vector3 index out of range"); + } + } + + const FloatPoint& Vector3::operator[](size_t index) const { + switch (index) { + case 0: + return x; + case 1: + return y; + case 2: + return z; + default: + throw std::out_of_range("Vector3 index out of range"); + } + } + +#pragma endregion + +#pragma region Vector4 + + FloatPoint& Vector4::operator[](size_t index) { + switch (index) { + case 0: + return x; + case 1: + return y; + case 2: + return z; + case 3: + return w; + default: + throw std::out_of_range("Vector4 index out of range"); + } + } + + const FloatPoint& Vector4::operator[](size_t index) const { + switch (index) { + case 0: + return x; + case 1: + return y; + case 2: + return z; + case 3: + return w; + default: + throw std::out_of_range("Vector4 index out of range"); + } + } + +#pragma endregion + +#pragma region Matrix4x4 + + Vector4& Matrix4x4::operator[](size_t index) { + return data.at(index); + } + + const Vector4& Matrix4x4::operator[](size_t index) const { + return data.at(index); + } + +#pragma endregion + +} // namespace Basalt::Shared::Math \ No newline at end of file diff --git a/BasaltPresenter/Shared/basalt/math.hpp b/BasaltPresenter/Shared/basalt/math.hpp index f5463bf..c536d06 100644 --- a/BasaltPresenter/Shared/basalt/math.hpp +++ b/BasaltPresenter/Shared/basalt/math.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include // Include array for std::array::at namespace Basalt::Shared::Math { @@ -7,19 +8,26 @@ namespace Basalt::Shared::Math { struct Vector3 { FloatPoint x, y, z; - }; - struct Vector4 { - FloatPoint x, y, z, w; - }; - struct Matrix4x4 { - Vector4 data[4]; + + FloatPoint& operator[](size_t index); + const FloatPoint& operator[](size_t index) const; }; - //template - // requires(std::integral || std::floating_point) - //struct Vector { - // TEle factor[VCnt]; - //}; + struct Vector4 { + FloatPoint x, y, z, w; + + FloatPoint& operator[](size_t index); + const FloatPoint& operator[](size_t index) const; + }; + + struct Matrix4x4 { + private: + std::array data; // Use std::array instead of raw array for .at() method + + public: + Vector4& operator[](size_t index); + const Vector4& operator[](size_t index) const; + }; #define NOT_IMPLEMENTED throw std::logic_error("not implemented function"); @@ -31,4 +39,4 @@ namespace Basalt::Shared::Math { #undef NOT_IMPLEMENTED -} // namespace Basalt::Shared::Math +} // namespace Basalt::Shared::Math \ No newline at end of file diff --git a/BasaltPresenter/Shared/basalt/object_loader.cpp b/BasaltPresenter/Shared/basalt/object_loader.cpp new file mode 100644 index 0000000..1d728bf --- /dev/null +++ b/BasaltPresenter/Shared/basalt/object_loader.cpp @@ -0,0 +1,13 @@ +#include "object_loader.hpp" + +namespace basalt::shared::object_loader { + + IObjectLoader::IObjectLoader() { + + } + + IObjectLoader::~IObjectLoader() { + + } + +} diff --git a/BasaltPresenter/Shared/basalt/object_loader.hpp b/BasaltPresenter/Shared/basalt/object_loader.hpp new file mode 100644 index 0000000..3425b63 --- /dev/null +++ b/BasaltPresenter/Shared/basalt/object_loader.hpp @@ -0,0 +1,13 @@ +#pragma once + +namespace basalt::shared::object_loader { + + class IObjectLoader { + public: + IObjectLoader(); + virtual ~IObjectLoader(); + + protected: + }; + +} // namespace basalt::shared::object_loader diff --git a/BasaltPresenter/Shared/basalt/pipe_operator.cpp b/BasaltPresenter/Shared/basalt/pipe_operator.cpp index 76691fa..64ec353 100644 --- a/BasaltPresenter/Shared/basalt/pipe_operator.cpp +++ b/BasaltPresenter/Shared/basalt/pipe_operator.cpp @@ -9,9 +9,9 @@ #include #endif -namespace Basalt::Shared { +namespace basalt::shared::pipe_operator { - PipeOperator::PipeOperator(const std::basic_string_view name) { + PipeOperator::PipeOperator(const char_types::BSStringView& name) { #if defined(BASALT_OS_WINDOWS) // Create Windows pipe name from given name auto fullname = std::format(BSTEXT("\\\\.\\pipe\\{}"), name); diff --git a/BasaltPresenter/Shared/basalt/pipe_operator.hpp b/BasaltPresenter/Shared/basalt/pipe_operator.hpp index c635b5a..c213076 100644 --- a/BasaltPresenter/Shared/basalt/pipe_operator.hpp +++ b/BasaltPresenter/Shared/basalt/pipe_operator.hpp @@ -1,13 +1,15 @@ #pragma once #include "char_types.hpp" +#include #include #if defined(BASALT_OS_WINDOWS) #include #else +// Nothing was included in POSIX #endif -namespace Basalt::Shared { +namespace basalt::shared::pipe_operator { class PipeOperator { public: @@ -20,7 +22,7 @@ namespace Basalt::Shared { #endif public: - PipeOperator(const std::basic_string_view name); + PipeOperator(const char_types::BSStringView& name); ~PipeOperator(); // Delete copy ctor PipeOperator(const PipeOperator&) = delete; @@ -29,10 +31,30 @@ namespace Basalt::Shared { PipeOperator(PipeOperator&&) noexcept; PipeOperator& operator=(PipeOperator&& other) noexcept; + public: void Read(void* buffer, size_t size); void Write(const void* buffer, size_t size); + template + void ReadPod(TPod& buffer) { + Read(&buffer, sizeof(TPod)); + } + template + void WritePod(const TPod& buffer) { + Write(&buffer, sizeof(TPod)); + } + void ReadString(std::string& buffer) { + size_t length = 0; + ReadPod(length); + buffer.resize(length); + Read(buffer.data(), length); + } + void WriteString(std::string_view& buffer) { + WritePod(buffer.size()); + Write(buffer.data(), buffer.size()); + } + private: Handle m_Handle; }; -} // namespace Basalt::Shared +} // namespace basalt::shared::pipe_operator diff --git a/Document/PROTOCOL.md b/Document/PROTOCOL.md index f3abe63..2c8cfac 100644 --- a/Document/PROTOCOL.md +++ b/Document/PROTOCOL.md @@ -14,14 +14,15 @@ Command protocol is tramsmitted by system named pipe. The name of pipe is `\\.\pipe\ed0e3f1f-d214-4880-9562-640bce15e72e` on Windows or `/tmp/ed0e3f1f-d214-4880-9562-640bce15e72e` on POSIX. -|Code|Direction|Comment| -|:---|:---|:---| -|`0x61`|Presenter<--Trainer|Handshake code (Are Presenter ready?)| -|`0x62`|Presenter-->Trainer|Handshake code (Presenter is ready).| -|`0x01`|Presenter-->Trainer|Data was ready. Please Trainer receive it.| -|`0x02`|Presenter<--Trainer|Data has been received. Please go into next loop.| -|`0x71`|Presenter-->Trainer|Actively Stop (Presenter request stop).| -|`0x71`|Presenter<--Trainer|Stop (Trainer agree the stop request, or trainer actively stop).| +|Code|Mnemonic|Direction|Comment| +|:---|:---|:---|:---| +|`0x61`|HANDSHAKE_REQUEST|Presenter<--Trainer|Handshake code (Are Presenter ready?)| +|`0x62`|HANDSHAKE_RESPONSE|Presenter-->Trainer|Handshake code (Presenter is ready).| +|`0x01`|DATA_READY|Presenter-->Trainer|Data was ready by Presenter. Trainer please receive it.| +|`0x02`|DATA_RECEIVED|Presenter<--Trainer|Data has been received by Trainer. Please go into next loop.| +|`0x21`|ACTIVELY_STOP|Presenter-->Trainer|Something was happened in Presenter and it want to stop.| +|`0x71`|STOP_REQUEST|Presenter<--Trainer|Trainer order Presenter to stop and quit.| +|`0x72`|STOP_RESPONSE|Presenter-->Trainer|Presenster is stopped.| ### Handshake