Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2005 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #include <marsyas/sched/TmTimerManager.h> 00020 00021 using namespace std; 00022 using namespace Marsyas; 00023 00038 #define TimerCreateWrapper(_NAME) \ 00039 struct Make##_NAME : public MakeTimer { \ 00040 Make##_NAME() {}; ~Make##_NAME() {}; \ 00041 TmTimer* make(std::string ident) { return new _NAME (ident); }; \ 00042 } 00043 #define registerTimer(_NAME) registry_[#_NAME] = new Make##_NAME(); 00044 00045 # include "TmRealTime.h" 00046 # include "TmVirtualTime.h" 00047 00048 TimerCreateWrapper(TmRealTime); 00049 TimerCreateWrapper(TmVirtualTime); 00050 00051 TmTimerManager* TmTimerManager::instance_ = NULL; 00052 00053 TmTimerManager::TmTimerManager() 00054 { 00055 addTimers(); 00056 } 00057 00058 TmTimerManager::~TmTimerManager() 00059 { 00060 delete instance_; 00061 instance_=NULL; 00062 } 00063 00064 void TmTimerManager::addTimers() 00065 { 00066 // register your timers here! 00067 registerTimer(TmRealTime); 00068 registerTimer(TmVirtualTime); 00069 } 00070 00071 TmTimerManager* 00072 TmTimerManager::getInstance() 00073 { 00074 if (instance_==NULL) { 00075 instance_=new TmTimerManager(); 00076 } 00077 return instance_; 00078 } 00079 00080 TmTimer* 00081 TmTimerManager::make(std::string class_name, std::string identifier) 00082 { 00083 MakeTimer* m = registry_[class_name]; 00084 if (m==NULL) { // does the map always return NULL when key is not in the map?? 00085 MRSWARN("TmTimerManager::make(string,string) name '"+class_name+"' does not name a timer"); 00086 return NULL; 00087 } 00088 return m->make(identifier); 00089 } 00090 00091 TmTimer* 00092 TmTimerManager::make(std::string class_name, std::string identifier, std::vector<TmParam> params) 00093 { 00094 TmTimer* tmr = make(class_name,identifier); 00095 if(tmr!=NULL) { 00096 tmr->updtimer(params); 00097 } 00098 return tmr; 00099 } 00100