transmission/libtransmission/watchdir.h

70 lines
1.7 KiB
C
Raw Normal View History

// 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),
// or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder.
#pragma once
2022-09-21 23:34:18 +00:00
#include <chrono>
2022-08-10 13:34:51 +00:00
#include <functional>
#include <memory>
#include <string_view>
2022-08-10 13:34:51 +00:00
extern "C"
{
struct event_base;
}
2022-08-10 13:34:51 +00:00
namespace libtransmission
{
class TimerMaker;
2022-08-10 13:34:51 +00:00
class Watchdir
{
public:
enum class Action
{
Done,
Retry
};
using Callback = std::function<Action(std::string_view dirname, std::string_view basename)>;
2022-08-10 13:34:51 +00:00
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;
[[nodiscard]] static auto generic_rescan_interval() noexcept
2022-08-10 13:34:51 +00:00
{
return generic_rescan_interval_;
2022-08-10 13:34:51 +00:00
}
static void set_generic_rescan_interval(std::chrono::milliseconds interval) noexcept
2022-08-10 13:34:51 +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);
[[nodiscard]] static std::unique_ptr<Watchdir> create_generic(
2022-08-10 13:34:51 +00:00
std::string_view dirname,
Callback callback,
libtransmission::TimerMaker& timer_maker,
std::chrono::milliseconds rescan_interval = generic_rescan_interval_);
2022-08-10 13:34:51 +00:00
private:
static inline auto generic_rescan_interval_ = std::chrono::milliseconds{ 1000 };
2022-08-10 13:34:51 +00:00
};
2022-08-10 13:34:51 +00:00
} // namespace libtransmission