Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
ProgressMonitor.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
6#include "ProgressMonitor.h"
7
8using namespace Stroika::Foundation;
10
11/*
12 ********************************************************************************
13 **************************** ProgressMonitor ***********************************
14 ********************************************************************************
15 */
17 : fRep_{make_shared<Rep_> ()}
18{
19}
20
23{
24 fRep_->fWorkThread_ = workThread;
25}
26
27ProgressMonitor::ProgressMonitor (ChangedCallbackType callback, Thread::Ptr workThread)
28 : ProgressMonitor{workThread}
29{
30 AddOnProgressCallback (callback);
31}
32
34 : ProgressMonitor{workThread}
35{
36 for (auto i : callbacks) {
38 }
39}
40
42{
43 RequireNotNull (fRep_);
44 fRep_->fCallbacks_.rwget ().rwref ().Append (make_shared<ChangedCallbackType> (progressChangedCallback));
45}
46
48{
49 RequireNotNull (fRep_);
50 fRep_->fCanceled_ = true;
51 if (fRep_->fWorkThread_ != nullptr) {
52 fRep_->fWorkThread_.Abort ();
53 }
54}
55
56/*
57 ********************************************************************************
58 *************************** ProgressMonitor::Updater ***************************
59 ********************************************************************************
60 */
61void ProgressMonitor::Updater::CallNotifyProgress_ () const noexcept
62{
63 RequireNotNull (fRep_);
64 for (shared_ptr<ChangedCallbackType> f : fRep_->fCallbacks_.load ()) {
65 // NB: a throw from ChangedCallbackType is DOCUMENTED to be illegal and will result in 'unexpected' - cuz of noexcept on this function (even threadabort)
66 (*f) (ProgressMonitor{fRep_}); // callbacks are noexcept, and should never hold a lock (or at least always guaraneed very short lived)
67 }
68}
#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