API Documentation
Loading...
Searching...
No Matches
CachedFactoryIOThread.h
Go to the documentation of this file.
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{
41 class DesignObjectLookup;
42 /**--------------------------------------------------------------------------------------------------
43 \brief A thread designed to read and write files using the FactoryIO interface. Thread will perform
44 all actions on a temp file, then move the file when accept() is called.
45 **/
47 {
48 public:
49 CachedFactoryIOThread(bool is_read);
50 void run() override;
52 bool isFinished() const;
54 void kill(bool terminate_current);
55
61 const Buffer<FactoryParameters>& lastRequests() const { return m_last_request; };
62 void stopThread() override;
63 void setExceptionHandler(const std::function<void(const Exception&)>& exception_handler)
64 {
65 m_exception_handler = exception_handler;
66 }
67 void setFinishedCallback(const std::function<void(bool success)>& finished_callback)
68 {
69 m_finished_callback = finished_callback;
70 }
73 bool isAccepted() const {return m_is_accepted;}
74 void accept();
75 void cancel();
76 void reset();
77 ModelFactory* factory() const { return m_factory; };
78 private:
79 volatile bool m_is_canceled = false;
80 volatile bool m_is_accepted = false;
81 volatile bool m_options_changed = false;
82 bool is_updating;
83 volatile bool m_is_read;
84 Buffer<FactoryParameters> m_next_request;//Thread safe
85 Buffer<FactoryParameters> m_current_request;//Not Thread Safe
86 Buffer<FactoryParameters> m_last_request;//Thread Safe
87 Buffer<std::pair<File, File>> m_temp_files;
88 ModelFactory* m_factory;
89 mutable std::mutex m_critical_section;//critical section for this object only
90 std::function<void(const Exception& e)> m_exception_handler;
91 std::function<void(bool success)> m_finished_callback;
92 };
93}
94#endif
#define NDEVR_FACTORY_API
Definition DLLInfo.h:57
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
A thread designed to read and write files using the FactoryIO interface. Thread will perform all acti...
Definition CachedFactoryIOThread.h:47
ModelFactory * factory() const
Definition CachedFactoryIOThread.h:77
void setFiles(const Buffer< FactoryParameters > &files)
void kill(bool terminate_current)
CachedFactoryIOThread(bool is_read)
bool writeFile(FactoryParameters &file)
void setFinishedCallback(const std::function< void(bool success)> &finished_callback)
Definition CachedFactoryIOThread.h:67
void setExceptionHandler(const std::function< void(const Exception &)> &exception_handler)
Definition CachedFactoryIOThread.h:63
bool isAccepted() const
Definition CachedFactoryIOThread.h:73
bool executeRead(Buffer< FactoryParameters > &requests)
bool executeWrite(Buffer< FactoryParameters > &requests)
const Buffer< FactoryParameters > & lastRequests() const
Definition CachedFactoryIOThread.h:61
bool readFile(FactoryParameters &file)
Provides consistent interface to handle errors through the throw expression. All exceptions generated...
Definition Exception.hpp:47
The core logic for importing and exporting files from the model heirarchy. Stores a series of IOFacto...
Definition ModelFactory.h:45
A thread is a single sequence stream within the software.
Definition Thread.h:67
Definition ACIColor.h:37
A container of input information that is to be filled with output information by an IOFactory.
Definition IOFactory.h:61