2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2015-2023 Mnemosyne LLC.
|
2022-02-07 16:25:02 +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
|
|
|
|
2022-08-17 16:08:36 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2022-10-01 14:12:49 +00:00
|
|
|
#define LIBTRANSMISSION_WATCHDIR_MODULE
|
|
|
|
|
2023-04-14 19:33:23 +00:00
|
|
|
#include "libtransmission/transmission.h"
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2023-04-14 19:33:23 +00:00
|
|
|
#include "libtransmission/watchdir-base.h"
|
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-08-10 13:34:51 +00:00
|
|
|
namespace
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2022-08-10 13:34:51 +00:00
|
|
|
class GenericWatchdir final : public impl::BaseWatchdir
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
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() }
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-08-10 13:34:51 +00:00
|
|
|
rescan_timer_->setCallback([this]() { scan(); });
|
|
|
|
rescan_timer_->startRepeating(rescan_interval);
|
|
|
|
scan();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2022-08-10 13:34:51 +00:00
|
|
|
private:
|
|
|
|
std::unique_ptr<Timer> rescan_timer_;
|
|
|
|
};
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2022-08-10 13:34:51 +00:00
|
|
|
} // namespace
|
2016-01-02 14:28:59 +00:00
|
|
|
|
2022-08-10 13:34:51 +00:00
|
|
|
std::unique_ptr<Watchdir> Watchdir::createGeneric(
|
|
|
|
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);
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
|
|
|
|
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*/)
|
2016-01-02 14:28:59 +00:00
|
|
|
{
|
2022-08-10 13:34:51 +00:00
|
|
|
return std::make_unique<GenericWatchdir>(dirname, std::move(callback), timer_maker, genericRescanInterval());
|
2016-01-02 14:28:59 +00:00
|
|
|
}
|
2022-08-10 13:34:51 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
} // namespace libtransmission
|