Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

TimerCommand.cpp

Go to the documentation of this file.
00001 #ifdef TEST
00002 
00003 #include "headers.h"
00004 
00005 static pthread_cond_t myCondition;
00006 
00010 
00011 string
00012 TimerCommand::getCommandString() {
00013     return timerCommandString;
00014 }
00015 
00016 
00020 void* 
00021 sampleWake(void* arg) {
00022     stringstream s;
00023     TimeValue tmp(TimeValue::getCurrentTime());
00024     s << tmp;
00025         debug(DEBUG_TIMER, "Time: %s, Message: %s", s.str().c_str(), (char*)arg);
00026         return NULL;
00027 }  // fn samplewake
00028 
00029 
00030 void* 
00031 sampleSignal(void* arg) {
00032     debug(DEBUG_TIMER, "Signalling");
00033     pthread_cond_signal(&myCondition);
00034     return NULL;
00035 }
00036 
00037 
00038 void 
00039 TimerCommand::run(std::ostream& s)
00040 {       
00041         bool* isValid = new bool;
00042         bool* isValid2 = new bool;
00043         *isValid = true;
00044         *isValid2 = true;
00045     Condition myCondition;
00046     Mutex myMutex;
00047     myMutex.lock();
00048 
00049         debug(DEBUG_TIMER, "Starting timer test");
00050 
00051     myCondition.timedWait(&myMutex, 15000);
00052     /*
00053         // add an event 
00054         ThreadSpawningTimer::instance()->addEvent(10000, sampleWake, (void *) "Third", isValid);
00055 
00056         // add an event but turn it off
00057         ThreadSpawningTimer::instance()->addEvent(8000, sampleWake, (void *) "Second", isValid2);
00058         *isValid2 = false;
00059 
00060         // add an event before the other ones
00061         ThreadSpawningTimer::instance()->addEvent(3000, sampleWake, (void *) "First", isValid);
00062 
00063     // a signal for the timedWait below
00064     //Timer::addEvent(15000, sampleSignal, NULL, isValid);
00065 
00066     stringstream tmp;
00067         tmp << *ThreadSpawningTimer::instance();
00068     debug(DEBUG_TIMER, "\n%s", tmp.str());
00069 
00070     bool result = Timer::timedWait(&myCondition, &myMutex, 15000);
00071     */
00072     //ThreadSpawningTimer::instance();
00073     //ThreadSpawningTimer::destroy();
00074 
00075 
00076     //CallbackTimer* t = new CallbackTimer();
00077     //t->setName("TimerCommand Test");
00078     //t->addEvent(10000, sampleWake, (void *)"Callback 3", isValid);
00079     //t->addEvent(5000, sampleWake, (void *) "Callback 2", isValid);
00080     //t->addEvent(2000, sampleWake, (void *) "Callback 1", isValid);
00081     //Timer::timedWait(&myCondition, &myMutex, 15000);
00082     //delete t;
00083 } 
00084 
00085 
00086 #endif
00087 

Generated at Thu Jul 11 13:31:52 2002 for Peekabooty by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001