This file is indexed.

/usr/include/ossim/parallel/ossimJob.h is in libossim-dev 2.2.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
//**************************************************************************************************
//                          OSSIM -- Open Source Software Image Map
//
// LICENSE: See top level LICENSE.txt file.
//
//**************************************************************************************************
//  $Id$
#ifndef ossimJob_HEADER
#define ossimJob_HEADER
#include <ossim/base/ossimObject.h>
#include <ossim/base/ossimString.h>
#include <list>
#include <mutex>
#include <memory>
class ossimJob;

/**
* This is the job callback interface
* It allows one to attach and listen for different states of the job
* and if properties have changed
*
* @code
* #include <ossim/base/Thread.h>
* #include <ossim/parallel/ossimJob.h>
* // 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";
*       ossim::Thread::sleepInSeconds(2);
*       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";
*       ossimJobCallback::started(job);
*    }
*    virtual void finished(std::shared_ptr<ossimJob> job) 
*    {
*       std::cout << "Finished job\n";
*       ossimJobCallback::finished(job);
*    }
* };
* 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;
* }
* @endcode
*/
class OSSIM_DLL ossimJobCallback
{
public:
   ossimJobCallback(std::shared_ptr<ossimJobCallback> nextCallback=0):m_nextCallback(nextCallback){}

   virtual void ready(std::shared_ptr<ossimJob> job)    {if(m_nextCallback) m_nextCallback->ready(job);   }
   virtual void started(std::shared_ptr<ossimJob> job)  {if(m_nextCallback) m_nextCallback->started(job); }
   virtual void finished(std::shared_ptr<ossimJob> job) {if(m_nextCallback) m_nextCallback->finished(job);}
   virtual void canceled(std::shared_ptr<ossimJob> job) {if(m_nextCallback) m_nextCallback->canceled(job);}

   virtual void nameChanged(const ossimString& name, std::shared_ptr<ossimJob> job)
   {if(m_nextCallback) m_nextCallback->nameChanged(name, job);}
   
   virtual void descriptionChanged(const ossimString& description, std::shared_ptr<ossimJob> job)
   {if(m_nextCallback) m_nextCallback->descriptionChanged(description, job);}

   virtual void idChanged(const ossimString& id, std::shared_ptr<ossimJob> job)
   {if(m_nextCallback) m_nextCallback->idChanged(id, job);}

   virtual void percentCompleteChanged(double percentValue, std::shared_ptr<ossimJob> job)
   {if(m_nextCallback) m_nextCallback->percentCompleteChanged(percentValue, job);}

   void setCallback(std::shared_ptr<ossimJobCallback> c){m_nextCallback = c;}
   std::shared_ptr<ossimJobCallback> callback(){return m_nextCallback;}

protected:
   std::shared_ptr<ossimJobCallback> m_nextCallback;
};


/**
* This is the job callback interface
* It allows one to attach and listen for different states of the job
* and if properties have changed
*
* @code
* #include <ossim/base/Thread.h>
* #include <ossim/parallel/ossimJob.h>
* // 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";
*       ossim::Thread::sleepInSeconds(2);
*       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";
*       ossimJobCallback::started(job);
*    }
*    virtual void finished(std::shared_ptr<ossimJob> job) 
*    {
*       std::cout << "Finished job\n";
*       ossimJobCallback::finished(job);
*    }
* };
* 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;
* }
* @endcode
*/
class OSSIM_DLL ossimJob : public std::enable_shared_from_this<ossimJob>
{
public:
   typedef std::list<std::shared_ptr<ossimJob> > List;

   /** 
   * 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
   */ 
   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)
   };
   
   ossimJob() : m_state(ossimJob_READY),  m_priority(0.0) {}

   /**
   * 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 run.
   */
   virtual void start();

   /**
   * This is a convenience method to get the shared representation 
   * of this pointer
   *
   * @return the shared pointer
   */
   std::shared_ptr<ossimJob> getSharedFromThis(){
      return shared_from_this();
   }

   /**
   * This is a convenience method to get the shared representation 
   * of this pointer
   *
   * @return the shared pointer
   */
   std::shared_ptr<const ossimJob> getSharedFromThis()const{
      return shared_from_this();
   }

   /**
   * When the pernet complete is set for the job it will call any callbacks 
   * and nofity percentCompleteChanged.
   *
   * @value percent complete
   */   
   void setPercentComplete(double value)
   {
      std::lock_guard<std::mutex> lock(m_jobMutex);
      if(m_callback)
      {
         m_callback->percentCompleteChanged(value, getSharedFromThis());
      }
   }

   /**
   * sets the priority of the job
   *
   * @param value priority value
   */
   void setPriority(double value)
   {
      std::lock_guard<std::mutex> lock(m_jobMutex);
      m_priority = value;
   }

   /*
   * @return the priotiy of the job
   */
   double priority()const
   {
      return m_priority;
   }

   /**
   * If derived interfaces implement a block this will allow one to release.
   * Derived classes must override.
   */
   virtual void release(){}

   /**
   * @return the state of the object
   */
   State state()const
   {
      std::lock_guard<std::mutex> lock(m_jobMutex);
      return m_state;
   }

   /**
   * Will clear out the state and the call setState
   *
   * @param value is the state you wish to reset to
   */
   virtual void resetState(int value)
   {
      m_jobMutex.lock();
      if(value != m_state)
      {
         m_state = ossimJob_NONE;
         m_jobMutex.unlock();
         setState(value);
      }
      else 
      {
         m_jobMutex.unlock();
      }

   }

   /**
   * Will allow you to set the state of the job
   *
   * @param value is the state you wish to set to
   * @param on will turn the value on if on is true
   *        and turn it off otherwise.
   */
   virtual void setState(int value, bool on=true);

   /**
   * @return true if the job is in a cancel state and false
   *         otherwise
   */
   bool isCanceled()const
   {
      std::lock_guard<std::mutex> lock(m_jobMutex);
      return (m_state & ossimJob_CANCEL);
   }

   /**
   * Sets the state if the object as cancelled
   */
   virtual void cancel()
   {
      // append the cancel flag to current state
      setState(ossimJob_CANCEL);
   }

   /**
   * Sets the state if the object as ready
   */
   virtual void ready()
   {
      resetState(ossimJob_READY);
   }

   /**
   * Sets the state if the object as running
   */
   virtual void running()
   {
      resetState(ossimJob_RUNNING);
   }

   /**
   * Sets the state if the object as finished
   */
   virtual void finished()
   {
      int newState = 0;
      {
         // maintain the cancel flag so we can indicate the job has now finished
         std::lock_guard<std::mutex> lock(m_jobMutex);
         newState = ((m_state & ossimJob_CANCEL) | 
            (ossimJob_FINISHED));
      }
      // now reset to the new state
      resetState(newState);
   }

   /**
   * @return true if the state of the object is in a ready state.
   */
   bool isReady()const
   {
      std::lock_guard<std::mutex> lock(m_jobMutex);
      return m_state & ossimJob_READY;
   }

   /**
   * @return true if the state of the object is in some kind of stopped state.
   */
   bool isStopped()const
   {
      std::lock_guard<std::mutex> lock(m_jobMutex);
      return (m_state & ossimJob_FINISHED);
   }

   /**
   * @return true if the state of the object is in a finished state.
   */
   bool isFinished()const
   {
      std::lock_guard<std::mutex> lock(m_jobMutex);
      return (m_state & ossimJob_FINISHED);
   }

   /**
   * @return true if the state of the object is in a running state.
   */
   bool isRunning()const
   {
      std::lock_guard<std::mutex> lock(m_jobMutex);
      return (m_state & ossimJob_RUNNING);
   }

   /**
   * @param callback callback used to call different state of a job
   */
   void setCallback(std::shared_ptr<ossimJobCallback> callback)
   {
      std::lock_guard<std::mutex> lock(m_jobMutex);
      m_callback = callback;
   }

   /**
   * Sets the name of a job
   *
   * @param value the name of the job
   */
   void setName(const ossimString& value)
   {
      bool changed = false;
      std::shared_ptr<ossimJobCallback> callback;
      {
         std::lock_guard<std::mutex> lock(m_jobMutex);
         changed = value!=m_name;
         m_name = value;
         callback = m_callback;
      }
      if(changed&&callback)
      {
         callback->nameChanged(value, getSharedFromThis());
      }
   }

   /**
   * @return the name of the job
   */
   const ossimString& name()const
   {
      std::lock_guard<std::mutex> lock(m_jobMutex);
      return m_name;
   }

   /*
   * sets the ID
   *
   * @param value the id to set the job to
   */
   void setId(const ossimString& value)
   {
      bool changed = false;
      std::shared_ptr<ossimJobCallback> callback;
      {
         std::lock_guard<std::mutex> lock(m_jobMutex);
         changed = value!=m_id;
         m_id = value;
         callback = m_callback;
      }
      if(changed&&callback)
      {
         callback->idChanged(value, getSharedFromThis());
      }
   }

   /*
   * @return id of the job
   */
   const ossimString& id()const
   {
      std::lock_guard<std::mutex> lock(m_jobMutex);
      return m_id;
   }

   /*
   * @param value the description to set on the job
   */
   void setDescription(const ossimString& value)
   {
      bool changed = false;
      std::shared_ptr<ossimJobCallback> callback;
      {
         std::lock_guard<std::mutex> lock(m_jobMutex);
         changed = value!=m_description;
         m_description = value;
         callback = m_callback;
      }
      if(changed&&callback)
      {
         callback->descriptionChanged(value, getSharedFromThis());
      }
   }

   /**
   * @return the desciption of the job
   */
   const ossimString& description()const
   {
      std::lock_guard<std::mutex> lock(m_jobMutex);
      return m_description;
   }

   /**
   * @return the callback
   */
   std::shared_ptr<ossimJobCallback> callback() {return m_callback;}

protected:
   mutable std::mutex m_jobMutex;
   ossimString m_name;
   ossimString m_description;
   ossimString m_id;
   State       m_state;
   double      m_priority;
   std::shared_ptr<ossimJobCallback> m_callback;

   /**
   * Abstract method and must be overriden by the base class.  The base ossimJob
   * will call run from the start method after setting some variables.
   */
   virtual void run()=0;
};

#endif