NDEVR
API Documentation
CachedFactoryIOThread

A thread designed to read and write files using the FactoryIO interface. More...

Inheritance diagram for CachedFactoryIOThread:
[legend]
Collaboration diagram for CachedFactoryIOThread:
[legend]

Public Member Functions

 CachedFactoryIOThread (bool is_read)
 Constructs a CachedFactoryIOThread configured for reading or writing.
void accept ()
 Accepts the current operation, allowing temporary files to be committed.
void cancel ()
 Cancels the current operation, discarding any temporary files or read data.
void deleteReadIDs ()
 Deletes all design objects that were created during a read operation.
void deleteTempFiles ()
 Deletes all temporary files created during a write operation.
bool executeRead (Buffer< FactoryParameters > &requests)
 Executes a read operation for all provided factory parameter requests.
bool executeWrite (Buffer< FactoryParameters > &requests)
 Executes a write operation for all provided factory parameter requests.
ModelFactoryfactory () const
 Returns the ModelFactory used for file I/O operations.
bool isAccepted () const
 Checks whether the operation has been accepted by the user.
bool isFinished () const
 Checks whether the thread has finished processing.
void kill (bool terminate_current)
 Kills the thread, optionally terminating the current operation.
const Buffer< FactoryParameters > & lastRequests () const
 Returns the last completed set of factory parameter requests.
bool readFile (FactoryParameters &file)
 Reads a single file using the ModelFactory.
void requestStopLoad ()
 Requests cancellation of the current in-progress load/save operation.
void reset ()
 Resets the accepted and canceled state so the thread can be reused.
void run () override
 Main thread loop.
void setExceptionHandler (const std::function< void(const Exception &)> &exception_handler)
 Sets a callback to handle exceptions thrown during file operations.
void setFiles (const Buffer< FactoryParameters > &files)
 Sets the files to be processed and triggers a re-evaluation of the current operation.
void setFinishedCallback (const std::function< void(bool success)> &finished_callback)
 Sets a callback invoked when the thread finishes processing.
void stopThread () override
 Stops the thread by killing it and canceling the current operation.
bool writeFile (FactoryParameters &file)
 Writes a single file using the ModelFactory, first to a temporary location.
bool writeTempFiles (ProgressInfo &info)
 Moves temporary files to their final destination after a write operation.
Public Member Functions inherited from Thread
 Thread ()
 Constructs a Thread with a default name.
 Thread (const StringView &name)
 Constructs a Thread with the specified name.
virtual ~Thread ()
 Destroys the Thread and cleans up resources.
void detach ()
 Detaches the thread, allowing it to run independently.
void forceStop ()
 Forces the running flag to false without waiting for the thread to finish.
bool isPrimaryThread () const
 Checks whether this thread is the primary thread.
bool isRunning () const
 Checks whether the thread is currently running.
void join ()
 Blocks the calling thread until this thread finishes execution.
virtual void requestStopThread ()
 Requests the thread to stop without blocking.
void setIsPrimaryThread (bool is_primary_thread)
 Sets whether this thread should be treated as the primary thread.
void setThreadName (const StringView &name)
 Sets the name of this thread.
virtual bool shouldExitThread () const
 Checks whether the thread has been requested to exit.
void start ()
 Starts the thread execution.
const StringthreadName () const
 Gets the name assigned to this thread.

Additional Inherited Members

Static Public Member Functions inherited from Thread
static ThreadCurrentThread ()
 Gets a reference to the Thread object for the calling thread.
static String CurrentThreadName ()
 Gets the name of the current thread.
static void ServiceVirtualThreads ()
 Services any virtual threads that require periodic execution.
static void SetCurrentThreadName (const StringView &name)
 Sets the name of the current thread.
static void StopAllThreads ()
 Stops all tracked threads.
Protected Member Functions inherited from Thread
const std::thread & self ()
 Gets a const reference to the underlying std::thread.
Protected Attributes inherited from Thread
volatile bool m_is_running = false
 Whether the thread is currently running.
volatile bool m_is_single_run = true
 Whether the thread should execute only once before stopping.

Detailed Description

A thread designed to read and write files using the FactoryIO interface.


Thread will perform all actions on a temp file, then move the file when accept() is called.

For write operations, files are first written to a temporary location. When accept() is called, the temporary files are moved to their final destination. This allows the user to confirm or cancel the operation before committing changes to disk. For read operations, the thread reads files into the DesignObjectLookup, and deleteReadIDs() cleans up if the operation is canceled.

Definition at line 52 of file CachedFactoryIOThread.h.

Constructor & Destructor Documentation

◆ CachedFactoryIOThread()

CachedFactoryIOThread::CachedFactoryIOThread ( bool is_read)

Constructs a CachedFactoryIOThread configured for reading or writing.

Parameters
[in]is_readWhether this thread is used for reading (true) or writing (false).

Member Function Documentation

◆ accept()

void CachedFactoryIOThread::accept ( )

Accepts the current operation, allowing temporary files to be committed.

For write operations, this triggers moving temp files to their final destinations.

◆ deleteReadIDs()

void CachedFactoryIOThread::deleteReadIDs ( )

Deletes all design objects that were created during a read operation.

Used to roll back a read when the operation is canceled.

◆ executeRead()

bool CachedFactoryIOThread::executeRead ( Buffer< FactoryParameters > & requests)

Executes a read operation for all provided factory parameter requests.

Parameters
[in]requestsThe list of FactoryParameters describing files to read.
Returns
True if all files were read successfully.

◆ executeWrite()

bool CachedFactoryIOThread::executeWrite ( Buffer< FactoryParameters > & requests)

Executes a write operation for all provided factory parameter requests.

Parameters
[in]requestsThe list of FactoryParameters describing files to write.
Returns
True if all files were written successfully.

◆ factory()

ModelFactory * CachedFactoryIOThread::factory ( ) const
inline

Returns the ModelFactory used for file I/O operations.

Returns
A pointer to the ModelFactory instance.

Definition at line 156 of file CachedFactoryIOThread.h.

◆ isAccepted()

bool CachedFactoryIOThread::isAccepted ( ) const
inline

Checks whether the operation has been accepted by the user.

Returns
True if accept() has been called.

Definition at line 141 of file CachedFactoryIOThread.h.

◆ isFinished()

bool CachedFactoryIOThread::isFinished ( ) const

Checks whether the thread has finished processing.

Returns
True if the thread is no longer updating and has been accepted or canceled.

◆ kill()

void CachedFactoryIOThread::kill ( bool terminate_current)

Kills the thread, optionally terminating the current operation.

Parameters
[in]terminate_currentWhether to cancel the current operation before stopping.

◆ lastRequests()

const Buffer< FactoryParameters > & CachedFactoryIOThread::lastRequests ( ) const
inline

Returns the last completed set of factory parameter requests.

Returns
A const reference to the buffer of FactoryParameters from the last operation.

Definition at line 110 of file CachedFactoryIOThread.h.

◆ readFile()

bool CachedFactoryIOThread::readFile ( FactoryParameters & file)

Reads a single file using the ModelFactory.

Parameters
[in]fileThe FactoryParameters describing the file to read.
Returns
True if the file was read successfully.

◆ requestStopLoad()

void CachedFactoryIOThread::requestStopLoad ( )

Requests cancellation of the current in-progress load/save operation.

Sets the cancel flag on all current FactoryParameters so the operation can exit gracefully.

◆ run()

void CachedFactoryIOThread::run ( )
overridevirtual

Main thread loop.

Waits for file requests and processes them until accepted or canceled.

Handles read and write operations, exception handling, progress reporting, and notifies the finished callback upon completion.

Reimplemented from Thread.

◆ setExceptionHandler()

void CachedFactoryIOThread::setExceptionHandler ( const std::function< void(const Exception &)> & exception_handler)
inline

Sets a callback to handle exceptions thrown during file operations.

Parameters
[in]exception_handlerA function called with the Exception when an error occurs.

Definition at line 117 of file CachedFactoryIOThread.h.

◆ setFiles()

void CachedFactoryIOThread::setFiles ( const Buffer< FactoryParameters > & files)

Sets the files to be processed and triggers a re-evaluation of the current operation.

Any in-progress operation is canceled before the new file list is applied.

Parameters
[in]filesThe list of FactoryParameters describing the files to process.

◆ setFinishedCallback()

void CachedFactoryIOThread::setFinishedCallback ( const std::function< void(bool success)> & finished_callback)
inline

Sets a callback invoked when the thread finishes processing.

Parameters
[in]finished_callbackA function called with true on success, false on failure.

Definition at line 124 of file CachedFactoryIOThread.h.

◆ writeFile()

bool CachedFactoryIOThread::writeFile ( FactoryParameters & file)

Writes a single file using the ModelFactory, first to a temporary location.

Parameters
[in]fileThe FactoryParameters describing the file to write.
Returns
True if the file was written successfully.

◆ writeTempFiles()

bool CachedFactoryIOThread::writeTempFiles ( ProgressInfo & info)

Moves temporary files to their final destination after a write operation.

Parameters
[in]infoProgressInfo to report move progress and errors.
Returns
True if all temporary files were successfully moved.

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