IJob.h
Go to the documentation of this file.
1 /********************************************************************
2 *
3 * Project Artec 3D Scanning SDK
4 *
5 * Purpose: Job interface.
6 *
7 * Copyright: Artec Group
8 *
9 ********************************************************************/
10 
11 #ifndef _IJOB_H_
12 #define _IJOB_H_
13 
15 #include <artec/sdk/base/IRef.h>
16 #include <artec/sdk/base/Errors.h>
17 
18 namespace artec { namespace sdk { namespace base
19 {
20 
21 class IJob;
22 class IJobObsever;
23 struct AlgorithmWorkset;
24 
25 extern "C"
26 {
27 
28 /// @brief Synchronously execute a job in several threads
29 /// @param job - this parameter is an algorithm or a procedure,
30 /// and it should be created with appropriate function like createXXXAlgorithm()
31 /// or createXXXProcedure(). TRef should be used to hold this pointer,
32 /// so the lifetime of the object will be cared of accordingly.
33 /// @param workset - this parameter is a simple structure which can be
34 /// created on stack or in dynamic memory. All his interface members,
35 /// such in, out, progress (if any) or cancellation (if any) should live till
36 /// the end of the job processing so please take care of that.
37 ErrorCode ABASESDK_LINK_SPEC executeJob( IJob* job, const AlgorithmWorkset * workset );
38 
39 /// @brief Asynchronously launch a job in several threads
40 /// @param job - this parameter is an algorithm or a procedure,
41 /// and it should be created with appropriate function like createXXXAlgorithm()
42 /// or createXXXProcedure(). TRef should be used to hold this pointer,
43 /// so the lifetime of the object will be cared of accordingly.
44 /// @param workset - this parameter is a simple structure which can be
45 /// created on stack or in dynamic memory. All his interface members,
46 /// such in, out, progress (if any) or cancellation (if any) should live till
47 /// the end of the job processing so please take care of that.
48 /// @param jobObsever - this parameter is intended to receive notifications
49 /// about job completeness. The particular class inheriting JobObseverBase should be defined and
50 /// implemented by user, and TRef should be used to hold this pointer.
51 /// The lifetime of this object will be cared of as well.
52 ErrorCode ABASESDK_LINK_SPEC launchJob( IJob* job, const AlgorithmWorkset * workset, IJobObsever* jobObsever );
53 
54 }
55 
56 /// Job Interface.
57 /// Used by executeJob and launchJob.
58 /// Base for algorithms family and scanning.
59 /// @see executeJob, launchJob
60 class IJob : public IRef
61 {
62 public:
63  /// Returns short job name for debug purposes
64  virtual const char* getDebugName() const = 0;
65 
66  /// Returns the required number of threads
67  /// @retval 0 Any positive number of threads is applicable.
68  /// @retval >0 The returned number of threads is mandatory.
69  virtual unsigned int getThreadsRequired() const = 0;
70 
71  /// Sets up the environment, makes a processing schedule
72  /// @note It's called only for the first working thread
73  virtual ErrorCode start( const AlgorithmWorkset* runSet ) = 0;
74 
75  /// Executes the algorithm's processing
76  /// @note It's called for all working threads
77  virtual ErrorCode process( int threadIndex ) = 0;
78 
79  /// Sums everything up in the end
80  /// @note It's called only for the last working thread in case
81  /// everything went ok and with no abortions
82  virtual ErrorCode finish() = 0;
83 
84  /// Cleans up the environment
85  /// @note The routine is called for the last working thread even if an error occurs
86  virtual ErrorCode reset() = 0;
87 };
88 
89 } } } // namespace artec::sdk::base
90 
91 #endif // _IJOB_H_
virtual ErrorCode process(int threadIndex)=0
ErrorCode ABASESDK_LINK_SPEC executeJob(IJob *job, const AlgorithmWorkset *workset)
Synchronously execute a job in several threads.
Workset for algorithms parameters.
virtual ErrorCode finish()=0
virtual unsigned int getThreadsRequired() const =0
virtual ErrorCode reset()=0
ErrorCode ABASESDK_LINK_SPEC launchJob(IJob *job, const AlgorithmWorkset *workset, IJobObsever *jobObsever)
Asynchronously launch a job in several threads.
virtual const char * getDebugName() const =0
Returns short job name for debug purposes.
#define ABASESDK_LINK_SPEC
Definition: BaseSdkDefines.h:7
virtual ErrorCode start(const AlgorithmWorkset *runSet)=0