aboutsummaryrefslogtreecommitdiff
path: root/source/lib/proto
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2024-05-17 17:58:38 +0200
committerFelix Morgner <felix.morgner@gmail.com>2024-05-17 17:58:38 +0200
commit577fc0845718ed8ad5bebf02a277c0579a817f77 (patch)
tree3d1cdc53c426a0ba60a7996619a7b787850bb3b3 /source/lib/proto
parentde5bf7ca3b7a2bf6be35b86486b00dc6a071b950 (diff)
downloadwanda-develop.tar.xz
wanda-develop.zip
wanda: restructure source layoutHEADdevelop
Diffstat (limited to 'source/lib/proto')
-rw-r--r--source/lib/proto/CMakeLists.txt38
-rw-r--r--source/lib/proto/include/wanda/proto/command.hpp46
-rw-r--r--source/lib/proto/include/wanda/proto/message.hpp84
-rw-r--r--source/lib/proto/include/wanda/proto/version.hpp12
-rw-r--r--source/lib/proto/src/command.cpp47
-rw-r--r--source/lib/proto/src/message.cpp82
6 files changed, 0 insertions, 309 deletions
diff --git a/source/lib/proto/CMakeLists.txt b/source/lib/proto/CMakeLists.txt
deleted file mode 100644
index b20663c..0000000
--- a/source/lib/proto/CMakeLists.txt
+++ /dev/null
@@ -1,38 +0,0 @@
-cmake_path(GET CMAKE_CURRENT_SOURCE_DIR STEM LIB_NAME)
-
-file(GLOB_RECURSE LIB_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" CONFIGURE_DEPENDS "**/*.hpp")
-file(GLOB_RECURSE LIB_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" CONFIGURE_DEPENDS "**/*.cpp")
-
-add_library("wanda-${LIB_NAME}" ${WANDA_LIBRARY_TYPE}
- ${LIB_SOURCES}
-)
-
-target_sources("wanda-${LIB_NAME}" INTERFACE
- FILE_SET HEADERS
- FILES ${LIB_HEADERS}
- BASE_DIRS "include"
-)
-
-target_include_directories("wanda-${LIB_NAME}" PUBLIC
- "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
-)
-
-target_include_directories("wanda-${LIB_NAME}" SYSTEM PUBLIC
- "$<INSTALL_INTERFACE:include>"
-)
-
-target_compile_features("wanda-${LIB_NAME}" PUBLIC
- "cxx_std_20"
-)
-
-target_link_libraries("wanda-${LIB_NAME}" PUBLIC
- "spdlog::spdlog_header_only"
-)
-
-if(NOT WANDA_APPLICATIONS_ONLY)
- install(TARGETS "wanda-${LIB_NAME}"
- FILE_SET HEADERS
- )
-endif()
-
-add_library("wanda::${LIB_NAME}" ALIAS "wanda-${LIB_NAME}")
diff --git a/source/lib/proto/include/wanda/proto/command.hpp b/source/lib/proto/include/wanda/proto/command.hpp
deleted file mode 100644
index c8dae65..0000000
--- a/source/lib/proto/include/wanda/proto/command.hpp
+++ /dev/null
@@ -1,46 +0,0 @@
-#ifndef WANDA_PROTO_COMMAND_HPP
-#define WANDA_PROTO_COMMAND_HPP
-
-#include "wanda/proto/message.hpp"
-
-#include <optional>
-#include <string>
-#include <vector>
-
-namespace wanda::proto
-{
- /**
- * @brief An enum to describe different command IDs
- */
- enum struct command_id : char
- {
- change, //< Change the wallpaper
- };
-
- /**
- * @brief A simple type to represent commands transported through the control connection
- */
- struct command
- {
- command_id const id;
- std::vector<std::string> const arguments;
-
- /**
- * @brief Convert the command to a message for transmission to a remote endpoint
- */
- std::optional<wanda::proto::message> message() const;
- };
-
- /**
- * @brief Extract a command from a message
- */
- std::optional<command> make_command(message message);
-
- /**
- * @brief A simple factory to create a "Change wallpaper" command
- */
- command make_change_command();
-
-} // namespace wanda::proto
-
-#endif \ No newline at end of file
diff --git a/source/lib/proto/include/wanda/proto/message.hpp b/source/lib/proto/include/wanda/proto/message.hpp
deleted file mode 100644
index 03a30c2..0000000
--- a/source/lib/proto/include/wanda/proto/message.hpp
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * @file message.hpp
- * @author Felix Morgner (felix.morgner@gmail.com)
- * @since 1.0.0
- */
-
-#ifndef WANDA_PROTO_MESSAGE_HPP
-#define WANDA_PROTO_MESSAGE_HPP
-
-#include <spdlog/common.h>
-
-#include <cstddef>
-#include <istream>
-#include <optional>
-#include <string>
-#include <string_view>
-
-namespace wanda::proto
-{
- /**
- * @brief A tag to mark messages originating from the controller
- */
- auto constexpr message_source_controller = "C";
-
- /**
- * @brief A tag to mark messages originating from the daemon
- */
- auto constexpr message_source_daemon = "D";
-
- /**
- * @brief The command of the hello message
- */
- auto constexpr message_command_hello = "HELLO";
-
- /**
- * @brief A control protocol message, consisting of a @p source, @p command, and @p arguments
- */
- struct message
- {
- /**
- * @brief Serialize this message into a string
- */
- explicit operator std::string() const;
-
- /**
- * @brief Get the size of the message as if it was serialized
- */
- std::size_t size() const;
-
- /**
- * @brief The source of the message
- */
- std::string source;
-
- /**
- * @brief The command of the message
- */
- std::string command;
-
- /**
- * @brief The arguments of the message command
- */
- std::optional<std::string> argument;
- };
-
- /**
- * @brief Deserialize a message from the given stream
- */
- std::istream & operator>>(std::istream & in, message & message);
-
- /**
- * @brief Serialize a message to the given stream
- */
- std::ostream & operator<<(std::ostream & out, message const & message);
-
-} // namespace wanda::proto
-
-template<>
-struct spdlog::fmt_lib::formatter<wanda::proto::message> : spdlog::fmt_lib::formatter<std::string>
-{
- auto format(wanda::proto::message const & message, format_context & context) const -> decltype(context.out());
-};
-
-#endif \ No newline at end of file
diff --git a/source/lib/proto/include/wanda/proto/version.hpp b/source/lib/proto/include/wanda/proto/version.hpp
deleted file mode 100644
index faa17d7..0000000
--- a/source/lib/proto/include/wanda/proto/version.hpp
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef WANDA_PROTO_VERSION_HPP
-#define WANDA_PROTO_VERSION_HPP
-
-namespace wanda::proto
-{
- inline namespace v1
- {
- auto constexpr version = "1.0.0";
- }
-} // namespace wanda::proto
-
-#endif \ No newline at end of file
diff --git a/source/lib/proto/src/command.cpp b/source/lib/proto/src/command.cpp
deleted file mode 100644
index 5a669f5..0000000
--- a/source/lib/proto/src/command.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-#include "wanda/proto/command.hpp"
-
-namespace wanda::proto
-{
- std::optional<message> command::message() const
- {
- using namespace std::string_literals;
- auto const command = [this] {
- switch (id)
- {
- case command_id::change:
- return "CHANGE"s;
- default:
- return ""s;
- }
- }();
-
- auto argument_string = std::string{};
- for (int index = 0ul; index < arguments.size(); ++index)
- {
- argument_string += (index) ? "," + arguments[index] : arguments[index];
- }
-
- if (command.empty())
- {
- return std::nullopt;
- }
-
- return wanda::proto::message{"C", command, argument_string};
- }
-
- std::optional<command> make_command(message message)
- {
- if (message.command == "CHANGE")
- {
- return {{command_id::change}};
- }
-
- return std::nullopt;
- }
-
- command make_change_command()
- {
- return {command_id::change};
- }
-
-} // namespace wanda::proto \ No newline at end of file
diff --git a/source/lib/proto/src/message.cpp b/source/lib/proto/src/message.cpp
deleted file mode 100644
index f44ca06..0000000
--- a/source/lib/proto/src/message.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-#include "wanda/proto/message.hpp"
-
-#include <spdlog/common.h>
-
-#include <ios>
-#include <iterator>
-#include <sstream>
-
-namespace wanda::proto
-{
- message::operator std::string() const
- {
- std::ostringstream buffer{};
- buffer << source
- << ':'
- << command;
- if (argument.has_value())
- {
- buffer << ':' << *argument;
- }
- return buffer.str();
- }
-
- std::size_t message::size() const
- {
- return static_cast<std::string>(*this).size();
- }
-
- template<typename InputIt, typename OutputIt, typename UnaryPredicate>
- OutputIt copy_until(InputIt first, InputIt last, OutputIt out, UnaryPredicate predicate)
- {
- while (first != last && !predicate(*first))
- {
- *out++ = *first++;
- }
- return out;
- }
-
- std::istream & operator>>(std::istream & in, message & message)
- {
- auto pos = std::istream_iterator<char>{in};
- auto end = std::istream_iterator<char>{};
- auto buffer = std::string{};
-
- copy_until(pos, end, std::back_inserter(buffer), [](auto const & c) { return c == ':'; });
- if (in.eof() || buffer.size() != 1)
- {
- in.setstate(std::ios_base::failbit);
- return in;
- }
- message.source = buffer;
-
- buffer.clear();
- copy_until(++pos, end, std::back_inserter(buffer), [](auto const & c) { return c == ':'; });
- if (in.eof())
- {
- in.setstate(std::ios_base::failbit);
- }
- message.command = buffer;
-
- buffer.clear();
- copy(++pos, end, std::back_inserter(buffer));
- if (buffer.size())
- {
- message.argument = std::optional{std::move(buffer)};
- }
-
- in.clear(in.rdstate() ^ std::ios_base::failbit);
- return in;
- }
-
- std::ostream & operator<<(std::ostream & out, message const & message)
- {
- return out << static_cast<std::string>(message);
- }
-
-} // namespace wanda::proto
-
-auto spdlog::fmt_lib::formatter<wanda::proto::message>::format(wanda::proto::message const & message, format_context & context) const -> decltype(context.out())
-{
- return formatter<std::string>::format(static_cast<std::string>(message), context);
-}