Nostro/interfaces/Nostro-Daemon.cppm

31 lines
1.5 KiB
Text
Raw Permalink Normal View History

2026-11-01 18:35:23 +01:00
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
export module Nostro:Daemon;
#ifdef NOSTRO_DBUS_ENABLED
import std;
namespace Nostro {
// How nostrod runs: where it keeps each user's connectors and transactions, and when it lets go.
export struct DaemonOptions {
// Each user's directory is users/<uid> below it.
std::filesystem::path state;
// A worker exits after this long without a call, and the front once no worker is left; the next call starts
// them again, D-Bus activation the front.
std::chrono::seconds idle{300};
// How long a call waits for polkit, the user's password prompt included, before it is refused.
std::chrono::seconds promptTimeout{300};
};
// The front: owns net.catcrafts.Nostro1 on the system bus, works out each caller's uid, and hands every call to
// that uid's worker, started on demand as a process of its own. It holds no connector itself. Returns 0 once it
// was idle with no worker left or the bus went away, after it ended its workers. Throws when it cannot start.
export std::int32_t RunDaemon(const DaemonOptions& options);
// A worker: the library for one user, `uid`, whom logind calls `name`, serving the front over the connected socket
// `fd`. Every call is authorised with polkit before it runs. Returns 0 when it was idle or the front went away.
export std::int32_t RunWorker(std::int32_t fd, std::uint32_t uid, std::string_view name, const DaemonOptions& options);
}
#endif