TimerAgent.cpp

Go to the documentation of this file.
00001 /*
00002  * This file is part of Micole Architecture
00003  *
00004  * Copyright (C) 2007 Micole partners
00005  *
00006  * Micole Architecture is free software: you can redistribute it 
00007  * and/or modify it under the terms of the GNU Lesser General 
00008  * Public License as published by the Free Software Foundation, 
00009  * either version 3 of the License, or (at your option) any 
00010  * later version.
00011  *
00012  * Micole Architecture is distributed in the hope that it will be 
00013  * useful, * but WITHOUT ANY WARRANTY; without even the implied 
00014  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00015  * PURPOSE.  See the GNU Lesser General Public License for more 
00016  * details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Micole Architecture.  If not, see
00020  * <http://www.gnu.org/licenses/>.
00021  */
00022 
00023 #include "stdafx.h"
00024 //#include "StdAfx.h"
00025 #include "TimerAgent.h"
00026 
00027 TimerAgent::TimerAgent(const string &name, const string &type, const int &delay)
00028 : MicoleAgentThread(name,type), _elapsedTime(0)
00029 {
00030         bindMessage( "^Time$", BUS_CALLBACK_OF(TimerAgent, handleTime));
00031         this->start();
00032         _threadActive = true;
00033         _delay = delay;
00034 }
00035 
00036 TimerAgent::~TimerAgent()
00037 {
00038         _threadActive = 0;
00039 }
00040 
00041 void TimerAgent::run ()
00042 {
00043         while(_threadActive)
00044         {
00045                 _elapsedTime+=_delay;
00046                 ::Sleep(_delay);
00047                 onTimer();
00048         }
00049 }
00050 
00051 
00052 void TimerAgent::handleTime(MicoleBus *app,int argc, const char **argv) 
00053 {
00054 }
00055 
00056 int TimerAgent::getElapsedTime()
00057 {
00058         return _elapsedTime;
00059 }
00060 
00064 void TimerAgent::prepareToStop(int argc, const char **argv)
00065 {
00066         _threadActive = false;
00067 }
00068 
00069 void TimerAgent::prepareToSuspend(int argc, const char **argv)
00070 {
00071         _threadActive = false;
00072 }

Generated on Tue Oct 16 17:10:43 2007 for Micole by  doxygen 1.4.7