The GLib side of the app. Variant reads imsd's Received dictionary by key and type as its SmsVariant writes it (`to`, the number the text arrived for, a tel: URI read like the status's `ppi`; `operator`, the SIM it arrived under), the GetStatus one with the subscriber's own number and the SIM's operator in it (`ppi`, a tel: URI as the frozen interface gives it; `operator`), and maps a GError to the core's error kinds off GDBus's own mapping. Client is the Sync logic's transport: asynchronous calls with their continuations as user data — every reply guarded where it is delivered (OnCallDone), as are the signal handlers and the name watch's callbacks: a throw is a fault the events hear, not the end of the process — the calls behind imsd's polkit gate allow interaction: Subscribe, List and Delete wait two minutes; Send has no bound of the client's, since imsd sends the text once its prompt lets the call through, however late, and a Send given up on would be failed by Sync and be sent all the same; GetStatus ten seconds — (one call: the Messaging status carries the own number, imsd reading both from one snapshot; AGENTS.md §1 names both interfaces), the Messaging and RegistrationChanged signals, and a watch on net.catcrafts.IMS1 whose appeared callback is where Sync subscribes. Notifier shows one desktop notification per conversation and replaces it as more texts arrive: one Notify at a time per conversation, since the id to replace comes with the answer; its default action asks the app for that conversation; the body is escaped when the server renders markup (GetCapabilities, asked once; Plasma and GNOME do), so a text's '<' or '&' shows as typed. Instance owns net.catcrafts.ImsdMessages and serves org.freedesktop.Application there, the Desktop Entry Specification's interface of a running application: Activate, Open and ActivateAction, each with its platform data — sent empty and not read: nothing in the app can use an activation token yet — and one action, quit, any other refused (the object registered before the name is asked for, so a launch that forwards the moment the name is granted finds it; Own tells a name another instance holds from a request that failed or was refused, and keeps the error's words); it forwards a call to the owner. project.cpp computes the gio flags once for the bus library, the executable and the Decode test. Tested: tests/Decode (every key of imsd's Received dictionary, one with ten of them, GetStatus, the own number, the SIM's operator, the error kinds, the markup escape, the parameters of the instance's three calls).
159 lines
6.8 KiB
C++
159 lines
6.8 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
|
|
|
// lint-disable-file no-char-pointer
|
|
import std;
|
|
import Crafter.Build;
|
|
#pragma crafter dependency "https://forgejo.catcrafts.net/Catcrafts/Crafter.LintRules.git" commit "e906f797da2cd0b1776dd1b420f9b04d3cd24baf"
|
|
import Crafter.LintRules;
|
|
namespace fs = std::filesystem;
|
|
using namespace Crafter;
|
|
|
|
// pkg-config wrapper (std-only: no popen in import std). Returns the flags
|
|
// split on whitespace, or empty if pkg-config is unavailable — callers
|
|
// provide a fallback for that case.
|
|
static std::vector<std::string> PkgConfig(std::string_view args) {
|
|
fs::path tmp = fs::temp_directory_path() /
|
|
std::format("imsd-messages-pkgconfig-{}.txt", std::hash<std::string_view>{}(args));
|
|
std::string cmd = std::format("pkg-config {} > {} 2>/dev/null", args, tmp.string());
|
|
std::vector<std::string> flags;
|
|
if (std::system(cmd.c_str()) == 0) {
|
|
std::ifstream f(tmp);
|
|
std::string flag;
|
|
while (f >> flag)
|
|
flags.push_back(flag);
|
|
}
|
|
std::error_code ec;
|
|
fs::remove(tmp, ec);
|
|
return flags;
|
|
}
|
|
|
|
// GDBus (gio-2.0) — bus layer for the two daemons; chosen over sd-bus because
|
|
// the platform stack (ModemManager, libqmi for the future direct-AKA port) is
|
|
// GLib, so they want a GMainLoop regardless. (imsd's reasoning; the same
|
|
// layer here.) Computed once, for each target that takes them.
|
|
struct GioFlags {
|
|
std::vector<std::string> compile;
|
|
std::vector<std::string> link;
|
|
};
|
|
|
|
static GioFlags ComputeGioFlags(const Configuration& cfg) {
|
|
GioFlags f;
|
|
if (!cfg.sysroot.empty()) {
|
|
// cross build (e.g. --target=aarch64-alpine-linux-musl
|
|
// --sysroot=<packaging/make-sysroot.sh output>): the host's
|
|
// pkg-config would answer for the wrong architecture. glib's
|
|
// include layout is stable across distros; the `-I=` form makes
|
|
// clang resolve the paths inside the sysroot.
|
|
f.compile = { "-I=/usr/include/glib-2.0", "-I=/usr/lib/glib-2.0/include" };
|
|
f.link = { "-lgio-2.0", "-lgobject-2.0", "-lglib-2.0" };
|
|
return f;
|
|
}
|
|
// native build: ask pkg-config. Only -I/-D flags pass through:
|
|
// pkg-config also emits -pthread, which would config-mismatch the
|
|
// shared prebuilt std.pcm (and pthread lives in libc on every
|
|
// platform we target).
|
|
for (std::string& flag : PkgConfig("--cflags gio-2.0"))
|
|
if (flag.starts_with("-I") || flag.starts_with("-D")) f.compile.push_back(std::move(flag));
|
|
for (std::string& flag : PkgConfig("--libs gio-2.0"))
|
|
if (flag.starts_with("-l") || flag.starts_with("-L")) f.link.push_back(std::move(flag));
|
|
if (f.link.empty()) f.link = { "-lgio-2.0", "-lgobject-2.0", "-lglib-2.0" };
|
|
return f;
|
|
}
|
|
|
|
static void ApplyGioFlags(Configuration& cfg, const GioFlags& f) {
|
|
for (const std::string& flag : f.compile) cfg.compileFlags.push_back(flag);
|
|
for (const std::string& flag : f.link) cfg.linkFlags.push_back(flag);
|
|
}
|
|
|
|
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
|
|
// --local builds Crafter.DB from the sibling checkout under ~/repos/Crafter
|
|
// instead of the forge, for work on both sides at once. The flag is this
|
|
// project's: it is removed before the arguments are forwarded, so a
|
|
// dependency's project.cpp never sees it.
|
|
std::vector<std::string> depArgs(args.begin(), args.end());
|
|
const bool local = std::erase(depArgs, "--local") > 0;
|
|
|
|
Configuration* db = local
|
|
? LocalProject({ .projectFile = "../Crafter/Crafter.DB/project.cpp", .args = depArgs })
|
|
: GitProject({ .source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.DB.git" }, .args = depArgs });
|
|
|
|
// imsd-messages-core — numbers, time, the model, word wrap, the store and
|
|
// the sync logic: std + Crafter.DB, no GLib, so every test runs with no
|
|
// bus, no phone and no GPU.
|
|
static auto Core = std::make_unique<Configuration>();
|
|
Core->path = "./";
|
|
Core->name = "imsd-messages-core";
|
|
Core->outputName = "imsd-messages-core";
|
|
ApplyStandardArgs(*Core, args);
|
|
Core->type = ConfigurationType::LibraryStatic;
|
|
Core->dependencies = { db };
|
|
{
|
|
std::array<fs::path, 7> ifaces = {
|
|
"interfaces/ImsdMessages",
|
|
"interfaces/ImsdMessages-Number",
|
|
"interfaces/ImsdMessages-Time",
|
|
"interfaces/ImsdMessages-Model",
|
|
"interfaces/ImsdMessages-Wrap",
|
|
"interfaces/ImsdMessages-Store",
|
|
"interfaces/ImsdMessages-Sync",
|
|
};
|
|
std::array<fs::path, 0> impls = {};
|
|
Core->GetInterfacesAndImplementations(ifaces, impls);
|
|
}
|
|
|
|
// imsd-messages-bus — the GLib side: imsd's dictionaries, the GDBus client
|
|
// of net.catcrafts.IMS1.Messaging, the desktop notifications and the app's
|
|
// own session-bus name. No window.
|
|
static auto Bus = std::make_unique<Configuration>();
|
|
Bus->path = "./";
|
|
Bus->name = "imsd-messages-bus";
|
|
Bus->outputName = "imsd-messages-bus";
|
|
ApplyStandardArgs(*Bus, args);
|
|
Bus->type = ConfigurationType::LibraryStatic;
|
|
Bus->dependencies = { Core.get() };
|
|
{
|
|
std::array<fs::path, 5> ifaces = {
|
|
"interfaces/ImsdMessages.Bus",
|
|
"interfaces/ImsdMessages.Bus-Variant",
|
|
"interfaces/ImsdMessages.Bus-Client",
|
|
"interfaces/ImsdMessages.Bus-Notifier",
|
|
"interfaces/ImsdMessages.Bus-Instance",
|
|
};
|
|
std::array<fs::path, 0> impls = {};
|
|
Bus->GetInterfacesAndImplementations(ifaces, impls);
|
|
}
|
|
const GioFlags gio = ComputeGioFlags(*Bus);
|
|
ApplyGioFlags(*Bus, gio);
|
|
|
|
// imsd-messages — the executable: the command line, the window and the
|
|
// wiring between the bus layer and the UI.
|
|
Configuration cfg;
|
|
cfg.path = "./";
|
|
cfg.name = "imsd-messages";
|
|
cfg.outputName = "imsd-messages";
|
|
ApplyStandardArgs(cfg, args);
|
|
cfg.type = ConfigurationType::Executable;
|
|
cfg.dependencies = { Core.get(), Bus.get() };
|
|
{
|
|
std::array<fs::path, 0> ifaces = {};
|
|
std::array<fs::path, 1> impls = { "implementations/main" };
|
|
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
|
}
|
|
ApplyGioFlags(cfg, gio);
|
|
|
|
cfg.AddTest("Number").Dependencies({ Core.get() });
|
|
cfg.AddTest("Time").Dependencies({ Core.get() });
|
|
cfg.AddTest("Wrap").Dependencies({ Core.get() });
|
|
cfg.AddTest("Model").Dependencies({ Core.get() });
|
|
cfg.AddTest("Store").Dependencies({ Core.get(), db });
|
|
cfg.AddTest("Sync").Dependencies({ Core.get() });
|
|
// The bus library's decoding test includes GLib's headers: the library's
|
|
// compile flags (its link flags come with the library).
|
|
TestBuilder decode = cfg.AddTest("Decode");
|
|
decode.Dependencies({ Core.get(), Bus.get() });
|
|
for (const std::string& flag : gio.compile) decode.CompileFlag(flag);
|
|
|
|
LintRules::AddRules(cfg);
|
|
return cfg;
|
|
}
|