aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/control_interface.cpp34
-rw-r--r--src/control_interface.hpp9
-rw-r--r--src/wandad.cpp17
3 files changed, 43 insertions, 17 deletions
diff --git a/src/control_interface.cpp b/src/control_interface.cpp
index caeb6da..a3ecdb8 100644
--- a/src/control_interface.cpp
+++ b/src/control_interface.cpp
@@ -2,6 +2,8 @@
#include <boost/system/error_code.hpp>
+#include <spdlog/fmt/ostr.h>
+
#include <unistd.h>
#include <algorithm>
@@ -24,12 +26,13 @@ socket_deleter::~socket_deleter()
// 'control_interface' implementation
-control_interface::control_interface(control_interface::key key, boost::asio::io_service &service, control_interface::protocol::endpoint endpoint)
+control_interface::control_interface(control_interface::key key, boost::asio::io_service &service, control_interface::protocol::endpoint endpoint, std::shared_ptr<spdlog::logger> logger)
: keyed{key},
m_service{service},
m_endpoint{std::move(endpoint)},
m_socket{m_service},
- m_acceptor{m_service}
+ m_acceptor{m_service},
+ m_logger{logger}
{
}
@@ -72,10 +75,11 @@ void control_interface::perform_accept()
m_acceptor.async_accept(m_socket, [that = shared_from_this(), this](auto const &error) {
if (error && error != boost::asio::error::operation_aborted)
{
- // TODO: Handle error
+ m_logger->error("failed to accept connection because '{}'", error);
}
else
{
+ m_logger->info("new incoming controller connection");
auto [connection, inserted] = m_connections.insert(make_control_connection(std::move(m_socket)));
if (inserted)
{
@@ -89,6 +93,14 @@ void control_interface::perform_accept()
void control_interface::on_close(control_connection::pointer connection)
{
+ if (static_cast<char>(connection->current_state()) >= static_cast<char>(control_connection::state::established))
+ {
+ m_logger->info("controller connection closed");
+ }
+ else
+ {
+ m_logger->info("controller connection aborted before it could be established");
+ }
m_connections.erase(connection);
}
@@ -96,36 +108,42 @@ void control_interface::on_received(control_connection::pointer connection, mess
{
if (m_connections.find(connection) == m_connections.cend())
{
- // TODO: Handle unknown connection
+ m_logger->error("received message from an unknown connection");
return;
}
if (message.source != message_source_controller)
{
- // TODO: Handle illegal message source
+ m_logger->error("received a deamon message");
return;
}
if (auto state = connection->current_state(); message.command == message_command_hello && state == control_connection::state::fresh)
{
+ m_logger->info("controller connection established");
+ if (message.argument.has_value())
+ {
+ m_logger->info("remote controller version '{}'", *message.argument);
+ }
connection->send({message_source_daemon, message_command_hello, message_argument_hello});
connection->update(control_connection::state::established);
}
else
{
- // TODO: Handle unexpected message
+ m_logger->warn("ignoring unknown message '{}'", message);
}
}
-control_interface::pointer make_interface(boost::asio::io_service &service, std::filesystem::path file)
+control_interface::pointer make_interface(boost::asio::io_service &service, std::filesystem::path file, std::shared_ptr<spdlog::logger> logger)
{
if (std::filesystem::exists(file))
{
+ logger->error("file '{}' exists", file.native());
return {};
}
control_interface::protocol::endpoint endpoint{file.string()};
- return std::make_shared<control_interface>(control_interface::key{}, service, std::move(endpoint));
+ return std::make_shared<control_interface>(control_interface::key{}, service, std::move(endpoint), logger);
}
} // namespace wanda \ No newline at end of file
diff --git a/src/control_interface.hpp b/src/control_interface.hpp
index adf7416..c11571a 100644
--- a/src/control_interface.hpp
+++ b/src/control_interface.hpp
@@ -7,6 +7,8 @@
#include <boost/asio.hpp>
#include <boost/system/error_code.hpp>
+#include <spdlog/spdlog.h>
+
#include <cstddef>
#include <filesystem>
#include <istream>
@@ -31,7 +33,7 @@ struct control_interface : control_connection::listener, keyed<control_interface
using protocol = boost::asio::local::stream_protocol;
using pointer = std::shared_ptr<control_interface>;
- control_interface(key, boost::asio::io_service &service, protocol::endpoint endpoint);
+ control_interface(key, boost::asio::io_service &service, protocol::endpoint endpoint, std::shared_ptr<spdlog::logger> logger);
boost::system::error_code start();
boost::system::error_code shutdown();
@@ -42,7 +44,7 @@ struct control_interface : control_connection::listener, keyed<control_interface
private:
void perform_accept();
- friend pointer make_interface(boost::asio::io_service &service, std::filesystem::path file);
+ friend pointer make_interface(boost::asio::io_service &service, std::filesystem::path file, std::shared_ptr<spdlog::logger> logger);
boost::asio::io_service &m_service;
protocol::endpoint m_endpoint;
@@ -50,9 +52,10 @@ struct control_interface : control_connection::listener, keyed<control_interface
protocol::acceptor m_acceptor;
socket_deleter m_deleter{m_endpoint.path()};
std::set<control_connection::pointer> m_connections;
+ std::shared_ptr<spdlog::logger> m_logger;
};
-control_interface::pointer make_interface(boost::asio::io_service &service, std::filesystem::path file);
+control_interface::pointer make_interface(boost::asio::io_service &service, std::filesystem::path file, std::shared_ptr<spdlog::logger> logger);
} // namespace wanda
diff --git a/src/wandad.cpp b/src/wandad.cpp
index beb9040..b7bc0fe 100644
--- a/src/wandad.cpp
+++ b/src/wandad.cpp
@@ -8,6 +8,9 @@
#include <boost/asio.hpp>
+#include <spdlog/spdlog.h>
+#include <spdlog/sinks/stdout_color_sinks.h>
+
#include <csignal>
#include <iostream>
#include <set>
@@ -36,20 +39,22 @@ int main()
{
using namespace wanda::std_ext;
- with(wanda::scan({"/usr/share/backgrounds"}, image_filter), [](auto const &list) {
+ auto log = spdlog::stdout_color_mt("wandad");
+ log->info("wanda is starting up");
+
+ 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 socket_path = wanda::xdg_path_for(wanda::xdg_directory::runtime_dir, wanda::environment{}) / ".wanda_interface";
- std::clog << "[wandad::main] Initializing control interface on socket '" << socket_path.native() << "'\n";
- auto interface = wanda::make_interface(service, socket_path);
+ log->info("starting control interface on '{}'", socket_path.native());
+ auto interface = wanda::make_interface(service, socket_path, log);
if(!interface)
{
- std::cerr << "[wandad::main] Failed to initialize control interface on socket '" << socket_path.native() << "'\n"
- << "[wandad::main] File already existed. Is 'wandad' running already?\n";
+ log->error("failed to start control interface");
return;
}
@@ -68,5 +73,5 @@ int main()
});
service.run();
- }) || [] { std::cerr << "Directory does not exist\n"; };
+ }) || [&] { log->error("wallpaper directory does not exist"); };
}