Changing screen is not an operation, and a navigation line per click buried the entries that matter. Providers now narrate the work itself instead: the exact command, the fallbacks and the counts, through a Qt-free trace sink that reaches the journal only, so the status bar stays short.
46 lines
1.8 KiB
C++
46 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
// Operator-level trace for package-manager work: the exact command a provider
|
|
// runs, the decisions it takes around it (a fallback to the user installation,
|
|
// a skipped step, a detected lock) and what it found.
|
|
//
|
|
// This is deliberately separate from ProgressCallback. Progress is what the
|
|
// user watches in the status bar while an operation runs, so it stays short;
|
|
// a trace is detail to read after the fact, so it lives in the journal, where
|
|
// being verbose costs nothing. Both reach the same file, but only progress
|
|
// flashes on screen.
|
|
//
|
|
// The host installs one sink for the whole process; providers call report()
|
|
// and stay Qt-free so they keep building into the headless unit tests. With no
|
|
// sink installed — every test binary — report() is a no-op.
|
|
namespace provider_trace {
|
|
|
|
// Receives (source, message): `source` is the provider id shown between
|
|
// brackets in the journal ("pacman", "flatpak"), `message` is one line.
|
|
using Sink = std::function<void(const std::string& source, const std::string& message)>;
|
|
|
|
// The one sink the process shares. A function-local static, so it is created on
|
|
// first use whatever order the providers and the host start in.
|
|
inline Sink& sink() {
|
|
static Sink instance;
|
|
return instance;
|
|
}
|
|
|
|
// Installs the sink, or clears it when given an empty function.
|
|
inline void setSink(Sink replacement) { sink() = std::move(replacement); }
|
|
|
|
// Reports one line of trace. A no-op when no sink is installed. Named
|
|
// `report` rather than `emit`: Qt defines `emit` as a macro, which would
|
|
// silently swallow the name in every translation unit that includes a Qt
|
|
// header.
|
|
inline void report(const std::string& source, const std::string& message) {
|
|
if (message.empty()) return;
|
|
if (sink()) sink()(source, message);
|
|
}
|
|
|
|
} // namespace provider_trace
|