casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ThreadController.h
Go to the documentation of this file.
1 //# Copyright (C) 2009
2 //# Associated Universities, Inc. Washington DC, USA.
3 //#
4 //# This library is free software; you can redistribute it and/or modify it
5 //# under the terms of the GNU Library General Public License as published by
6 //# the Free Software Foundation; either version 2 of the License, or (at your
7 //# option) any later version.
8 //#
9 //# This library is distributed in the hope that it will be useful, but WITHOUT
10 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 //# License for more details.
13 //#
14 //# You should have received a copy of the GNU Library General Public License
15 //# along with this library; if not, write to the Free Software Foundation,
16 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
17 //#
18 //# Correspondence concerning AIPS++ should be addressed as follows:
19 //# Internet email: aips2-request@nrao.edu.
20 //# Postal address: AIPS++ Project Office
21 //# National Radio Astronomy Observatory
22 //# 520 Edgemont Road
23 //# Charlottesville, VA 22903-2475 USA
24 //#
25 
26 #ifndef THREADCONTROLLER_H_
27 #define THREADCONTROLLER_H_
28 
30 
31 namespace casa {
32 
33 //# Forward declarations.
34 class ProgressMonitor;
35 class BackgroundThread;
36 class PlotMSPlot;
37 
38 // Typedefs for using post-thread methods.
39 // <group>
40 typedef void* PMSPTObject;
41 typedef void PMSPTMethod(PMSPTObject, bool);
42 // </group>
43 
45 public:
46  // Constructor which takes the progress widget to use, and an optional
47  // post-thread method that should be called when the thread is finished.
50  PMSPTObject postThreadObject = NULL);
51 
52  virtual ~ThreadController();
53 
54  //***********************************************************************
55  // Thread Communication Interface
56  //***********************************************************************
57 
58  //Worker classes can store and error message.
59  virtual void setError( const casacore::String& errorMessage );
60  // Allows the cache to set the status.
61  virtual void setStatus(const casacore::String& status);
62  virtual void setProgress(unsigned int progress);
63  virtual void finished( );
64  // These signals are used to update the QtProgressWidget across different
65  // threads. They shouldn't need to be used by other classes, even
66  // children.
67  // <group>
68  virtual void initializeProgress(const casacore::String& operationName);
69  virtual void setProgress(unsigned int progress, const casacore::String& status);
70  virtual void finishProgress();
71 
72  // </group>
73 
74  // Work classes can specify whether they support background operation, pause/resume,
75  //and cancelling.
76  virtual void setAllowedOperations(bool background, bool pauseResume, bool cancel);
77 
78  //Callback for classes doing the work to check whether they should
79  //cancel what they are doing or not.
80  virtual bool wasCanceled() const;
81 
82  //********************************************************************
83  // Thread Control
84  //********************************************************************
85 
86  //Store the thread that will be doing the work
87  void setWorkThread( BackgroundThread* workThread );
88 
89  // For when the user requests "background" for the thread.
90  virtual void background();
91 
92  // For when the user requests "pause" for the thread.
93  virtual void pause();
94 
95  // For when the user requests "resume" for the thread.
96  virtual void resume();
97 
98  // For when the user requests "cancel" for the thread.
99  virtual void cancel();
100 
101  // Executes the post-thread method as needed. Does nothing if a
102  // post-thread method was not set in the constructor.
103  virtual void postThreadMethod();
104 
105  //Returns the result of the background operation.
106  bool getResult() const;
107 
108  //Returns any error from the background operation.
109  casacore::String getError() const;
110  bool isErrorWarning() const;
112  PlotMSPlot* getPlot();
113 protected:
114 
115  //Starts the thread
116  void startThread();
117 
118  // Flag for whether thread was canceled or not.
119  volatile bool wasCanceled_;
120 
121  //Holds error messages
125 
126 
127 
128  // Progress widget.
130 
131  // Method/Object to run when thread is finished.
132  // <group>
135  // </group>
136 
137 
138 private:
139  ThreadController( const ThreadController& controller );
141 
143 
144 };
145 
146 } /* namespace casa */
147 #endif /* THREADCONTROLLER_H_ */
virtual void finished()
Thread signals it is done.
virtual void cancel()
For when the user requests &quot;cancel&quot; for the thread.
void setWorkThread(BackgroundThread *workThread)
void startThread()
Starts the thread.
PMSPTMethod * itsPostThreadMethod_
Method/Object to run when thread is finished.
virtual void postThreadMethod()
Executes the post-thread method as needed.
virtual bool wasCanceled() const
Callback for classes doing the work to check whether they should cancel what they are doing or not...
virtual void setAllowedOperations(bool background, bool pauseResume, bool cancel)
Work classes can specify whether they support background operation, pause/resume, and cancelling.
bool isErrorWarning() const
virtual void setError(const casacore::String &errorMessage)
casacore::String getErrorTitle() const
void * PMSPTObject
Typedefs for using post-thread methods.
ProgressMonitor * itsProgressWidget_
Progress widget.
casacore::String errorTitle
virtual void initializeProgress(const casacore::String &operationName)
These signals are used to update the QtProgressWidget across different threads.
virtual void pause()
For when the user requests &quot;pause&quot; for the thread.
virtual void setStatus(const casacore::String &status)
Allows the cache to set the status.
ThreadController(ProgressMonitor *progress, PMSPTMethod postThreadMethod=NULL, PMSPTObject postThreadObject=NULL)
Constructor which takes the progress widget to use, and an optional post-thread method that should be...
ThreadController operator=(const ThreadController &other)
Abstraction for a display widget that can show the progress of an operation.
volatile bool wasCanceled_
Flag for whether thread was canceled or not.
casacore::String error
Holds error messages.
virtual void background()
For when the user requests &quot;background&quot; for the thread.
Class for a single &quot;plot&quot; concept.
Definition: PlotMSPlot.h:57
BackgroundThread * bgThread
virtual void resume()
For when the user requests &quot;resume&quot; for the thread.
virtual void finishProgress()
PlotMSPlot * getPlot()
void PMSPTMethod(PMSPTObject, bool)
virtual void setProgress(unsigned int progress)
Allows the cache to set the progress.
casacore::String getError() const
Returns any error from the background operation.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
bool getResult() const
Returns the result of the background operation.
PMSPTObject itsPostThreadObject_
Manages a thread to do a background operation and communicates back to its controller with regard to ...
Defines communication mechanisms that the model and data can use to communicate with the UI concernin...