1 | /**************************************************************************************** |
2 | |
3 | Copyright (C) 2015 Autodesk, Inc. |
4 | All rights reserved. |
5 | |
6 | Use of this software is subject to the terms of the Autodesk license agreement |
7 | provided at the time of installation or download, or which otherwise accompanies |
8 | this software in either electronic or hard copy form. |
9 | |
10 | ****************************************************************************************/ |
11 | |
12 | //! \file fbxprogress.h |
13 | #ifndef _FBXSDK_FILEIO_PROGRESS_H_ |
14 | #define _FBXSDK_FILEIO_PROGRESS_H_ |
15 | |
16 | #include <fbxsdk/fbxsdk_def.h> |
17 | |
18 | #include <fbxsdk/core/base/fbxstring.h> |
19 | |
20 | #include <fbxsdk/fbxsdk_nsbegin.h> |
21 | |
22 | typedef bool (*FbxProgressCallback)(void* pArgs, float pPercentage, const char* pStatus); |
23 | |
24 | #if !defined(FBXSDK_ENV_WINSTORE) && !defined(FBXSDK_ENV_EMSCRIPTEN) |
25 | class FbxSpinLock; |
26 | #endif |
27 | |
28 | /** Class for progress reporting |
29 | * \nosubgrouping |
30 | */ |
31 | class FBXSDK_DLL FbxProgress |
32 | { |
33 | public: |
34 | /** Register a callback function for progress reporting in single thread mode. |
35 | * \param pCallback Pointer of the callback function. |
36 | * \param pArgs Pointer to the optional arguments passed to the callback function. */ |
37 | void SetProgressCallback(FbxProgressCallback pCallback, void* pArgs=NULL); |
38 | |
39 | /** Set the total amount of workload needed to complete the progress. |
40 | * \param pTotal Total amount of workload. |
41 | * \remark The default total is 100.0. */ |
42 | void SetTotal(float pTotal); |
43 | |
44 | /** Set the threshold at which the progress callback should be called. |
45 | * \param pThreshold The threshold value, between 0.0 and 100.0, that triggers the callback. |
46 | * \remark The default threshold is 1.0, meaning that every 1% the callback is triggered. */ |
47 | void SetThreshold(float pThreshold); |
48 | |
49 | /** Update current progress with recent workload. |
50 | * \param pDelta Delta amount of workload progressed so far. |
51 | * \param pStatus Optional current progress status string. |
52 | * \remark If a callback is set, it will be called upon caling this function. */ |
53 | void Update(float pDelta, const char* pStatus=NULL); |
54 | |
55 | //! Reset the progress status percentage and status string. |
56 | void Reset(); |
57 | |
58 | /** Retrieve the progress status. |
59 | * \param pStatus Optional current progress status string. |
60 | * \return The current progress percentage. */ |
61 | float GetProgress(FbxString* pStatus=NULL); |
62 | |
63 | /** Set the progress status to completed. |
64 | * \param pStatus Optional current progress status string. */ |
65 | void Complete(const char* pStatus=NULL); |
66 | |
67 | //! Cancel this progress. |
68 | void Cancel(); |
69 | |
70 | //! Query whether user canceled this progress. |
71 | inline bool IsCanceled() const { return mCanceled; } |
72 | |
73 | /***************************************************************************************************************************** |
74 | ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! ** |
75 | *****************************************************************************************************************************/ |
76 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
77 | FbxProgress(); |
78 | ~FbxProgress(); |
79 | |
80 | private: |
81 | void Acquire(); |
82 | void Release(); |
83 | float GetPercent() const; |
84 | bool ExecuteCallback() const; |
85 | |
86 | #if !defined(FBXSDK_ENV_WINSTORE) && !defined(FBXSDK_ENV_EMSCRIPTEN) |
87 | FbxSpinLock* mLock; |
88 | #endif |
89 | float mCurrent; |
90 | float mPrevious; |
91 | float mTotal; |
92 | float mThreshold; |
93 | FbxString mStatus; |
94 | FbxProgressCallback mCallback; |
95 | void* mCallbackArgs; |
96 | bool mCanceled; |
97 | #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/ |
98 | }; |
99 | |
100 | #include <fbxsdk/fbxsdk_nsend.h> |
101 | |
102 | #endif /* _FBXSDK_FILEIO_PROGRESS_H_ */ |
103 | |