forked from ossimlabs/ossim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathossimJob.cpp
More file actions
71 lines (62 loc) · 1.64 KB
/
Copy pathossimJob.cpp
File metadata and controls
71 lines (62 loc) · 1.64 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
#include <ossim/parallel/ossimJob.h>
void ossimJob::start()
{
setState(ossimJob_RUNNING);
run();
if(!(state() & ossimJob_CANCEL))
{
setState(ossimJob_FINISHED);
}
}
void ossimJob::setState(int value, bool on)
{
std::shared_ptr<ossimJob> thisShared = getSharedFromThis();
// we will need to make sure that the state flags are set properly
// so if you turn on running then you can't have finished or ready turned onturned on
// but can stil have cancel turned on
//
int newState = m_state;
if(on)
{
newState = ((newState | value)&ossimJob_ALL);
}
else
{
newState = ((newState & ~value)&ossimJob_ALL);
}
int oldState = 0;
int currentState = 0;
std::shared_ptr<ossimJobCallback> callback;
bool stateChangedFlag = false;
{
std::lock_guard<std::mutex> lock(m_jobMutex);
stateChangedFlag = newState != m_state;
oldState = m_state;
m_state = static_cast<State>(newState);
currentState = m_state;
callback = m_callback;
}
if(stateChangedFlag&&callback)
{
if(!(oldState&ossimJob_READY)&&
(currentState&ossimJob_READY))
{
callback->ready(thisShared);
}
else if(!(oldState&ossimJob_RUNNING)&&
(currentState&ossimJob_RUNNING))
{
callback->started(thisShared);
}
else if(!(oldState&ossimJob_CANCEL)&&
(currentState&ossimJob_CANCEL))
{
callback->canceled(thisShared);
}
else if(!(oldState&ossimJob_FINISHED)&&
(currentState&ossimJob_FINISHED))
{
callback->finished(thisShared);
}
}
}