Main Page   Namespace List   Class Hierarchy   Data Structures   File List   Namespace Members   Data Fields   Globals   Related Pages  

TimerTarget.cpp

Go to the documentation of this file.
00001 /*
00002  * TimerTarget.cpp
00003  *
00004  * Copyright 2003, MobileSpear Inc. (www.mobilespear.com). All rights reserved.
00005  * Copyright 2003, David Resnick. All rights reserved.
00006  *
00007  * See the file doc\license.txt for the terms of usage and distribution.
00008  */
00009 
00010 #include <bogotel/portability.h>
00011 #include <bogotel/TimerTarget.h>
00012 #include <bogotel/devbase.h>
00013 #include <bogotel/Timer.h>
00014 #include <bogotel/util.h>
00015 
00016 namespace bogotel {
00017 
00018     boost::mutex CTimerTarget::s_mtxId; 
00019     long         CTimerTarget::s_lId(0);
00020 
00021     CTimerTarget::CTimerTarget() :
00022     m_iStateId(0)
00023     {
00024         boost::mutex::scoped_lock lock(s_mtxId);
00025         m_lId = s_lId++;
00026     }
00027 
00028     CTimerTarget::~CTimerTarget()
00029     {}
00030 
00031     void CTimerTarget::setTimer(int period, int timerType)
00032     {
00033         CDevBase::m_pTimer->add(period, this, timerType, getStateId());
00034     }
00035 
00036     void CTimerTarget::timerExpired(int timerType, int stateId)
00037     {
00038         char method[] = "CTimerTarget::timerExpired";
00039 
00040         // check if our state has changed since the timer was set
00041         // making this timer expiration irrelevent
00042         if (timerValid(stateId)) {
00043             g_util->log(9, -1, "%s: expired timer valid.", method);
00044             _timerExpired(timerType, stateId);
00045         } else {
00046             g_util->log(9, -1, "%s: expired timer invalid.", method);
00047         }
00048     }
00049 
00050     void CTimerTarget::incStateId()
00051     { 
00052         m_iStateId++; 
00053     }
00054 
00055     int CTimerTarget::getStateId()
00056     {
00057         return m_iStateId;
00058     }
00059 
00060     long CTimerTarget::getId()
00061     {
00062         return m_lId;
00063     }
00064 
00065     bool CTimerTarget::timerValid(int stateId) 
00066     { 
00067         return m_iStateId == stateId; 
00068     }
00069 
00070     std::string CTimerTarget::toString()
00071     {
00072         std::ostringstream str;
00073         str << "id:" << m_lId;
00074         return str.str();
00075     }
00076 
00077 }
00078 

Generated on Tue Aug 12 12:41:30 2003 for bogotel by doxygen 1.3. Hosted by SourceForge.net Logo