1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-23 08:13:27 +00:00
transmission/libtransmission/watchdir-generic.cc

65 lines
1.8 KiB
C++
Raw Normal View History

// This file Copyright © 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.
2023-07-08 15:24:03 +00:00
#include <chrono>
#include <memory>
#include <string_view>
2022-08-17 16:08:36 +00:00
#include <utility>
#define LIBTRANSMISSION_WATCHDIR_MODULE
2023-07-08 15:24:03 +00:00
#include "libtransmission/timer.h"
#include "libtransmission/watchdir.h"
#include "libtransmission/watchdir-base.h"
2022-08-10 13:34:51 +00:00
namespace libtransmission
{
2022-08-10 13:34:51 +00:00
namespace
{
2022-08-10 13:34:51 +00:00
class GenericWatchdir final : public impl::BaseWatchdir
{
2022-08-10 13:34:51 +00:00
public:
GenericWatchdir(
std::string_view dirname,
Callback callback,
libtransmission::TimerMaker& timer_maker,
std::chrono::milliseconds rescan_interval)
: BaseWatchdir{ dirname, std::move(callback), timer_maker }
, rescan_timer_{ timer_maker.create() }
{
rescan_timer_->set_callback([this]() { scan(); });
rescan_timer_->start_repeating(rescan_interval);
2022-08-10 13:34:51 +00:00
scan();
}
2022-08-10 13:34:51 +00:00
private:
std::unique_ptr<Timer> rescan_timer_;
};
2022-08-10 13:34:51 +00:00
} // namespace
std::unique_ptr<Watchdir> 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)
{
return std::make_unique<GenericWatchdir>(dirname, std::move(callback), timer_maker, rescan_interval);
}
2022-08-10 13:34:51 +00:00
#if !defined(WITH_INOTIFY) && !defined(WITH_KQUEUE) && !defined(_WIN32)
// no native impl, so use generic
std::unique_ptr<Watchdir> Watchdir::create(
std::string_view dirname,
Callback callback,
libtransmission::TimerMaker& timer_maker,
struct event_base* /*evbase*/)
{
return std::make_unique<GenericWatchdir>(dirname, std::move(callback), timer_maker, generic_rescan_interval());
}
2022-08-10 13:34:51 +00:00
#endif
} // namespace libtransmission