User Manual, Developers Guide and API Documentation

CanTimeout.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 
00029 #include <WNS/simulator/ISimulator.hpp>
00030 #include <WNS/events/scheduler/Interface.hpp>
00031 
00032 #include <WNS/events/CanTimeout.hpp>
00033 #include <WNS/Assure.hpp>
00034 
00035 using namespace wns::events;
00036 
00037 CanTimeout::CanTimeout() :
00038     event(),
00039     scheduler(wns::simulator::getEventScheduler())
00040 {
00041 }
00042 
00043 
00044 CanTimeout::~CanTimeout()
00045 {
00046     if (this->hasTimeoutSet()) {
00047         this->cancelTimeout();
00048     }
00049 }
00050 
00051 
00052 void
00053 CanTimeout::setTimeout(double delay)
00054 {
00055     assure(!this->hasTimeoutSet(), "A timer has been set already.");
00056 
00057     TimeoutEvent toEvent(this);
00058     this->event =
00059         this->scheduler->scheduleDelay(toEvent, delay);
00060 }
00061 
00062 
00063 void
00064 CanTimeout::setNewTimeout(double delay)
00065 {
00066     if (this->hasTimeoutSet()) {
00067         this->cancelTimeout();
00068     }
00069 
00070     this->setTimeout(delay);
00071 }
00072 
00073 
00074 bool
00075 CanTimeout::hasTimeoutSet() const
00076 {
00077     // will be automatically converted bool
00078     return this->event;
00079 }
00080 
00081 
00082 void
00083 CanTimeout::cancelTimeout()
00084 {
00085     assure(this->hasTimeoutSet(), "No timer has been set.");
00086 
00087     this->scheduler->cancelEvent(this->event);
00088     this->event = scheduler::IEventPtr();
00089 }
00090 
00091 
00092 CanTimeout::TimeoutEvent::TimeoutEvent(CanTimeout* _target) :
00093     target(_target)
00094 {
00095     assure(this->target, "target not valid (NULL)");
00096 }
00097 
00098 
00099 CanTimeout::TimeoutEvent::~TimeoutEvent()
00100 {
00101     target = NULL;
00102 }
00103 
00104 void
00105 CanTimeout::TimeoutEvent::operator()()
00106 {
00107     assure(this->target, "target not valid (NULL)");
00108 
00109     this->target->event = scheduler::IEventPtr();
00110     this->target->onTimeout();
00111 }
00112 
00113 void
00114 CanTimeout::TimeoutEvent::print(std::ostream& aStreamRef) const
00115 {
00116     aStreamRef << "<" << TypeInfo::create(*this) <<" instance at "
00117            << static_cast<const void* const>(this) << ">";
00118 
00119     aStreamRef << ", target: " << wns::TypeInfo::create(*this->target);
00120 }
00121 
00122 /*
00123   Local Variables:
00124   mode: c++
00125   fill-column: 80
00126   c-basic-offset: 8
00127   c-comment-only-line-offset: 0
00128   c-tab-always-indent: t
00129   indent-tabs-mode: t
00130   tab-width: 8
00131   End:
00132 */

Generated on Tue May 22 03:31:34 2012 for openWNS by  doxygen 1.5.5