Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
PhosphorRules::RuleStoreWatcher Class Reference

Opt-in cross-process auto-reload for a RuleStore. More...

#include <PhosphorRules/RuleStoreWatcher.h>

Inheritance diagram for PhosphorRules::RuleStoreWatcher:
[legend]

Public Member Functions

 RuleStoreWatcher (RuleStore &store, QObject *parent=nullptr)
 ~RuleStoreWatcher () override
 RuleStoreWatcher (const RuleStoreWatcher &)=delete
RuleStoreWatcher & operator= (const RuleStoreWatcher &)=delete
void start ()
 Begin watching.

Detailed Description

Opt-in cross-process auto-reload for a RuleStore.

Watches the store's backing rules.json and calls RuleStore::load() when it changes on disk, so a process that OWNS a store reflects another process's writes (or a hand edit of the file) without a manual reload. The daemon, the standalone plasmazones-settings and plasmazones-editor each run one over their own store.

The hard parts are delegated to PhosphorFsLoader::WatchedDirectorySet:

  • a 50 ms debounce that coalesces the temp-write + atomic-rename save burst into one reload,
  • re-arming the per-file watch after every rescan (an atomic rename swaps the inode, which QFileSystemWatcher silently drops),
  • parent-directory watching while the file does not exist yet, promoting to a direct watch when it materialises.

Self-writes need no special handling: RuleStore::load() is idempotent — it re-reads the file but only emits rulesChanged when the content actually differs — so a watcher event from the store's own save() reloads to identical content and emits nothing.

Opt-in by construction — a consumer creates this only when it wants the behaviour, so the base RuleStore carries no watcher overhead and a test fixture that only needs the store never installs a file watch.

GUI-thread only — inherits WatchedDirectorySet's thread affinity: construct and call start() from the thread that owns the store.

Constructor & Destructor Documentation

◆ RuleStoreWatcher() [1/2]

PhosphorRules::RuleStoreWatcher::RuleStoreWatcher ( RuleStore & store,
QObject * parent = nullptr )
explicit
Parameters
storeBorrowed store to reload on external change. Must outlive this watcher.
parentQt parent.

◆ ~RuleStoreWatcher()

PhosphorRules::RuleStoreWatcher::~RuleStoreWatcher ( )
override

◆ RuleStoreWatcher() [2/2]

PhosphorRules::RuleStoreWatcher::RuleStoreWatcher ( const RuleStoreWatcher & )
delete

Member Function Documentation

◆ operator=()

RuleStoreWatcher & PhosphorRules::RuleStoreWatcher::operator= ( const RuleStoreWatcher & )
delete

◆ start()

void PhosphorRules::RuleStoreWatcher::start ( )

Begin watching.

Registers the store file's parent directory with live reload and installs the initial per-file watch. Deferred from the ctor so a consumer can connect to the store's rulesChanged before the first scan runs. Calling more than once is a no-op after the first.

The registration triggers one immediate synchronous reload of the store; because RuleStore::load() is idempotent, that is a no-op when the file has not changed since the store's own constructor load.


The documentation for this class was generated from the following file: