User Manual, Developers Guide and API Documentation

KeyBuilder.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  * Glue                                                                       *
00003  * __________________________________________________________________________ *
00004  *                                                                            *
00005  * Copyright (C) 2005-2006                                                    *
00006  * Lehrstuhl fuer Kommunikationsnetze (ComNets)                               *
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany                                 *
00008  * phone: ++49-241-80-27910 (phone), fax: ++49-241-80-22242                   *
00009  * email: wns@comnets.rwth-aachen.de                                          *
00010  * www: http://wns.comnets.rwth-aachen.de                                     *
00011  ******************************************************************************/
00012 
00013 #include <GLUE/KeyBuilder.hpp>
00014 #include <GLUE/convergence/Upper.hpp>
00015 
00016 #include <WNS/ldk/fun/FUN.hpp>
00017 
00018 using namespace glue;
00019 
00020 STATIC_FACTORY_REGISTER_WITH_CREATOR(KeyBuilder, wns::ldk::KeyBuilder,
00021                                      "glue.KeyBuilder",
00022                                      wns::ldk::FUNConfigCreator);
00023 
00024 Key::Key(const Address& address1,
00025          const Address& address2)
00026     : address1_(address1),
00027       address2_(address2)
00028 {
00029     if (address2_.getInteger() < address1_.getInteger())
00030     {
00031         address2_ = address1;
00032         address1_ = address2;
00033     }
00034 }
00035 
00036 bool
00037 Key::operator<(const wns::ldk::Key& other) const
00038 {
00039     assure( typeid( other ) == typeid( Key ),
00040             "comparing different key types");
00041     const Key* otherID = static_cast<const Key*>(&other);
00042 
00043     if ((address1_.getInteger() + 10000 * address2_.getInteger()) <
00044         (otherID->address1_.getInteger() + 10000 * otherID->address2_.getInteger()))
00045     {
00046         return true;
00047     }
00048     return false;
00049 }
00050 
00051 std::string
00052 Key::str() const
00053 {
00054     std::stringstream ss;
00055     ss << "(" << address1_.getInteger() << "|" << address2_.getInteger() << ")";
00056     return ss.str();
00057 }
00058 
00059 
00060 KeyBuilder::KeyBuilder(const wns::ldk::fun::FUN* fun,
00061                        const wns::pyconfig::View& config)
00062     : fun_(fun),
00063       config_(config)
00064 {
00065 
00066 }
00067 
00068 void
00069 KeyBuilder::onFUNCreated()
00070 {
00071     friends_.unicastUpper = fun_->findFriend<convergence::UnicastUpper*>(config_.get<std::string>("unicastUpper"));
00072 }
00073 
00074 wns::ldk::ConstKeyPtr
00075 KeyBuilder::operator()(const wns::ldk::CompoundPtr& compound, int) const
00076 {
00077     convergence::UnicastUpperCommand* command = friends_.unicastUpper->getCommand(compound->getCommandPool());
00078 
00079     return wns::ldk::ConstKeyPtr(new Key(command->peer.sourceMACAddress,
00080                                          command->peer.targetMACAddress));
00081 }

Generated on Thu May 24 03:31:57 2012 for openWNS by  doxygen 1.5.5