User Manual, Developers Guide and API Documentation

PhysicalResource.hpp

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. 5, 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 #ifndef _PHYSICALRESOURCE_HPP
00029 #define _PHYSICALRESOURCE_HPP
00030 
00031 #include <RISE/medium/PhysicalResourceObserver.hpp>
00032 #include <RISE/transmissionobjects/transmissionobject.hpp>
00033 #include <RISE/misc/pointer.hpp>
00034 #include <RISE/misc/RISELogger.hpp>
00035 
00036 #include <WNS/Functor.hpp>
00037 #include <WNS/container/FastList.hpp>
00038 #include <WNS/Interval.hpp>
00039 #include <WNS/PowerRatio.hpp>
00040 
00041 #ifndef WNS_USE_STLPORT
00042 #include <ext/slist>
00043 #else
00044 #include <slist>
00045 #endif
00046 
00047 namespace rise {
00048     class PhysicalResourceObserver;
00049 }
00050 
00051 namespace rise { namespace medium {
00071     class PhysicalResource {
00072         friend class Gather80211StationData;
00073         // Medium manages PhysicalResources
00074         friend class Medium;
00075 
00079 #ifndef WNS_USE_STLPORT
00080         typedef __gnu_cxx::slist<PhysicalResourceObserver*> ReceiverContainer;
00081 #else
00082         typedef std::slist<PhysicalResourceObserver*> ReceiverContainer;
00083 #endif
00084 
00087         typedef ReceiverContainer::const_iterator ReceiverIterator;
00088 
00092         typedef wns::container::FastList<TransmissionObjectPtr> TransmissionObjectContainer;
00093 
00097         typedef wns::Interval<double> Range;
00098 
00099     public:
00106         typedef wns::container::FastList<TransmissionObjectPtr>::iterator TransmissionObjectIterator;
00107 
00112         void startTransmission(TransmissionObjectPtr transmissionObject)
00113         {
00114             transmissionObject->setPhysicalResource(this);
00115             transmissionObject->setIsStart(true);
00116             notifyReceivers(transmissionObject);
00117             transmissionObjects.push_front(transmissionObject);
00118         };
00119 
00124         void stopTransmission(TransmissionObjectPtr transmissionObject)
00125         {
00126             transmissionObject->setIsStart(false);
00127             notifyReceivers(transmissionObject);
00128             transmissionObjects.remove(transmissionObject);
00129         };
00130 
00139         void attach(PhysicalResourceObserver *r);
00140 
00149         void detach(PhysicalResourceObserver *r);
00150 
00157         bool operator ==(const PhysicalResource &p) const
00158         {
00159             return (frequencyRange == p.frequencyRange);
00160         }
00161 
00162         bool operator !=(const PhysicalResource &p) const
00163         {
00164             return !(*this==p);
00165         }
00166 
00170         TransmissionObjectIterator getTOBegin() const
00171         {
00172             return transmissionObjects.begin();
00173         }
00174 
00178         TransmissionObjectIterator getTOEnd() const
00179         {
00180             return transmissionObjects.end();
00181         }
00182 
00187         bool contains(TransmissionObjectPtr t)
00188         {
00189             return transmissionObjects.contains(t);
00190         }
00191 
00195         double getFrequency() const
00196         {
00197             return frequency;
00198         }
00199 
00203         double getBandwidth() const
00204         {
00205             return bandwidth;
00206         }
00207 
00211         Range getFrequencyRange()
00212         {
00213             return frequencyRange;
00214         }
00215 
00219         void mobilityUpdate(Transmitter* transmitter)
00220         {
00221             MESSAGE_BEGIN(NORMAL, log, m, "Calling Mobility update for ");
00222             m << receivers.size() << " receivers on PhysicalResource";
00223             MESSAGE_END();
00224             std::for_each(
00225                 receivers.begin(),
00226                 receivers.end(),
00227                 std::bind2nd(
00228                     std::mem_fun(
00229                         &PhysicalResourceObserver::mobilityUpdate),
00230                     transmitter));
00231         };
00232 
00233     private:
00239         PhysicalResource(double f, double b);
00240 
00246         virtual ~PhysicalResource();
00247 
00251         PhysicalResource();
00252 
00256         void notifyReceivers(const TransmissionObjectPtr& transmissionObject) const
00257         {
00258             MESSAGE_BEGIN(NORMAL, log, m, "NotifyReceivers (start=");
00259             m << transmissionObject->getIsStart()<< ")";
00260             MESSAGE_END();
00261             std::for_each(
00262                 receivers.begin(),
00263                 receivers.end(),
00264                 std::bind2nd(
00265                     std::mem_fun(
00266                         &PhysicalResourceObserver::notify),
00267                     transmissionObject));
00268             // this calls Receiver::notify(TransmissionObjectPtr t)
00269             // in class Receiver derived from PhysicalResourceObserver
00270         };
00271 
00275         double frequency;
00276 
00280         double bandwidth;
00281 
00285         Range frequencyRange;
00286 
00291         ReceiverContainer receivers;
00292 
00296         TransmissionObjectContainer transmissionObjects;
00297 
00301         RISELogger log;
00302 
00306         PhysicalResource(const PhysicalResource&);
00307 
00311         PhysicalResource& operator=(const PhysicalResource&);
00312 
00313     };
00314 }}
00315 #endif
00316 
00317 

Generated on Fri May 25 03:31:58 2012 for openWNS by  doxygen 1.5.5