LCOV - code coverage report
Current view: top level - graphics/GenericPlotter - PlotOperation.cc (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 0 57 0.0 %
Date: 2023-10-25 08:47:59 Functions: 0 19 0.0 %

          Line data    Source code
       1             : //# PlotOperation.cc: 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             : #include <graphics/GenericPlotter/PlotOperation.h>
      28             : 
      29             : using namespace casacore;
      30             : namespace casa {
      31             : 
      32             : ///////////////////////////////
      33             : // PLOTOPERATION DEFINITIONS //
      34             : ///////////////////////////////
      35             : 
      36           0 : PlotOperation::PlotOperation(const String& name, PlotMutexPtr mutex) :
      37           0 :         m_name(name), m_cancelRequested(false), m_mutex(mutex) {
      38           0 :     reset();
      39           0 : }
      40             : 
      41           0 : PlotOperation::~PlotOperation() { }
      42             : 
      43             : 
      44             : #define PO_GETTER(TYPE, NAME)                                                 \
      45             :     m_mutex->lock();                                                          \
      46             :     TYPE temp = NAME;                                                         \
      47             :     m_mutex->unlock();                                                        \
      48             :     return temp;
      49             : 
      50           0 : String PlotOperation::name() const { PO_GETTER(String, m_name) } 
      51           0 : bool PlotOperation::inProgress() const { PO_GETTER(bool, m_inProgress) }
      52           0 : bool PlotOperation::isFinished() const { PO_GETTER(bool, m_isFinished) }
      53           0 : unsigned int PlotOperation::currentProgress() const {
      54           0 :     PO_GETTER(unsigned int, m_currentProgress) }
      55           0 : String PlotOperation::currentStatus() const {
      56           0 :     PO_GETTER(String, m_currentStatus) }
      57           0 : bool PlotOperation::cancelRequested() const {
      58           0 :     PO_GETTER(bool, m_cancelRequested) }
      59             : 
      60             : 
      61             : #define PO_SETTER(NAME, TEMP, VAL)                                            \
      62             :     if( TEMP != VAL ) {                                                       \
      63             :         m_mutex->lock();                                                      \
      64             :         NAME = VAL;                                                           \
      65             :         m_mutex->unlock();                                                    \
      66             :         notifyWatchers();                                                     \
      67             :     }
      68             : 
      69           0 : void PlotOperation::setInProgress(bool val) {
      70           0 :     PO_SETTER(m_inProgress, inProgress(), val) }
      71           0 : void PlotOperation::setIsFinished(bool val) {
      72           0 :     PO_SETTER(m_isFinished, isFinished(), val) }
      73           0 : void PlotOperation::setCurrentProgress(unsigned int val) {
      74           0 :     if(val > 100) val = 100;
      75           0 :     PO_SETTER(m_currentProgress, currentProgress(), val)
      76           0 : }
      77           0 : void PlotOperation::setCurrentStatus(const String& val) {
      78           0 :     PO_SETTER(m_currentStatus, currentStatus(), val) }
      79           0 : void PlotOperation::setCancelRequested(bool val) {
      80           0 :     PO_SETTER(m_cancelRequested, cancelRequested(), val); }
      81             : 
      82           0 : void PlotOperation::setMutex(PlotMutexPtr mutex) { m_mutex = mutex; }
      83             : 
      84           0 : void PlotOperation::addWatcher(PlotOperationWatcher* watcher) {
      85           0 :     if(watcher == NULL) return;
      86           0 :     for(unsigned int i = 0; i < m_watchers.size(); i++)
      87           0 :         if(m_watchers[i] == watcher) return;
      88           0 :     m_watchers.push_back(watcher);
      89             : }
      90             : 
      91           0 : void PlotOperation::removeWatcher(PlotOperationWatcher* watcher) {
      92           0 :     if(watcher == NULL) return;
      93           0 :     for(unsigned int i = 0; i < m_watchers.size(); i++) {
      94           0 :         if(m_watchers[i] == watcher) {
      95           0 :             m_watchers.erase(m_watchers.begin() + i);
      96           0 :             return;
      97             :         }
      98             :     }
      99             : }
     100             : 
     101           0 : void PlotOperation::reset() {
     102           0 :     m_inProgress = false;
     103           0 :     m_isFinished = false;
     104           0 :     m_currentProgress = 0;
     105           0 :     m_currentStatus = "";
     106           0 :     m_cancelRequested = false;
     107           0 :     notifyWatchers();
     108           0 : }
     109             : 
     110           0 : void PlotOperation::finish() {
     111           0 :     m_inProgress = false;
     112           0 :     m_isFinished = true;
     113           0 :     m_currentProgress = 100;
     114           0 :     m_currentStatus = "Finished.";
     115           0 :     notifyWatchers();
     116           0 : }
     117             : 
     118             : 
     119           0 : void PlotOperation::notifyWatchers() const {
     120           0 :     for(unsigned int i = 0; i < m_watchers.size(); i++)
     121           0 :         m_watchers[i]->operationChanged(*this);
     122           0 : }
     123             : 
     124             : }

Generated by: LCOV version 1.16