Stroika Library 3.0d23x
 
Loading...
Searching...
No Matches
ProgressMonitor.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
7
8#include "ProgressMonitor.h"
9
10using namespace Stroika::Foundation;
11using namespace Stroika::Foundation::Execution;
12
13using Memory::MakeSharedPtr;
14
15/*
16 ********************************************************************************
17 ******************************* ProgressMonitor ********************************
18 ********************************************************************************
19 */
21 : fRep_{MakeSharedPtr<Rep_> ()}
22{
23}
24
27{
28 fRep_->fWorkThread_ = workThread;
29}
30
31ProgressMonitor::ProgressMonitor (ChangedCallbackType callback, Thread::Ptr workThread)
32 : ProgressMonitor{workThread}
33{
34 AddOnProgressCallback (callback);
35}
36
38 : ProgressMonitor{workThread}
39{
40 for (auto i : callbacks) {
42 }
43}
44
46{
47 RequireNotNull (fRep_);
48 fRep_->fCallbacks_.rwget ().rwref ().Append (MakeSharedPtr<ChangedCallbackType> (progressChangedCallback));
49}
50
52{
53 RequireNotNull (fRep_);
54 fRep_->fCanceled_ = true;
55 if (fRep_->fWorkThread_ != nullptr) {
56 fRep_->fWorkThread_.Abort ();
57 }
58}
59
60/*
61 ********************************************************************************
62 *************************** ProgressMonitor::Updater ***************************
63 ********************************************************************************
64 */
65void ProgressMonitor::Updater::CallNotifyProgress_ () const noexcept
66{
67 RequireNotNull (fRep_);
68 for (shared_ptr<ChangedCallbackType> f : fRep_->fCallbacks_.load ()) {
69 // NB: a throw from ChangedCallbackType is DOCUMENTED to be illegal and will result in 'unexpected' - cuz of noexcept on this function (even threadabort)
70 (*f) (ProgressMonitor{fRep_}); // callbacks are noexcept, and should never hold a lock (or at least always guaraneed very short lived)
71 }
72}
#define RequireNotNull(p)
Definition Assertions.h:347
nonvirtual void AddOnProgressCallback(const ChangedCallbackType &progressChangedCallback)
Thread::Ptr is a (unsynchronized) smart pointer referencing an internally synchronized std::thread ob...
Definition Thread.h:334
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
Definition Iterable.h:237