Files

63 lines
1.7 KiB
C++
Raw Permalink Normal View History

2020-04-17 19:33:06 +02:00
/*
* This file is part of the Flowee project
2026-04-09 18:56:13 +02:00
* Copyright (C) 2020-2026 Tom Zander <tom@flowee.org>
2020-04-17 19:33:06 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Action.h"
#include "DownloadManager.h"
#include <functional>
2025-02-11 16:46:21 +01:00
#include <boost/asio/bind_executor.hpp>
2020-04-17 19:33:06 +02:00
Action::Action(DownloadManager *parent)
: m_dlm(parent),
2025-02-08 19:05:26 +01:00
m_timer(parent->ioContext())
2020-04-17 19:33:06 +02:00
{
}
void Action::again()
{
if (m_dlm->powerMode() != P2PNet::NormalPower || m_cancelled) {
2025-03-07 14:31:02 +01:00
m_dlm->done(this);
return;
}
2026-04-09 18:56:13 +02:00
m_timer.expires_after(std::chrono::milliseconds(m_interval));
2025-02-11 16:46:21 +01:00
m_timer.async_wait(boost::asio::bind_executor(m_dlm->strand(),
std::bind(&Action::execute, this, std::placeholders::_1)));
2020-04-17 19:33:06 +02:00
}
2021-02-03 14:33:38 +01:00
void Action::setInterval(int milliseconds)
{
m_interval = milliseconds;
}
2020-04-17 19:33:06 +02:00
void Action::start()
{
assert(m_dlm);
2023-04-01 22:58:41 +02:00
// first time we just call it, no timer. But in the strand.
2025-02-11 16:46:21 +01:00
m_dlm->strand().post(std::bind(&Action::execute, this, boost::system::error_code()), std::allocator<void>());
2020-04-17 19:33:06 +02:00
}
void Action::cancel()
{
m_cancelled = true;
2020-04-17 19:33:06 +02:00
m_timer.cancel();
}
Action::~Action()
{
}