Line data Source code
1 : //# CasapyWatcher.cc: Class to notify children about casapy events. 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 <stdcasa/CasapyWatcher.h> 28 : 29 : using namespace std; 30 : using namespace casacore; 31 : 32 : namespace casac { 33 : 34 : /////////////////////////////// 35 : // CASAPYWATCHER DEFINITIONS // 36 : /////////////////////////////// 37 : 38 : // Static // 39 : 40 : vector<CasapyWatcher*> *CasapyWatcher::WATCHERS = 0; 41 : 42 : // CasapyWatcher::Singleton CasapyWatcher::SINGLETON = Singleton(); 43 : 44 : 45 0 : void CasapyWatcher::registerWatcher(CasapyWatcher* watcher) { 46 : 47 0 : if ( WATCHERS == 0 ) { 48 0 : WATCHERS = new vector<CasapyWatcher*>(); 49 : } 50 : 51 0 : if ( watcher == NULL ) return; 52 : 53 0 : for ( unsigned int i = 0; i < WATCHERS->size(); i++ ) 54 0 : if ( watcher == (*WATCHERS)[i] ) return; 55 : 56 0 : WATCHERS->push_back(watcher); 57 : } 58 : 59 0 : void CasapyWatcher::unregisterWatcher(CasapyWatcher* watcher) { 60 0 : if ( WATCHERS == 0 ) return; 61 0 : if ( watcher == NULL ) return; 62 0 : for ( unsigned int i = 0; i < WATCHERS->size(); i++ ) { 63 0 : if ( (*WATCHERS)[i] == watcher ) { 64 0 : WATCHERS->erase(WATCHERS->begin() + i); 65 0 : break; 66 : } 67 : } 68 : } 69 : 70 : 71 329 : void CasapyWatcher::logChanged_(const String& sinkLocation) { 72 329 : if ( WATCHERS == 0 ) return; 73 0 : for ( unsigned int i = 0; i < WATCHERS->size(); i++ ) 74 0 : (*WATCHERS)[i]->logChanged(sinkLocation); 75 : } 76 : 77 461 : void CasapyWatcher::logChanged_(LogMessage::Priority filterPriority) { 78 461 : if ( WATCHERS == 0 ) return; 79 0 : for ( unsigned int i = 0; i < WATCHERS->size(); i++ ) 80 0 : (*WATCHERS)[i]->logChanged(filterPriority); 81 : } 82 : 83 0 : void CasapyWatcher::casapyClosing_() { 84 0 : if ( WATCHERS == 0 ) return; 85 0 : for ( unsigned int i = 0; i < WATCHERS->size(); i++ ) 86 0 : (*WATCHERS)[i]->casapyClosing(); 87 : } 88 : 89 : 90 : // Non-Static // 91 : 92 0 : CasapyWatcher::CasapyWatcher() { } 93 0 : CasapyWatcher::~CasapyWatcher() { unregisterWatcher(this); } 94 0 : void CasapyWatcher::logChanged(const String& /*sinkLocation*/) { } 95 0 : void CasapyWatcher::logChanged(LogMessage::Priority /*filterPriority*/) { } 96 0 : void CasapyWatcher::casapyClosing() { } 97 : 98 : }