OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ossimJob Class Referenceabstract

This is the job callback interface It allows one to attach and listen for different states of the job and if properties have changed. More...

#include <ossimJob.h>

Inheritance diagram for ossimJob:
ossimFileWalker::ossimFileWalkerJob ossimHlzTool::PatchProcessorJob ossimMultiThreadSequencer::ossimGetTileJob RadialProcessorJob SectorProcessorJob ossimHlzTool::LsFitPatchProcessorJob ossimHlzTool::NormPatchProcessorJob

Public Types

enum  State {
  ossimJob_NONE = 0, ossimJob_READY = 1, ossimJob_RUNNING = 2, ossimJob_CANCEL = 4,
  ossimJob_FINISHED = 8, ossimJob_ALL = (ossimJob_READY|ossimJob_RUNNING|ossimJob_CANCEL|ossimJob_FINISHED)
}
 
This is a Bit vector. More...
 
typedef std::list< std::shared_ptr< ossimJob > > List
 

Public Member Functions

 ossimJob ()
 
virtual void start ()
 Main entry point to the job. More...
 
std::shared_ptr< ossimJobgetSharedFromThis ()
 This is a convenience method to get the shared representation of this pointer. More...
 
std::shared_ptr< const ossimJobgetSharedFromThis () const
 This is a convenience method to get the shared representation of this pointer. More...
 
void setPercentComplete (double value)
 When the pernet complete is set for the job it will call any callbacks and nofity percentCompleteChanged. More...
 
void setPriority (double value)
 sets the priority of the job More...
 
double priority () const
 
virtual void release ()
 If derived interfaces implement a block this will allow one to release. More...
 
State state () const
 
virtual void resetState (int value)
 Will clear out the state and the call setState. More...
 
virtual void setState (int value, bool on=true)
 Will allow you to set the state of the job. More...
 
bool isCanceled () const
 
virtual void cancel ()
 Sets the state if the object as cancelled. More...
 
virtual void ready ()
 Sets the state if the object as ready. More...
 
virtual void running ()
 Sets the state if the object as running. More...
 
virtual void finished ()
 Sets the state if the object as finished. More...
 
bool isReady () const
 
bool isStopped () const
 
bool isFinished () const
 
bool isRunning () const
 
void setCallback (std::shared_ptr< ossimJobCallback > callback)
 
void setName (const ossimString &value)
 Sets the name of a job. More...
 
const ossimStringname () const
 
void setId (const ossimString &value)
 
const ossimStringid () const
 
void setDescription (const ossimString &value)
 
const ossimStringdescription () const
 
std::shared_ptr< ossimJobCallbackcallback ()
 

Protected Member Functions

virtual void run ()=0
 Abstract method and must be overriden by the base class. More...
 

Protected Attributes

std::mutex m_jobMutex
 
ossimString m_name
 
ossimString m_description
 
ossimString m_id
 
State m_state
 
double m_priority
 
std::shared_ptr< ossimJobCallbackm_callback
 

Detailed Description

This is the job callback interface It allows one to attach and listen for different states of the job and if properties have changed.

// Put your includes here:
// System includes:
#include <memory>
#include <iostream>
class TestJob : public ossimJob
{
public:
TestJob(){}
protected:
virtual void run()
{
std:cout << "Running Job\n";
std::cout << "Finished Running Job\n";
}
};
class MyCallback : public ossimJobCallback
{
public:
MyCallback(){}
virtual void started(std::shared_ptr<ossimJob> job)
{
std::cout << "Started job\n";
}
virtual void finished(std::shared_ptr<ossimJob> job)
{
std::cout << "Finished job\n";
}
};
int main(int argc, char *argv[])
{
std::shared_ptr<TestJob> job = std::make_shared<TestJob>();
job->setCallback(std::make_shared<MyCallback>());
job->start();
return 0;
}

Definition at line 149 of file ossimJob.h.

Member Typedef Documentation

◆ List

typedef std::list<std::shared_ptr<ossimJob> > ossimJob::List

Definition at line 152 of file ossimJob.h.

Member Enumeration Documentation

◆ State


This is a Bit vector.

The only value that can be assigned as both active is FINISHED and CANCEL. CANCELED job may not yet be finished. Once the job is finished the Cancel is complete

Enumerator
ossimJob_NONE 
ossimJob_READY 
ossimJob_RUNNING 
ossimJob_CANCEL 
ossimJob_FINISHED 
ossimJob_ALL 

Definition at line 158 of file ossimJob.h.

Constructor & Destructor Documentation

◆ ossimJob()

ossimJob::ossimJob ( )
inline

Definition at line 168 of file ossimJob.h.

Member Function Documentation

◆ callback()

std::shared_ptr<ossimJobCallback> ossimJob::callback ( )
inline
Returns
the callback

Definition at line 465 of file ossimJob.h.

Referenced by setState().

465 {return m_callback;}
std::shared_ptr< ossimJobCallback > m_callback
Definition: ossimJob.h:474

◆ cancel()

virtual void ossimJob::cancel ( )
inlinevirtual

Sets the state if the object as cancelled.

Definition at line 291 of file ossimJob.h.

292  {
293  // append the cancel flag to current state
295  }
virtual void setState(int value, bool on=true)
Will allow you to set the state of the job.
Definition: ossimJob.cpp:14

◆ description()

const ossimString& ossimJob::description ( ) const
inline
Returns
the desciption of the job

Definition at line 456 of file ossimJob.h.

457  {
458  std::lock_guard<std::mutex> lock(m_jobMutex);
459  return m_description;
460  }
ossimString m_description
Definition: ossimJob.h:470
std::mutex m_jobMutex
Definition: ossimJob.h:468

◆ finished()

virtual void ossimJob::finished ( )
inlinevirtual

Sets the state if the object as finished.

Definition at line 316 of file ossimJob.h.

Referenced by ossimMultiThreadSequencer::ossimGetTileJob::run().

317  {
318  int newState = 0;
319  {
320  // maintain the cancel flag so we can indicate the job has now finished
321  std::lock_guard<std::mutex> lock(m_jobMutex);
322  newState = ((m_state & ossimJob_CANCEL) |
324  }
325  // now reset to the new state
326  resetState(newState);
327  }
virtual void resetState(int value)
Will clear out the state and the call setState.
Definition: ossimJob.h:253
std::mutex m_jobMutex
Definition: ossimJob.h:468
State m_state
Definition: ossimJob.h:472

◆ getSharedFromThis() [1/2]

std::shared_ptr<ossimJob> ossimJob::getSharedFromThis ( )
inline

This is a convenience method to get the shared representation of this pointer.

Returns
the shared pointer

Definition at line 185 of file ossimJob.h.

Referenced by setState().

185  {
186  return shared_from_this();
187  }

◆ getSharedFromThis() [2/2]

std::shared_ptr<const ossimJob> ossimJob::getSharedFromThis ( ) const
inline

This is a convenience method to get the shared representation of this pointer.

Returns
the shared pointer

Definition at line 195 of file ossimJob.h.

195  {
196  return shared_from_this();
197  }

◆ id()

const ossimString& ossimJob::id ( ) const
inline

Definition at line 428 of file ossimJob.h.

429  {
430  std::lock_guard<std::mutex> lock(m_jobMutex);
431  return m_id;
432  }
std::mutex m_jobMutex
Definition: ossimJob.h:468
ossimString m_id
Definition: ossimJob.h:471

◆ isCanceled()

bool ossimJob::isCanceled ( ) const
inline
Returns
true if the job is in a cancel state and false otherwise

Definition at line 282 of file ossimJob.h.

283  {
284  std::lock_guard<std::mutex> lock(m_jobMutex);
285  return (m_state & ossimJob_CANCEL);
286  }
std::mutex m_jobMutex
Definition: ossimJob.h:468
State m_state
Definition: ossimJob.h:472

◆ isFinished()

bool ossimJob::isFinished ( ) const
inline
Returns
true if the state of the object is in a finished state.

Definition at line 350 of file ossimJob.h.

351  {
352  std::lock_guard<std::mutex> lock(m_jobMutex);
353  return (m_state & ossimJob_FINISHED);
354  }
std::mutex m_jobMutex
Definition: ossimJob.h:468
State m_state
Definition: ossimJob.h:472

◆ isReady()

bool ossimJob::isReady ( ) const
inline
Returns
true if the state of the object is in a ready state.

Definition at line 332 of file ossimJob.h.

333  {
334  std::lock_guard<std::mutex> lock(m_jobMutex);
335  return m_state & ossimJob_READY;
336  }
std::mutex m_jobMutex
Definition: ossimJob.h:468
State m_state
Definition: ossimJob.h:472

◆ isRunning()

bool ossimJob::isRunning ( ) const
inline
Returns
true if the state of the object is in a running state.

Definition at line 359 of file ossimJob.h.

360  {
361  std::lock_guard<std::mutex> lock(m_jobMutex);
362  return (m_state & ossimJob_RUNNING);
363  }
std::mutex m_jobMutex
Definition: ossimJob.h:468
State m_state
Definition: ossimJob.h:472

◆ isStopped()

bool ossimJob::isStopped ( ) const
inline
Returns
true if the state of the object is in some kind of stopped state.

Definition at line 341 of file ossimJob.h.

342  {
343  std::lock_guard<std::mutex> lock(m_jobMutex);
344  return (m_state & ossimJob_FINISHED);
345  }
std::mutex m_jobMutex
Definition: ossimJob.h:468
State m_state
Definition: ossimJob.h:472

◆ name()

const ossimString& ossimJob::name ( ) const
inline
Returns
the name of the job

Definition at line 398 of file ossimJob.h.

399  {
400  std::lock_guard<std::mutex> lock(m_jobMutex);
401  return m_name;
402  }
std::mutex m_jobMutex
Definition: ossimJob.h:468
ossimString m_name
Definition: ossimJob.h:469

◆ priority()

double ossimJob::priority ( ) const
inline

Definition at line 228 of file ossimJob.h.

229  {
230  return m_priority;
231  }
double m_priority
Definition: ossimJob.h:473

◆ ready()

virtual void ossimJob::ready ( )
inlinevirtual

Sets the state if the object as ready.

Definition at line 300 of file ossimJob.h.

301  {
303  }
virtual void resetState(int value)
Will clear out the state and the call setState.
Definition: ossimJob.h:253

◆ release()

virtual void ossimJob::release ( )
inlinevirtual

If derived interfaces implement a block this will allow one to release.

Derived classes must override.

Definition at line 237 of file ossimJob.h.

237 {}

◆ resetState()

virtual void ossimJob::resetState ( int  value)
inlinevirtual

Will clear out the state and the call setState.

Parameters
valueis the state you wish to reset to

Definition at line 253 of file ossimJob.h.

254  {
255  m_jobMutex.lock();
256  if(value != m_state)
257  {
259  m_jobMutex.unlock();
260  setState(value);
261  }
262  else
263  {
264  m_jobMutex.unlock();
265  }
266 
267  }
std::mutex m_jobMutex
Definition: ossimJob.h:468
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

◆ run()

virtual void ossimJob::run ( )
protectedpure virtual

Abstract method and must be overriden by the base class.

The base ossimJob will call run from the start method after setting some variables.

Implemented in ossimFileWalker::ossimFileWalkerJob, RadialProcessorJob, SectorProcessorJob, ossimHlzTool::PatchProcessorJob, and ossimMultiThreadSequencer::ossimGetTileJob.

Referenced by start().

◆ running()

virtual void ossimJob::running ( )
inlinevirtual

Sets the state if the object as running.

Definition at line 308 of file ossimJob.h.

Referenced by ossimMultiThreadSequencer::ossimGetTileJob::run().

309  {
311  }
virtual void resetState(int value)
Will clear out the state and the call setState.
Definition: ossimJob.h:253

◆ setCallback()

void ossimJob::setCallback ( std::shared_ptr< ossimJobCallback callback)
inline
Parameters
callbackcallback used to call different state of a job

Definition at line 368 of file ossimJob.h.

369  {
370  std::lock_guard<std::mutex> lock(m_jobMutex);
372  }
std::mutex m_jobMutex
Definition: ossimJob.h:468
std::shared_ptr< ossimJobCallback > m_callback
Definition: ossimJob.h:474
std::shared_ptr< ossimJobCallback > callback()
Definition: ossimJob.h:465

◆ setDescription()

void ossimJob::setDescription ( const ossimString value)
inline

Definition at line 437 of file ossimJob.h.

438  {
439  bool changed = false;
440  std::shared_ptr<ossimJobCallback> callback;
441  {
442  std::lock_guard<std::mutex> lock(m_jobMutex);
443  changed = value!=m_description;
444  m_description = value;
446  }
447  if(changed&&callback)
448  {
449  callback->descriptionChanged(value, getSharedFromThis());
450  }
451  }
ossimString m_description
Definition: ossimJob.h:470
std::mutex m_jobMutex
Definition: ossimJob.h:468
std::shared_ptr< ossimJobCallback > m_callback
Definition: ossimJob.h:474
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

◆ setId()

void ossimJob::setId ( const ossimString value)
inline

Definition at line 409 of file ossimJob.h.

410  {
411  bool changed = false;
412  std::shared_ptr<ossimJobCallback> callback;
413  {
414  std::lock_guard<std::mutex> lock(m_jobMutex);
415  changed = value!=m_id;
416  m_id = value;
418  }
419  if(changed&&callback)
420  {
421  callback->idChanged(value, getSharedFromThis());
422  }
423  }
std::mutex m_jobMutex
Definition: ossimJob.h:468
std::shared_ptr< ossimJobCallback > m_callback
Definition: ossimJob.h:474
ossimString m_id
Definition: ossimJob.h:471
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

◆ setName()

void ossimJob::setName ( const ossimString value)
inline

Sets the name of a job.

Parameters
valuethe name of the job

Definition at line 379 of file ossimJob.h.

380  {
381  bool changed = false;
382  std::shared_ptr<ossimJobCallback> callback;
383  {
384  std::lock_guard<std::mutex> lock(m_jobMutex);
385  changed = value!=m_name;
386  m_name = value;
388  }
389  if(changed&&callback)
390  {
391  callback->nameChanged(value, getSharedFromThis());
392  }
393  }
std::mutex m_jobMutex
Definition: ossimJob.h:468
std::shared_ptr< ossimJobCallback > m_callback
Definition: ossimJob.h:474
ossimString m_name
Definition: ossimJob.h:469
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

◆ setPercentComplete()

void ossimJob::setPercentComplete ( double  value)
inline

When the pernet complete is set for the job it will call any callbacks and nofity percentCompleteChanged.

percent complete

Definition at line 205 of file ossimJob.h.

206  {
207  std::lock_guard<std::mutex> lock(m_jobMutex);
208  if(m_callback)
209  {
210  m_callback->percentCompleteChanged(value, getSharedFromThis());
211  }
212  }
std::mutex m_jobMutex
Definition: ossimJob.h:468
std::shared_ptr< ossimJobCallback > m_callback
Definition: ossimJob.h:474
std::shared_ptr< ossimJob > getSharedFromThis()
This is a convenience method to get the shared representation of this pointer.
Definition: ossimJob.h:185

◆ setPriority()

void ossimJob::setPriority ( double  value)
inline

sets the priority of the job

Parameters
valuepriority value

Definition at line 219 of file ossimJob.h.

220  {
221  std::lock_guard<std::mutex> lock(m_jobMutex);
222  m_priority = value;
223  }
double m_priority
Definition: ossimJob.h:473
std::mutex m_jobMutex
Definition: ossimJob.h:468

◆ setState()

void ossimJob::setState ( int  value,
bool  on = true 
)
virtual

Will allow you to set the state of the job.

Parameters
valueis the state you wish to set to
onwill turn the value on if on is true and turn it off otherwise.

Definition at line 14 of file ossimJob.cpp.

References callback(), getSharedFromThis(), m_callback, m_jobMutex, m_state, ossimJob_ALL, ossimJob_CANCEL, ossimJob_FINISHED, ossimJob_READY, and ossimJob_RUNNING.

Referenced by start().

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 }
State
This is a Bit vector.
Definition: ossimJob.h:158
std::mutex m_jobMutex
Definition: ossimJob.h:468
std::shared_ptr< ossimJobCallback > m_callback
Definition: ossimJob.h:474
State m_state
Definition: ossimJob.h:472
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

◆ start()

void ossimJob::start ( )
virtual

Main entry point to the job.

It will set the state as running and then call the pure virtual method run. Once completed the job is marked finished only if the job was not canceled.

Classes must override the run method.

See also
run.

Definition at line 4 of file ossimJob.cpp.

References ossimJob_CANCEL, ossimJob_FINISHED, ossimJob_RUNNING, run(), setState(), and state().

5 {
7  run();
8  if(!(state() & ossimJob_CANCEL))
9  {
11  }
12 }
State state() const
Definition: ossimJob.h:242
virtual void setState(int value, bool on=true)
Will allow you to set the state of the job.
Definition: ossimJob.cpp:14
virtual void run()=0
Abstract method and must be overriden by the base class.

◆ state()

State ossimJob::state ( ) const
inline
Returns
the state of the object

Definition at line 242 of file ossimJob.h.

Referenced by start().

243  {
244  std::lock_guard<std::mutex> lock(m_jobMutex);
245  return m_state;
246  }
std::mutex m_jobMutex
Definition: ossimJob.h:468
State m_state
Definition: ossimJob.h:472

Member Data Documentation

◆ m_callback

std::shared_ptr<ossimJobCallback> ossimJob::m_callback
protected

Definition at line 474 of file ossimJob.h.

Referenced by setState().

◆ m_description

ossimString ossimJob::m_description
protected

Definition at line 470 of file ossimJob.h.

◆ m_id

ossimString ossimJob::m_id
protected

Definition at line 471 of file ossimJob.h.

◆ m_jobMutex

std::mutex ossimJob::m_jobMutex
mutableprotected

Definition at line 468 of file ossimJob.h.

Referenced by setState().

◆ m_name

ossimString ossimJob::m_name
protected

Definition at line 469 of file ossimJob.h.

◆ m_priority

double ossimJob::m_priority
protected

Definition at line 473 of file ossimJob.h.

◆ m_state

State ossimJob::m_state
protected

Definition at line 472 of file ossimJob.h.

Referenced by setState().


The documentation for this class was generated from the following files: