|
| 1 | +/*++ |
| 2 | +
|
| 3 | +Copyright (C) 2018 Autodesk Inc. |
| 4 | +
|
| 5 | +All rights reserved. |
| 6 | +
|
| 7 | +Redistribution and use in source and binary forms, with or without modification, |
| 8 | +are permitted provided that the following conditions are met: |
| 9 | +
|
| 10 | +1. Redistributions of source code must retain the above copyright notice, this |
| 11 | +list of conditions and the following disclaimer. |
| 12 | +2. Redistributions in binary form must reproduce the above copyright notice, |
| 13 | +this list of conditions and the following disclaimer in the documentation |
| 14 | +and/or other materials provided with the distribution. |
| 15 | +
|
| 16 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 17 | +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| 20 | +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 | +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 | +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 23 | +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | +
|
| 27 | +Abstract: Progress Monitor |
| 28 | +
|
| 29 | +--*/ |
| 30 | + |
| 31 | +#ifndef __NMR_PROGRESSMONITOR |
| 32 | +#define __NMR_PROGRESSMONITOR |
| 33 | + |
| 34 | +#include "Common/3MF_ProgressTypes.h" |
| 35 | + |
| 36 | +#include <memory> |
| 37 | +#include <mutex> |
| 38 | +#include <stack> |
| 39 | + |
| 40 | +namespace NMR |
| 41 | +{ |
| 42 | +#define PROGRESS_SLICEUPDATE 1000 |
| 43 | +#define PROGRESS_NODEUPDATE 100000 |
| 44 | +#define PROGRESS_TRIANGLEUPDATE 100000 |
| 45 | +#define PROGRESS_READUPDATE 20000 |
| 46 | +#define PROGRESS_READSLICESUPDATE 100 |
| 47 | +#define PROGRESS_READBUFFERUPDATE 100 |
| 48 | + |
| 49 | + class CProgressMonitor |
| 50 | + { |
| 51 | + public: |
| 52 | + CProgressMonitor(); |
| 53 | + void SetProgressCallback(Lib3MFProgressCallback callback, void* userData); |
| 54 | + void ClearProgressCallback(); |
| 55 | + // Returns true if the last callback call returned false |
| 56 | + bool WasAborted(); |
| 57 | + // If Progress() returns false, the task calling it should try to abort |
| 58 | + bool QueryCancelled(); |
| 59 | + bool Progress(double progress, ProgressIdentifier identifier); |
| 60 | + |
| 61 | + static void GetProgressMessage(ProgressIdentifier progressIdentifier, const char ** progressString); |
| 62 | + |
| 63 | + void PushLevel(double relativeStart, double relativeEnd); |
| 64 | + std::pair<double, double> PopLevel(); |
| 65 | + void ResetLevels(); |
| 66 | + private: |
| 67 | + Lib3MFProgressCallback m_progressCallback; |
| 68 | + void* m_userData; |
| 69 | + bool m_lastCallbackResult; |
| 70 | + std::stack<std::pair<double, double>> m_levels; |
| 71 | + |
| 72 | + std::pair<double, double> Level(); |
| 73 | + std::mutex m_callbackMutex; |
| 74 | + }; |
| 75 | + |
| 76 | + typedef std::shared_ptr <CProgressMonitor> PProgressMonitor; |
| 77 | +}; |
| 78 | + |
| 79 | +#endif // __NMR_PROGRESSMONITOR |
0 commit comments