diff options
Diffstat (limited to 'source/lib')
| -rw-r--r-- | source/lib/CMakeLists.txt | 71 | ||||
| -rw-r--r-- | source/lib/control/CMakeLists.txt | 44 | ||||
| -rw-r--r-- | source/lib/control/include/wanda/control/commander.hpp (renamed from source/lib/include/wanda/commander.hpp) | 30 | ||||
| -rw-r--r-- | source/lib/control/include/wanda/control/connection.hpp (renamed from source/lib/include/wanda/control_connection.hpp) | 28 | ||||
| -rw-r--r-- | source/lib/control/include/wanda/control/interface.hpp (renamed from source/lib/include/wanda/control_interface.hpp) | 34 | ||||
| -rw-r--r-- | source/lib/control/src/commander.cpp | 79 | ||||
| -rw-r--r-- | source/lib/control/src/connection.cpp (renamed from source/lib/src/control_connection.cpp) | 34 | ||||
| -rw-r--r-- | source/lib/control/src/interface.cpp (renamed from source/lib/src/control_interface.cpp) | 68 | ||||
| -rw-r--r-- | source/lib/meta/CMakeLists.txt | 29 | ||||
| -rw-r--r-- | source/lib/meta/include/wanda/meta/deferred_failure.hpp (renamed from source/lib/include/wanda/deferred_failure.hpp) | 8 | ||||
| -rw-r--r-- | source/lib/meta/include/wanda/meta/keyed.hpp (renamed from source/lib/include/wanda/keyed.hpp) | 8 | ||||
| -rw-r--r-- | source/lib/meta/include/wanda/meta/type_wrapper.hpp (renamed from source/lib/include/wanda/type_wrapper.hpp) | 10 | ||||
| -rw-r--r-- | source/lib/proto/CMakeLists.txt | 38 | ||||
| -rw-r--r-- | source/lib/proto/include/wanda/proto/command.hpp (renamed from source/lib/include/wanda/command.hpp) | 12 | ||||
| -rw-r--r-- | source/lib/proto/include/wanda/proto/message.hpp (renamed from source/lib/include/wanda/message.hpp) | 27 | ||||
| -rw-r--r-- | source/lib/proto/include/wanda/proto/version.hpp | 12 | ||||
| -rw-r--r-- | source/lib/proto/src/command.cpp (renamed from source/lib/src/command.cpp) | 8 | ||||
| -rw-r--r-- | source/lib/proto/src/message.cpp (renamed from source/lib/src/message.cpp) | 13 | ||||
| -rw-r--r-- | source/lib/src/commander.cpp | 77 | ||||
| -rw-r--r-- | source/lib/std_ext/CMakeLists.txt | 29 | ||||
| -rw-r--r-- | source/lib/std_ext/include/wanda/std_ext/expected.hpp (renamed from source/lib/include/wanda/expected.hpp) | 34 | ||||
| -rw-r--r-- | source/lib/std_ext/include/wanda/std_ext/optional.hpp (renamed from source/lib/include/wanda/optional.hpp) | 6 | ||||
| -rw-r--r-- | source/lib/system/CMakeLists.txt | 68 | ||||
| -rw-r--r-- | source/lib/system/include/wanda/system/environment.hpp (renamed from source/lib/include/wanda/environment.hpp) | 12 | ||||
| -rw-r--r-- | source/lib/system/include/wanda/system/filesystem.hpp (renamed from source/lib/include/wanda/filesystem.hpp) | 8 | ||||
| -rw-r--r-- | source/lib/system/include/wanda/system/logging.hpp (renamed from source/lib/include/wanda/logging.hpp) | 10 | ||||
| -rw-r--r-- | source/lib/system/include/wanda/system/magic.hpp (renamed from source/lib/include/wanda/magic.hpp) | 8 | ||||
| -rw-r--r-- | source/lib/system/include/wanda/system/setting.hpp (renamed from source/lib/include/wanda/setting.hpp) | 18 | ||||
| -rw-r--r-- | source/lib/system/include/wanda/system/wallpaper.hpp (renamed from source/lib/include/wanda/wallpaper.hpp) | 8 | ||||
| -rw-r--r-- | source/lib/system/include/wanda/system/xdg.hpp (renamed from source/lib/include/wanda/xdg.hpp) | 10 | ||||
| -rw-r--r-- | source/lib/system/src/environment.cpp (renamed from source/lib/src/environment.cpp) | 6 | ||||
| -rw-r--r-- | source/lib/system/src/filesystem.cpp (renamed from source/lib/src/filesystem.cpp) | 6 | ||||
| -rw-r--r-- | source/lib/system/src/logging.cpp (renamed from source/lib/src/logging.cpp) | 6 | ||||
| -rw-r--r-- | source/lib/system/src/setting.cpp (renamed from source/lib/src/setting.cpp) | 6 | ||||
| -rw-r--r-- | source/lib/system/src/wallpaper.cpp (renamed from source/lib/src/wallpaper.cpp) | 18 | ||||
| -rw-r--r-- | source/lib/system/src/xdg.cpp (renamed from source/lib/src/xdg.cpp) | 6 |
36 files changed, 528 insertions, 361 deletions
diff --git a/source/lib/CMakeLists.txt b/source/lib/CMakeLists.txt index bf3cd5f..e2bb4b5 100644 --- a/source/lib/CMakeLists.txt +++ b/source/lib/CMakeLists.txt @@ -1,66 +1,5 @@ -find_package("asio") -find_package("Boost") -find_package("JPEG") -find_package("PNG") -find_package("spdlog") -find_package("Threads") - -find_package("PkgConfig" REQUIRED) - -pkg_check_modules("GIO" - REQUIRED - IMPORTED_TARGET - GLOBAL - "gio-2.0" -) - -pkg_check_modules("libmagic" - REQUIRED - IMPORTED_TARGET - GLOBAL - "libmagic" -) - -file(GLOB_RECURSE WANDA_LIB_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" CONFIGURE_DEPENDS "**/*.cpp") -file(GLOB_RECURSE WANDA_LIB_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" CONFIGURE_DEPENDS "**/*.hpp") - -add_library("wanda") - -target_sources("wanda" PRIVATE - ${WANDA_LIB_SOURCES} -) - -target_sources("wanda" INTERFACE - FILE_SET HEADERS - FILES ${WANDA_LIB_HEADERS} - BASE_DIRS "include" -) - -target_include_directories("wanda" PUBLIC - $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> -) - -target_include_directories("wanda" SYSTEM PUBLIC - $<INSTALL_INTERFACE:include> -) - -target_compile_features("wanda" PUBLIC - "cxx_std_20" -) - -target_link_libraries("wanda" PUBLIC - "asio::asio" - "boost::boost" - "JPEG::JPEG" - "PkgConfig::GIO" - "PkgConfig::libmagic" - "PNG::PNG" - "spdlog::spdlog" - "Threads::Threads" -) - -install(TARGETS "wanda" - FILE_SET HEADERS -) - -add_library("wanda::wanda" ALIAS "wanda") +add_subdirectory("control") +add_subdirectory("meta") +add_subdirectory("proto") +add_subdirectory("std_ext") +add_subdirectory("system") diff --git a/source/lib/control/CMakeLists.txt b/source/lib/control/CMakeLists.txt new file mode 100644 index 0000000..3236cf8 --- /dev/null +++ b/source/lib/control/CMakeLists.txt @@ -0,0 +1,44 @@ +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") + +find_package("asio" REQUIRED) +find_package("spdlog" REQUIRED) + +add_library("wanda-${LIB_NAME}" + ${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 + "wanda::meta" + "wanda::proto" + "wanda::system" + + "asio::asio" + "spdlog::spdlog" +) + +install(TARGETS "wanda-${LIB_NAME}" + FILE_SET HEADERS +) + +add_library("wanda::${LIB_NAME}" ALIAS "wanda-${LIB_NAME}")
\ No newline at end of file diff --git a/source/lib/include/wanda/commander.hpp b/source/lib/control/include/wanda/control/commander.hpp index 52fbbb8..c993fc0 100644 --- a/source/lib/include/wanda/commander.hpp +++ b/source/lib/control/include/wanda/control/commander.hpp @@ -1,9 +1,9 @@ -#ifndef WANDA_COMMANDER_HPP -#define WANDA_COMMANDER_HPP +#ifndef WANDA_CONTROL_COMMANDER_HPP +#define WANDA_CONTROL_COMMANDER_HPP -#include "wanda/command.hpp" -#include "wanda/control_connection.hpp" -#include "wanda/message.hpp" +#include "wanda/control/connection.hpp" +#include "wanda/proto/command.hpp" +#include "wanda/proto/message.hpp" #include <asio.hpp> @@ -13,13 +13,13 @@ #include <string> #include <vector> -namespace wanda +namespace wanda::control { /** * @brief The remote control client - * + * */ - struct commander : wanda::control_connection::listener + struct commander : connection::listener { /** * @brief The interface to be implemented by remote control listeners @@ -49,18 +49,18 @@ namespace wanda /** * @brief Send a command to the remote daemon endpoint */ - void send(command command); + void send(proto::command command); - void on_error(control_connection::pointer connection, std::error_code error) override; - void on_received(control_connection::pointer connection, message message) override; + void on_error(connection::pointer connection, std::error_code error) override; + void on_received(connection::pointer connection, proto::message message) override; private: asio::io_service & m_service; - wanda::control_connection::protocol::endpoint m_endpoint; - wanda::control_connection::protocol::socket m_socket; - wanda::control_connection::pointer m_connection; + wanda::control::connection::protocol::endpoint m_endpoint; + wanda::control::connection::protocol::socket m_socket; + wanda::control::connection::pointer m_connection; listener & m_listener; }; -} // namespace wanda +} // namespace wanda::control #endif
\ No newline at end of file diff --git a/source/lib/include/wanda/control_connection.hpp b/source/lib/control/include/wanda/control/connection.hpp index cfab0df..1ca451d 100644 --- a/source/lib/include/wanda/control_connection.hpp +++ b/source/lib/control/include/wanda/control/connection.hpp @@ -1,8 +1,8 @@ #ifndef WANDA_CONTROL_CONNECTION_HPP #define WANDA_CONTROL_CONNECTION_HPP -#include "wanda/keyed.hpp" -#include "wanda/message.hpp" +#include "wanda/meta/keyed.hpp" +#include "wanda/proto/message.hpp" #include <asio.hpp> @@ -13,15 +13,15 @@ #include <string> #include <system_error> -namespace wanda +namespace wanda::control { /** * @brief A connection to a remote control endpoint */ - struct control_connection : keyed<control_connection>, std::enable_shared_from_this<control_connection> + struct connection : meta::keyed<connection>, std::enable_shared_from_this<connection> { using protocol = asio::local::stream_protocol; - using pointer = std::shared_ptr<control_connection>; + using pointer = std::shared_ptr<connection>; /** * @brief The interface to be implemented by the control interface listener @@ -29,7 +29,7 @@ namespace wanda struct listener { virtual void on_close(pointer connection) {} - virtual void on_received(pointer connection, message message) {} + virtual void on_received(pointer connection, proto::message message) {} virtual void on_error(pointer connection, std::error_code) {} }; @@ -46,21 +46,21 @@ namespace wanda /** * @internal * @brief Construct a new control connection object - * + * * @note This constructor is keyed on a private key type so it can only be constructed using the #wanda::make_connection factory */ - control_connection(key, protocol::socket socket); + connection(key, protocol::socket socket); /** * @brief Add the given listener to this control connection's listener set - * + * * @returns <code>true</code> iff. the listener was not already in the listener set */ bool add(listener * listener); /** * @brief Remove the given listener from this control connection's listener set - * + * * @return <code>true</code> iff. the listener was previously registered with this control connection */ bool remove(listener * listener); @@ -78,7 +78,7 @@ namespace wanda /** * @brief Send the given message to the remote endpoint */ - void send(message message); + void send(proto::message message); /** * @brief Set the connection state to the provided state @@ -91,7 +91,7 @@ namespace wanda state current_state() const; private: - friend pointer make_control_connection(protocol::socket && socket); + friend pointer make_connection(protocol::socket && socket); void perform_read(); @@ -107,8 +107,8 @@ namespace wanda /** * @brief Create a new control connection */ - control_connection::pointer make_control_connection(control_connection::protocol::socket && socket); + connection::pointer make_connection(connection::protocol::socket && socket); -} // namespace wanda +} // namespace wanda::control #endif
\ No newline at end of file diff --git a/source/lib/include/wanda/control_interface.hpp b/source/lib/control/include/wanda/control/interface.hpp index 4f4da87..3dca85f 100644 --- a/source/lib/include/wanda/control_interface.hpp +++ b/source/lib/control/include/wanda/control/interface.hpp @@ -1,5 +1,5 @@ /** - * @file environment.hpp + * @file interface.hpp * @author Felix Morgner (felix.morgner@gmail.com) * @since 1.0.0 */ @@ -7,9 +7,9 @@ #ifndef WANDA_CONTROL_INTERFACE_HPP #define WANDA_CONTROL_INTERFACE_HPP -#include "wanda/command.hpp" -#include "wanda/control_connection.hpp" -#include "wanda/keyed.hpp" +#include "wanda/control/connection.hpp" +#include "wanda/meta/keyed.hpp" +#include "wanda/proto/command.hpp" #include <asio.hpp> #include <spdlog/spdlog.h> @@ -23,7 +23,7 @@ #include <string> #include <type_traits> -namespace wanda +namespace wanda::control { /** * @brief An RAII type to delete a socket file upon destruction @@ -38,26 +38,26 @@ namespace wanda /** * @brief The daemon control interface */ - struct control_interface : control_connection::listener, keyed<control_interface>, std::enable_shared_from_this<control_interface> + struct interface : connection::listener, meta::keyed<interface>, std::enable_shared_from_this<interface> { using protocol = asio::local::stream_protocol; - using pointer = std::shared_ptr<control_interface>; + using pointer = std::shared_ptr<interface>; /** * @brief The interface to be implemented by the control interface listener */ struct listener { - virtual void on_received(control_interface & interface, command command){}; + virtual void on_received(interface & interface, proto::command command){}; }; /** * @internal * @brief Construct a new control interface object - * + * * @note This constructor is keyed on a private key type so it can only be constructed using the #wanda::make_interface factory */ - control_interface(key, asio::io_service & service, protocol::endpoint endpoint, listener & listener); + interface(key, asio::io_service & service, protocol::endpoint endpoint, listener & listener); /** * @brief Start handling of controller connections @@ -69,13 +69,13 @@ namespace wanda */ std::error_code shutdown(); - void on_close(control_connection::pointer connection) override; - void on_received(control_connection::pointer connection, message message) override; + void on_close(connection::pointer connection) override; + void on_received(connection::pointer connection, proto::message message) override; private: void perform_accept(); - friend pointer make_interface(asio::io_service & service, std::filesystem::path file, control_interface::listener & listener); + friend pointer make_interface(asio::io_service & service, std::filesystem::path file, interface::listener & listener); asio::io_service & m_service; protocol::endpoint m_endpoint; @@ -83,14 +83,14 @@ namespace wanda protocol::acceptor m_acceptor; listener & m_listener; socket_deleter m_deleter{m_endpoint.path()}; - std::set<control_connection::pointer> m_connections; + std::set<connection::pointer> m_connections; }; /** - * @brief A factory to create new #control_interface instances + * @brief A factory to create new #interface instances */ - control_interface::pointer make_interface(asio::io_service & service, std::filesystem::path socket, control_interface::listener & listener); + interface::pointer make_interface(asio::io_service & service, std::filesystem::path socket, interface::listener & listener); -} // namespace wanda +} // namespace wanda::control #endif
\ No newline at end of file diff --git a/source/lib/control/src/commander.cpp b/source/lib/control/src/commander.cpp new file mode 100644 index 0000000..3db2c59 --- /dev/null +++ b/source/lib/control/src/commander.cpp @@ -0,0 +1,79 @@ +#include "wanda/control/commander.hpp" + +#include "wanda/proto/message.hpp" +#include "wanda/proto/version.hpp" +#include "wanda/std_ext/optional.hpp" +#include "wanda/system/logging.hpp" + +#include <spdlog/fmt/ostr.h> + +namespace wanda::control +{ + commander::commander(asio::io_service & service, std::filesystem::path socket, listener & listener) + : m_service{service} + , m_endpoint{socket.string()} + , m_socket{service} + , m_listener{listener} + { + } + + void commander::start() + { + m_socket.async_connect(m_endpoint, [&](auto const & error) { + if (error) + { + system::get_logger()->error("error while connecting to control interface: '{}'", error.message()); + } + else + { + system::get_logger()->info("establishing connection to wanda deamon"); + m_connection = wanda::control::make_connection(std::move(m_socket)); + m_connection->add(this); + m_connection->start(); + m_connection->send({proto::message_source_controller, proto::message_command_hello, proto::version}); + } + }); + } + + void commander::stop() + { + system::get_logger()->info("closing control connection"); + m_connection->close(); + } + + void commander::send(proto::command command) + { + using namespace wanda::std_ext; + + if (!m_connection || m_connection->current_state() != connection::state::established) + { + system::get_logger()->error("tried to send command without an established connection"); + m_listener.on_error(*this, "tried to send command without an established connection"); + return; + } + + with(command.message(), [&](auto const & message) { m_connection->send(message); }) || + [&] { system::get_logger()->error("unknown command"); }; + } + + void commander::on_error(connection::pointer connection, std::error_code error) + { + system::get_logger()->error("control interface communication error: '{}'", error.message()); + } + + void commander::on_received(connection::pointer connection, proto::message message) + { + if (auto state = connection->current_state(); message.command == "HELLO" && state == connection::state::fresh) + { + system::get_logger()->info("connection to wanda deamon successfully established"); + connection->update(connection::state::established); + m_listener.on_connected(*this); + } + else + { + system::get_logger()->error("unexpected message: '{}'", message); + m_listener.on_error(*this, "unexpected message '" + static_cast<std::string>(message) + '\''); + } + } + +} // namespace wanda::control
\ No newline at end of file diff --git a/source/lib/src/control_connection.cpp b/source/lib/control/src/connection.cpp index ace13d2..30fc8af 100644 --- a/source/lib/src/control_connection.cpp +++ b/source/lib/control/src/connection.cpp @@ -1,32 +1,36 @@ -#include "wanda/control_connection.hpp" +#include "wanda/control/connection.hpp" + +#include "wanda/proto/message.hpp" + +#include <asio.hpp> #include <limits> -namespace wanda +namespace wanda::control { - control_connection::pointer make_control_connection(control_connection::protocol::socket && socket) + connection::pointer make_connection(connection::protocol::socket && socket) { - return std::make_shared<control_connection>(control_connection::key{}, std::move(socket)); + return std::make_shared<connection>(connection::key{}, std::move(socket)); } - control_connection::control_connection(control_connection::key key, control_connection::protocol::socket socket) + connection::connection(connection::key key, connection::protocol::socket socket) : keyed{key} , m_socket{std::move(socket)} { } - bool control_connection::add(listener * listener) + bool connection::add(listener * listener) { auto [_, inserted] = m_listeners.insert(listener); return inserted; } - bool control_connection::remove(listener * listener) + bool connection::remove(listener * listener) { return m_listeners.erase(listener); } - void control_connection::start() + void connection::start() { if (m_state == state::unknown) { @@ -35,7 +39,7 @@ namespace wanda } } - void control_connection::send(message message) + void connection::send(proto::message message) { m_output << message << '\n'; asio::async_write(m_socket, m_out, asio::transfer_exactly(message.size() + 1), [that = shared_from_this(), this](auto const & error, auto const length) { @@ -50,7 +54,7 @@ namespace wanda }); } - void control_connection::close() + void connection::close() { if (auto error = std::error_code{}; m_socket.cancel(error)) { @@ -75,17 +79,17 @@ namespace wanda m_listeners.clear(); } - void control_connection::update(state state) + void connection::update(state state) { m_state = state; } - control_connection::state control_connection::current_state() const + connection::state connection::current_state() const { return m_state; } - void control_connection::perform_read() + void connection::perform_read() { asio::async_read_until(m_socket, m_in, '\n', [that = shared_from_this(), this](auto const & error, auto const length) { if (error) @@ -98,7 +102,7 @@ namespace wanda } else { - auto msg = message{}; + auto msg = proto::message{}; m_input >> msg; if (!m_input) { @@ -117,4 +121,4 @@ namespace wanda }); } -} // namespace wanda
\ No newline at end of file +} // namespace wanda::control
\ No newline at end of file diff --git a/source/lib/src/control_interface.cpp b/source/lib/control/src/interface.cpp index 68005f9..b0c4dd2 100644 --- a/source/lib/src/control_interface.cpp +++ b/source/lib/control/src/interface.cpp @@ -1,9 +1,10 @@ -#include "wanda/control_interface.hpp" -#include "wanda/logging.hpp" -#include "wanda/optional.hpp" +#include "wanda/control/interface.hpp" -#include <spdlog/fmt/ostr.h> +#include "wanda/proto/version.hpp" +#include "wanda/std_ext/optional.hpp" +#include "wanda/system/logging.hpp" +#include <spdlog/fmt/ostr.h> #include <unistd.h> #include <algorithm> @@ -12,7 +13,7 @@ #include <system_error> #include <utility> -namespace wanda +namespace wanda::control { // 'socket_deleter' implementation @@ -24,9 +25,9 @@ namespace wanda } } - // 'control_interface' implementation + // 'interface' implementation - control_interface::control_interface(control_interface::key key, asio::io_service & service, control_interface::protocol::endpoint endpoint, listener & listener) + interface::interface(interface::key key, asio::io_service & service, interface::protocol::endpoint endpoint, listener & listener) : keyed{key} , m_service{service} , m_endpoint{std::move(endpoint)} @@ -36,7 +37,7 @@ namespace wanda { } - std::error_code control_interface::start() + std::error_code interface::start() { if (auto error = std::error_code{}; m_acceptor.open(m_endpoint.protocol(), error)) { @@ -59,7 +60,7 @@ namespace wanda } } - std::error_code control_interface::shutdown() + std::error_code interface::shutdown() { for (auto & connection : m_connections) { @@ -70,17 +71,17 @@ namespace wanda return m_acceptor.close(error); } - void control_interface::perform_accept() + void interface::perform_accept() { m_acceptor.async_accept(m_socket, [that = shared_from_this(), this](auto const & error) { if (error && error != asio::error::operation_aborted) { - get_logger()->error("failed to accept connection because '{}'", error.message()); + system::get_logger()->error("failed to accept connection because '{}'", error.message()); } else { - get_logger()->info("new incoming controller connection"); - auto [connection, inserted] = m_connections.insert(make_control_connection(std::move(m_socket))); + system::get_logger()->info("new incoming controller connection"); + auto [connection, inserted] = m_connections.insert(make_connection(std::move(m_socket))); if (inserted) { (*connection)->add(this); @@ -91,64 +92,67 @@ namespace wanda }); } - void control_interface::on_close(control_connection::pointer connection) + void interface::on_close(connection::pointer connection) { - if (static_cast<char>(connection->current_state()) >= static_cast<char>(control_connection::state::established)) + if (static_cast<char>(connection->current_state()) >= static_cast<char>(connection::state::established)) { - get_logger()->info("controller connection closed"); + system::get_logger()->info("controller connection closed"); } else { - get_logger()->info("controller connection aborted before it could be established"); + system::get_logger()->info("controller connection aborted before it could be established"); } m_connections.erase(connection); } - void control_interface::on_received(control_connection::pointer connection, message message) + void interface::on_received(connection::pointer connection, proto::message message) { using namespace wanda::std_ext; if (m_connections.find(connection) == m_connections.cend()) { - get_logger()->error("received message from an unknown connection"); + system::get_logger()->error("received message from an unknown connection"); return; } - if (message.source != message_source_controller) + if (message.source != proto::message_source_controller) { - get_logger()->error("received a deamon message"); + system::get_logger()->error("received a deamon message"); return; } - if (auto state = connection->current_state(); message.command == message_command_hello && state == control_connection::state::fresh) + if (auto state = connection->current_state(); message.command == proto::message_command_hello && state == connection::state::fresh) { - get_logger()->info("controller connection established"); + system::get_logger()->info("controller connection established"); if (message.argument.has_value()) { - get_logger()->info("remote controller version '{}'", *message.argument); + system::get_logger()->info("remote controller version '{}'", *message.argument); } - connection->send({message_source_daemon, message_command_hello, message_argument_hello}); - connection->update(control_connection::state::established); + connection->send({proto::message_source_daemon, proto::message_command_hello, proto::version}); + connection->update(connection::state::established); } else { with(make_command(message), [&](auto const & command) { m_listener.on_received(*this, command); }) || - [&] { get_logger()->warn("ignoring unknown message '{}'", message); }; + [&] { system::get_logger()->warn("ignoring unknown message '{}'", message); }; } } - control_interface::pointer make_interface(asio::io_service & service, std::filesystem::path socket, control_interface::listener & listener) + interface::pointer make_interface(asio::io_service & service, std::filesystem::path socket, interface::listener & listener) { if (std::filesystem::exists(socket)) { - get_logger()->error("socket '{}' exists", socket.native()); + system::get_logger()->error("socket '{}' exists", socket.native()); return {}; } - control_interface::protocol::endpoint endpoint{socket.string()}; - return std::make_shared<control_interface>(control_interface::key{}, service, std::move(endpoint), listener); + interface::protocol::endpoint endpoint + { + socket.string() + }; + return std::make_shared<interface>(interface::key{}, service, std::move(endpoint), listener); } -} // namespace wanda
\ No newline at end of file +} // namespace wanda::control
\ No newline at end of file diff --git a/source/lib/meta/CMakeLists.txt b/source/lib/meta/CMakeLists.txt new file mode 100644 index 0000000..e6e3372 --- /dev/null +++ b/source/lib/meta/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_path(GET CMAKE_CURRENT_SOURCE_DIR STEM LIB_NAME) + +file(GLOB_RECURSE LIB_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" CONFIGURE_DEPENDS "**/*.hpp") + +add_library("wanda-${LIB_NAME}" INTERFACE) + +target_sources("wanda-${LIB_NAME}" INTERFACE + FILE_SET HEADERS + FILES ${LIB_HEADERS} + BASE_DIRS "include" +) + +target_include_directories("wanda-${LIB_NAME}" INTERFACE + "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" +) + +target_include_directories("wanda-${LIB_NAME}" SYSTEM INTERFACE + "$<INSTALL_INTERFACE:include>" +) + +target_compile_features("wanda-${LIB_NAME}" INTERFACE + "cxx_std_20" +) + +install(TARGETS "wanda-${LIB_NAME}" + FILE_SET HEADERS +) + +add_library("wanda::${LIB_NAME}" ALIAS "wanda-${LIB_NAME}") diff --git a/source/lib/include/wanda/deferred_failure.hpp b/source/lib/meta/include/wanda/meta/deferred_failure.hpp index 5db26f6..f74d923 100644 --- a/source/lib/include/wanda/deferred_failure.hpp +++ b/source/lib/meta/include/wanda/meta/deferred_failure.hpp @@ -4,18 +4,18 @@ * @since 1.0.0 */ -#ifndef WANDA_DEFERRED_FAILURE_HPP -#define WANDA_DEFERRED_FAILURE_HPP +#ifndef WANDA_META_DEFERRED_FAILURE_HPP +#define WANDA_META_DEFERRED_FAILURE_HPP #include <type_traits> -namespace +namespace wanda::meta { /** * @brief A helper type to defer static_assert failures */ template<typename...> using deferred_failure = std::false_type; -} // namespace +} // namespace wanda::meta #endif
\ No newline at end of file diff --git a/source/lib/include/wanda/keyed.hpp b/source/lib/meta/include/wanda/meta/keyed.hpp index 58f17ad..a09d1eb 100644 --- a/source/lib/include/wanda/keyed.hpp +++ b/source/lib/meta/include/wanda/meta/keyed.hpp @@ -4,10 +4,10 @@ * @since 1.0.0 */ -#ifndef WANDA_KEYED_HPP -#define WANDA_KEYED_HPP +#ifndef WANDA_META_KEYED_HPP +#define WANDA_META_KEYED_HPP -namespace wanda +namespace wanda::meta { /** * @brief A tag type to prevent construction of a type without a factory @@ -23,6 +23,6 @@ namespace wanda explicit keyed(key) {} }; -} // namespace wanda +} // namespace wanda::meta #endif
\ No newline at end of file diff --git a/source/lib/include/wanda/type_wrapper.hpp b/source/lib/meta/include/wanda/meta/type_wrapper.hpp index 12684cb..1d34c09 100644 --- a/source/lib/include/wanda/type_wrapper.hpp +++ b/source/lib/meta/include/wanda/meta/type_wrapper.hpp @@ -4,16 +4,16 @@ * @since 1.0.0 */ -#ifndef WANDA_TYPE_WRAPPER_HPP -#define WANDA_TYPE_WRAPPER_HPP +#ifndef WANDA_META_TYPE_WRAPPER_HPP +#define WANDA_META_TYPE_WRAPPER_HPP #include <utility> -namespace wanda +namespace wanda::meta { /** * @brief A type to create a distinct type based on an existing type - * + * * @tparam InnerType The type to wrap * @tparam TagType A tag type to identify the distinct type */ @@ -42,6 +42,6 @@ namespace wanda InnerType m_value; }; -} // namespace wanda +} // namespace wanda::meta #endif
\ No newline at end of file diff --git a/source/lib/proto/CMakeLists.txt b/source/lib/proto/CMakeLists.txt new file mode 100644 index 0000000..9967a95 --- /dev/null +++ b/source/lib/proto/CMakeLists.txt @@ -0,0 +1,38 @@ +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") + +find_package("fmt" REQUIRED) + +add_library("wanda-${LIB_NAME}" + ${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 + "fmt::fmt" +) + +install(TARGETS "wanda-${LIB_NAME}" + FILE_SET HEADERS +) + +add_library("wanda::${LIB_NAME}" ALIAS "wanda-${LIB_NAME}") diff --git a/source/lib/include/wanda/command.hpp b/source/lib/proto/include/wanda/proto/command.hpp index 67938de..c8dae65 100644 --- a/source/lib/include/wanda/command.hpp +++ b/source/lib/proto/include/wanda/proto/command.hpp @@ -1,13 +1,13 @@ -#ifndef WANDA_COMMAND_HPP -#define WANDA_COMMAND_HPP +#ifndef WANDA_PROTO_COMMAND_HPP +#define WANDA_PROTO_COMMAND_HPP -#include "wanda/message.hpp" +#include "wanda/proto/message.hpp" #include <optional> #include <string> #include <vector> -namespace wanda +namespace wanda::proto { /** * @brief An enum to describe different command IDs @@ -28,7 +28,7 @@ namespace wanda /** * @brief Convert the command to a message for transmission to a remote endpoint */ - std::optional<wanda::message> message() const; + std::optional<wanda::proto::message> message() const; }; /** @@ -41,6 +41,6 @@ namespace wanda */ command make_change_command(); -} // namespace wanda +} // namespace wanda::proto #endif
\ No newline at end of file diff --git a/source/lib/include/wanda/message.hpp b/source/lib/proto/include/wanda/proto/message.hpp index 0f3034c..f4a6a3b 100644 --- a/source/lib/include/wanda/message.hpp +++ b/source/lib/proto/include/wanda/proto/message.hpp @@ -4,25 +4,19 @@ * @since 1.0.0 */ -#ifndef WANDA_MESSAGE_HPP -#define WANDA_MESSAGE_HPP +#ifndef WANDA_PROTO_MESSAGE_HPP +#define WANDA_PROTO_MESSAGE_HPP + +#include <fmt/core.h> #include <cstddef> #include <istream> #include <optional> #include <string> -#include <fmt/core.h> +#include <string_view> -namespace wanda +namespace wanda::proto { - inline namespace v1 - { - /** - * @brief The version argument for the hello message reflecting the current version - */ - auto constexpr message_argument_hello = "1.0.0"; - } // namespace v1 - /** * @brief A tag to mark messages originating from the controller */ @@ -79,15 +73,12 @@ namespace wanda */ std::ostream & operator<<(std::ostream & out, message const & message); -} // namespace wanda +} // namespace wanda::proto template<> -struct fmt::formatter<wanda::message> : fmt::formatter<std::string> +struct fmt::formatter<wanda::proto::message> : fmt::formatter<std::string> { - auto format(wanda::message const & message, format_context & context) const - { - return formatter<string_view>::format(static_cast<std::string>(message), context); - } + 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 new file mode 100644 index 0000000..faa17d7 --- /dev/null +++ b/source/lib/proto/include/wanda/proto/version.hpp @@ -0,0 +1,12 @@ +#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/src/command.cpp b/source/lib/proto/src/command.cpp index 83c6b73..5a669f5 100644 --- a/source/lib/src/command.cpp +++ b/source/lib/proto/src/command.cpp @@ -1,6 +1,6 @@ -#include "wanda/command.hpp" +#include "wanda/proto/command.hpp" -namespace wanda +namespace wanda::proto { std::optional<message> command::message() const { @@ -26,7 +26,7 @@ namespace wanda return std::nullopt; } - return wanda::message{"C", command, argument_string}; + return wanda::proto::message{"C", command, argument_string}; } std::optional<command> make_command(message message) @@ -44,4 +44,4 @@ namespace wanda return {command_id::change}; } -} // namespace wanda
\ No newline at end of file +} // namespace wanda::proto
\ No newline at end of file diff --git a/source/lib/src/message.cpp b/source/lib/proto/src/message.cpp index 34930bc..dad3e86 100644 --- a/source/lib/src/message.cpp +++ b/source/lib/proto/src/message.cpp @@ -1,10 +1,12 @@ -#include "wanda/message.hpp" +#include "wanda/proto/message.hpp" + +#include <fmt/format.h> #include <ios> #include <iterator> #include <sstream> -namespace wanda +namespace wanda::proto { message::operator std::string() const { @@ -72,4 +74,9 @@ namespace wanda return out << static_cast<std::string>(message); } -} // namespace wanda
\ No newline at end of file +} // namespace wanda::proto + +auto fmt::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); +} diff --git a/source/lib/src/commander.cpp b/source/lib/src/commander.cpp deleted file mode 100644 index 5122b62..0000000 --- a/source/lib/src/commander.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "wanda/commander.hpp" -#include "wanda/logging.hpp" -#include "wanda/message.hpp" -#include "wanda/optional.hpp" - -#include <spdlog/fmt/ostr.h> - -namespace wanda -{ - commander::commander(asio::io_service & service, std::filesystem::path socket, listener & listener) - : m_service{service} - , m_endpoint{socket.string()} - , m_socket{service} - , m_listener{listener} - { - } - - void commander::start() - { - m_socket.async_connect(m_endpoint, [&](auto const & error) { - if (error) - { - get_logger()->error("error while connecting to control interface: '{}'", error.message()); - } - else - { - get_logger()->info("establishing connection to wanda deamon"); - m_connection = wanda::make_control_connection(std::move(m_socket)); - m_connection->add(this); - m_connection->start(); - m_connection->send({message_source_controller, message_command_hello, message_argument_hello}); - } - }); - } - - void commander::stop() - { - get_logger()->info("closing control connection"); - m_connection->close(); - } - - void commander::send(command command) - { - using namespace wanda::std_ext; - - if (!m_connection || m_connection->current_state() != control_connection::state::established) - { - get_logger()->error("tried to send command without an established connection"); - m_listener.on_error(*this, "tried to send command without an established connection"); - return; - } - - with(command.message(), [&](auto const & message) { m_connection->send(message); }) || - [&] { get_logger()->error("unknown command"); }; - } - - void commander::on_error(control_connection::pointer connection, std::error_code error) - { - get_logger()->error("control interface communication error: '{}'", error.message()); - } - - void commander::on_received(wanda::control_connection::pointer connection, message message) - { - if (auto state = connection->current_state(); message.command == "HELLO" && state == control_connection::state::fresh) - { - get_logger()->info("connection to wanda deamon successfully established"); - connection->update(control_connection::state::established); - m_listener.on_connected(*this); - } - else - { - get_logger()->error("unexpected message: '{}'", message); - m_listener.on_error(*this, "unexpected message '" + static_cast<std::string>(message) + '\''); - } - } - -} // namespace wanda
\ No newline at end of file diff --git a/source/lib/std_ext/CMakeLists.txt b/source/lib/std_ext/CMakeLists.txt new file mode 100644 index 0000000..e6e3372 --- /dev/null +++ b/source/lib/std_ext/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_path(GET CMAKE_CURRENT_SOURCE_DIR STEM LIB_NAME) + +file(GLOB_RECURSE LIB_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" CONFIGURE_DEPENDS "**/*.hpp") + +add_library("wanda-${LIB_NAME}" INTERFACE) + +target_sources("wanda-${LIB_NAME}" INTERFACE + FILE_SET HEADERS + FILES ${LIB_HEADERS} + BASE_DIRS "include" +) + +target_include_directories("wanda-${LIB_NAME}" INTERFACE + "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" +) + +target_include_directories("wanda-${LIB_NAME}" SYSTEM INTERFACE + "$<INSTALL_INTERFACE:include>" +) + +target_compile_features("wanda-${LIB_NAME}" INTERFACE + "cxx_std_20" +) + +install(TARGETS "wanda-${LIB_NAME}" + FILE_SET HEADERS +) + +add_library("wanda::${LIB_NAME}" ALIAS "wanda-${LIB_NAME}") diff --git a/source/lib/include/wanda/expected.hpp b/source/lib/std_ext/include/wanda/std_ext/expected.hpp index fff0d81..83629db 100644 --- a/source/lib/include/wanda/expected.hpp +++ b/source/lib/std_ext/include/wanda/std_ext/expected.hpp @@ -4,18 +4,18 @@ * @since 1.0.0 */ -#ifndef WANDA_EXPECTED_HPP -#define WANDA_EXPECTED_HPP +#ifndef WANDA_STD_EXT_EXPECTED_HPP +#define WANDA_STD_EXT_EXPECTED_HPP #include <initializer_list> #include <type_traits> #include <utility> -namespace wanda +namespace wanda::std_ext { /** - * @brief A type to represent the error case of a computation based on #wanda::expected - */ + * @brief A type to represent the error case of a computation based on #wanda::expected + */ template<typename ErrorType> struct unexpected { @@ -207,11 +207,11 @@ namespace wanda }; template<typename ErrorType> - unexpected(ErrorType)->unexpected<ErrorType>; + unexpected(ErrorType) -> unexpected<ErrorType>; /** - * @brief Compare two @p unexpected instances for equality - */ + * @brief Compare two @p unexpected instances for equality + */ template<typename ErrorType1, typename ErrorType2> constexpr bool operator==(unexpected<ErrorType1> const & lhs, unexpected<ErrorType2> const & rhs) { @@ -219,8 +219,8 @@ namespace wanda } /** - * @brief Compare two @p unexpected instances for inequality - */ + * @brief Compare two @p unexpected instances for inequality + */ template<typename ErrorType1, typename ErrorType2> constexpr bool operator!=(unexpected<ErrorType1> const & lhs, unexpected<ErrorType2> const & rhs) { @@ -228,8 +228,8 @@ namespace wanda } /** - * @brief Swap the error values of two @p unexpected instances - */ + * @brief Swap the error values of two @p unexpected instances + */ template< typename Err, std::enable_if_t<std::is_swappable_v<Err>> * = nullptr> @@ -239,18 +239,18 @@ namespace wanda } /** - * @brief A tag type for @p unexpected - */ + * @brief A tag type for @p unexpected + */ struct unexpect_t { explicit unexpect_t() = default; }; /** - * @brief A tap for @p unexpected - */ + * @brief A tap for @p unexpected + */ inline constexpr unexpect_t unexpect{}; -} // namespace wanda +} // namespace wanda::std_ext #endif
\ No newline at end of file diff --git a/source/lib/include/wanda/optional.hpp b/source/lib/std_ext/include/wanda/std_ext/optional.hpp index da3774c..763e8ac 100644 --- a/source/lib/include/wanda/optional.hpp +++ b/source/lib/std_ext/include/wanda/std_ext/optional.hpp @@ -4,8 +4,8 @@ * @since 1.0.0 */ -#ifndef WANDA_OPTIONAL_HPP -#define WANDA_OPTIONAL_HPP +#ifndef WANDA_STD_EXT_OPTIONAL_HPP +#define WANDA_STD_EXT_OPTIONAL_HPP #include <optional> @@ -46,7 +46,7 @@ namespace wanda::std_ext /** * @brief Unwrap the given optional object, if present, and pass it to the handler - * + * * @return A successful computation iff. the object was present, a failed computation otherwise. */ template<typename ObjectType, typename HandlerType> diff --git a/source/lib/system/CMakeLists.txt b/source/lib/system/CMakeLists.txt new file mode 100644 index 0000000..813bcc7 --- /dev/null +++ b/source/lib/system/CMakeLists.txt @@ -0,0 +1,68 @@ +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") + +find_package("Boost" REQUIRED) +find_package("fmt" REQUIRED) +find_package("JPEG" REQUIRED) +find_package("PNG" REQUIRED) +find_package("spdlog" REQUIRED) + +find_package("PkgConfig" REQUIRED) + +pkg_check_modules("GIO" + REQUIRED + IMPORTED_TARGET + GLOBAL + "gio-2.0" +) + +pkg_check_modules("libmagic" + REQUIRED + IMPORTED_TARGET + GLOBAL + "libmagic" +) + +add_library("wanda-${LIB_NAME}" + ${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 + "wanda::meta" + "wanda::std_ext" + + "boost::boost" + "fmt::fmt" + "JPEG::JPEG" + "PNG::PNG" + "spdlog::spdlog" + + "PkgConfig::GIO" + "PkgConfig::libmagic" +) + +install(TARGETS "wanda-${LIB_NAME}" + FILE_SET HEADERS +) + +add_library("wanda::${LIB_NAME}" ALIAS "wanda-${LIB_NAME}") diff --git a/source/lib/include/wanda/environment.hpp b/source/lib/system/include/wanda/system/environment.hpp index 5a702a8..8cd9ecf 100644 --- a/source/lib/include/wanda/environment.hpp +++ b/source/lib/system/include/wanda/system/environment.hpp @@ -4,15 +4,15 @@ * @since 1.0.0 */ -#ifndef WANDA_ENVIRONMENT_HPP -#define WANDA_ENVIRONMENT_HPP +#ifndef WANDA_SYSTEM_ENVIRONMENT_HPP +#define WANDA_SYSTEM_ENVIRONMENT_HPP #include <unistd.h> #include <map> #include <string> -namespace wanda +namespace wanda::system { /** * @brief A type to provide access to the runtime environment @@ -32,14 +32,14 @@ namespace wanda /** * @brief Get the value of the given variable - * + * * @return A mutable reference to the value of the given environment variable */ std::string & operator[](std::string const & variable); /** * @brief Get the value of the given variable - * + * * @return An immutable reference to the value of the given environment variable */ std::string const & operator[](std::string const & variable) const; @@ -56,6 +56,6 @@ namespace wanda map_type m_cache{}; }; -} // namespace wanda +} // namespace wanda::system #endif
\ No newline at end of file diff --git a/source/lib/include/wanda/filesystem.hpp b/source/lib/system/include/wanda/system/filesystem.hpp index 1975bc5..971db90 100644 --- a/source/lib/include/wanda/filesystem.hpp +++ b/source/lib/system/include/wanda/system/filesystem.hpp @@ -4,14 +4,14 @@ * @since 1.0.0 */ -#ifndef WANDA_FILESYSTEM_HPP -#define WANDA_FILESYSTEM_HPP +#ifndef WANDA_SYSTEM_FILESYSTEM_HPP +#define WANDA_SYSTEM_FILESYSTEM_HPP #include <filesystem> #include <optional> #include <vector> -namespace wanda +namespace wanda::system { /** * @brief Covenience alias for path lists @@ -34,6 +34,6 @@ namespace wanda * @brief Pick a random path from the given list */ std::filesystem::path random_pick(path_list const & paths); -} // namespace wanda +} // namespace wanda::system #endif
\ No newline at end of file diff --git a/source/lib/include/wanda/logging.hpp b/source/lib/system/include/wanda/system/logging.hpp index b3c1665..8a9a90e 100644 --- a/source/lib/include/wanda/logging.hpp +++ b/source/lib/system/include/wanda/system/logging.hpp @@ -4,15 +4,15 @@ * @since 1.0.0 */ -#ifndef WANDA_LOGGING_HPP -#define WANDA_LOGGING_HPP +#ifndef WANDA_SYSTEM_LOGGING_HPP +#define WANDA_SYSTEM_LOGGING_HPP #include <spdlog/sinks/null_sink.h> #include <spdlog/spdlog.h> #include <memory> -namespace wanda +namespace wanda::system { /** * @brief A covenience alias to represent a handle for a logger @@ -21,7 +21,7 @@ namespace wanda /** * @brief Initialize the shared logger - * + * * @note The logger will only ever be initialized once, even if this function is called multiple times */ void initialize_logger(spdlog::sink_ptr sink = std::make_shared<spdlog::sinks::null_sink_st>()); @@ -30,6 +30,6 @@ namespace wanda * @brief Get the shared logger */ logger_ptr get_logger(); -} // namespace wanda +} // namespace wanda::system #endif
\ No newline at end of file diff --git a/source/lib/include/wanda/magic.hpp b/source/lib/system/include/wanda/system/magic.hpp index fcb153e..a8ea1ba 100644 --- a/source/lib/include/wanda/magic.hpp +++ b/source/lib/system/include/wanda/system/magic.hpp @@ -1,5 +1,5 @@ -#ifndef WANDA_MAGIC_HPP -#define WANDA_MAGIC_HPP +#ifndef WANDA_SYSTEM_MAGIC_HPP +#define WANDA_SYSTEM_MAGIC_HPP #include <magic.h> @@ -8,7 +8,7 @@ #include <string> #include <type_traits> -namespace wanda +namespace wanda::system { struct magic { @@ -53,6 +53,6 @@ namespace wanda std::unique_ptr<std::remove_pointer_t<magic_t>, closer> m_handle; }; -} // namespace wanda +} // namespace wanda::system #endif
\ No newline at end of file diff --git a/source/lib/include/wanda/setting.hpp b/source/lib/system/include/wanda/system/setting.hpp index abbd56f..e0be3f4 100644 --- a/source/lib/include/wanda/setting.hpp +++ b/source/lib/system/include/wanda/system/setting.hpp @@ -4,11 +4,11 @@ * @since 1.0.0 */ -#ifndef WANDA_setting_HPP -#define WANDA_setting_HPP +#ifndef WANDA_SYSTEM_SETTING_HPP +#define WANDA_SYSTEM_SETTING_HPP -#include "wanda/deferred_failure.hpp" -#include "wanda/type_wrapper.hpp" +#include "wanda/meta/deferred_failure.hpp" +#include "wanda/meta/type_wrapper.hpp" #include <gio/gio.h> @@ -21,14 +21,14 @@ #include <variant> #include <vector> -namespace wanda +namespace wanda::system { struct setting; /** * @brief A convenience type to represent setting keys */ - using key = type_wrapper<std::string, struct KeyTag>; + using key = meta::type_wrapper<std::string, struct KeyTag>; namespace literals { @@ -59,7 +59,7 @@ namespace wanda /** * @brief Assign the given @p value to the settings entry - * + * * @returns @p true iff. the value could be successfully assigned */ template<typename Type> @@ -136,7 +136,7 @@ namespace wanda /** * @brief Get the entry for the given key - * + * * @return An <code>std::optional</code> wrapping the entry associated with * the given key, or an empty <code>std::optional</code> if the desired key * does not exist in the setting's schema. @@ -151,6 +151,6 @@ namespace wanda friend std::optional<setting> literals::operator""_setting(char const *, std::size_t); }; -} // namespace wanda +} // namespace wanda::system #endif
\ No newline at end of file diff --git a/source/lib/include/wanda/wallpaper.hpp b/source/lib/system/include/wanda/system/wallpaper.hpp index 0cad473..7965fb0 100644 --- a/source/lib/include/wanda/wallpaper.hpp +++ b/source/lib/system/include/wanda/system/wallpaper.hpp @@ -4,8 +4,8 @@ * @since 1.0.0 */ -#ifndef WANDA_WALLPAPER_HPP -#define WANDA_WALLPAPER_HPP +#ifndef WANDA_SYSTEM_WALLPAPER_HPP +#define WANDA_SYSTEM_WALLPAPER_HPP #include <spdlog/sinks/null_sink.h> #include <spdlog/spdlog.h> @@ -13,12 +13,12 @@ #include <filesystem> #include <memory> -namespace wanda +namespace wanda::system { /** * @brief Set the wallpaper to the file specified by the given path */ void set_wallpaper(std::filesystem::path wallpaper); -} // namespace wanda +} // namespace wanda::system #endif
\ No newline at end of file diff --git a/source/lib/include/wanda/xdg.hpp b/source/lib/system/include/wanda/system/xdg.hpp index 833e4a0..ae01feb 100644 --- a/source/lib/include/wanda/xdg.hpp +++ b/source/lib/system/include/wanda/system/xdg.hpp @@ -4,16 +4,16 @@ * @since 1.0.0 */ -#ifndef WANDA_XDG_HPP -#define WANDA_XDG_HPP +#ifndef WANDA_SYSTEM_XDG_HPP +#define WANDA_SYSTEM_XDG_HPP -#include "wanda/environment.hpp" +#include "wanda/system/environment.hpp" #include <cstddef> #include <filesystem> #include <type_traits> -namespace wanda +namespace wanda::system { /** * @brief An @p enum to represet the standardized XDG directories @@ -35,6 +35,6 @@ namespace wanda * @brief Get the path to the given @p directory given the provided @p environment */ std::filesystem::path xdg_path_for(xdg_directory directory, environment const & environment); -} // namespace wanda +} // namespace wanda::system #endif
\ No newline at end of file diff --git a/source/lib/src/environment.cpp b/source/lib/system/src/environment.cpp index 2f1af0a..8f79531 100644 --- a/source/lib/src/environment.cpp +++ b/source/lib/system/src/environment.cpp @@ -1,8 +1,8 @@ -#include "wanda/environment.hpp" +#include "wanda/system/environment.hpp" #include <string> -namespace wanda +namespace wanda::system { environment::environment(char const * const * env) { @@ -68,4 +68,4 @@ namespace wanda return m_cache.cend(); } -} // namespace wanda
\ No newline at end of file +} // namespace wanda::system
\ No newline at end of file diff --git a/source/lib/src/filesystem.cpp b/source/lib/system/src/filesystem.cpp index 35b6b40..04dfff3 100644 --- a/source/lib/src/filesystem.cpp +++ b/source/lib/system/src/filesystem.cpp @@ -1,9 +1,9 @@ -#include "wanda/filesystem.hpp" +#include "wanda/system/filesystem.hpp" #include <random> #include <ranges> -namespace wanda +namespace wanda::system { std::optional<path_list> scan(std::filesystem::path source, bool(filter)(std::filesystem::path const &)) { @@ -28,4 +28,4 @@ namespace wanda return paths[distribution(generator)]; } -} // namespace wanda
\ No newline at end of file +} // namespace wanda::system
\ No newline at end of file diff --git a/source/lib/src/logging.cpp b/source/lib/system/src/logging.cpp index 0aa7e40..83dc9f6 100644 --- a/source/lib/src/logging.cpp +++ b/source/lib/system/src/logging.cpp @@ -1,6 +1,6 @@ -#include "wanda/logging.hpp" +#include "wanda/system/logging.hpp" -namespace wanda +namespace wanda::system { std::function<void(spdlog::sink_ptr)> initializer = [](spdlog::sink_ptr sink) { spdlog::register_logger(std::make_shared<spdlog::logger>("wanda", sink)); @@ -18,4 +18,4 @@ namespace wanda return spdlog::get("wanda"); } -} // namespace wanda
\ No newline at end of file +} // namespace wanda::system
\ No newline at end of file diff --git a/source/lib/src/setting.cpp b/source/lib/system/src/setting.cpp index b3f661e..1553eae 100644 --- a/source/lib/src/setting.cpp +++ b/source/lib/system/src/setting.cpp @@ -1,9 +1,9 @@ -#include "wanda/setting.hpp" +#include "wanda/system/setting.hpp" #include <algorithm> #include <type_traits> -namespace wanda +namespace wanda::system { // UDL implementations @@ -99,4 +99,4 @@ namespace wanda return {}; } -} // namespace wanda
\ No newline at end of file +} // namespace wanda::system
\ No newline at end of file diff --git a/source/lib/src/wallpaper.cpp b/source/lib/system/src/wallpaper.cpp index c9c5cfe..ebb8bd7 100644 --- a/source/lib/src/wallpaper.cpp +++ b/source/lib/system/src/wallpaper.cpp @@ -1,22 +1,22 @@ -#include "wanda/logging.hpp" -#include "wanda/magic.hpp" -#include "wanda/optional.hpp" -#include "wanda/setting.hpp" -#include "wanda/wallpaper.hpp" +#include "wanda/system/wallpaper.hpp" + +#include "wanda/std_ext/optional.hpp" +#include "wanda/system/logging.hpp" +#include "wanda/system/magic.hpp" +#include "wanda/system/setting.hpp" #include <boost/gil.hpp> #include <boost/gil/extension/io/jpeg.hpp> #include <boost/gil/extension/io/png.hpp> #include <boost/gil/extension/numeric/resample.hpp> #include <boost/gil/extension/numeric/sampler.hpp> - #include <fmt/format.h> #include <algorithm> #include <cmath> #include <memory> -namespace wanda +namespace wanda::system { namespace { @@ -61,7 +61,7 @@ namespace wanda void set_wallpaper(std::filesystem::path wallpaper) { - using namespace wanda::literals; + using namespace wanda::system::literals; using namespace wanda::std_ext; using namespace std::string_literals; @@ -88,4 +88,4 @@ namespace wanda [&] { get_logger()->error("invalid setting"); }; } -} // namespace wanda +} // namespace wanda::system diff --git a/source/lib/src/xdg.cpp b/source/lib/system/src/xdg.cpp index cfd1719..109beb1 100644 --- a/source/lib/src/xdg.cpp +++ b/source/lib/system/src/xdg.cpp @@ -1,8 +1,8 @@ -#include "wanda/xdg.hpp" +#include "wanda/system/xdg.hpp" #include <unistd.h> -namespace wanda +namespace wanda::system { std::string xdg_variable(xdg_directory directory) { @@ -43,4 +43,4 @@ namespace wanda return ""; } -} // namespace wanda
\ No newline at end of file +} // namespace wanda::system
\ No newline at end of file |
