InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TaskInfo.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Florin Trofin
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: All information contained herein is, and remains
18 // the property of Adobe Systems Incorporated and its suppliers,
19 // if any. The intellectual and technical concepts contained
20 // herein are proprietary to Adobe Systems Incorporated and its
21 // suppliers and may be covered by U.S. and Foreign Patents,
22 // patents in process, and are protected by trade secret or copyright law.
23 // Dissemination of this information or reproduction of this material
24 // is strictly forbidden unless prior written permission is obtained
25 // from Adobe Systems Incorporated.
26 //
27 //========================================================================================
28 
29 #ifndef __TASKINFO_H__
30 #define __TASKINFO_H__
31 
32 #include <utility>
33 #include <boost/intrusive_ptr.hpp>
34 #include <boost/operators.hpp>
35 #include "AsyncWork.h"
36 #include "PMString.h"
37 #include <adobe/move.hpp>
38 
39 
40 struct AsyncWorkPacketJobSpec;
41 
42 class IDTask;
43 class MemXferBytes;
44 // We need intrusive_ptr instead of shared_ptr because of size constraints (intrusive_ptr has the same size as T*)
45 typedef boost::intrusive_ptr<IDTask> IDTaskPtr;
46 
47 
48 //---------------------------------------------------------------------------------------
53 {
55  enum AlertType { kGenericMsg,
56  kInformationMsg,
59  };
60 
63  : fAlertType(kGenericMsg)
64  {
65  }
66 
71  AlertMessage(AlertType type, PMString const& message)
72  : fAlertType(type), fMessage(message)
73  {
74  }
75 
78 };
79 
81 typedef std::vector<AlertMessage> AlertMessageQueue;
82 
83 //---------------------------------------------------------------------------------------
84 class IErrorState;
85 
89 {
91  ErrorStateInfo() : fCode(kSuccess), fErrorInfoClass(kInvalidClass)
92  {}
93 
97  explicit ErrorStateInfo(IErrorState* errState);
101  void WriteErrorInfoToBuffer(IPMUnknown* errorInfo);
102 
107 
108  ErrorCode fCode;
111  boost::shared_ptr<MemXferBytes> fErrorInfoBuffer;
113 };
114 
115 //---------------------------------------------------------------------------------------
116 
117 //========================================================================================
118 
125 {
126 public:
128  typedef std::pair<uint32, uint32> ProgressRange;
129 
133  {
134  ProgressData() : fRange(0, 0), fPercentage(0.0), fCurrentPosition(0)
135  {}
136 
141  };
142 
143  // Constructor
145  {}
146 
155  bool GetCurrentData(ProgressData& data) const;
156 
157  // Convenience accessors
162  {
163  ProgressData data;
164  GetCurrentData(data);
165  return data.fTaskStatusText;
166  }
167 
171  inline ProgressRange GetRange() const
172  {
173  ProgressData data;
174  GetCurrentData(data);
175  return data.fRange;
176  }
177 
181  inline uint32 GetCurrentPosition() const
182  {
183  ProgressData data;
184  GetCurrentData(data);
185  return data.fCurrentPosition;
186  }
187 
192  {
193  ProgressData data;
194  GetCurrentData(data);
195  return data.fPercentage;
196  }
197 
198 private:
199  friend class IDTaskAccessor;
200 
201  void SetRange(ProgressRange range);
202 
205  void SetCurrentPosition(uint32 pos);
206 
207  void SetTaskCompletionPercentage(PMReal percentage);
208 
209  ProgressData fData;
210  IDThreading::spin_mutex fDataLock;
211 };
212 
213 //========================================================================================
214 
218 {
219 public:
220 
224  {
225  kQueued = 0x0,
226  kRunning = 0x1,
227  kFinishing = 0x2,
228  kCompleted = 0x3,
229  kCancelling = 0x4,
230  kCancelled = 0x5,
231  kWaiting = 0x6,
232  kForceKilled = 0x7,
233  };
234 
237  struct StatusData
238  {
240  {}
241 
243  AlertMessageQueue fAlertMessageQueue;
246  };
247 
251  {}
252 
255  TaskState GetCurrentState() const;
256 
261 
264  AlertMessageQueue GetAlertMessages() const;
265 
269  void ClearAlertMessages();
270 
273  bool WasCancelled() const;
274 
276  StatusData GetCurrentData() const;
277 
278 private:
279  friend class IDTaskAccessor;
280 
281  /* ---------- Called only internally -----------------*/
282 
283  void SetState(TaskState newState);
284 
285  void AppendAlert(const AlertMessage& msg);
286 
287  void SetExitErrorStateInfo(const ErrorStateInfo &info);
288 
289  // Sets the internal state to cancelled
290  void Cancel();
291 
292  StatusData fStatusData;
293  IDThreading::spin_mutex fDataLock;
294 };
295 
296 
297 
298 //========================================================================================
299 
305 class TaskInfo : boost::equality_comparable<TaskInfo, TaskInfo>
306 {
307 public:
308 
309  typedef AsyncWorkPacketID TaskID;
311  explicit TaskInfo(const IDTaskPtr& myTask);
313  explicit TaskInfo(IDTask& myTask);
317  TaskInfo();
319  ~TaskInfo();
323  TaskInfo(const TaskInfo& other);
324 
328  TaskInfo(adobe::move_from<TaskInfo> other);
329 
333  TaskInfo& operator=(TaskInfo other);
334 
336 
340  TaskID GetID() const;
341 
352 
362 
367  const AsyncWorkPacketJobSpec& GetJobSpec() const;
368 
372  PMString GetName() const;
373 
380 
384  void ClearAlertMessages();
385 
390 
395  AlertMessageQueue GetAlertMessages() const;
396 
402 
406  bool WasCancelled() const;
407 
411  inline bool IsValid() const
412  {
413  return fTask != nil;
414  }
416 
418 
423  void Cancel();
424 
429 
431 
432  // Operators:
434  friend inline void swap(TaskInfo& left, TaskInfo& right)
435  {
436  swap(left.fTask, right.fTask);
437  }
438 
440  friend inline bool operator==(TaskInfo const& left, TaskInfo const& right)
441  {
442  return left.GetID() == right.GetID();
443  }
444 
445 private:
446 
447  IDTaskPtr fTask;
448 };
449 
450 // specialize adobe::type_info<> to avoid typeid problems across DLL boundaries
451 ADOBE_NAME_TYPE_0("taskinfo:indesign:adobe",TaskInfo);
452 
453 #endif // __TASKINFO_H__