refactor(sdk): gather the plugin headers under include/sdk

include/ held the public plugin interface (package-manager.h, plugin.h,
provider-plugin.h, progress-tracker.h) next to the application's own
headers, so telling them apart meant knowing which four were special.

They move to include/sdk/. The installed layout does not change: make
install still puts them flat in include/PacManager, so a plugin author's
existing -I keeps working. The include path gains include/sdk, so the
flat #include in the sources and in every plugin stays as it was.
This commit is contained in:
BlackAngelTV committed 2026-09-29 21:23:37 +02:00
1 parent 60424c8d50
commit 91f88b1acc
5 files changed
+21 -21

No files matched your search

+252
View File
@@ -0,0 +1,252 @@
#pragma once
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <algorithm>
#include <cctype>
// One *installation* of a package. The same application can be present several
// times over — flatpak installs one copy in the user installation and another
// system-wide, or two different remotes or branches of the same id — and acting
// on "the package" is then ambiguous: flatpak refuses ("Multiple installed refs
// match …"). A provider that can have several fills `instances` so the view can
// list them and the user can choose the ones to act on.
struct PackageInstance {
// What the user reads: "utilisateur · flathub · stable".
std::string label;
// What the provider needs to act on exactly that one, in its own syntax
// ("user:com.example.App/x86_64/stable" for flatpak). The provider is the
// only one that understands it, which is why it is never shown and never
// rebuilt by the view.
std::string target;
};
// Information about a single package
struct PackageInfo {
std::string name;
std::string version;
std::string description;
std::string repository;
std::string size;
std::string installedSize;
// Id of the provider that owns this package (e.g. "pacman", "flatpak").
// Filled by the aggregating workers so operations can be routed to the
// right manager without the user picking one.
std::string provider;
// Every provider offering this package, after duplicate rows have been
// merged (used for display). The routing id stays in `provider`.
std::vector<std::string> providers;
// Every installation of this package, when the provider can have more than
// one (see PackageInstance). Empty means a single installation, which is
// what every provider but flatpak reports.
std::vector<PackageInstance> instances;
bool installed = false;
bool updateAvailable = false;
// Cleanup classification, filled by providers that report maintainable
// leftovers (see IPackageManager::listCleanupCandidates): true when no
// installed package requires this one, so it is safe to bulk-remove.
bool orphan = false;
// Short reason this row shows up as a cleanup candidate (e.g. "Orphelin",
// "Étranger"), empty for regular packages.
std::string cleanupReason;
};
// Merge packages that share the same name (offered by several providers) into
// a single row. The first occurrence keeps its metadata and provider id (so
// operations keep a deterministic default); later occurrences are folded in:
// installed/updateAvailable become true if any provider reports them, and
// their provider id is added to pkg.providers for display.
inline void mergeProviderDuplicates(std::vector<PackageInfo>& packages) {
// Every tagged package advertises at least its own provider.
for (auto& pkg : packages) {
if (pkg.providers.empty() && !pkg.provider.empty()) {
pkg.providers.push_back(pkg.provider);
}
}
std::map<std::string, std::size_t> firstIndex;
std::vector<std::size_t> toDrop;
for (std::size_t i = 0; i < packages.size(); ++i) {
const std::string& name = packages[i].name;
if (name.empty()) continue;
auto it = firstIndex.find(name);
if (it == firstIndex.end()) {
firstIndex.emplace(name, i);
continue;
}
PackageInfo& first = packages[it->second];
const PackageInfo& dup = packages[i];
first.installed = first.installed || dup.installed;
first.updateAvailable = first.updateAvailable || dup.updateAvailable;
// The installations of both rows belong to the merged one: that is how a
// package installed system-wide *and* per-user still shows the two
// copies the user can choose from.
for (const PackageInstance& instance : dup.instances) {
bool known = false;
for (const PackageInstance& existing : first.instances) {
if (existing.target == instance.target) { known = true; break; }
}
if (!known) first.instances.push_back(instance);
}
if (!dup.provider.empty()) {
bool known = false;
for (const auto& p : first.providers) {
if (p == dup.provider) {
known = true;
break;
}
}
if (!known) first.providers.push_back(dup.provider);
}
toDrop.push_back(i);
}
for (auto it = toDrop.rbegin(); it != toDrop.rend(); ++it) {
packages.erase(packages.begin() + static_cast<std::ptrdiff_t>(*it));
}
}
// Sort aggregated results by provider, then by name (case-insensitive), so
// packages from the same manager stay grouped. Providers are ordered by their
// position in providerOrder (query order); providers absent from it sort last
// and are compared by id.
inline void sortByProviderThenName(std::vector<PackageInfo>& packages,
const std::vector<std::string>& providerOrder = {}) {
auto ciLess = [](const std::string& a, const std::string& b) {
std::size_t i = 0;
for (; i < a.size() && i < b.size(); ++i) {
unsigned char ca =
static_cast<unsigned char>(std::tolower(static_cast<unsigned char>(a[i])));
unsigned char cb =
static_cast<unsigned char>(std::tolower(static_cast<unsigned char>(b[i])));
if (ca != cb) return ca < cb;
}
return a.size() < b.size();
};
auto rank = [&](const std::string& id) {
for (std::size_t i = 0; i < providerOrder.size(); ++i) {
if (providerOrder[i] == id) return static_cast<int>(i);
}
return static_cast<int>(providerOrder.size());
};
std::stable_sort(packages.begin(), packages.end(),
[&](const PackageInfo& a, const PackageInfo& b) {
int ra = rank(a.provider);
int rb = rank(b.provider);
if (ra != rb) return ra < rb;
if (a.provider != b.provider) return a.provider < b.provider;
return ciLess(a.name, b.name);
});
}
// Progress reported during an operation: a human-readable message plus an
// optional percentage (0-100) when the tool exposes real progress, or -1 when
// the exact position is unknown. -1 lets the UI keep an indeterminate bar.
using ProgressCallback = std::function<void(const std::string& message, int percent)>;
// Abstract interface for the package manager
class IPackageManager {
public:
virtual ~IPackageManager() = default;
// Identity
virtual std::string getName() const = 0;
virtual std::string getVersion() const = 0;
virtual std::string getDescription() const = 0;
// Capabilities
virtual bool canSearch() const = 0;
virtual bool canInstall() const = 0;
virtual bool canRemove() const = 0;
virtual bool canUpdate() const = 0;
virtual bool canListInstalled() const = 0;
// Operations
virtual std::vector<PackageInfo> search(const std::string& query) = 0;
virtual bool install(const std::string& packageName,
ProgressCallback progressCallback = nullptr) = 0;
virtual bool remove(const std::string& packageName,
ProgressCallback progressCallback = nullptr) = 0;
virtual bool update(const std::string& packageName = "",
ProgressCallback progressCallback = nullptr) = 0;
virtual std::vector<PackageInfo> listInstalled() = 0;
virtual std::vector<PackageInfo> listUpdates() = 0;
virtual bool refresh(ProgressCallback progressCallback = nullptr) = 0;
// ---- Cleanup (optional) ----
// Providers that can reclaim unused/legacy packages override these; the
// defaults leave providers that only install packages working unchanged.
// Whether the provider can enumerate cleanup candidates at all.
virtual bool canListCleanup() const { return false; }
// Packages a cleanup can reclaim: orphans (nothing installed requires
// them) and legacy leftovers (installed from outside the sync
// repositories, e.g. AUR or manual builds). Rows carry `orphan` and
// `cleanupReason`.
virtual std::vector<PackageInfo> listCleanupCandidates() { return {}; }
// Remove several packages in one operation (a single privileged command
// instead of one per package). Defaults to a sequence of remove() calls.
virtual bool removePackages(const std::vector<std::string>& packages,
ProgressCallback progressCallback = nullptr) {
bool success = true;
for (const auto& name : packages) {
success = remove(name, progressCallback) && success;
}
return success;
}
// Whether cleanCache() actually has something to trim here, so the UI only
// offers the action for providers that own a cache.
virtual bool canCleanCache() const { return false; }
// Free the disk space held by the provider's caches (package cache,
// unused runtimes...). Returns false when the cleanup failed; the reason is
// then in lastError().
virtual bool cleanCache(ProgressCallback progressCallback = nullptr) {
(void)progressCallback;
return false;
}
// ---- Installation from a file (optional) ----
// Providers that can install a package straight from a file — the Flatpak
// bundle formats, typically — override these, so the app can act on what
// the user drops on the window or opens from the file manager ("Ouvrir
// avec PacManager"). A provider only claims the formats it owns.
// Whether this provider understands that file (or URL).
virtual bool canInstallFile(const std::string& path) const {
(void)path;
return false;
}
// Install the package the file describes. Returns false when the install
// failed; the reason is then in lastError().
virtual bool installFile(const std::string& path,
ProgressCallback progressCallback = nullptr) {
(void)path;
(void)progressCallback;
return false;
}
// Check if the package manager is available on the system
virtual bool isAvailable() const = 0;
// Whether privileged operations need a password (e.g. sudo for pacman).
// Providers that run per-user (e.g. flatpak) can keep the default.
virtual bool requiresPassword() const { return false; }
// Last error reported by the most recent failed operation, if any. Used
// to surface the real command output to the user instead of a generic
// failure message.
virtual std::string lastError() const { return {}; }
};
+51
View File
@@ -0,0 +1,51 @@
#pragma once
#include <string>
// Every plugin is either a package-manager provider (implements
// IPackageManager) or a generic addon (implements IPlugin). The kind tells the
// host which C ABI create function to resolve and how to treat the plugin in
// the UI.
enum class PluginKind {
Provider, // adds a package manager (pacman, flatpak, apt, ...)
Addon, // any other extension: UI tweak, helper, ... as long as C++
};
// Metadata describing a plugin, whether it is compiled into the application
// (pacman) or loaded at runtime from an external shared library.
struct PluginInfo {
std::string id; // unique identifier, e.g. "pacman", "flatpak"
std::string name; // display name, e.g. "Flatpak"
std::string version; // plugin version
std::string description; // what this plugin does
std::string author; // who wrote the plugin
PluginKind kind = PluginKind::Provider;
bool builtin = false; // true when compiled into the application
std::string path; // filesystem path (external plugins only)
bool available = false; // provider: backing tool present; addon: can run here
// OS package name providing a provider's backing tool (e.g. "flatpak").
// Empty when the plugin cannot be installed from the application.
std::string installHint;
};
class QMainWindow; // host window, handed to UI addons via onUiReady()
// Base interface every non-provider plugin implements. Providers implement
// IPackageManager instead. Both kinds are owned and lifecycle-managed by the
// PluginManager.
class IPlugin {
public:
virtual ~IPlugin() = default;
// Called when the plugin is loaded (at discovery or reload). Keep it
// lightweight: the main window does not exist yet, so no UI work here.
virtual void onLoad() {}
// Called when the plugin is unloaded (reload, shutdown) so it can release
// what onLoad() acquired.
virtual void onUnload() {}
// Whether the plugin can run on this system. Providers report whether
// their backing tool is installed; addons usually return true.
virtual bool isAvailable() const { return true; }
// Called once the main window exists, so UI addons can attach their own
// widgets (toolbar buttons, status-bar items, ...). Default: no-op.
virtual void onUiReady(QMainWindow* /*mainWindow*/) {}
};
+386
View File
@@ -0,0 +1,386 @@
#pragma once
#include <algorithm>
#include <cctype>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <memory>
#include <string>
#include "package-manager.h"
#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
// Reading a package manager's output: streaming it as it is produced, and
// turning it into a progress bar.
//
// No tool reports progress in a form that can be forwarded as-is, which is why
// the bar used to jump around instead of filling up. pacman restarts its
// "(1/24)" counter at every phase of a transaction — "(1/24) téléchargement…",
// then "(1/24) installation…" — so a bar fed with those numbers goes
// 0→100→0→100 a few times per update; flatpak prints "Installing 2/3…" next to
// bare "42 %" updates of the file being unpacked, and the AUR helpers do both.
// ProgressTracker folds all of it into a single percentage that only ever moves
// forward, and runStreamed() hands the lines over as they arrive: a flatpak or
// AUR update used to buffer its whole output and report nothing until it was
// already over.
// ---------------------------------------------------------------------------
// Streaming a command's output
// ---------------------------------------------------------------------------
// One piece of a command's output. `partial` marks a chunk that ended with a
// carriage return: the tool is rewriting a progress meter in place (pacman and
// flatpak both do that), so the chunk carries progress but no message worth
// showing.
struct OutputChunk {
std::string text;
bool partial = false;
};
using OutputHandler = std::function<void(const OutputChunk& chunk)>;
// Drops the ANSI escape sequences a tool emits once it thinks it is on a
// terminal (colours, cursor moves, erase-line). They are noise in the status
// bar and garbage in the journal, which replays the output as a terminal would
// show it.
inline std::string stripAnsi(const std::string& text) {
std::string out;
out.reserve(text.size());
for (std::size_t i = 0; i < text.size(); ++i) {
if (text[i] != '\033') {
out += text[i];
continue;
}
// CSI (ESC [ … final byte): colours, cursor moves, erase.
if (i + 1 < text.size() && text[i + 1] == '[') {
std::size_t j = i + 2;
while (j < text.size() && static_cast<unsigned char>(text[j]) >= 0x20
&& static_cast<unsigned char>(text[j]) <= 0x3f) {
++j;
}
i = j; // the final byte, or the last one when the run was cut
continue;
}
// OSC (ESC ] … BEL or ESC \): window titles, hyperlinks.
if (i + 1 < text.size() && text[i + 1] == ']') {
std::size_t j = i + 2;
while (j < text.size() && text[j] != '\a' && text[j] != '\033') ++j;
i = (j < text.size() && text[j] == '\033') ? j + 1 : j;
continue;
}
// Anything else is a two-byte sequence (ESC ( B, ESC =, …).
if (i + 1 < text.size()) ++i;
}
return out;
}
// Closes a popen() stream. A named deleter avoids the GCC warning about the
// function-pointer attributes carried by decltype(&pclose) being dropped.
struct ProcessCloser {
void operator()(FILE* file) const {
if (file) pclose(file);
}
};
// Reads whatever the command has already written, without waiting for a buffer
// to fill: that is what hands a '\r' update over while the tool is still
// running. One name for both platforms, the Windows CRT calling read() _read().
inline long readOutput(int fd, char* buffer, unsigned int size) {
#ifdef _WIN32
return static_cast<long>(::_read(fd, buffer, size));
#else
return static_cast<long>(::read(fd, buffer, size));
#endif
}
// Runs `command` through a shell, reports its output as it is produced and
// returns everything it printed (byte-for-byte, so callers keep inspecting the
// full output for `error:` lines and the like).
//
// Chunks are cut on '\n' (a real line) and on '\r' (an in-place update), and
// the escape sequences some tools colour their output with are removed. Reads
// go through read() rather than stdio, so a '\r' update is handed over as soon
// as the tool writes it: a line-oriented read would sit on it until the next
// newline, and a download meter never emits one.
inline std::string runStreamed(const std::string& command, const OutputHandler& onChunk) {
std::string output;
std::string pending;
// Empty lines are noise for a progress bar, so only non-empty chunks are
// handed over.
auto deliver = [&](bool partial) {
if (!pending.empty() && onChunk) onChunk(OutputChunk{stripAnsi(pending), partial});
pending.clear();
};
auto feed = [&](const char* data, std::size_t length) {
for (std::size_t i = 0; i < length; ++i) {
const char c = data[i];
if (c == '\n' || c == '\r') {
output += pending;
output += c;
deliver(c == '\r');
} else {
pending += c;
}
}
};
std::unique_ptr<FILE, ProcessCloser> pipe(popen(command.c_str(), "r"));
if (!pipe) return output;
char buffer[512];
for (;;) {
const auto count = readOutput(fileno(pipe.get()), buffer, sizeof(buffer));
if (count > 0) {
feed(buffer, static_cast<std::size_t>(count));
continue;
}
if (count < 0 && errno == EINTR) continue;
break;
}
deliver(/*partial=*/false); // Last line when the command ends without one.
// pclose() is what waits for the shell.
return output;
}
// ---------------------------------------------------------------------------
// Turning that output into a percentage
// ---------------------------------------------------------------------------
// Builds a monotonic 0-99 percentage out of a package manager's chatter.
//
// The work is modelled as two halves — downloading, then applying (installing,
// upgrading or removing) — because that is the shape every tool has: it fetches
// what it needs, then writes it. A phase the tracker cannot place (pacman's key
// integrity checks, its file conflict analysis, its disk space check) holds the
// bar where it is rather than sending it backwards, and 100 % is left to the
// caller so the bar can be completed when the operation is known to have
// succeeded.
class ProgressTracker {
public:
// Feeds one line or chunk. Returns the new percentage when it moved, or -1
// when the chunk said nothing new — which also keeps the UI free of
// duplicate updates on the hundreds of lines a long update produces.
int feed(const std::string& text) {
if (text.empty()) return -1;
const std::string lowered = lower(text);
int current = 0;
int total = 0;
const bool hasCounter = parseCounter(lowered, &current, &total);
const int filePercent = parsePercent(lowered);
int candidate = -1;
if (containsAny(lowered, kApplyWords)) {
candidate = applyProgress(hasCounter, current, total);
} else if (containsAny(lowered, kDownloadWords)
|| (!hasCounter && filePercent >= 0)) {
candidate = downloadProgress(hasCounter, current, total, filePercent);
} else if (containsAny(lowered, kFinalWords)) {
candidate = kFinalPercent;
}
if (candidate < 0) return -1;
candidate = std::min(candidate, kMaxPercent);
if (candidate <= m_percent) return -1;
m_percent = candidate;
return m_percent;
}
int percent() const { return m_percent; }
private:
// Where each half of the work sits on the bar. Downloading usually takes
// the smaller share; the last few percent are left for pacman's hooks.
static constexpr int kDownloadHigh = 45;
static constexpr int kApplyBase = 3;
static constexpr int kApplyHigh = 97;
static constexpr int kFinalPercent = 98;
static constexpr int kMaxPercent = 99;
// Keywords are matched lowercased, in French and English: pacman output
// follows the system locale, and the AUR helpers wrap pacman.
static constexpr const char* kDownloadWords[] = {
"téléchargement", "telechargement", "récupération", "recuperation",
"downloading", "download", "fetching", "receiving",
};
static constexpr const char* kApplyWords[] = {
"installation", "installing", "réinstallation", "reinstallation",
"reinstalling", "mise à niveau", "mise a niveau", "upgrading",
"suppression", "removing", "uninstalling", "désinstallation",
};
static constexpr const char* kFinalWords[] = {
"finalisation", "finalizing", "hook", "traitement des",
};
static std::string lower(const std::string& text) {
std::string out = text;
for (char& c : out) {
// Bytes of UTF-8 accents are left alone: every keyword is written
// with the accents the tools themselves print.
if (c < 0) continue;
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
}
return out;
}
template <size_t N>
static bool containsAny(const std::string& text, const char* const (&words)[N]) {
for (size_t i = 0; i < N; ++i) {
if (text.find(words[i]) != std::string::npos) return true;
}
return false;
}
// Reads a "current/total" counter out of a line: pacman's "(3/24)" and the
// "Installing 2/3" of flatpak and the helpers. Anything that looks like a
// ratio without being a counter (a version, a path, a date) is rejected.
static bool parseCounter(const std::string& text, int* current, int* total) {
for (size_t slash = text.find('/'); slash != std::string::npos;
slash = text.find('/', slash + 1)) {
size_t begin = slash;
while (begin > 0 && std::isdigit(static_cast<unsigned char>(text[begin - 1]))) {
--begin;
}
if (begin == slash) continue;
// A dot or a slash right before the number means this is not a
// counter but part of a longer token.
if (begin > 0 && (text[begin - 1] == '.' || text[begin - 1] == '/')) continue;
size_t end = slash + 1;
while (end < text.size() && std::isdigit(static_cast<unsigned char>(text[end]))) {
++end;
}
if (end == slash + 1) continue;
if (end < text.size() && (text[end] == '.' || text[end] == '/')) continue;
const std::string numerator = text.substr(begin, slash - begin);
const std::string denominator = text.substr(slash + 1, end - slash - 1);
if (numerator.size() > 6 || denominator.size() > 6) continue;
const int cur = std::atoi(numerator.c_str());
const int den = std::atoi(denominator.c_str());
if (den <= 0) continue;
*current = cur;
*total = den;
return true;
}
return false;
}
// Reads a bare percentage ("100 %", "42%", "42,5 %") — how download meters
// report the file they are fetching.
static int parsePercent(const std::string& text) {
for (size_t sign = text.find('%'); sign != std::string::npos;
sign = text.find('%', sign + 1)) {
size_t begin = sign;
while (begin > 0 && (std::isdigit(static_cast<unsigned char>(text[begin - 1]))
|| text[begin - 1] == '.' || text[begin - 1] == ',')) {
--begin;
}
if (begin == sign) continue;
std::string number = text.substr(begin, sign - begin);
// "42,5 %" is what a French locale writes; atof() stops at the
// comma, so the decimal separator is normalised first.
std::replace(number.begin(), number.end(), ',', '.');
const double value = std::atof(number.c_str());
return static_cast<int>(std::clamp(value, 0.0, 100.0));
}
return -1;
}
// Download half. The counter counts packages and the percentage counts the
// file being fetched, so combining them places the bar inside the package
// currently downloading instead of jumping to the end of the half as soon
// as the first one lands.
int downloadProgress(bool hasCounter, int current, int total, int filePercent) {
m_sawDownload = true;
if (hasCounter) {
m_downloadCurrent = std::max(m_downloadCurrent, current);
m_downloadTotal = std::max(m_downloadTotal, total);
}
if (m_downloadTotal > 0) {
const int donePackages = std::max(1, m_downloadCurrent) - 1;
const int done = donePackages * 100 + std::max(0, filePercent);
return kDownloadHigh * done / (m_downloadTotal * 100);
}
if (filePercent >= 0) return kDownloadHigh * filePercent / 100;
return -1;
}
// Apply half. A transaction with nothing to download (everything cached)
// starts near zero instead of pretending the download half happened.
int applyProgress(bool hasCounter, int current, int total) {
if (hasCounter) {
m_applied = std::max(m_applied, current);
m_applyTotal = std::max(m_applyTotal, total);
} else {
++m_applied; // Tools that print one line per package without a counter.
}
const int low = m_sawDownload ? kDownloadHigh : kApplyBase;
if (m_applyTotal <= 0) {
// Nothing to scale against: creep forward so the bar still shows
// the operation is alive.
return low + std::min(m_applied, kApplyHigh - low);
}
const int done = std::min(m_applied, m_applyTotal);
return low + (kApplyHigh - low) * done / m_applyTotal;
}
int m_percent = 0;
int m_downloadCurrent = 0;
int m_downloadTotal = 0;
int m_applied = 0;
int m_applyTotal = 0;
bool m_sawDownload = false;
};
// Runs an action command and reports its progress as (message, percent).
//
// Every provider needs the same three things — the output streamed live, the
// percentages folded into one monotonic value, and an empty message for the
// in-place updates that have no text of their own — so the whole thing lives
// here rather than being copied into each provider. The full output is still
// returned for the `error:` checks the providers run afterwards.
//
// An in-place meter is the one update that carries a number but no sentence, so
// every 10 % step of it is also reported as a line ("⏳ 40 %"): it is what the
// status bar shows and what the journal records while a tool rewrites its
// progress bar without ever printing a newline.
inline std::string runWithProgress(const std::string& command, ProgressCallback callback) {
ProgressTracker tracker;
constexpr int kMilestoneStep = 10;
int milestone = 0;
return runStreamed(command, [&](const OutputChunk& chunk) {
if (!callback) return;
const int percent = tracker.feed(chunk.text);
// A partial chunk is an in-place progress meter: it carries a real
// percentage but nothing worth printing in the status bar.
if (!chunk.partial) {
callback(chunk.text, percent);
return;
}
if (percent >= 0) callback(std::string(), percent);
if (percent < 0 || percent - milestone < kMilestoneStep) return;
milestone = percent;
callback("⏳ " + std::to_string(percent) + " %", percent);
});
}
+63
View File
@@ -0,0 +1,63 @@
#pragma once
#include "plugin.h"
#include "package-manager.h"
// ---- External plugin contract (C ABI) ----
//
// A plugin is a shared library (lib*.so / *.dll) dropped in a plugin directory
// (see PluginManager). It must export the metadata symbols below plus one
// create function, depending on its kind:
// - provider plugins (kind "provider") export fws_create_provider() returning
// an IPackageManager* (use FWS_PROVIDER_PLUGIN);
// - addon plugins (kind "addon") export fws_create_plugin() returning an
// IPlugin* (use FWS_ADDON_PLUGIN).
// A plugin that does not export fws_plugin_kind() is treated as a provider
// (legacy plugins keep working).
//
// #include "provider-plugin.h"
// #include "my-manager.h"
// FWS_PROVIDER_PLUGIN(MyManager, "myprov", "My Provider", "1.0.0",
// "Manages my stuff", "Jane Doe");
//
// #include "provider-plugin.h"
// #include "my-addon.h"
// FWS_ADDON_PLUGIN(MyAddon, "myaddon", "My Addon", "1.0.0",
// "Tweaks the UI", "Jane Doe");
//
// Plugins are compiled with the same toolchain/headers as the host, exactly
// like Qt plugins, so the IPackageManager/IPlugin vtables and struct layouts
// match.
extern "C" {
const char* fws_plugin_id();
const char* fws_plugin_name();
const char* fws_plugin_version();
const char* fws_plugin_description();
const char* fws_plugin_author();
// "provider" (default when missing) or "addon": picks which create
// function the host resolves.
const char* fws_plugin_kind();
IPackageManager* fws_create_provider();
IPlugin* fws_create_plugin();
// Optional: OS package name that provides the backing tool, so the app can
// offer to install it when unavailable. May be omitted by a plugin.
const char* fws_plugin_install_hint();
}
#define FWS_PROVIDER_PLUGIN(PluginClass, id_, name_, version_, desc_, author_) \
extern "C" const char* fws_plugin_kind() { return "provider"; } \
extern "C" const char* fws_plugin_id() { return id_; } \
extern "C" const char* fws_plugin_name() { return name_; } \
extern "C" const char* fws_plugin_version() { return version_; } \
extern "C" const char* fws_plugin_description() { return desc_; } \
extern "C" const char* fws_plugin_author() { return author_; } \
extern "C" IPackageManager* fws_create_provider() { return new PluginClass(); }
#define FWS_ADDON_PLUGIN(AddonClass, id_, name_, version_, desc_, author_) \
extern "C" const char* fws_plugin_kind() { return "addon"; } \
extern "C" const char* fws_plugin_id() { return id_; } \
extern "C" const char* fws_plugin_name() { return name_; } \
extern "C" const char* fws_plugin_version() { return version_; } \
extern "C" const char* fws_plugin_description() { return desc_; } \
extern "C" const char* fws_plugin_author() { return author_; } \
extern "C" IPlugin* fws_create_plugin() { return new AddonClass(); }