Fray Engine
Loading...
Searching...
No Matches
fray::FrayManager Class Reference

Owns and coordinates projects, their queues, application work, prompts, and logs. Project work runs on separate project threads; drive manager operations from one controlling thread. More...

#include <fray_manager.hpp>

Classes

struct  OpeningDecisionStatus
 Latest database-choice action and its result, once it finishes. More...
struct  OpeningOrigin
 Address of the process that requested a project open. More...
struct  OpeningStatus
 A queued project open and its result, once finished. More...
struct  ProjectLogWorker
 Dedicated queue and worker for one project's log writes. More...
struct  Entry
 Associates a project and its queue with its managed worker thread. More...
struct  ShutdownEntry
 Project resources retained while shutdown progresses. More...
struct  PendingPrompt
 Retains a prompt request and its eventual response until consumed. More...
struct  CloseTaskGuard
 Ensures a queued close clears its closing marker even on early exit. More...

Public Types

enum class  OpeningDecision { resolve , cancel }
 The queued action applied to a project's database choice. More...
enum class  ShutdownPhase { running , stopping , ready }
 Progress of an Engine-owned shutdown request. More...
using RenameNotifier
 Callback receiving a renamed project's ID, new path key, and name.

Public Member Functions

logs::LogStore & logStore ()
 Returns the manager-owned log store by reference.
void forwardLogEntry (const logs::Entry &entry, ipc::IPCManager &ipc, bool includeLoading)
 Sends a prepared log line to the renderer with a limited lifetime.
void queueConsoleEntry (const logs::Entry &entry, ipc::IPCManager &ipc, bool includeLoading=true)
 Queues a prepared entry for Console delivery independently of persistence.
void recordCommand (const message::InData &incoming, ipc::IPCManager &ipc, bool received)
 Splits a stamped command into its disk log record and its Console entry, honoring the message's flags. The record is written under the command's UID unless MESSAGE_FLAG_NO_LOG is set; the Console is sent a COMMAND_CONSOLE_ADD unless MESSAGE_FLAG_NO_CONSOLE is set. Both go onto their own queues and return at once; neither waits for the other or for delivery.
void handleReceipt (const message::InData &incoming, ipc::IPCManager &ipc)
 Handles a MSG_RECEIPT: logs it under its own UID and tells the Console the original command arrived. The log record is skipped when the original had MESSAGE_FLAG_NO_LOG, and the Console message when it had MESSAGE_FLAG_NO_CONSOLE. A known entry gets a COMMAND_CONSOLE_UPDATE; if the Engine no longer holds the UID, a COMMAND_CONSOLE_ADD is sent instead, as already received, built from what the receipt carries. This is the only place a receipt becomes a Console message. Invalid receipts are logged and ignored.
void handleNotification (const message::InData &incoming, ipc::IPCManager &ipc)
 Handles COMMAND_NOTIFY: logs the notification and adds it to the Console as a notification entry. The log record is skipped when MESSAGE_FLAG_NO_LOG is set and the Console message when MESSAGE_FLAG_NO_CONSOLE is set. Both go onto their own queues and return at once. Invalid payloads are logged and ignored.
void addNotification (ProcessKind sender, NotificationSeverity severity, const std::string &title, const std::string &description, const std::string &project, std::uint32_t flags, ipc::IPCManager &ipc, const std::string &uid="", ProcessKind destination=PROCESS_KIND_ENGINE)
 Logs a notification and adds it to the Console, as handleNotification does for received ones. Safe from any thread; both go onto their own queues and return at once.
ConsoleEntry describeCommand (const message::InData &incoming)
 Describes a command as a Console entry.
void stopConsoleDelivery ()
 Stops and drains Console delivery before its IPC manager is destroyed. Call from the controlling thread, not from the Console worker.
void beginConsoleShutdown ()
 Stops accepting Console deliveries while allowing its queued work to drain.
bool consoleStopped () const
 Returns whether the Console delivery worker has finished its local queue.
void persistLogEntry (const logs::Entry &entry)
 Queues persistence on the project's worker or the application worker.
void recordLogEntry (logs::Entry entry, ipc::IPCManager *ipc, bool includeLoading=true)
 Identifies a log entry and submits it independently to Console and persistence. Application writes are submitted before Console delivery so a subsequent history request sees them.
void recordEngineLog (const char *level, F_long thread, const std::string &project, const char *text, ipc::IPCManager *ipc, std::uint64_t arrivedUs=0, bool consoleVisible=true)
 Prepares an Engine log line and independently queues Console delivery and persistence.
 FrayManager (const std::string &applicationId="Fray")
 Constructs a manager with its own thread manager and application worker.
 FrayManager (threads::ThreadManager &threads, const std::string &applicationId="Fray")
 Constructs a manager using an externally owned thread manager.
 FrayManager (const FrayManager &)=delete
 Copy construction is disabled because the manager owns running work.
FrayManager & operator= (const FrayManager &)=delete
 Copy assignment is disabled because the manager owns running work.
 ~FrayManager ()
 Shuts down owned work and releases the process-wide manager slot.
F_err openApplicationState (const std::filesystem::path &directory)
 Opens the application directory and its default state namespace.
F_err loadButtonStyle (const std::string &defaults, std::string &css)
 Loads the Engine-owned application button stylesheet.
F_err saveButtonStyle (const std::string &css)
 Saves the Engine-owned application button stylesheet.
F_err switchApplicationState (const std::filesystem::path &path)
 Selects and persists an existing application database without replacing active state on failure. Previously borrowed application state references become invalid after a successful switch.
std::filesystem::path applicationStatePath ()
 Returns the currently open application database path.
F_err readApplicationPreferences (ApplicationPreferences &output)
 Reads an authoritative application preferences snapshot.
F_err resetApplicationPreferences ()
 Resets only application preference values in one database transaction.
F_err openState (const std::string &name)
 Opens an additional application state namespace.
state::StateManager & state (const std::string &name)
 Returns a borrowed reference to an open application state namespace.
template<typename T>
F_err set (const std::string &key, const T &value)
 Writes a value in the default application state namespace.
template<typename T>
F_err get (const std::string &key, T &value)
 Reads a value from the default application state namespace.
void requestShutdown ()
 Starts or retries Engine-owned shutdown without joining any worker. Previously accepted application work drains; new application work is rejected.
void shutdown ()
 Requests shutdown without waiting for project work or worker termination.
ShutdownPhase advanceShutdown ()
 Advances shutdown using only local state and nonblocking queue operations. Pending opens, closes and worker termination are checked independently.
ShutdownPhase shutdownPhase ()
 Reads shutdown progress without advancing it.
void finishShutdown ()
 Releases local workers after shutdown is ready. The normal Engine path calls this only after advanceShutdown reports ready. If an owner destroys the manager early, this safety fallback joins its active local workers. Call on the controlling thread, never from a worker being joined.
void cancelPrompts (const std::string &reason, bool closing=false)
 Completes outstanding prompts as dismissed with an error under _promptMutex.
bool takePromptResponse (uint64_t requestId, PromptResponse &response)
 Consumes a completed prompt response under _promptMutex.
const std::string & applicationId () const
 Returns the application identifier by reference.
bool postApplication (std::function< void()> task)
 Posts work to the application thread without waiting for it.
void handleApplicationMessage (const message::InData &incoming, ipc::IPCManager &ipc)
 Routes an incoming Engine message, dispatching project work asynchronously. Called by the Engine message thread; may stop IPC or enqueue application work.
bool requestPrompt (ipc::IPCManager &ipc, const PromptRequest &request, uint64_t &requestId)
 Sends a renderer prompt and tracks its response under _promptMutex.
F_err openProject (const std::string &path, files::ConflictChoice choice=files::ConflictChoice::Ask, bool cancelOnDatabaseConflict=false, files::OpenMode mode=files::OpenMode::OpenOrCreate, std::optional< OpeningOrigin > origin=std::nullopt, std::optional< std::size_t > restoreOrder=std::nullopt, const std::string &expectedId="")
 Queues a project open on its own worker.
std::optional< OpeningStatus > openingStatus (const std::string &path)
 Reads the latest project-open state for a folder or archive path.
void setOpeningNotifier (std::function< void(const OpeningStatus &)> notifier)
 Installs a publisher for completed project-open states.
std::vector< std::string > databaseCandidates (const std::string &name)
 Lists candidate databases for an opening project.
F_err resolveDatabase (const std::string &name, const DatabaseChoice &choice)
 Queues a database choice on the project thread. Inspect openingDecisionStatus() for its eventual result.
F_err cancelProject (const std::string &name)
 Queues cancellation of a pending open and retires it after cancellation. Inspect openingDecisionStatus() for its eventual result.
std::optional< OpeningDecisionStatus > openingDecisionStatus (const std::string &path)
 Reads the latest queued database-choice action for a project path. The result remains available after cancellation until the path is opened again.
ProjectManager & project (const std::string &name)
 Returns a non-owning reference to an open project under registry lookup. The reference is valid only while the project remains registered.
F_err restoreProjects (ipc::IPCManager &ipc)
 Queues restoration of the saved project session when enabled.
void setClosingNotifier (std::function< void(const ProjectClosingStatuses &)> notifier)
 Installs a nonblocking pending-close snapshot notifier and sends its initial snapshot.
void setRenameNotifier (RenameNotifier notifier)
 Installs the rename callback under _mutex unless the manager is marked shut down.
void setRenameFailureNotifier (std::function< void(const std::string &)> notifier)
 Installs a notifier for asynchronously failed project renames.
void setShutdownCloseNotifier (std::function< void(const std::string &name, const std::string &id, F_err result, bool packaged, const std::string &path)> notifier)
 Installs the callback reporting projects closed by shutdown, under _mutex unless the manager is marked shut down.
void setLogResolvedNotifier (std::function< void(const std::string &openingTag, const std::string &id)> notifier)
 Installs the opening-log resolution callback under _mutex unless the manager is marked shut down.
void requestCloseProject (const std::string &target, bool package, std::function< void(const std::string &, F_err, bool)> completion)
 Queues a project close without waiting for completion.
F_err closeProject (const std::string &name)
 Queues a project close and removes its registry entry on success. Retired workers are joined later, after they have stopped.
std::optional< ProjectManager::CloseStatus > closeStatus (const std::string &name)
 Reads the latest project close state, including after registry removal.
F_err close ()
 Queues all open project closes independently; entries remain registered. Already queued closes are included; repeated calls while pending add any newly open projects.
std::optional< ProjectManager::CloseStatus > closeAllStatus ()
 Reads the latest aggregate close state.

Static Public Member Functions

static void sendConsoleEntry (Command operation, const ConsoleEntry &entry, ipc::IPCManager &ipc)
 Sends a Console entry to the Renderer without waiting; a dropped send is not retried.

Private Types

using Projects = std::unordered_map<std::string, Entry>
 Registry mapping canonical project path keys to owned project entries.

Private Member Functions

ProjectClosingStatuses closingStatusesLocked ()
 Builds the pending-close snapshot without taking a project lock. Caller holds _mutex, including when a project worker is stalled.
void publishClosingLocked ()
 Publishes the current pending-close snapshot while holding _mutex.
std::string logProjectIdentity (const std::string &target)
 Resolves a message's project target to its log identity without changing dispatch.
Projects::iterator lookup (const std::string &target, F_err &error, bool includeClosed=false)
 Looks up a project by path or unique bare name; caller must hold _mutex.
std::optional< Entry > find (const std::string &name, F_err &error, bool includeClosed=false)
 Looks up and copies an entry under _mutex.
F_err queueOpeningDecision (const std::string &name, OpeningDecision action, const DatabaseChoice &choice, bool shutdownAction=false)
 Queues a database-choice action and records its result locally.
void retire (Entry &entry)
 Shuts down a project queue and joins its worker. Call outside _mutex and not on the worker being joined.
void retainRetiredLocked (Entry entry)
 Stops an entry's queues and retains it until its workers can safely be joined. Caller holds _mutex; neither worker is joined here.
void reapRetired ()
 Joins already-finished retired workers without waiting for active projects. Call outside _mutex and outside a retired worker.
void forgetProject (ProjectManager *project)
 Removes a project from open order and closes its tracked log. Caller holds _mutex; this does not remove the registry entry.
bool isActiveProjectLocked (const ProjectManager *project) const
 Tests whether a project is the currently active eligible project. Caller holds _mutex.
F_err saveShutdownSessionLocked ()
 Writes the captured project session to application state. Caller holds _mutex.
void captureShutdownSessionLocked ()
 Captures open project identities and paths before shutdown starts closing them. Caller holds _mutex after accepted application work has drained.
void updateShutdownSessionPath (const std::string &id, const std::string &path)
 Updates the shutdown snapshot after a queued rename has finished.
void notifyRenameFailure (const std::string &id)
 Reports an asynchronous rename failure without holding the manager mutex.
void finishLogRename (const std::string &id, const std::shared_ptr< ProjectLogWorker > &worker, const std::shared_ptr< threads::TaskQueue > &queue, const std::shared_ptr< ProjectManager > &project, const std::filesystem::path &folder, F_err result)
 Resumes logging and releases any close deferred behind a rename on the log worker.
void attachLog (ProjectManager *project)
 Registers queued project-log rename coordination after opening. Call without holding _mutex because this installs a project callback.
F_err reserveProjectIdentity (ProjectManager *project)
 Reserves a unique identity and updates a copied project's persisted identity if necessary. The registry reservation prevents concurrent project workers from choosing the same identity.
F_err registerOpenedProject (ProjectManager *project)
 Reserves identity and registers a successfully opened project.
void recordOpen (ProjectManager *project)
 Records an open project, opens its log, and resolves its opening tag. Opens and flushes the project log without holding the manager mutex. Log entries received during opening are held on the log worker until the session is ready.
void rekey (ProjectManager *project, const std::filesystem::path &path)
 Updates the registry and notifies listeners after a project rename. Takes _mutex, retains a colliding closed entry for later retirement, and calls the notifier outside it.
F_err applyApplicationDefaults (state::StateManager &state)
 Adds missing application preference defaults without replacing saved values.
F_err validateApplicationState (state::StateManager &state)
 Verifies that an existing state table is an application database.
F_err validateApplicationPreferences (state::StateManager &state)
 Validates the types of saved application preferences that are present.
void init ()
 Claims the process-wide manager slot and starts application, log, and Console workers.
F_err switchApplicationStateLocked (const std::filesystem::path &path, bool persist)
 Switches to an existing application database while retaining the current one on failure. Caller must hold _mutex.
void queueLogClose (const std::shared_ptr< ProjectManager > &project, const std::shared_ptr< threads::TaskQueue > &queue, const std::shared_ptr< ProjectLogWorker > &worker, const std::string &id, std::function< void(ProjectManager &, const std::shared_ptr< threads::TaskQueue > &)> task)
 Closes the project log on its worker, then returns close work to the project queue.
F_err enqueueProjectTask (const std::string &target, bool allowLatest, bool closing, std::function< void(ProjectManager &, const std::shared_ptr< threads::TaskQueue > &)> task, ProjectManager *exact=nullptr)
 Finds an open project and posts work to its queue under _mutex.
F_err enqueueProjectTaskLocked (const std::string &target, bool allowLatest, bool closing, std::function< void(ProjectManager &, const std::shared_ptr< threads::TaskQueue > &)> task, ProjectManager *exact)
 Selects and queues project work while the caller holds _mutex.
void finishCloseAllMemberLocked (ProjectManager *project, F_err result)
 Records an aggregate member's result while holding _mutex.
void finishProjectClose (ProjectManager &project, const std::shared_ptr< threads::TaskQueue > &queue, F_err result, bool removeOnSuccess=false)
 Clears the closing marker and, on success, forgets the project and stops its queue. Takes _mutex and updates any active aggregate close.
F_err queueProjectClose (const std::string &target, std::function< F_err(ProjectManager &, bool &)> operation, std::function< void(const std::string &, F_err, bool)> completion, ProjectManager *exact=nullptr, bool removeOnSuccess=false)
 Queues a close operation; an empty target selects the latest open project. If supplied, completion runs on the project thread, or on the caller if dispatch fails.
void handleProjectMessage (const message::InData &incoming, ipc::IPCManager &ipc)
 Validates and dispatches a project message to its project queue.
void announceActiveProject (ipc::IPCManager &ipc)
 Announces the most recently opened eligible project and its saved layout. Selects under _mutex, reads layout on the project thread, and queues renderer messages.
void watchProjectOpenings (ipc::IPCManager &ipc)
 Installs independent project-opening result and active-project announcements.
void handleLogMessage (const message::InData &incoming, ipc::IPCManager &ipc)
 Stores and forwards incoming log entries or sends a filtered log page.
void watchRenames (ipc::IPCManager &ipc)
 Installs callbacks forwarding project renames and resolved opening log tags. Callbacks capture ipc by reference and are cleared on shutdown.

Static Private Member Functions

static std::string projectKey (const std::string &path, std::error_code &error)
 Canonicalizes a project path, removing a .fry extension.
static std::string openingTag (const ProjectManager *project)
 Creates the temporary log tag used while a project opens.
static void toProto (const logs::Entry &entry, LogEntry &out)
 Copies a stored log entry into its protobuf representation.

Private Attributes

std::string _applicationId
 Application identifier supplied when opening projects.
std::filesystem::path _applicationDirectory
 Engine directory containing the selected-database location file.
std::unique_ptr< files::FileManager > _files = std::make_unique<files::FileManager>()
 Application directory and database ownership; state managers detach before this is destroyed.
std::unordered_map< std::string, std::unique_ptr< state::StateManager > > _states
 Open application state namespaces, guarded by _mutex.
std::unique_ptr< threads::ThreadManager > _ownedThreads
 Optional owned thread manager used by the standalone constructor.
threads::ThreadManager * _threads
 Non-owning pointer to the owned or externally supplied thread manager.
threads::ThreadManager::Id _applicationThread = 0
 Identifier of the application queue worker.
std::shared_ptr< threads::TaskQueue > _applicationQueue = std::make_shared<threads::TaskQueue>()
 Queue for application-level work, separate from project queues.
threads::ThreadManager::Id _consoleThread = 0
 Independent worker for forwarding prepared Console entries.
std::shared_ptr< threads::TaskQueue > _consoleQueue = std::make_shared<threads::TaskQueue>()
 Queue of Console deliveries; it does not wait for log persistence.
console::EntryList _consoleEntries
 Console entries the Engine owns; only the Console worker changes them.
std::atomic< bool > _consoleStopping {false}
 Whether new Console deliveries are disabled during final local teardown.
threads::ThreadManager::Id _logThread = 0
 Worker for application log writes and history reads.
std::shared_ptr< threads::TaskQueue > _logQueue = std::make_shared<threads::TaskQueue>()
 Serializes application log writes and asynchronous history reads.
std::mutex _projectLogsMutex
 Protects the opening-tag and project-ID log routes.
std::unordered_map< std::string, std::shared_ptr< ProjectLogWorker > > _projectLogRoutes
 Routes project IDs and temporary opening tags to their dedicated workers.
std::unordered_map< std::string, std::shared_ptr< ProjectLogWorker > > _projectLogPaths
 Resolves registered project paths to log workers; guarded by _projectLogsMutex.
bool _shutdown = false
 Whether shutdown has progressed past application queue termination; guarded by _mutex.
ShutdownPhase _shutdownPhase = ShutdownPhase::running
 Shutdown state and project ownership; guarded by _mutex.
std::unordered_map< ProjectManager *, ShutdownEntry > _shutdownEntries
ProjectSession _shutdownSession
 Shutdown snapshot and capture state; guarded by _mutex.
bool _shutdownSessionCaptured = false
std::uint64_t _activeAnnouncementRevision = 0
 Monotonic ordering for active-project announcements; guarded by _mutex.
std::mutex _mutex
 Protects the project registry, ordering, closing state, shutdown state, and notifiers.
std::function< void(const std::string &id, const std::string &path, const std::string &name)> _renameNotifier
 Rename callback receiving project ID, canonical path key, and name; guarded by _mutex.
std::function< void(const std::string &id)> _renameFailureNotifier
 Reports asynchronously failed project renames; guarded by _mutex.
std::function< void(const std::string &openingTag, const std::string &id)> _logResolvedNotifier
 Callback mapping an opening log tag to a project ID; guarded by _mutex.
std::function< void(const std::string &name, const std::string &id, F_err result, bool packaged, const std::string &path)> _shutdownCloseNotifier
 Callback reporting a project closed by shutdown: name, ID, result, whether it was packaged, and resulting path; guarded by _mutex.
Projects _projects
 Project entries keyed by canonical working path; guarded by _mutex.
std::unordered_map< std::string, OpeningDecisionStatus > _openingDecisions
 Latest queued database-choice action for each canonical project path, guarded by _mutex.
std::unordered_map< std::string, OpeningStatus > _openingStatuses
 Latest project open for each canonical path, guarded by _mutex.
std::function< void(const OpeningStatus &)> _openingNotifier
 Publisher for opening state changes, guarded by _mutex.
std::vector< Entry > _retiredProjects
 Closed project workers retained until they have both stopped; guarded by _mutex.
std::vector< ProjectManager * > _openOrder
 Non-owning projects in opening order; guarded by _mutex.
std::unordered_set< ProjectManager * > _closingProjects
 Non-owning projects with a queued close in progress; guarded by _mutex.
std::unordered_map< std::string, ProjectManager::CloseStatus > _closeStatuses
 Latest close state by project path, retained after removal; guarded by _mutex.
std::unordered_map< ProjectManager *, std::string > _closeStatusKeys
 Original path for each active close, guarded by _mutex.
std::optional< ProjectManager::CloseStatus > _closeAllStatus
 Latest aggregate close state; guarded by _mutex.
std::unordered_set< ProjectManager * > _closeAllProjects
 Projects still included in the active aggregate close; guarded by _mutex.
bool _closeAllFailed = false
 Whether an aggregate close member failed; guarded by _mutex.
std::uint64_t _closingRevision = 0
 Revision of the pending-close snapshot, guarded by _mutex.
std::function< void(const ProjectClosingStatuses &)> _closingNotifier
 Queues a snapshot notification; invoked under _mutex and must not block.
logs::LogStore _logs
 Store for engine and project log entries.
std::unordered_map< ProjectManager *, std::string > _logIds
 Maps non-owning project pointers to their open log IDs; guarded by _mutex.
std::mutex _promptMutex
 Protects pending prompts and prompt shutdown state.
std::unordered_map< uint64_t, PendingPrompt > _pendingPrompts
 Pending prompts indexed by request message ID; guarded by _promptMutex.
bool _promptClosing = false
 Rejects new prompts after closing begins; guarded by _promptMutex.

Static Private Attributes

static std::atomic< bool > _active {false}
 Process-wide guard against multiple live managers.
static FrayManager * _acceptedApplicationTask = nullptr
 Identifies application work accepted before shutdown on its worker thread.

Detailed Description

Owns and coordinates projects, their queues, application work, prompts, and logs. Project work runs on separate project threads; drive manager operations from one controlling thread.

Definition at line 37 of file fray_manager.hpp.

Member Typedef Documentation

◆ Projects

using fray::FrayManager::Projects = std::unordered_map<std::string, Entry>
private

Registry mapping canonical project path keys to owned project entries.

Definition at line 230 of file fray_manager.hpp.

◆ RenameNotifier

Initial value:
std::function<void(const std::string& id, const std::string& path,
const std::string& name)>

Callback receiving a renamed project's ID, new path key, and name.

Definition at line 3121 of file fray_manager.hpp.

Member Enumeration Documentation

◆ OpeningDecision

The queued action applied to a project's database choice.

Enumerator
resolve 
cancel 

Definition at line 41 of file fray_manager.hpp.

◆ ShutdownPhase

Progress of an Engine-owned shutdown request.

Enumerator
running 
stopping 
ready 

Definition at line 74 of file fray_manager.hpp.

Constructor & Destructor Documentation

◆ FrayManager() [1/3]

fray::FrayManager::FrayManager ( const std::string & applicationId = "Fray")
inlineexplicit

Constructs a manager with its own thread manager and application worker.

Parameters
applicationIdIdentifier passed to projects.
Exceptions
std::logic_errorIf another manager is active.

Definition at line 1516 of file fray_manager.hpp.

◆ FrayManager() [2/3]

fray::FrayManager::FrayManager ( threads::ThreadManager & threads,
const std::string & applicationId = "Fray" )
inlineexplicit

Constructs a manager using an externally owned thread manager.

Parameters
threadsThread manager that must outlive this manager.
applicationIdIdentifier passed to projects.
Exceptions
std::logic_errorIf another manager is active.

Definition at line 1531 of file fray_manager.hpp.

◆ FrayManager() [3/3]

fray::FrayManager::FrayManager ( const FrayManager & )
delete

Copy construction is disabled because the manager owns running work.

◆ ~FrayManager()

fray::FrayManager::~FrayManager ( )
inline

Shuts down owned work and releases the process-wide manager slot.

Definition at line 1552 of file fray_manager.hpp.

Member Function Documentation

◆ addNotification()

void fray::FrayManager::addNotification ( ProcessKind sender,
NotificationSeverity severity,
const std::string & title,
const std::string & description,
const std::string & project,
std::uint32_t flags,
ipc::IPCManager & ipc,
const std::string & uid = "",
ProcessKind destination = PROCESS_KIND_ENGINE )
inline

Logs a notification and adds it to the Console, as handleNotification does for received ones. Safe from any thread; both go onto their own queues and return at once.

Parameters
senderProcess the notification is attributed to.
severityNotification severity.
titleNonempty title.
descriptionOptional detail text.
projectStable project ID, or empty for the application.
flagsMessage flags selecting whether it is logged and shown in the Console.
ipcIPC manager that must remain alive until stopConsoleDelivery completes.
uidEntry UID; empty generates a new one.
destinationProcess the notification was addressed to.

Definition of FrayManager::addNotification.

Definition at line 775 of file fray_message_handler.hpp.

◆ advanceShutdown()

ShutdownPhase fray::FrayManager::advanceShutdown ( )
inline

Advances shutdown using only local state and nonblocking queue operations. Pending opens, closes and worker termination are checked independently.

Returns
Current shutdown phase.

Definition at line 1949 of file fray_manager.hpp.

◆ announceActiveProject()

void fray::FrayManager::announceActiveProject ( ipc::IPCManager & ipc)
inlineprivate

Announces the most recently opened eligible project and its saved layout. Selects under _mutex, reads layout on the project thread, and queues renderer messages.

Announces the most recently opened eligible project and its saved layout to the renderer. Selects under _mutex, reads layout on the project queue, and installs rename and log callbacks; sends are queued.

Parameters
ipcIPC manager that must outlive queued work and registered callbacks.

Definition at line 369 of file project_message_handler.hpp.

◆ applicationId()

const std::string & fray::FrayManager::applicationId ( ) const
inline

Returns the application identifier by reference.

Definition at line 2246 of file fray_manager.hpp.

◆ applicationStatePath()

std::filesystem::path fray::FrayManager::applicationStatePath ( )
inline

Returns the currently open application database path.

Returns
Database path, or an empty path if application state is not open.

Definition at line 1749 of file fray_manager.hpp.

◆ applyApplicationDefaults()

F_err fray::FrayManager::applyApplicationDefaults ( state::StateManager & state)
inlineprivate

Adds missing application preference defaults without replacing saved values.

Parameters
stateOpen default application state.
Returns
NONE on success, otherwise the first state error.

Definition at line 1185 of file fray_manager.hpp.

◆ attachLog()

void fray::FrayManager::attachLog ( ProjectManager * project)
inlineprivate

Registers queued project-log rename coordination after opening. Call without holding _mutex because this installs a project callback.

Parameters
projectOpen project whose log follows folder renames.

Definition at line 846 of file fray_manager.hpp.

◆ beginConsoleShutdown()

void fray::FrayManager::beginConsoleShutdown ( )
inline

Stops accepting Console deliveries while allowing its queued work to drain.

Definition at line 1413 of file fray_manager.hpp.

◆ cancelProject()

F_err fray::FrayManager::cancelProject ( const std::string & name)
inline

Queues cancellation of a pending open and retires it after cancellation. Inspect openingDecisionStatus() for its eventual result.

Parameters
nameProject path or unique bare name.
Returns
NONE when queued, PROJECT_AMBIGUOUS for an ambiguous name, or FAILED_OPEN_PROJECT for lookup or queue failure.

Definition at line 2619 of file fray_manager.hpp.

◆ cancelPrompts()

void fray::FrayManager::cancelPrompts ( const std::string & reason,
bool closing = false )
inline

Completes outstanding prompts as dismissed with an error under _promptMutex.

Parameters
reasonError text placed in each incomplete response.
closingWhether to reject future prompt requests.

Definition at line 2206 of file fray_manager.hpp.

◆ captureShutdownSessionLocked()

void fray::FrayManager::captureShutdownSessionLocked ( )
inlineprivate

Captures open project identities and paths before shutdown starts closing them. Caller holds _mutex after accepted application work has drained.

Definition at line 716 of file fray_manager.hpp.

◆ close()

F_err fray::FrayManager::close ( )
inline

Queues all open project closes independently; entries remain registered. Already queued closes are included; repeated calls while pending add any newly open projects.

Returns
NONE when accepted, or FAILED_CLOSE_PROJECT if any dispatch was rejected.

Definition at line 3284 of file fray_manager.hpp.

◆ closeAllStatus()

std::optional< ProjectManager::CloseStatus > fray::FrayManager::closeAllStatus ( )
inline

Reads the latest aggregate close state.

Returns
Pending or completed state, or nullopt before the first close-all request.

Definition at line 3328 of file fray_manager.hpp.

◆ closeProject()

F_err fray::FrayManager::closeProject ( const std::string & name)
inline

Queues a project close and removes its registry entry on success. Retired workers are joined later, after they have stopped.

Parameters
nameProject path or unique bare name; a closed registered entry can also be removed.
Returns
NONE when queued or a closed entry was removed, otherwise a lookup or dispatch error.

Definition at line 3196 of file fray_manager.hpp.

◆ closeStatus()

std::optional< ProjectManager::CloseStatus > fray::FrayManager::closeStatus ( const std::string & name)
inline

Reads the latest project close state, including after registry removal.

Parameters
nameProject path or unique bare name.
Returns
Close state, or nullopt if no unique matching close is recorded.

Definition at line 3239 of file fray_manager.hpp.

◆ closingStatusesLocked()

ProjectClosingStatuses fray::FrayManager::closingStatusesLocked ( )
inlineprivate

Builds the pending-close snapshot without taking a project lock. Caller holds _mutex, including when a project worker is stalled.

Returns
Current revision and projects whose close has been queued.

Definition at line 279 of file fray_manager.hpp.

◆ consoleStopped()

bool fray::FrayManager::consoleStopped ( ) const
inline

Returns whether the Console delivery worker has finished its local queue.

Definition at line 1420 of file fray_manager.hpp.

◆ databaseCandidates()

std::vector< std::string > fray::FrayManager::databaseCandidates ( const std::string & name)
inline

Lists candidate databases for an opening project.

Parameters
nameProject path or unique bare name.
Returns
Candidate paths, or an empty vector if no matching project or candidates exist.

Definition at line 2589 of file fray_manager.hpp.

◆ describeCommand()

ConsoleEntry fray::FrayManager::describeCommand ( const message::InData & incoming)
inline

Describes a command as a Console entry.

Parameters
incomingCommand stamped with its UID.
Returns
A pending command entry with the arrival time in milliseconds.

Definition of FrayManager::describeCommand.

Definition at line 667 of file fray_message_handler.hpp.

◆ enqueueProjectTask()

F_err fray::FrayManager::enqueueProjectTask ( const std::string & target,
bool allowLatest,
bool closing,
std::function< void(ProjectManager &, const std::shared_ptr< threads::TaskQueue > &)> task,
ProjectManager * exact = nullptr )
inlineprivate

Finds an open project and posts work to its queue under _mutex.

Parameters
targetPath or unique bare name; empty can select the latest project.
allowLatestWhether an empty target selects the most recently opened project.
closingWhether to mark the project as closing until the task finishes.
taskWork receiving the project and its shared queue on the project thread.
exactOptional registered project to select instead of target.
Returns
NONE if queued, PROJECT_NOT_FOUND or PROJECT_AMBIGUOUS for lookup failure, or FAILED_CLOSE_PROJECT if closing or the queue is stopped.

Definition at line 2737 of file fray_manager.hpp.

◆ enqueueProjectTaskLocked()

F_err fray::FrayManager::enqueueProjectTaskLocked ( const std::string & target,
bool allowLatest,
bool closing,
std::function< void(ProjectManager &, const std::shared_ptr< threads::TaskQueue > &)> task,
ProjectManager * exact )
inlineprivate

Selects and queues project work while the caller holds _mutex.

Parameters
targetPath or unique bare name; empty can select the latest project.
allowLatestWhether an empty target selects the latest project.
closingWhether this is a close task.
taskWork receiving the selected project and its queue.
exactOptional registered project to select instead of target.
Returns
NONE when queued, otherwise a lookup or dispatch error.

Definition at line 2757 of file fray_manager.hpp.

◆ find()

std::optional< Entry > fray::FrayManager::find ( const std::string & name,
F_err & error,
bool includeClosed = false )
inlineprivate

Looks up and copies an entry under _mutex.

Parameters
nameProject path or unique bare name.
errorReceives the lookup result.
includeClosedWhether to include closed entries.
Returns
Shared-ownership entry copy, or nullopt if no unique match exists.

Definition at line 489 of file fray_manager.hpp.

◆ finishCloseAllMemberLocked()

void fray::FrayManager::finishCloseAllMemberLocked ( ProjectManager * project,
F_err result )
inlineprivate

Records an aggregate member's result while holding _mutex.

Parameters
projectProject whose close finished or could not be dispatched.
resultClose result.

Definition at line 2881 of file fray_manager.hpp.

◆ finishLogRename()

void fray::FrayManager::finishLogRename ( const std::string & id,
const std::shared_ptr< ProjectLogWorker > & worker,
const std::shared_ptr< threads::TaskQueue > & queue,
const std::shared_ptr< ProjectManager > & project,
const std::filesystem::path & folder,
F_err result )
inlineprivate

Resumes logging and releases any close deferred behind a rename on the log worker.

Parameters
idProject log identity.
workerProject log worker.
queueProject task queue.
projectProject retained while the rename finishes.
folderFinal working folder.
resultProject rename result.

Definition at line 797 of file fray_manager.hpp.

◆ finishProjectClose()

void fray::FrayManager::finishProjectClose ( ProjectManager & project,
const std::shared_ptr< threads::TaskQueue > & queue,
F_err result,
bool removeOnSuccess = false )
inlineprivate

Clears the closing marker and, on success, forgets the project and stops its queue. Takes _mutex and updates any active aggregate close.

Parameters
projectProject whose close finished.
queueProject queue to shut down on success.
resultClose result; NONE indicates success.
removeOnSuccessWhether to remove the project from the registry.

Definition at line 2902 of file fray_manager.hpp.

◆ finishShutdown()

void fray::FrayManager::finishShutdown ( )
inline

Releases local workers after shutdown is ready. The normal Engine path calls this only after advanceShutdown reports ready. If an owner destroys the manager early, this safety fallback joins its active local workers. Call on the controlling thread, never from a worker being joined.

Definition at line 2092 of file fray_manager.hpp.

◆ forgetProject()

void fray::FrayManager::forgetProject ( ProjectManager * project)
inlineprivate

Removes a project from open order and closes its tracked log. Caller holds _mutex; this does not remove the registry entry.

Parameters
projectNon-owning project pointer to forget.

Definition at line 670 of file fray_manager.hpp.

◆ forwardLogEntry()

void fray::FrayManager::forwardLogEntry ( const logs::Entry & entry,
ipc::IPCManager & ipc,
bool includeLoading )
inline

Sends a prepared log line to the renderer with a limited lifetime.

Sends a prepared log entry to the renderer with a five-second lifetime.

Parameters
entryPrepared line to forward.
ipcIPC manager used to send it; must remain alive during the call.
includeLoadingWhether this line belongs in the startup window.

Definition at line 885 of file fray_message_handler.hpp.

◆ get()

template<typename T>
F_err fray::FrayManager::get ( const std::string & key,
T & value )
inline

Reads a value from the default application state namespace.

Template Parameters
TValue type supported by StateManager.
Parameters
keyState key to read.
valueReceives the value on success.
Returns
NONE on success, otherwise a state error.

Definition at line 1895 of file fray_manager.hpp.

◆ handleApplicationMessage()

void fray::FrayManager::handleApplicationMessage ( const message::InData & incoming,
ipc::IPCManager & ipc )
inline

Routes an incoming Engine message, dispatching project work asynchronously. Called by the Engine message thread; may stop IPC or enqueue application work.

Routes an Engine application message, dispatching project work asynchronously. Runs on the Engine message thread; quit starts local shutdown, prompts update under _promptMutex, and create work is posted to the application queue.

Parameters
incomingParsed incoming message.
ipcIPC manager used for replies; must outlive queued work.

Performs the filesystem operation on the application queue.

Definition at line 241 of file fray_message_handler.hpp.

◆ handleLogMessage()

void fray::FrayManager::handleLogMessage ( const message::InData & incoming,
ipc::IPCManager & ipc )
inlineprivate

Stores and forwards incoming log entries or sends a filtered log page.

Stores and forwards external log entries or sends filtered log pages to the renderer. Invalid payloads and unsupported senders are ignored.

Parameters
incomingParsed log message.
ipcIPC manager used to send renderer messages.

Definition at line 911 of file fray_message_handler.hpp.

◆ handleNotification()

void fray::FrayManager::handleNotification ( const message::InData & incoming,
ipc::IPCManager & ipc )
inline

Handles COMMAND_NOTIFY: logs the notification and adds it to the Console as a notification entry. The log record is skipped when MESSAGE_FLAG_NO_LOG is set and the Console message when MESSAGE_FLAG_NO_CONSOLE is set. Both go onto their own queues and return at once. Invalid payloads are logged and ignored.

Parameters
incomingNotification stamped with its UID.
ipcIPC manager that must remain alive until stopConsoleDelivery completes.

Definition of FrayManager::handleNotification.

Definition at line 749 of file fray_message_handler.hpp.

◆ handleProjectMessage()

void fray::FrayManager::handleProjectMessage ( const message::InData & incoming,
ipc::IPCManager & ipc )
inlineprivate

Validates and dispatches a project message to its project queue.

Validates and posts a project message to the selected project queue. Close failures receive a reply; failed layout dispatch triggers an active-project resync.

Parameters
incomingParsed message to route.
ipcIPC manager for asynchronous replies; must outlive queued work.

Definition at line 444 of file project_message_handler.hpp.

◆ handleReceipt()

void fray::FrayManager::handleReceipt ( const message::InData & incoming,
ipc::IPCManager & ipc )
inline

Handles a MSG_RECEIPT: logs it under its own UID and tells the Console the original command arrived. The log record is skipped when the original had MESSAGE_FLAG_NO_LOG, and the Console message when it had MESSAGE_FLAG_NO_CONSOLE. A known entry gets a COMMAND_CONSOLE_UPDATE; if the Engine no longer holds the UID, a COMMAND_CONSOLE_ADD is sent instead, as already received, built from what the receipt carries. This is the only place a receipt becomes a Console message. Invalid receipts are logged and ignored.

Parameters
incomingReceipt from the destination process, carrying a Receipt payload.
ipcIPC manager that must remain alive until stopConsoleDelivery completes.

Definition of FrayManager::handleReceipt.

Definition at line 824 of file fray_message_handler.hpp.

◆ init()

void fray::FrayManager::init ( )
inlineprivate

Claims the process-wide manager slot and starts application, log, and Console workers.

Exceptions
std::logic_errorIf another manager is active.

Definition at line 1254 of file fray_manager.hpp.

◆ isActiveProjectLocked()

bool fray::FrayManager::isActiveProjectLocked ( const ProjectManager * project) const
inlineprivate

Tests whether a project is the currently active eligible project. Caller holds _mutex.

Parameters
projectRegistered project to check.
Returns
True when it is the most recently opened non-closing project.

Definition at line 688 of file fray_manager.hpp.

◆ loadButtonStyle()

F_err fray::FrayManager::loadButtonStyle ( const std::string & defaults,
std::string & css )
inline

Loads the Engine-owned application button stylesheet.

Parameters
defaultsPackaged stylesheet used only on first load.
cssReceives the saved stylesheet.
Returns
NONE on success, otherwise a file error.

Definition at line 1625 of file fray_manager.hpp.

◆ logProjectIdentity()

std::string fray::FrayManager::logProjectIdentity ( const std::string & target)
inlineprivate

Resolves a message's project target to its log identity without changing dispatch.

Parameters
targetProject path, unique name, stable ID, or opening tag.
Returns
Stable ID or opening tag when registered; otherwise the original target.

Definition at line 379 of file fray_manager.hpp.

◆ logStore()

logs::LogStore & fray::FrayManager::logStore ( )
inline

Returns the manager-owned log store by reference.

Definition at line 1293 of file fray_manager.hpp.

◆ lookup()

Projects::iterator fray::FrayManager::lookup ( const std::string & target,
F_err & error,
bool includeClosed = false )
inlineprivate

Looks up a project by path or unique bare name; caller must hold _mutex.

Parameters
targetProject path or bare name.
errorReceives NONE, PROJECT_NOT_FOUND, or PROJECT_AMBIGUOUS.
includeClosedWhether to include entries that are neither open nor opening.
Returns
Matching registry iterator, or _projects.end() on failure.

Definition at line 438 of file fray_manager.hpp.

◆ notifyRenameFailure()

void fray::FrayManager::notifyRenameFailure ( const std::string & id)
inlineprivate

Reports an asynchronous rename failure without holding the manager mutex.

Parameters
idStable project identity.

Definition at line 776 of file fray_manager.hpp.

◆ openApplicationState()

F_err fray::FrayManager::openApplicationState ( const std::filesystem::path & directory)
inline

Opens the application directory and its default state namespace.

Parameters
directoryExisting directory containing the application database.
Returns
NONE on success, otherwise a file or state opening error.

Definition at line 1563 of file fray_manager.hpp.

◆ openingDecisionStatus()

std::optional< OpeningDecisionStatus > fray::FrayManager::openingDecisionStatus ( const std::string & path)
inline

Reads the latest queued database-choice action for a project path. The result remains available after cancellation until the path is opened again.

Parameters
pathProject folder or archive path.
Returns
Current action and optional result, or nullopt if no action has been queued for this path.

Definition at line 2631 of file fray_manager.hpp.

◆ openingStatus()

std::optional< OpeningStatus > fray::FrayManager::openingStatus ( const std::string & path)
inline

Reads the latest project-open state for a folder or archive path.

Parameters
pathProject folder or archive path.
Returns
The open state, or nullopt if no open was queued for that path.

Definition at line 2557 of file fray_manager.hpp.

◆ openingTag()

std::string fray::FrayManager::openingTag ( const ProjectManager * project)
inlinestaticprivate

Creates the temporary log tag used while a project opens.

Parameters
projectProject whose address identifies the opening.
Returns
Temporary opening tag.

Definition at line 766 of file fray_manager.hpp.

◆ openProject()

F_err fray::FrayManager::openProject ( const std::string & path,
files::ConflictChoice choice = files::ConflictChoice::Ask,
bool cancelOnDatabaseConflict = false,
files::OpenMode mode = files::OpenMode::OpenOrCreate,
std::optional< OpeningOrigin > origin = std::nullopt,
std::optional< std::size_t > restoreOrder = std::nullopt,
const std::string & expectedId = "" )
inline

Queues a project open on its own worker.

Parameters
pathProject folder or archive path.
choiceFolder/archive conflict policy.
cancelOnDatabaseConflictWhether to cancel a pending database choice automatically.
modeWhether to open, create, or resolve an existing folder.
originOptional message origin for publishing the eventual result.
restoreOrderOptional saved ordering used for startup restoration.
expectedIdOptional saved identity that a restored project must match.
Returns
NONE when queued, or an immediate validation or dispatch error.

Definition at line 2308 of file fray_manager.hpp.

◆ openState()

F_err fray::FrayManager::openState ( const std::string & name)
inline

Opens an additional application state namespace.

Parameters
nameState namespace to open.
Returns
NONE on success or if already open; otherwise a state opening error.

Definition at line 1829 of file fray_manager.hpp.

◆ operator=()

FrayManager & fray::FrayManager::operator= ( const FrayManager & )
delete

Copy assignment is disabled because the manager owns running work.

◆ persistLogEntry()

void fray::FrayManager::persistLogEntry ( const logs::Entry & entry)
inline

Queues persistence on the project's worker or the application worker.

Parameters
entryPrepared entry to persist.

Definition at line 1429 of file fray_manager.hpp.

◆ postApplication()

bool fray::FrayManager::postApplication ( std::function< void()> task)
inline

Posts work to the application thread without waiting for it.

Parameters
taskWork to enqueue.
Returns
True if accepted, false if the queue has shut down.

Restores the previous application task marker.

Definition at line 2253 of file fray_manager.hpp.

◆ project()

ProjectManager & fray::FrayManager::project ( const std::string & name)
inline

Returns a non-owning reference to an open project under registry lookup. The reference is valid only while the project remains registered.

Parameters
nameProject path or unique bare name.
Returns
Matching open project.
Exceptions
std::invalid_argumentIf the name is ambiguous.
std::out_of_rangeIf the project is not open.

Definition at line 2655 of file fray_manager.hpp.

◆ projectKey()

std::string fray::FrayManager::projectKey ( const std::string & path,
std::error_code & error )
inlinestaticprivate

Canonicalizes a project path, removing a .fry extension.

Parameters
pathProject folder or archive path; empty and embedded-NUL paths are invalid.
errorReceives invalid_argument or a filesystem error on failure.
Returns
Canonical working-path key, or an empty string on error.

Definition at line 355 of file fray_manager.hpp.

◆ publishClosingLocked()

void fray::FrayManager::publishClosingLocked ( )
inlineprivate

Publishes the current pending-close snapshot while holding _mutex.

Definition at line 312 of file fray_manager.hpp.

◆ queueConsoleEntry()

void fray::FrayManager::queueConsoleEntry ( const logs::Entry & entry,
ipc::IPCManager & ipc,
bool includeLoading = true )
inline

Queues a prepared entry for Console delivery independently of persistence.

Parameters
entryPrepared entry copied into the queue.
ipcIPC manager that must remain alive until stopConsoleDelivery completes.
includeLoadingWhether this line belongs in the startup window.

Definition at line 1312 of file fray_manager.hpp.

◆ queueLogClose()

void fray::FrayManager::queueLogClose ( const std::shared_ptr< ProjectManager > & project,
const std::shared_ptr< threads::TaskQueue > & queue,
const std::shared_ptr< ProjectLogWorker > & worker,
const std::string & id,
std::function< void(ProjectManager &, const std::shared_ptr< threads::TaskQueue > &)> task )
inlineprivate

Closes the project log on its worker, then returns close work to the project queue.

Parameters
projectProject retained until the close task runs.
queueProject's task queue.
workerProject's log worker.
idProject log identity.
taskProject close work.

Definition at line 2677 of file fray_manager.hpp.

◆ queueOpeningDecision()

F_err fray::FrayManager::queueOpeningDecision ( const std::string & name,
OpeningDecision action,
const DatabaseChoice & choice,
bool shutdownAction = false )
inlineprivate

Queues a database-choice action and records its result locally.

Parameters
nameProject path or unique bare name.
actionAction to apply.
choiceDatabase selection used when resolving.
shutdownActionWhether this is the manager's own shutdown cancellation.
Returns
NONE when queued, or a lookup or dispatch error.

Definition at line 507 of file fray_manager.hpp.

◆ queueProjectClose()

F_err fray::FrayManager::queueProjectClose ( const std::string & target,
std::function< F_err(ProjectManager &, bool &)> operation,
std::function< void(const std::string &, F_err, bool)> completion,
ProjectManager * exact = nullptr,
bool removeOnSuccess = false )
inlineprivate

Queues a close operation; an empty target selects the latest open project. If supplied, completion runs on the project thread, or on the caller if dispatch fails.

Parameters
targetProject path, unique bare name, or empty for latest.
operationClose work receiving the project and a packaged output flag.
completionCallback receiving project name or target, result, and whether packaging occurred.
exactOptional registered project to select instead of target.
removeOnSuccessWhether successful close removes the registry entry.
Returns
NONE when queued, or the dispatch error.

Definition at line 3006 of file fray_manager.hpp.

◆ readApplicationPreferences()

F_err fray::FrayManager::readApplicationPreferences ( ApplicationPreferences & output)
inline

Reads an authoritative application preferences snapshot.

Parameters
outputReceives the complete snapshot on success.
Returns
NONE on success, otherwise a state error.

Definition at line 1761 of file fray_manager.hpp.

◆ reapRetired()

void fray::FrayManager::reapRetired ( )
inlineprivate

Joins already-finished retired workers without waiting for active projects. Call outside _mutex and outside a retired worker.

Definition at line 644 of file fray_manager.hpp.

◆ recordCommand()

void fray::FrayManager::recordCommand ( const message::InData & incoming,
ipc::IPCManager & ipc,
bool received )
inline

Splits a stamped command into its disk log record and its Console entry, honoring the message's flags. The record is written under the command's UID unless MESSAGE_FLAG_NO_LOG is set; the Console is sent a COMMAND_CONSOLE_ADD unless MESSAGE_FLAG_NO_CONSOLE is set. Both go onto their own queues and return at once; neither waits for the other or for delivery.

Parameters
incomingCommand stamped with its UID.
ipcIPC manager that must remain alive until stopConsoleDelivery completes.
receivedTrue when the Engine itself is the destination, so the entry is added as already received; false when a receipt from the destination is still to come.

Definition of FrayManager::recordCommand.

Definition at line 705 of file fray_message_handler.hpp.

◆ recordEngineLog()

void fray::FrayManager::recordEngineLog ( const char * level,
F_long thread,
const std::string & project,
const char * text,
ipc::IPCManager * ipc,
std::uint64_t arrivedUs = 0,
bool consoleVisible = true )
inline

Prepares an Engine log line and independently queues Console delivery and persistence.

Parameters
levelLog severity.
threadOriginating thread identifier.
projectProject ID or temporary opening tag.
textLog text.
ipcOptional non-owning IPC manager; null stores without forwarding.
arrivedUsCaptured arrival time in microseconds, or zero to stamp now.
consoleVisibleWhether this entry may be delivered to the Console.

Definition at line 1489 of file fray_manager.hpp.

◆ recordLogEntry()

void fray::FrayManager::recordLogEntry ( logs::Entry entry,
ipc::IPCManager * ipc,
bool includeLoading = true )
inline

Identifies a log entry and submits it independently to Console and persistence. Application writes are submitted before Console delivery so a subsequent history request sees them.

Parameters
entryUnstamped log entry.
ipcOptional IPC manager used for Console delivery.
includeLoadingWhether this line belongs in the startup window.

Definition at line 1463 of file fray_manager.hpp.

◆ recordOpen()

void fray::FrayManager::recordOpen ( ProjectManager * project)
inlineprivate

Records an open project, opens its log, and resolves its opening tag. Opens and flushes the project log without holding the manager mutex. Log entries received during opening are held on the log worker until the session is ready.

Parameters
projectProject to register if still open and present.

Definition at line 1023 of file fray_manager.hpp.

◆ registerOpenedProject()

F_err fray::FrayManager::registerOpenedProject ( ProjectManager * project)
inlineprivate

Reserves identity and registers a successfully opened project.

Parameters
projectProject on its own worker.
Returns
NONE on success, otherwise an identity or state error.

Definition at line 1000 of file fray_manager.hpp.

◆ rekey()

void fray::FrayManager::rekey ( ProjectManager * project,
const std::filesystem::path & path )
inlineprivate

Updates the registry and notifies listeners after a project rename. Takes _mutex, retains a colliding closed entry for later retirement, and calls the notifier outside it.

Parameters
projectRenamed project.
pathNew working path to canonicalize.

Definition at line 1133 of file fray_manager.hpp.

◆ requestCloseProject()

void fray::FrayManager::requestCloseProject ( const std::string & target,
bool package,
std::function< void(const std::string &, F_err, bool)> completion )
inline

Queues a project close without waiting for completion.

Parameters
targetProject path, unique bare name, or empty for the latest project.
packageWhether to package the project when closing.
completionCallback receiving name or target, close result, and whether packaging occurred; runs on the project thread or caller on dispatch failure.

Definition at line 3179 of file fray_manager.hpp.

◆ requestPrompt()

bool fray::FrayManager::requestPrompt ( ipc::IPCManager & ipc,
const PromptRequest & request,
uint64_t & requestId )
inline

Sends a renderer prompt and tracks its response under _promptMutex.

Validates and sends a prompt to the renderer, tracking its eventual response. Takes _promptMutex while registering and sending; does not wait for a response.

Parameters
ipcIPC manager used to send the request.
requestPrompt with a nonblank title and nonblank labeled buttons.
requestIdReceives the generated message ID only on success.
Returns
True if queued; false for invalid input, shutdown, frame construction failure, or send failure.

Definition at line 192 of file fray_message_handler.hpp.

◆ requestShutdown()

void fray::FrayManager::requestShutdown ( )
inline

Starts or retries Engine-owned shutdown without joining any worker. Previously accepted application work drains; new application work is rejected.

Definition at line 1913 of file fray_manager.hpp.

◆ reserveProjectIdentity()

F_err fray::FrayManager::reserveProjectIdentity ( ProjectManager * project)
inlineprivate

Reserves a unique identity and updates a copied project's persisted identity if necessary. The registry reservation prevents concurrent project workers from choosing the same identity.

Parameters
projectOpen project to register.
Returns
NONE on success, otherwise a state or registration error.

Definition at line 941 of file fray_manager.hpp.

◆ resetApplicationPreferences()

F_err fray::FrayManager::resetApplicationPreferences ( )
inline

Resets only application preference values in one database transaction.

Returns
NONE on success, otherwise a state error.

Definition at line 1793 of file fray_manager.hpp.

◆ resolveDatabase()

F_err fray::FrayManager::resolveDatabase ( const std::string & name,
const DatabaseChoice & choice )
inline

Queues a database choice on the project thread. Inspect openingDecisionStatus() for its eventual result.

Parameters
nameProject path or unique bare name.
choiceDatabase selection to apply.
Returns
NONE when queued, PROJECT_AMBIGUOUS for an ambiguous name, or FAILED_OPEN_PROJECT for lookup or queue failure.

Definition at line 2606 of file fray_manager.hpp.

◆ restoreProjects()

F_err fray::FrayManager::restoreProjects ( ipc::IPCManager & ipc)
inline

Queues restoration of the saved project session when enabled.

Parameters
ipcIPC manager that must outlive queued work.
Returns
NONE when restoration is disabled, absent, or queued; otherwise a state or dispatch error.

Definition of FrayManager::restoreProjects.

Definition at line 123 of file fray_message_handler.hpp.

◆ retainRetiredLocked()

void fray::FrayManager::retainRetiredLocked ( Entry entry)
inlineprivate

Stops an entry's queues and retains it until its workers can safely be joined. Caller holds _mutex; neither worker is joined here.

Parameters
entryRemoved project entry.

Definition at line 631 of file fray_manager.hpp.

◆ retire()

void fray::FrayManager::retire ( Entry & entry)
inlineprivate

Shuts down a project queue and joins its worker. Call outside _mutex and not on the worker being joined.

Parameters
entryProject entry whose worker is retired.

Definition at line 601 of file fray_manager.hpp.

◆ saveButtonStyle()

F_err fray::FrayManager::saveButtonStyle ( const std::string & css)
inline

Saves the Engine-owned application button stylesheet.

Parameters
cssComplete stylesheet text.
Returns
NONE on success, otherwise a file error.

Definition at line 1638 of file fray_manager.hpp.

◆ saveShutdownSessionLocked()

F_err fray::FrayManager::saveShutdownSessionLocked ( )
inlineprivate

Writes the captured project session to application state. Caller holds _mutex.

Returns
NONE on success, otherwise a state error.

Definition at line 702 of file fray_manager.hpp.

◆ sendConsoleEntry()

void fray::FrayManager::sendConsoleEntry ( Command operation,
const ConsoleEntry & entry,
ipc::IPCManager & ipc )
inlinestatic

Sends a Console entry to the Renderer without waiting; a dropped send is not retried.

Parameters
operationCOMMAND_CONSOLE_ADD or COMMAND_CONSOLE_UPDATE.
entryEntry to send.
ipcIPC manager used to send the frame.

Definition of FrayManager::sendConsoleEntry.

Definition at line 691 of file fray_message_handler.hpp.

◆ set()

template<typename T>
F_err fray::FrayManager::set ( const std::string & key,
const T & value )
inline

Writes a value in the default application state namespace.

Template Parameters
TValue type supported by StateManager.
Parameters
keyState key to write.
valueValue to persist.
Returns
NONE on success, otherwise a state error.

Definition at line 1873 of file fray_manager.hpp.

◆ setClosingNotifier()

void fray::FrayManager::setClosingNotifier ( std::function< void(const ProjectClosingStatuses &)> notifier)
inline

Installs a nonblocking pending-close snapshot notifier and sends its initial snapshot.

Parameters
notifierCallback invoked under _mutex; it must only queue work and must not reenter this manager.

Definition at line 3106 of file fray_manager.hpp.

◆ setLogResolvedNotifier()

void fray::FrayManager::setLogResolvedNotifier ( std::function< void(const std::string &openingTag, const std::string &id)> notifier)
inline

Installs the opening-log resolution callback under _mutex unless the manager is marked shut down.

Parameters
notifierCallback receiving the temporary opening tag and project ID; empty clears it.

Definition at line 3165 of file fray_manager.hpp.

◆ setOpeningNotifier()

void fray::FrayManager::setOpeningNotifier ( std::function< void(const OpeningStatus &)> notifier)
inline

Installs a publisher for completed project-open states.

Parameters
notifierPublisher invoked outside the manager lock; empty clears it.

Definition at line 2576 of file fray_manager.hpp.

◆ setRenameFailureNotifier()

void fray::FrayManager::setRenameFailureNotifier ( std::function< void(const std::string &)> notifier)
inline

Installs a notifier for asynchronously failed project renames.

Parameters
notifierCallback receiving the stable project ID.

Definition at line 3140 of file fray_manager.hpp.

◆ setRenameNotifier()

void fray::FrayManager::setRenameNotifier ( RenameNotifier notifier)
inline

Installs the rename callback under _mutex unless the manager is marked shut down.

Parameters
notifierCallback receiving project ID, new path key, and name; empty clears it.

Definition at line 3128 of file fray_manager.hpp.

◆ setShutdownCloseNotifier()

void fray::FrayManager::setShutdownCloseNotifier ( std::function< void(const std::string &name, const std::string &id, F_err result, bool packaged, const std::string &path)> notifier)
inline

Installs the callback reporting projects closed by shutdown, under _mutex unless the manager is marked shut down.

Parameters
notifierCallback receiving name, ID, result, packaged flag and path; empty clears it. It runs on a project worker and must only queue work.

Definition at line 3152 of file fray_manager.hpp.

◆ shutdown()

void fray::FrayManager::shutdown ( )
inline

Requests shutdown without waiting for project work or worker termination.

Definition at line 1939 of file fray_manager.hpp.

◆ shutdownPhase()

ShutdownPhase fray::FrayManager::shutdownPhase ( )
inline

Reads shutdown progress without advancing it.

Returns
Current Engine-local shutdown phase.

Definition at line 2080 of file fray_manager.hpp.

◆ state()

state::StateManager & fray::FrayManager::state ( const std::string & name)
inline

Returns a borrowed reference to an open application state namespace.

Parameters
nameState namespace to find.
Returns
Open state manager; the caller must coordinate its lifetime with shutdown.
Exceptions
std::out_of_rangeIf the namespace is not open.

Definition at line 1855 of file fray_manager.hpp.

◆ stopConsoleDelivery()

void fray::FrayManager::stopConsoleDelivery ( )
inline

Stops and drains Console delivery before its IPC manager is destroyed. Call from the controlling thread, not from the Console worker.

Definition at line 1406 of file fray_manager.hpp.

◆ switchApplicationState()

F_err fray::FrayManager::switchApplicationState ( const std::filesystem::path & path)
inline

Selects and persists an existing application database without replacing active state on failure. Previously borrowed application state references become invalid after a successful switch.

Parameters
pathExisting application database file.
Returns
NONE on success, otherwise a file or state error.

Definition at line 1733 of file fray_manager.hpp.

◆ switchApplicationStateLocked()

F_err fray::FrayManager::switchApplicationStateLocked ( const std::filesystem::path & path,
bool persist )
inlineprivate

Switches to an existing application database while retaining the current one on failure. Caller must hold _mutex.

Parameters
pathExisting application database file.
persistWhether to update the Engine-adjacent selected-database location.
Returns
NONE on success, otherwise a file or state error.

Definition at line 1653 of file fray_manager.hpp.

◆ takePromptResponse()

bool fray::FrayManager::takePromptResponse ( uint64_t requestId,
PromptResponse & response )
inline

Consumes a completed prompt response under _promptMutex.

Parameters
requestIdMessage ID returned by requestPrompt.
responseReceives the response on success; unchanged otherwise.
Returns
True if a completed response was removed; false if missing or incomplete.

Definition at line 2230 of file fray_manager.hpp.

◆ toProto()

void fray::FrayManager::toProto ( const logs::Entry & entry,
LogEntry & out )
inlinestaticprivate

Copies a stored log entry into its protobuf representation.

Parameters
entryStored log entry.
outProtobuf to populate.

Definition at line 3059 of file fray_manager.hpp.

◆ updateShutdownSessionPath()

void fray::FrayManager::updateShutdownSessionPath ( const std::string & id,
const std::string & path )
inlineprivate

Updates the shutdown snapshot after a queued rename has finished.

Parameters
idStable project identity.
pathFinal working-folder path before close or packaging.

Definition at line 744 of file fray_manager.hpp.

◆ validateApplicationPreferences()

F_err fray::FrayManager::validateApplicationPreferences ( state::StateManager & state)
inlineprivate

Validates the types of saved application preferences that are present.

Parameters
stateOpen default application state.
Returns
NONE when valid, otherwise the first state error.

Definition at line 1228 of file fray_manager.hpp.

◆ validateApplicationState()

F_err fray::FrayManager::validateApplicationState ( state::StateManager & state)
inlineprivate

Verifies that an existing state table is an application database.

Parameters
stateOpen state namespace.
Returns
NONE if the application marker is valid, otherwise a state error.

Definition at line 1210 of file fray_manager.hpp.

◆ watchProjectOpenings()

void fray::FrayManager::watchProjectOpenings ( ipc::IPCManager & ipc)
inlineprivate

Installs independent project-opening result and active-project announcements.

Parameters
ipcIPC manager that must outlive queued work.

Definition of FrayManager::watchProjectOpenings.

Definition at line 104 of file fray_message_handler.hpp.

◆ watchRenames()

void fray::FrayManager::watchRenames ( ipc::IPCManager & ipc)
inlineprivate

Installs callbacks forwarding project renames and resolved opening log tags. Callbacks capture ipc by reference and are cleared on shutdown.

Registers renderer notifications for renames and resolved opening log tags. Callbacks capture ipc by reference; shutdown clears them.

Parameters
ipcIPC manager that must outlive the callbacks.

Definition at line 313 of file project_message_handler.hpp.

Member Data Documentation

◆ _acceptedApplicationTask

FrayManager* fray::FrayManager::_acceptedApplicationTask = nullptr
inlinethread_localstaticprivate

Identifies application work accepted before shutdown on its worker thread.

Definition at line 207 of file fray_manager.hpp.

◆ _active

std::atomic<bool> fray::FrayManager::_active {false}
inlinestaticprivate

Process-wide guard against multiple live managers.

Definition at line 149 of file fray_manager.hpp.

◆ _activeAnnouncementRevision

std::uint64_t fray::FrayManager::_activeAnnouncementRevision = 0
private

Monotonic ordering for active-project announcements; guarded by _mutex.

Definition at line 205 of file fray_manager.hpp.

◆ _applicationDirectory

std::filesystem::path fray::FrayManager::_applicationDirectory
private

Engine directory containing the selected-database location file.

Definition at line 155 of file fray_manager.hpp.

◆ _applicationId

std::string fray::FrayManager::_applicationId
private

Application identifier supplied when opening projects.

Definition at line 153 of file fray_manager.hpp.

◆ _applicationQueue

std::shared_ptr<threads::TaskQueue> fray::FrayManager::_applicationQueue = std::make_shared<threads::TaskQueue>()
private

Queue for application-level work, separate from project queues.

Definition at line 175 of file fray_manager.hpp.

◆ _applicationThread

threads::ThreadManager::Id fray::FrayManager::_applicationThread = 0
private

Identifier of the application queue worker.

Definition at line 171 of file fray_manager.hpp.

◆ _closeAllFailed

bool fray::FrayManager::_closeAllFailed = false
private

Whether an aggregate close member failed; guarded by _mutex.

Definition at line 260 of file fray_manager.hpp.

◆ _closeAllProjects

std::unordered_set<ProjectManager*> fray::FrayManager::_closeAllProjects
private

Projects still included in the active aggregate close; guarded by _mutex.

Definition at line 258 of file fray_manager.hpp.

◆ _closeAllStatus

std::optional<ProjectManager::CloseStatus> fray::FrayManager::_closeAllStatus
private

Latest aggregate close state; guarded by _mutex.

Definition at line 256 of file fray_manager.hpp.

◆ _closeStatuses

std::unordered_map<std::string, ProjectManager::CloseStatus> fray::FrayManager::_closeStatuses
private

Latest close state by project path, retained after removal; guarded by _mutex.

Definition at line 252 of file fray_manager.hpp.

◆ _closeStatusKeys

std::unordered_map<ProjectManager*, std::string> fray::FrayManager::_closeStatusKeys
private

Original path for each active close, guarded by _mutex.

Definition at line 254 of file fray_manager.hpp.

◆ _closingNotifier

std::function<void(const ProjectClosingStatuses&)> fray::FrayManager::_closingNotifier
private

Queues a snapshot notification; invoked under _mutex and must not block.

Definition at line 264 of file fray_manager.hpp.

◆ _closingProjects

std::unordered_set<ProjectManager*> fray::FrayManager::_closingProjects
private

Non-owning projects with a queued close in progress; guarded by _mutex.

Definition at line 250 of file fray_manager.hpp.

◆ _closingRevision

std::uint64_t fray::FrayManager::_closingRevision = 0
private

Revision of the pending-close snapshot, guarded by _mutex.

Definition at line 262 of file fray_manager.hpp.

◆ _consoleEntries

console::EntryList fray::FrayManager::_consoleEntries
private

Console entries the Engine owns; only the Console worker changes them.

Definition at line 181 of file fray_manager.hpp.

◆ _consoleQueue

std::shared_ptr<threads::TaskQueue> fray::FrayManager::_consoleQueue = std::make_shared<threads::TaskQueue>()
private

Queue of Console deliveries; it does not wait for log persistence.

Definition at line 179 of file fray_manager.hpp.

◆ _consoleStopping

std::atomic<bool> fray::FrayManager::_consoleStopping {false}
private

Whether new Console deliveries are disabled during final local teardown.

Definition at line 183 of file fray_manager.hpp.

◆ _consoleThread

threads::ThreadManager::Id fray::FrayManager::_consoleThread = 0
private

Independent worker for forwarding prepared Console entries.

Definition at line 177 of file fray_manager.hpp.

◆ _files

std::unique_ptr<files::FileManager> fray::FrayManager::_files = std::make_unique<files::FileManager>()
private

Application directory and database ownership; state managers detach before this is destroyed.

Definition at line 157 of file fray_manager.hpp.

◆ _logIds

std::unordered_map<ProjectManager*, std::string> fray::FrayManager::_logIds
private

Maps non-owning project pointers to their open log IDs; guarded by _mutex.

Definition at line 272 of file fray_manager.hpp.

◆ _logQueue

std::shared_ptr<threads::TaskQueue> fray::FrayManager::_logQueue = std::make_shared<threads::TaskQueue>()
private

Serializes application log writes and asynchronous history reads.

Definition at line 187 of file fray_manager.hpp.

◆ _logResolvedNotifier

std::function<void(const std::string& openingTag, const std::string& id)> fray::FrayManager::_logResolvedNotifier
private

Callback mapping an opening log tag to a project ID; guarded by _mutex.

Definition at line 221 of file fray_manager.hpp.

◆ _logs

logs::LogStore fray::FrayManager::_logs
private

Store for engine and project log entries.

Definition at line 268 of file fray_manager.hpp.

◆ _logThread

threads::ThreadManager::Id fray::FrayManager::_logThread = 0
private

Worker for application log writes and history reads.

Definition at line 185 of file fray_manager.hpp.

◆ _mutex

std::mutex fray::FrayManager::_mutex
private

Protects the project registry, ordering, closing state, shutdown state, and notifiers.

Definition at line 211 of file fray_manager.hpp.

◆ _openingDecisions

std::unordered_map<std::string, OpeningDecisionStatus> fray::FrayManager::_openingDecisions
private

Latest queued database-choice action for each canonical project path, guarded by _mutex.

Definition at line 236 of file fray_manager.hpp.

◆ _openingNotifier

std::function<void(const OpeningStatus&)> fray::FrayManager::_openingNotifier
private

Publisher for opening state changes, guarded by _mutex.

Definition at line 240 of file fray_manager.hpp.

◆ _openingStatuses

std::unordered_map<std::string, OpeningStatus> fray::FrayManager::_openingStatuses
private

Latest project open for each canonical path, guarded by _mutex.

Definition at line 238 of file fray_manager.hpp.

◆ _openOrder

std::vector<ProjectManager*> fray::FrayManager::_openOrder
private

Non-owning projects in opening order; guarded by _mutex.

Definition at line 246 of file fray_manager.hpp.

◆ _ownedThreads

std::unique_ptr<threads::ThreadManager> fray::FrayManager::_ownedThreads
private

Optional owned thread manager used by the standalone constructor.

Definition at line 163 of file fray_manager.hpp.

◆ _pendingPrompts

std::unordered_map<uint64_t, PendingPrompt> fray::FrayManager::_pendingPrompts
private

Pending prompts indexed by request message ID; guarded by _promptMutex.

Definition at line 343 of file fray_manager.hpp.

◆ _projectLogPaths

std::unordered_map<std::string, std::shared_ptr<ProjectLogWorker> > fray::FrayManager::_projectLogPaths
private

Resolves registered project paths to log workers; guarded by _projectLogsMutex.

Definition at line 193 of file fray_manager.hpp.

◆ _projectLogRoutes

std::unordered_map<std::string, std::shared_ptr<ProjectLogWorker> > fray::FrayManager::_projectLogRoutes
private

Routes project IDs and temporary opening tags to their dedicated workers.

Definition at line 191 of file fray_manager.hpp.

◆ _projectLogsMutex

std::mutex fray::FrayManager::_projectLogsMutex
private

Protects the opening-tag and project-ID log routes.

Definition at line 189 of file fray_manager.hpp.

◆ _projects

Projects fray::FrayManager::_projects
private

Project entries keyed by canonical working path; guarded by _mutex.

Definition at line 234 of file fray_manager.hpp.

◆ _promptClosing

bool fray::FrayManager::_promptClosing = false
private

Rejects new prompts after closing begins; guarded by _promptMutex.

Definition at line 347 of file fray_manager.hpp.

◆ _promptMutex

std::mutex fray::FrayManager::_promptMutex
private

Protects pending prompts and prompt shutdown state.

Definition at line 339 of file fray_manager.hpp.

◆ _renameFailureNotifier

std::function<void(const std::string& id)> fray::FrayManager::_renameFailureNotifier
private

Reports asynchronously failed project renames; guarded by _mutex.

Definition at line 217 of file fray_manager.hpp.

◆ _renameNotifier

std::function<void(const std::string& id, const std::string& path, const std::string& name)> fray::FrayManager::_renameNotifier
private

Rename callback receiving project ID, canonical path key, and name; guarded by _mutex.

Definition at line 215 of file fray_manager.hpp.

◆ _retiredProjects

std::vector<Entry> fray::FrayManager::_retiredProjects
private

Closed project workers retained until they have both stopped; guarded by _mutex.

Definition at line 242 of file fray_manager.hpp.

◆ _shutdown

bool fray::FrayManager::_shutdown = false
private

Whether shutdown has progressed past application queue termination; guarded by _mutex.

Definition at line 197 of file fray_manager.hpp.

◆ _shutdownCloseNotifier

std::function<void(const std::string& name, const std::string& id, F_err result, bool packaged, const std::string& path)> fray::FrayManager::_shutdownCloseNotifier
private

Callback reporting a project closed by shutdown: name, ID, result, whether it was packaged, and resulting path; guarded by _mutex.

Definition at line 226 of file fray_manager.hpp.

◆ _shutdownEntries

std::unordered_map<ProjectManager*, ShutdownEntry> fray::FrayManager::_shutdownEntries
private

Definition at line 200 of file fray_manager.hpp.

◆ _shutdownPhase

ShutdownPhase fray::FrayManager::_shutdownPhase = ShutdownPhase::running
private

Shutdown state and project ownership; guarded by _mutex.

Definition at line 199 of file fray_manager.hpp.

◆ _shutdownSession

ProjectSession fray::FrayManager::_shutdownSession
private

Shutdown snapshot and capture state; guarded by _mutex.

Definition at line 202 of file fray_manager.hpp.

◆ _shutdownSessionCaptured

bool fray::FrayManager::_shutdownSessionCaptured = false
private

Definition at line 203 of file fray_manager.hpp.

◆ _states

std::unordered_map<std::string, std::unique_ptr<state::StateManager> > fray::FrayManager::_states
private

Open application state namespaces, guarded by _mutex.

Definition at line 159 of file fray_manager.hpp.

◆ _threads

threads::ThreadManager* fray::FrayManager::_threads
private

Non-owning pointer to the owned or externally supplied thread manager.

Definition at line 167 of file fray_manager.hpp.


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