Identity, startup and disk space

This chapter has no single example module to walk through, unlike the previous two: each topic below is a self-contained Basemodule/IndiModule helper, shown through how an actual core module (src/modules/...) uses it today — not the pedagogical hello* series.

getWebroot(): where a module writes its own files

Every file a module exposes to the frontend (a preview JPEG, a saved FITS, an archive folder) goes under the same webroot, one subfolder per module:

// src/modules/allsky/allsky.cpp
QDir dir;
dir.mkdir(getWebroot() + "/" + getModuleName());
dir.mkdir(getWebroot() + "/" + getModuleName() + "/" + mFolder);
dir.mkdir(getWebroot() + "/" + getModuleName() + "/" + mFolder + "/images");

getModuleName() (this instance’s name, not its class — see Type, template and family) keeps two instances of the same module class from colliding on disk. Navigator follows the same pattern for its own live preview:

// src/modules/navigator/navigator.cpp
atomicSaveJpeg(im, getWebroot() + "/" + getModuleName() + ".jpeg", quality);

(atomicSaveJpeg() itself is covered in Serving a live preview image.)

getMinFreePercent(): the disk-full guard every capture module repeats

Saving a frame to a nearly-full disk is a real failure mode, not a hypothetical one — several core modules guard against it with the exact same shape of check right before writing:

// src/modules/sequencer/sequencer.cpp, newBLOB()
QStorageInfo storage(mCurrentFolder);
qint64 freeBytes  = storage.bytesFree();
qint64 totalBytes = storage.bytesTotal();
if (totalBytes > 0 && freeBytes * 100 / totalBytes < getMinFreePercent())
{
    logWarning("Sequencer: disk too full (%1 MB free, threshold %2%) — FITS not saved: %3",
    {freeBytes / (1024 * 1024), getMinFreePercent(), mCurrentFolder});
}

Allsky and Dofassistant repeat the same QStorageInfo/getMinFreePercent() pair before their own saves. The threshold itself (a percentage, not an absolute size) is set server-wide by the controller — a module never calls the matching setMinFreePercent(), only reads it.

getClassName(): per-type storage, independent of the instance’s name

getClassName() returns the module’s actual C++/library type ("Sequencer", "Focus"…), the identity that profiles and per-type stored data key on — never the instance name (getModuleName()) or the display template (see Type, template and family). Sequencer uses it to look up another instance’s stored profile without loading it, so a planner can ask about a sequence’s duration regardless of which profile happens to be active right now:

// src/modules/sequencer/sequencer.cpp, onModuleQuery()
QJsonObject obj;
if (getDbProfile(getClassName(), params["profile"].toString(), obj))
{
    // obj is this profile's own stored JSON, as last saved — not the
    // live datastore, and not necessarily the profile currently loaded.
    ...
}

onAfterInit(): runs once, right after construction — and must chain up

IndiModule::onAfterInit() is what actually implements indiatstart/devatstart/confsatstart (Connecting to a device) — connecting to the INDI server and/or its devices once, right after the module is instantiated (Controller::loadModule()), never reconsidered on a later manual reconnect. A module that needs its own one-time startup step overrides it too, but must call the parent implementation first, or startup connection silently stops happening for it:

// src/modules/allsky/allsky.cpp
void Allsky::onAfterInit(void)
{
    IndiModule::onAfterInit();
    checkArchives();
};
// src/modules/parkmanager/parkmanager.cpp
void Parkmanager::onAfterInit(void)
{
    IndiModule::onAfterInit();
}

Parkmanager’s override does nothing beyond the chain-up itself — it exists only so a reader looking for “what happens at startup” finds an explicit, searchable override instead of wondering whether the behavior was forgotten.

Not covered here: killMe, sendDump, getModuleInfo, getAvailableModuleLibs, getHelpContent, setMinFreePercent

These also live on Basemodule, but they’re the controller’s own API for managing a module instance from outside (listing it, querying its metadata, unloading it, setting the disk threshold above) — no core module ever calls them on itself. They belong to the controller/architecture side of the documentation, not to “what a module can do,” which is this chapter’s scope.