From ac34053c57180b042426d82310d9ff57770387c9 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 29 Nov 2018 22:40:56 +0100 Subject: wanda: extract core components --- CMakeLists.txt | 32 +++++++++++++++++++----------- src/main.cpp | 61 ---------------------------------------------------------- src/wandad.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 72 deletions(-) delete mode 100644 src/main.cpp create mode 100644 src/wandad.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index cbb15a6..a8f6d2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,32 +19,42 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules") include("ConanDependencies") include("SystemDependencies") -add_executable("wanda" - # Executable - "src/main.cpp" - - # Components +add_library("core" OBJECT "src/control_connection.cpp" "src/control_connection.hpp" "src/control_interface.cpp" "src/control_interface.hpp" "src/deferred_failure.hpp" - "src/filesystem.cpp" - "src/filesystem.hpp" "src/keyed.hpp" "src/optional.hpp" + "src/type_wrapper.hpp" +) + +target_link_libraries("core" + "CONAN_PKG::boost_asio" +) + +add_executable("wandad" + "src/filesystem.cpp" + "src/filesystem.hpp" "src/setting.cpp" "src/setting.hpp" - "src/type_wrapper.hpp" "src/wallpaper.cpp" "src/wallpaper.hpp" + "src/wandad.cpp" ) -target_link_libraries("wanda" - "CONAN_PKG::boost_asio" - "CONAN_PKG::boost_config" +target_link_libraries("wandad" + # Internal components + "core" + + # Conan dependencies "CONAN_PKG::boost_program_options" + + # System dependencies "SYSTEM::C++FS" "SYSTEM::GIO" + + # CMake dependencies "Threads::Threads" ) diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index 169efd9..0000000 --- a/src/main.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "control_interface.hpp" -#include "filesystem.hpp" -#include "optional.hpp" -#include "setting.hpp" -#include "wallpaper.hpp" - -#include - -#include -#include -#include -#include - -namespace -{ - -constexpr auto image_filter = [](auto const &path) { - static auto const extensions = std::set{ - std::filesystem::path{".jpg"}, - std::filesystem::path{".png"}, - }; - - if (!std::filesystem::is_regular_file(path)) - { - return false; - } - - return extensions.find(path.extension()) != extensions.cend(); -}; - -} // namespace - -int main() -{ - using namespace wanda::std_ext; - - with(wanda::scan({"/usr/share/backgrounds"}, image_filter), [](auto const &list) { - auto wallpaper = wanda::random_pick(list); - wanda::set_wallpaper(wallpaper); - - auto service = boost::asio::io_service{}; - auto interface = wanda::make_interface(service, ".wanda_interface"); - auto status = interface->start(); - - if (status) - { - return; - } - - auto signals = boost::asio::signal_set{service, SIGINT}; - signals.async_wait([&](auto const &error, auto const signal) { - if (!error && signal == SIGINT) - { - interface->shutdown(); - service.stop(); - } - }); - - service.run(); - }) || [] { std::cerr << "Directory does not exist\n"; }; -} diff --git a/src/wandad.cpp b/src/wandad.cpp new file mode 100644 index 0000000..169efd9 --- /dev/null +++ b/src/wandad.cpp @@ -0,0 +1,61 @@ +#include "control_interface.hpp" +#include "filesystem.hpp" +#include "optional.hpp" +#include "setting.hpp" +#include "wallpaper.hpp" + +#include + +#include +#include +#include +#include + +namespace +{ + +constexpr auto image_filter = [](auto const &path) { + static auto const extensions = std::set{ + std::filesystem::path{".jpg"}, + std::filesystem::path{".png"}, + }; + + if (!std::filesystem::is_regular_file(path)) + { + return false; + } + + return extensions.find(path.extension()) != extensions.cend(); +}; + +} // namespace + +int main() +{ + using namespace wanda::std_ext; + + with(wanda::scan({"/usr/share/backgrounds"}, image_filter), [](auto const &list) { + auto wallpaper = wanda::random_pick(list); + wanda::set_wallpaper(wallpaper); + + auto service = boost::asio::io_service{}; + auto interface = wanda::make_interface(service, ".wanda_interface"); + auto status = interface->start(); + + if (status) + { + return; + } + + auto signals = boost::asio::signal_set{service, SIGINT}; + signals.async_wait([&](auto const &error, auto const signal) { + if (!error && signal == SIGINT) + { + interface->shutdown(); + service.stop(); + } + }); + + service.run(); + }) || [] { std::cerr << "Directory does not exist\n"; }; +} -- cgit v1.2.3