TSyncProcessorWrap.h
Go to the documentation of this file.
1 #ifndef iproc_TSyncProcessorWrap_included
2 #define iproc_TSyncProcessorWrap_included
3 
4 
5 // Qt includes
6 #include <QtCore/QMap>
7 
8 // ACF includes
9 #include "iprm/IParamsSet.h"
10 #include "iproc/IProcessor.h"
11 
12 
13 namespace iproc
14 {
15 
16 
22 template <class Base>
23 class TSyncProcessorWrap: public Base
24 {
25 public:
26  typedef Base BaseClass;
27 
29 
30  // pseudo-reimplemented (iproc::IProcessor)
31  virtual int GetProcessorState(const iprm::IParamsSet* paramsPtr) const;
32  virtual bool AreParamsAccepted(
33  const iprm::IParamsSet* paramsPtr,
34  const istd::IPolymorphic* inputPtr,
35  const istd::IChangeable* outputPtr) const;
36  virtual int BeginTask(
37  const iprm::IParamsSet* paramsPtr,
38  const istd::IPolymorphic* inputPtr,
39  istd::IChangeable* outputPtr,
40  ibase::IProgressManager* progressManagerPtr = NULL);
41  virtual int WaitTaskFinished(
42  int taskId = -1,
43  double timeoutTime = -1,
44  bool killOnTimeout = true);
45  virtual void CancelTask(int taskId = -1);
46  virtual int GetReadyTask();
47  virtual int GetTaskState(int taskId = -1) const;
48  virtual void InitProcessor(const iprm::IParamsSet* paramsPtr);
49 
50 private:
51  typedef QMap<int, int> TaskToStateMap;
52 
53  TaskToStateMap m_taskToStateMap;
54  int m_nextTaskId;
55 };
56 
57 
58 // public methods
59 
60 template <class Base>
62 : m_nextTaskId(0)
63 {
64 }
65 
66 
67 // pseudo-reimplemented (iproc::IProcessor)
68 
69 template <class Base>
71 {
72  return IProcessor::PS_READY;
73 }
74 
75 
76 template <class Base>
78  const iprm::IParamsSet* /*paramsPtr*/,
79  const istd::IPolymorphic* /*inputPtr*/,
80  const istd::IChangeable* /*outputPtr*/) const
81 {
82  return true;
83 }
84 
85 
86 template <class Base>
88  const iprm::IParamsSet* paramsPtr,
89  const istd::IPolymorphic* inputPtr,
90  istd::IChangeable* outputPtr,
91  ibase::IProgressManager* progressManagerPtr)
92 {
93  int retVal = m_nextTaskId;
94  m_taskToStateMap[retVal] = this->DoProcessing(paramsPtr, inputPtr, outputPtr, progressManagerPtr);
95 
96  m_nextTaskId = (m_nextTaskId + 1) & 0x7fff;
97 
98  return retVal;
99 }
100 
101 
102 template <class Base>
104  int taskId,
105  double /*timeoutTime*/,
106  bool /*killOnTimeout*/)
107 {
108  int retVal = IProcessor::TS_NONE;
109 
110  if (taskId >= 0){
111  TaskToStateMap::iterator foundIter = m_taskToStateMap.find(taskId);
112  if (foundIter != m_taskToStateMap.end()){
113  retVal = foundIter.value();
114 
115  m_taskToStateMap.erase(foundIter);
116  }
117  }
118  else{
119  for ( TaskToStateMap::const_iterator iter = m_taskToStateMap.begin();
120  iter != m_taskToStateMap.end();
121  ++iter){ // we are looking for worst status value. This values are sorted worst => bigger.
122  int taskState = iter.value();
123  if (taskState > retVal){
124  retVal = taskState;
125  }
126  }
127 
128  m_taskToStateMap.clear();
129  }
130 
131  return retVal;
132 }
133 
134 
135 template <class Base>
137 {
138  if (taskId >= 0){
139  m_taskToStateMap.remove(taskId);
140  }
141  else{
142  m_taskToStateMap.clear();
143  }
144 }
145 
146 
147 template <class Base>
149 {
150  if (!m_taskToStateMap.isEmpty()){
151  return m_taskToStateMap.begin().key();
152  }
153  else{
154  return -1;
155  }
156 }
157 
158 
159 template <class Base>
161 {
162  int retVal = IProcessor::TS_NONE;
163 
164  if (taskId >= 0){
165  TaskToStateMap::ConstIterator foundIter = m_taskToStateMap.constFind(taskId);
166  if (foundIter != m_taskToStateMap.constEnd()){
167  retVal = foundIter.value();
168  }
169  }
170  else{
171  for ( TaskToStateMap::const_iterator iter = m_taskToStateMap.begin();
172  iter != m_taskToStateMap.end();
173  ++iter){ // we are looking for worst status value. This values are sorted worst => bigger.
174  int taskState = iter.value();
175  if (taskState > retVal){
176  retVal = taskState;
177  }
178  }
179  }
180 
181  return retVal;
182 }
183 
184 
185 template <class Base>
187 {
188 }
189 
190 
191 // global typdefs
192 
194 
195 
196 } // namespace iproc
197 
198 
199 #endif // !iproc_TSyncProcessorWrap_included
200 
201 
virtual bool AreParamsAccepted(const iprm::IParamsSet *paramsPtr, const istd::IPolymorphic *inputPtr, const istd::IChangeable *outputPtr) const
Wrapper of iproc::IProcessor for simple synchrone processor implementations.
TSyncProcessorWrap< IProcessor > CSyncProcessorBase
virtual void InitProcessor(const iprm::IParamsSet *paramsPtr)
virtual int GetProcessorState(const iprm::IParamsSet *paramsPtr) const
Processor is initialized and ready.
Definition: IProcessor.h:52
virtual void CancelTask(int taskId=-1)
virtual int WaitTaskFinished(int taskId=-1, double timeoutTime=-1, bool killOnTimeout=true)
virtual int GetTaskState(int taskId=-1) const
virtual int BeginTask(const iprm::IParamsSet *paramsPtr, const istd::IPolymorphic *inputPtr, istd::IChangeable *outputPtr, ibase::IProgressManager *progressManagerPtr=NULL)
Task state is undefined.
Definition: IProcessor.h:67

© 2007-2011 Witold Gantzke and Kirill Lepskiy