mirror of
https://github.com/badaix/snapcast.git
synced 2025-06-27 15:07:06 +02:00
Use callback function instead of class
This commit is contained in:
parent
efd050a716
commit
f0985cbce4
4 changed files with 40 additions and 33 deletions
|
@ -36,7 +36,7 @@ using namespace std;
|
|||
namespace streamreader
|
||||
{
|
||||
|
||||
Watchdog::Watchdog(const boost::asio::any_io_executor& executor, WatchdogListener* listener) : timer_(executor), listener_(listener)
|
||||
Watchdog::Watchdog(const boost::asio::any_io_executor& executor) : timer_(executor)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -47,9 +47,10 @@ Watchdog::~Watchdog()
|
|||
}
|
||||
|
||||
|
||||
void Watchdog::start(const std::chrono::milliseconds& timeout)
|
||||
void Watchdog::start(const std::chrono::milliseconds& timeout, TimeoutHandler&& handler)
|
||||
{
|
||||
LOG(INFO, LOG_TAG) << "Starting watchdog, timeout: " << std::chrono::duration_cast<std::chrono::seconds>(timeout).count() << "s\n";
|
||||
handler_ = std::move(handler);
|
||||
timeout_ms_ = timeout;
|
||||
trigger();
|
||||
}
|
||||
|
@ -70,7 +71,8 @@ void Watchdog::trigger()
|
|||
if (!ec)
|
||||
{
|
||||
LOG(INFO, LOG_TAG) << "Timed out: " << std::chrono::duration_cast<std::chrono::seconds>(timeout_ms_).count() << "s\n";
|
||||
listener_->onTimeout(*this, timeout_ms_);
|
||||
if (handler_)
|
||||
handler_(timeout_ms_);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue