2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright 2015-2022 Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2022-09-21 23:34:18 +00:00
|
|
|
#include <chrono>
|
2022-08-10 13:34:51 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
2021-11-15 04:49:56 +00:00
|
|
|
#include <string_view>
|
|
|
|
|
2022-08-10 13:34:51 +00:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
struct event_base;
|
|
|
|
}
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2022-08-10 13:34:51 +00:00
|
|
|
namespace libtransmission
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
|
|
|
|
2022-10-01 14:12:49 +00:00
|
|
|
class TimerMaker;
|
|
|
|
|
2022-08-10 13:34:51 +00:00
|
|
|
class Watchdir
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Watchdir() = default;
|
|
|
|
virtual ~Watchdir() = default;
|
|
|
|
Watchdir(Watchdir&&) = delete;
|
|
|
|
Watchdir(Watchdir const&) = delete;
|
|
|
|
Watchdir& operator=(Watchdir&&) = delete;
|
|
|
|
Watchdir& operator=(Watchdir const&) = delete;
|
|
|
|
|
|
|
|
[[nodiscard]] virtual std::string_view dirname() const noexcept = 0;
|
|
|
|
|
|
|
|
enum class Action
|
|
|
|
{
|
|
|
|
Done,
|
|
|
|
Retry
|
|
|
|
};
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2022-08-10 13:34:51 +00:00
|
|
|
using Callback = std::function<Action(std::string_view dirname, std::string_view basename)>;
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2022-08-10 13:34:51 +00:00
|
|
|
[[nodiscard]] static auto genericRescanInterval() noexcept
|
|
|
|
{
|
2022-11-07 17:48:26 +00:00
|
|
|
return generic_rescan_interval;
|
2022-08-10 13:34:51 +00:00
|
|
|
}
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2022-08-10 13:34:51 +00:00
|
|
|
static void setGenericRescanInterval(std::chrono::milliseconds interval) noexcept
|
|
|
|
{
|
2022-11-07 17:48:26 +00:00
|
|
|
generic_rescan_interval = interval;
|
2022-08-10 13:34:51 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 02:49:51 +00:00
|
|
|
[[nodiscard]] static std::unique_ptr<Watchdir> create(
|
2022-08-10 13:34:51 +00:00
|
|
|
std::string_view dirname,
|
|
|
|
Callback callback,
|
|
|
|
libtransmission::TimerMaker& timer_maker,
|
|
|
|
struct event_base* evbase);
|
|
|
|
|
2022-09-09 02:49:51 +00:00
|
|
|
[[nodiscard]] static std::unique_ptr<Watchdir> createGeneric(
|
2022-08-10 13:34:51 +00:00
|
|
|
std::string_view dirname,
|
|
|
|
Callback callback,
|
|
|
|
libtransmission::TimerMaker& timer_maker,
|
2022-11-07 17:48:26 +00:00
|
|
|
std::chrono::milliseconds rescan_interval = generic_rescan_interval);
|
2022-08-10 13:34:51 +00:00
|
|
|
|
|
|
|
private:
|
2023-01-28 21:26:23 +00:00
|
|
|
static inline auto generic_rescan_interval = std::chrono::milliseconds{ 1000 };
|
2022-08-10 13:34:51 +00:00
|
|
|
};
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2022-08-10 13:34:51 +00:00
|
|
|
} // namespace libtransmission
|