-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBatchProcess.cpp
More file actions
executable file
·78 lines (61 loc) · 1.67 KB
/
BatchProcess.cpp
File metadata and controls
executable file
·78 lines (61 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2006-12 HumaNature Studios Inc.
#include "CorePch.h"
#include "BatchProcess.h"
#include "ProcessEvent.h"
DEFINE_TYPE_NS(core, BatchProcess);
namespace core {
BatchProcess::BatchProcess()
: mProgress(0.0f)
, mCurrentProcess(nullptr)
, mNumProcessesCompleted(0)
{
mName = "BatchProcess";
logInfo("BatchProcess","creating 0x%p",this);
}
BatchProcess::~BatchProcess()
{
logInfo("BatchProcess","deleting 0x%p",this);
}
void BatchProcess::onBegin()
{
startNextProcess();
}
void BatchProcess::AddProcess(Process* p)
{
if (NULL != p)
{
mProcessList.push_back(p);
}
}
void BatchProcess::startNextProcess()
{
if(!mProcessList.empty())
{
mCurrentProcess = *mProcessList.begin();
mCurrentProcess->addEventListener(ProcessEvent::PROCESS_ENDED, this, &BatchProcess::handleProcessEnded, true);
mCurrentProcess->begin();
}
else
{
checkDone();
}
}
void BatchProcess::handleProcessEnded(const Event*)
{
mNumProcessesCompleted++;
// pop the completed process from the list
mProcessList.pop_front();
mCurrentProcess = nullptr;
startNextProcess();
checkDone();
}
void BatchProcess::checkDone()
{
mProgress = float(mNumProcessesCompleted) / float(mProcessList.size());
if (mProcessList.empty())
{
// is complete
Process::end();
}
}
} // namespace core