diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2023-09-07 14:36:23 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2023-09-07 14:36:23 +0200 |
| commit | 152c44ffb96143683a7fdaabac1c747aaf6ad0dc (patch) | |
| tree | c03c530efa97ed721b63416ca854deec25962d20 /source/app/src | |
| parent | 13cf6fe70cc68bd4d803385f5c6d7fe9c7691247 (diff) | |
| download | wanda-152c44ffb96143683a7fdaabac1c747aaf6ad0dc.tar.xz wanda-152c44ffb96143683a7fdaabac1c747aaf6ad0dc.zip | |
apps: split apps into directories
Diffstat (limited to 'source/app/src')
| -rw-r--r-- | source/app/src/wandac.cpp | 93 | ||||
| -rw-r--r-- | source/app/src/wandad.cpp | 147 |
2 files changed, 0 insertions, 240 deletions
diff --git a/source/app/src/wandac.cpp b/source/app/src/wandac.cpp deleted file mode 100644 index 65af1db..0000000 --- a/source/app/src/wandac.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include <wanda/control/commander.hpp> -#include <wanda/proto/command.hpp> -#include <wanda/system/environment.hpp> -#include <wanda/system/logging.hpp> -#include <wanda/system/xdg.hpp> - -#include <boost/asio/io_context.hpp> -#include <boost/asio/post.hpp> -#include <lyra/lyra.hpp> -#include <spdlog/sinks/stdout_color_sinks.h> -#include <spdlog/spdlog.h> - -#include <cstdlib> -#include <filesystem> -#include <iostream> -#include <memory> - -struct cli -{ - std::string command{}; - bool help{}; - - lyra::cli_parser parser{}; - - auto parse(int argc, char const * const * argv, std::ostream & error) - { - parser |= // - lyra::help(help) | // - lyra::arg{command, "command"}("The command to send to the deamon").required(); - - auto result = parser.parse({argc, argv}); - - if (!result) - { - error << "Error while processing command line arguments: " << result.message() << '\n' << parser << '\n'; - return false; - } - - return true; - } -}; - -struct listener : wanda::control::commander::listener -{ - listener(::cli & cli, boost::asio::io_context & service) - : m_cli{cli} - , m_service{service} - { - } - - void on_connected(wanda::control::commander & commander) override - { - if (m_cli.command == "change") - { - commander.send(wanda::proto::make_change_command()); - - post(m_service, [&] { commander.stop(); }); - } - } - -private: - ::cli & m_cli; - boost::asio::io_context & m_service; -}; - -int main(int argc, char const * const * argv) -{ - auto cli = ::cli{}; - if (!cli.parse(argc, argv, std::cerr)) - { - return EXIT_FAILURE; - } - else if (cli.help) - { - std::cout << cli.parser << '\n'; - return EXIT_SUCCESS; - } - - wanda::system::initialize_logger(std::make_shared<spdlog::sinks::stderr_color_sink_st>()); - - auto interface = - wanda::system::xdg_path_for(wanda::system::xdg_directory::runtime_dir, wanda::system::environment{}) / - ".wanda_interface"; - auto service = boost::asio::io_context{}; - auto listener = ::listener{cli, service}; - - auto commander = wanda::control::commander{service, interface, listener}; - - wanda::system::get_logger()->info("trying to connect to wanda control interface on '{}'", interface.native()); - commander.start(); - - service.run(); -} diff --git a/source/app/src/wandad.cpp b/source/app/src/wandad.cpp deleted file mode 100644 index 8d16a7e..0000000 --- a/source/app/src/wandad.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#include <wanda/control/interface.hpp> -#include <wanda/proto/command.hpp> -#include <wanda/std_ext/optional.hpp> -#include <wanda/system/environment.hpp> -#include <wanda/system/filesystem.hpp> -#include <wanda/system/logging.hpp> -#include <wanda/system/setting.hpp> -#include <wanda/system/wallpaper.hpp> -#include <wanda/system/xdg.hpp> - -#include <boost/asio/io_context.hpp> -#include <boost/asio/signal_set.hpp> -#include <lyra/lyra.hpp> -#include <spdlog/sinks/stdout_color_sinks.h> - -#include <csignal> -#include <cstdlib> -#include <iostream> -#include <set> -#include <string> - -namespace -{ - constexpr auto image_filter = [](auto const & path) { - static auto const extensions = std::set<std::filesystem::path>{ - std::filesystem::path{".jpg"}, - std::filesystem::path{".png"}, - }; - - if (!std::filesystem::is_regular_file(path)) - { - return false; - } - - return extensions.find(path.extension()) != extensions.cend(); - }; - - struct cli - { - std::string wallpaper_directory{}; - bool help{}; - - lyra::cli_parser parser{}; - - auto parse(int argc, char const * const * argv, std::ostream & error) - { - parser |= // - lyra::help(help) | // - lyra::arg{wallpaper_directory, "directory"}("The wallpaper source directory").required(); - - auto result = parser.parse({argc, argv}); - - if (!result) - { - error << "Error while processing command line arguments: " << result.message() << '\n' << parser << '\n'; - return false; - } - - return true; - } - }; - - struct listener : wanda::control::interface::listener - { - listener(std::vector<std::filesystem::path> const & wallpapers) - : m_wallpapers{wallpapers} - { - } - - void on_received(wanda::control::interface & interface, wanda::proto::command command) override - { - switch (command.id) - { - case wanda::proto::command_id::change: { - auto wallpaper = wanda::system::random_pick(m_wallpapers); - wanda::system::get_logger()->info("changing wallpaper to '{}'", wallpaper.native()); - wanda::system::set_wallpaper(wallpaper); - break; - } - default: - wanda::system::get_logger()->error("received unknown command '{}'", static_cast<int>(command.id)); - } - } - - private: - std::vector<std::filesystem::path> const & m_wallpapers; - }; - -} // namespace - -int main(int argc, char const * const * argv) -{ - using namespace wanda::std_ext; - - auto cli = ::cli{}; - if (!cli.parse(argc, argv, std::cerr)) - { - return EXIT_FAILURE; - } - else if (cli.help) - { - std::cout << cli.parser << '\n'; - return EXIT_SUCCESS; - } - - wanda::system::initialize_logger(std::make_shared<spdlog::sinks::stdout_color_sink_st>()); - wanda::system::get_logger()->info("wanda is starting up"); - - with(wanda::system::scan({cli.wallpaper_directory}, image_filter), - [&](auto const & list) { - auto service = boost::asio::io_context{}; - auto socket_path = - wanda::system::xdg_path_for(wanda::system::xdg_directory::runtime_dir, wanda::system::environment{}) / - ".wanda_interface"; - - wanda::system::get_logger()->info("starting control interface on '{}'", socket_path.native()); - auto listener = ::listener{list}; - auto interface = wanda::control::make_interface(service, socket_path, listener); - - if (!interface) - { - wanda::system::get_logger()->error("failed to start control interface"); - return; - } - - if (interface->start()) - { - return; - } - - auto signals = boost::asio::signal_set{service, SIGINT, SIGTERM}; - signals.async_wait([&](auto const & error, auto const signal) { - if (!error) - { - wanda::system::get_logger()->info("Received signal {}. terminating...", signal); - interface->shutdown(); - service.stop(); - } - }); - - auto wallpaper = wanda::system::random_pick(list); - wanda::system::set_wallpaper(wallpaper); - - service.run(); - }) || - [&] { wanda::system::get_logger()->error("wallpaper directory does not exist"); }; -} |
