OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimJob.cpp
Go to the documentation of this file.
2 
3 
5 {
7  run();
8  if(!(state() & ossimJob_CANCEL))
9  {
11  }
12 }
13 
14 void ossimJob::setState(int value, bool on)
15 {
16  std::shared_ptr<ossimJob> thisShared = getSharedFromThis();
17 
18  // we will need to make sure that the state flags are set properly
19  // so if you turn on running then you can't have finished or ready turned onturned on
20  // but can stil have cancel turned on
21  //
22  int newState = m_state;
23  if(on)
24  {
25  newState = ((newState | value)&ossimJob_ALL);
26  }
27  else
28  {
29  newState = ((newState & ~value)&ossimJob_ALL);
30  }
31 
32  int oldState = 0;
33  int currentState = 0;
34  std::shared_ptr<ossimJobCallback> callback;
35 
36  bool stateChangedFlag = false;
37  {
38  std::lock_guard<std::mutex> lock(m_jobMutex);
39 
40  stateChangedFlag = newState != m_state;
41  oldState = m_state;
42  m_state = static_cast<State>(newState);
43  currentState = m_state;
45  }
46 
47  if(stateChangedFlag&&callback)
48  {
49  if(!(oldState&ossimJob_READY)&&
50  (currentState&ossimJob_READY))
51  {
52  callback->ready(thisShared);
53  }
54  else if(!(oldState&ossimJob_RUNNING)&&
55  (currentState&ossimJob_RUNNING))
56  {
57  callback->started(thisShared);
58  }
59  else if(!(oldState&ossimJob_CANCEL)&&
60  (currentState&ossimJob_CANCEL))
61  {
62  callback->canceled(thisShared);
63  }
64  else if(!(oldState&ossimJob_FINISHED)&&
65  (currentState&ossimJob_FINISHED))
66  {
67  callback->finished(thisShared);
68  }
69  }
70 }
71 
State state() const
Definition: ossimJob.h:242
State
This is a Bit vector.
Definition: ossimJob.h:158
std::mutex m_jobMutex
Definition: ossimJob.h:468
virtual void start()
Main entry point to the job.
Definition: ossimJob.cpp:4
std::shared_ptr< ossimJobCallback > m_callback
Definition: ossimJob.h:474
virtual void setState(int value, bool on=true)
Will allow you to set the state of the job.
Definition: ossimJob.cpp:14
State m_state
Definition: ossimJob.h:472
virtual void run()=0
Abstract method and must be overriden by the base class.
std::shared_ptr< ossimJobCallback > callback()
Definition: ossimJob.h:465
std::shared_ptr< ossimJob > getSharedFromThis()
This is a convenience method to get the shared representation of this pointer.
Definition: ossimJob.h:185