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.
|
2015-04-04 17:43:56 +00:00
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2015-04-04 17:43:56 +00:00
|
|
|
|
2022-09-13 06:37:12 +00:00
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
2015-04-04 17:43:56 +00:00
|
|
|
|
2022-09-13 06:37:12 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/variant.h>
|
|
|
|
#include <libtransmission/error.h>
|
|
|
|
#include <libtransmission/utils.h>
|
|
|
|
#include <libtransmission/file.h>
|
|
|
|
#include <libtransmission/log.h>
|
|
|
|
|
|
|
|
using namespace std::literals;
|
|
|
|
|
|
|
|
class tr_daemon
|
2015-04-04 17:43:56 +00:00
|
|
|
{
|
2022-09-13 06:37:12 +00:00
|
|
|
public:
|
|
|
|
tr_daemon() = default;
|
|
|
|
|
|
|
|
~tr_daemon()
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SYS_SIGNALFD_H
|
|
|
|
if (sigfd_ != -1)
|
|
|
|
{
|
|
|
|
close(sigfd_);
|
|
|
|
}
|
|
|
|
#endif /* signalfd API */
|
|
|
|
tr_variantClear(&settings_);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool spawn(bool foreground, int* exit_code, tr_error** error);
|
|
|
|
bool init(int argc, char* argv[], bool* foreground, int* ret);
|
|
|
|
void handle_error(tr_error*);
|
|
|
|
int start(bool foreground);
|
|
|
|
void periodic_update();
|
|
|
|
void reconfigure();
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
private:
|
|
|
|
#ifdef HAVE_SYS_SIGNALFD_H
|
|
|
|
int sigfd_ = -1;
|
|
|
|
#endif /* signalfd API */
|
|
|
|
bool paused_ = false;
|
|
|
|
bool seen_hup_ = false;
|
|
|
|
std::string config_dir_;
|
|
|
|
tr_variant settings_ = {};
|
|
|
|
tr_session* my_session_ = nullptr;
|
|
|
|
char const* log_file_name_ = nullptr;
|
|
|
|
struct event_base* ev_base_ = nullptr;
|
|
|
|
tr_sys_file_t logfile_ = TR_BAD_SYS_FILE;
|
|
|
|
tr_quark key_pidfile_ = tr_quark_new("pidfile"sv);
|
|
|
|
tr_quark key_watch_dir_force_generic_ = tr_quark_new("watch-dir-force-generic"sv);
|
2015-04-04 17:43:56 +00:00
|
|
|
|
2022-09-13 06:37:12 +00:00
|
|
|
bool parse_args(int argc, char const** argv, bool* dump_settings, bool* foreground, int* exit_code);
|
|
|
|
bool reopen_log_file(char const* filename);
|
|
|
|
bool setup_signals();
|
|
|
|
void report_status();
|
|
|
|
};
|