casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlotOperation.h
Go to the documentation of this file.
1 //# PlotOperation.h: Classes for managing large, threaded plot operations.
2 //# Copyright (C) 2009
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: $
27 #ifndef PLOTOPERATION_H_
28 #define PLOTOPERATION_H_
29 
30 #include <casa/BasicSL/String.h>
32 
33 #include <vector>
34 
35 namespace casa {
36 
37 //# Forward Declarations
38 class PlotOperationWatcher;
39 
40 
41 // Abstract class, for a synchronization mutex specific to the threading
42 // library used by the plotting implementations.
43 class PlotMutex {
44 public:
45  // Constructor.
46  PlotMutex() { }
47 
48  // Destructor.
49  virtual ~PlotMutex() { }
50 
51 
52  // ABSTRACT METHODS //
53 
54  // Locks the mutex.
55  virtual void lock() = 0;
56 
57  // Unlocks the mutex.
58  virtual void unlock() = 0;
59 
60  // Tries to lock the mutex, and returns immediately with either true for
61  // success (mutex is now locked), or false (mutex is unavailable).
62  virtual bool tryLock() = 0;
63 };
65 
66 
67 // Simple object to synchronize operation progress information across threads.
68 class PlotOperation {
69 public:
70  // Constructor which takes the operation name and a synchronization mutex.
72 
73  // Destructor.
75 
76 
77  // Accessors (synchronized).
78  // <group>
79  casacore::String name() const;
80  bool inProgress() const;
81  bool isFinished() const;
82  unsigned int currentProgress() const;
84  bool cancelRequested() const;
85  // </group>
86 
87  // Mutators (synchronized). Any mutator will notify registered watchers of
88  // a change.
89  // <group>
90  void setInProgress(bool inProgress);
91  void setIsFinished(bool isFinished);
92  void setCurrentProgress(unsigned int currentProgress);
93  void setCurrentStatus(const casacore::String& currentStatus);
94  void setCancelRequested(bool cancel);
95  // </group>
96 
97  // Sets the operation's mutex to the given.
98  void setMutex(PlotMutexPtr mutex);
99 
100  // Adds the given watcher for this object.
101  void addWatcher(PlotOperationWatcher* watcher);
102 
103  // Removes the given watcher for this object.
104  void removeWatcher(PlotOperationWatcher* watcher);
105 
106  // Resets the in progress, is finished, current progress, and current
107  // status members. Will notify registered watchers of a change.
108  void reset();
109 
110  // Updates in progress, is finished, current progress, and current status
111  // members to reflect a "finished" state. Will notify registered watchers
112  // of a change.
113  void finish();
114 
115 private:
116  // Name.
118 
119  // Flags.
121 
122  // Current progress (0 - 100)%.
123  unsigned int m_currentProgress;
124 
125  // Current status message.
127 
128  // Cancel requested flag.
130 
131  // Synchronization mutex.
133 
134  // Watchers.
135  std::vector<PlotOperationWatcher*> m_watchers;
136 
137 
138  // Notifies any registered watchers that the operation has changed.
139  void notifyWatchers() const;
140 };
142 
143 
144 // Abstract interface for any object that wants to watch a PlotOperation object
145 // for changes.
147 public:
148  // Constructor.
150 
151  // Destructor.
152  virtual ~PlotOperationWatcher() { }
153 
154 
155  // This method is called to notify the watcher that the given PlotOperation
156  // object has changed.
157  virtual void operationChanged(const PlotOperation& operation) = 0;
158 };
159 
160 }
161 
162 #endif /* PLOTOPERATION_H_ */
PlotMutex()
Constructor.
Definition: PlotOperation.h:46
bool isFinished() const
PlotMutexPtr m_mutex
Synchronization mutex.
void setInProgress(bool inProgress)
Mutators (synchronized).
std::vector< PlotOperationWatcher * > m_watchers
Watchers.
void reset()
Resets the in progress, is finished, current progress, and current status members.
Simple object to synchronize operation progress information across threads.
Definition: PlotOperation.h:68
unsigned int m_currentProgress
Current progress (0 - 100)%.
void setCancelRequested(bool cancel)
void setCurrentProgress(unsigned int currentProgress)
casacore::String m_name
Name.
virtual ~PlotOperationWatcher()
Destructor.
void setCurrentStatus(const casacore::String &currentStatus)
void finish()
Updates in progress, is finished, current progress, and current status members to reflect a &quot;finished...
casacore::String currentStatus() const
bool m_cancelRequested
Cancel requested flag.
casacore::String name() const
Accessors (synchronized).
casacore::String m_currentStatus
Current status message.
PlotOperation(const casacore::String &name, PlotMutexPtr mutex)
Constructor which takes the operation name and a synchronization mutex.
bool inProgress() const
Abstract interface for any object that wants to watch a PlotOperation object for changes.
bool m_inProgress
Flags.
void notifyWatchers() const
Notifies any registered watchers that the operation has changed.
void setMutex(PlotMutexPtr mutex)
Sets the operation&#39;s mutex to the given.
void setIsFinished(bool isFinished)
PlotOperationWatcher()
Constructor.
void addWatcher(PlotOperationWatcher *watcher)
Adds the given watcher for this object.
void removeWatcher(PlotOperationWatcher *watcher)
Removes the given watcher for this object.
Abstract class, for a synchronization mutex specific to the threading library used by the plotting im...
Definition: PlotOperation.h:43
virtual void unlock()=0
Unlocks the mutex.
virtual bool tryLock()=0
Tries to lock the mutex, and returns immediately with either true for success (mutex is now locked)...
virtual void operationChanged(const PlotOperation &operation)=0
This method is called to notify the watcher that the given PlotOperation object has changed...
~PlotOperation()
Destructor.
casacore::CountedPtr< PlotOperation > PlotOperationPtr
casacore::CountedPtr< PlotMutex > PlotMutexPtr
Definition: PlotOperation.h:64
virtual ~PlotMutex()
Destructor.
Definition: PlotOperation.h:49
unsigned int currentProgress() const
String: the storage and methods of handling collections of characters.
Definition: String.h:223
bool cancelRequested() const
virtual void lock()=0
ABSTRACT METHODS //.