NDEVR
API Documentation
CachedFactoryIOThread.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: IOFactory
28File: CachedFactoryIOThread
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#if NDEVR_SUPPORTS_THREADING
35#include <NDEVR/ModelFactory.h>
36#include <NDEVR/Thread.h>
37#include <NDEVR/File.h>
38#include <mutex>
39namespace NDEVR
40{
53 {
54 public:
57 CachedFactoryIOThread(bool is_read);
58
63 void run() override;
64
70
73 bool isFinished() const;
74
80
83 void kill(bool terminate_current);
84
89
92
97
102
107
110 const Buffer<FactoryParameters>& lastRequests() const { return m_last_request; };
111
113 void stopThread() override;
114
117 void setExceptionHandler(const std::function<void(const Exception&)>& exception_handler)
118 {
119 m_exception_handler = exception_handler;
120 }
121
124 void setFinishedCallback(const std::function<void(bool success)>& finished_callback)
125 {
126 m_finished_callback = finished_callback;
127 }
128
133
138
141 bool isAccepted() const {return m_is_accepted;}
142
146 void accept();
147
149 void cancel();
150
152 void reset();
153
156 ModelFactory* factory() const { return m_factory; };
157 private:
158 volatile bool m_is_canceled = false;
159 volatile bool m_is_accepted = false;
160 volatile bool m_options_changed = false;
161 bool is_updating;
162 volatile bool m_is_read;
163 Buffer<FactoryParameters> m_next_request;
164 Buffer<FactoryParameters> m_current_request;
165 Buffer<FactoryParameters> m_last_request;
166 Buffer<std::pair<File, File>> m_temp_files;
167 ModelFactory* m_factory;
168 mutable std::mutex m_critical_section;
169 std::function<void(const Exception& e)> m_exception_handler;
170 std::function<void(bool success)> m_finished_callback;
171 };
172}
173#endif
Provides cross-platform DLL export/import macros for the IOFactory module.
#define NDEVR_FACTORY_API
GCC/Clang symbol visibility — marks symbols as visible in the shared library.
Definition DLLInfo.h:92
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
void stopThread() override
Stops the thread by killing it and canceling the current operation.
void setExceptionHandler(const std::function< void(const Exception &)> &exception_handler)
Sets a callback to handle exceptions thrown during file operations.
bool readFile(FactoryParameters &file)
Reads a single file using the ModelFactory.
void kill(bool terminate_current)
Kills the thread, optionally terminating the current operation.
void setFiles(const Buffer< FactoryParameters > &files)
Sets the files to be processed and triggers a re-evaluation of the current operation.
ModelFactory * factory() const
Returns the ModelFactory used for file I/O operations.
void deleteReadIDs()
Deletes all design objects that were created during a read operation.
bool writeFile(FactoryParameters &file)
Writes a single file using the ModelFactory, first to a temporary location.
void reset()
Resets the accepted and canceled state so the thread can be reused.
const Buffer< FactoryParameters > & lastRequests() const
Returns the last completed set of factory parameter requests.
void run() override
Main thread loop.
bool isFinished() const
Checks whether the thread has finished processing.
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 requestStopLoad()
Requests cancellation of the current in-progress load/save operation.
bool executeWrite(Buffer< FactoryParameters > &requests)
Executes a write operation for all provided factory parameter requests.
void setFinishedCallback(const std::function< void(bool success)> &finished_callback)
Sets a callback invoked when the thread finishes processing.
bool executeRead(Buffer< FactoryParameters > &requests)
Executes a read operation for all provided factory parameter requests.
bool isAccepted() const
Checks whether the operation has been accepted by the user.
void deleteTempFiles()
Deletes all temporary files created during a write operation.
CachedFactoryIOThread(bool is_read)
Constructs a CachedFactoryIOThread configured for reading or writing.
bool writeTempFiles(ProgressInfo &info)
Moves temporary files to their final destination after a write operation.
A core class where all Design Objects including models, materials, and geometries are stored.
Provides consistent interface to handle errors through the throw expression.
Definition Exception.hpp:47
The core logic for importing and exporting files from the model hierarchy.
Used with InfoPipe to signal that the system will be using progress.
Thread()
Constructs a Thread with a default name.
The primary namespace for the NDEVR SDK.
A container of input information that is to be filled with output information by an IOFactory.
Definition IOFactory.h:105