User Manual, Developers Guide and API Documentation

Association.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. 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 #include <DLL/StationManager.hpp>
00029 #include <DLL/services/control/Association.hpp>
00030 #include <DLL/Layer2.hpp>
00031 #include <WNS/StaticFactory.hpp>
00032 #include <WNS/module/Base.hpp>
00033 
00034 using namespace dll::services::control;
00035 
00036 STATIC_FACTORY_REGISTER_WITH_CREATOR(Association,
00037                      wns::ldk::ControlServiceInterface,
00038                      "dll.services.control.Association",
00039                      wns::ldk::CSRConfigCreator);
00040 
00041 Association::Association(wns::ldk::ControlServiceRegistry* csr, const wns::pyconfig::View& config) :
00042     ControlService(csr),
00043     csr_(csr),
00044     serviceName_(config.get<std::string>("serviceName")),
00045     masterStation_(),
00046     slaveStations_(),
00047     logger_(config.get("logger"))
00048 {
00049 
00050 }
00051 
00052 wns::service::dll::UnicastAddress
00053 Association::getAssociation()
00054 {
00055     assure(masterStation_.isValid(), serviceName_ + " Association not found.");
00056     return masterStation_;
00057 }
00058 
00059 bool
00060 Association::hasAssociation()
00061 {
00062     return (masterStation_.isValid());
00063 }
00064 
00065 bool
00066 Association::hasAssociated(const wns::service::dll::UnicastAddress& slave) const
00067 {
00068     for (std::list<wns::service::dll::UnicastAddress>::const_iterator it = slaveStations_.begin();
00069          it != slaveStations_.end();
00070          ++it)
00071     {
00072         if (*it == slave)
00073         {
00074             return true;
00075         }
00076     }
00077     return false;
00078 
00079 }
00080 
00081 void
00082 Association::registerAssociation(wns::service::dll::UnicastAddress slave, wns::service::dll::UnicastAddress master)
00083 {
00084     // append to list
00085     slaveStations_.push_back(slave);
00086 
00087     MESSAGE_BEGIN(NORMAL, logger_, m, serviceName_ + " registered association from : ");
00088     m << slave;
00089     MESSAGE_END();
00090 
00091     this->AssociationInfo::forEachObserver(AssociationFunctor( &AssociationObserverInterface::onAssociated,
00092                                    slave,
00093                                    master));
00094 }
00095 
00096 std::vector<wns::service::dll::UnicastAddress>
00097 Association::getAssociated()
00098 {
00099     std::vector<wns::service::dll::UnicastAddress> allAssociations;
00100 
00101     for (std::list<wns::service::dll::UnicastAddress>::const_iterator it = slaveStations_.begin(); it != slaveStations_.end(); ++it)
00102     {
00103         allAssociations.push_back(*it);
00104     }
00105     return allAssociations;
00106 }
00107 
00108 void
00109 Association::associate(wns::service::dll::UnicastAddress slave, wns::service::dll::UnicastAddress master)
00110 {
00111     // 1. Store the destination as the station I am associated to (my
00112     // master)
00113     this->masterStation_ = master;
00114 
00115     MESSAGE_BEGIN(NORMAL, logger_, m, serviceName_ + " associating ");
00116     m << slave << " to " << master;
00117     MESSAGE_END();
00118 
00119     // 2. Register the association at the master's association service
00120     // first obtain pointer to my peer service at the master's side
00121     dll::services::control::Association* peerService =
00122         this->csr_->getLayer<dll::ILayer2*>()->getStationManager()->getStationByMAC(master)
00123         ->getControlService<dll::services::control::Association>(serviceName_);
00124     // then register the association
00125     peerService->registerAssociation(slave, master);
00126 }
00127 
00128 void
00129 Association::associate(dll::ILayer2* slave, dll::ILayer2* master)
00130 {
00131     this->associate(slave->getDLLAddress(), master->getDLLAddress());
00132 } //associate
00133 
00134 
00135 void
00136 Association::releaseFromMaster()
00137 {
00138     MESSAGE_BEGIN(NORMAL, logger_, m, serviceName_ + " releasing association to ");
00139     m << masterStation_;
00140     MESSAGE_END();
00141 
00142     masterStation_ = wns::service::dll::UnicastAddress();
00143 } //releaseFromMaster
00144 
00145 void
00146 Association::releaseClient(wns::service::dll::UnicastAddress slave)
00147 {
00148     // safety check
00149     assure( std::find(slaveStations_.begin(), slaveStations_.end(), slave) != slaveStations_.end(),
00150         "Trying to release unknown client association" );
00151 
00152     // remove from my set of slaves
00153     slaveStations_.remove(slave);
00154 }
00155 void
00156 Association::releaseClient(dll::ILayer2* slave)
00157 {
00158     this->releaseClient(slave->getDLLAddress());
00159 } //releaseFromMaster
00160 
00161 

Generated on Fri Feb 10 03:32:29 2012 for openWNS by  doxygen 1.5.5