1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-30 11:36:07 +00:00
transmission/libtransmission/watchdir.h
Charles Kerr 93db8f088a
fix: cppcoreguidelines-pro-type-cstyle-cast (#4685)
* fix: libtransmission cppcoreguidelines-pro-type-cstyle-cast

* fix: libtransmission cppcoreguidelines-avoid-do-while

* refactor: inline static class fields

* fix: libtransmission cppcoreguidelines-avoid-reference-coroutine-parameters

* fix: announcer.cc cppcoreguidelines-narrowing-conversions
2023-01-28 15:26:23 -06:00

69 lines
1.7 KiB
C++

// This file Copyright 2015-2022 Mnemosyne LLC.
// 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
#include <chrono>
#include <functional>
#include <memory>
#include <string_view>
extern "C"
{
struct event_base;
}
namespace libtransmission
{
class TimerMaker;
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
};
using Callback = std::function<Action(std::string_view dirname, std::string_view basename)>;
[[nodiscard]] static auto genericRescanInterval() noexcept
{
return generic_rescan_interval;
}
static void setGenericRescanInterval(std::chrono::milliseconds interval) noexcept
{
generic_rescan_interval = interval;
}
[[nodiscard]] static std::unique_ptr<Watchdir> create(
std::string_view dirname,
Callback callback,
libtransmission::TimerMaker& timer_maker,
struct event_base* evbase);
[[nodiscard]] static std::unique_ptr<Watchdir> createGeneric(
std::string_view dirname,
Callback callback,
libtransmission::TimerMaker& timer_maker,
std::chrono::milliseconds rescan_interval = generic_rescan_interval);
private:
static inline auto generic_rescan_interval = std::chrono::milliseconds{ 1000 };
};
} // namespace libtransmission