![]() |
User Manual, Developers Guide and API Documentation |
![]() |
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/Pilot.hpp> 00014 00015 #include <WNS/ldk/helper/FakePDU.hpp> 00016 #include <WNS/pyconfig/View.hpp> 00017 #include <WNS/Exception.hpp> 00018 00019 using namespace glue; 00020 00021 Pilot::Pilot(wns::ldk::fun::FUN* fun, wns::pyconfig::View& config) 00022 : wns::ldk::CommandTypeSpecifier<wns::ldk::EmptyCommand>(fun), 00023 00024 enabled(config.get<bool>("startEnabled")), 00025 timeout(config.get<double>("transmissionTimeout")), 00026 delayedSend(false), 00027 logger(config.get<wns::pyconfig::View>("logger")) 00028 { 00029 if (enabled) enable(); 00030 } // Pilot 00031 00032 Pilot::~Pilot() 00033 { 00034 } // ~Pilot 00035 00036 void 00037 Pilot::enable() 00038 { 00039 enabled = true; 00040 startPeriodicTimeout(timeout); 00041 } // enable 00042 00043 void 00044 Pilot::disable() 00045 { 00046 enabled = false; 00047 cancelPeriodicTimeout(); 00048 } // disable 00049 00050 void 00051 Pilot::attach(Observer* observer) 00052 { 00053 observers.push_back(observer); 00054 } // attach 00055 00056 void 00057 Pilot::detach(Observer* observer) 00058 { 00059 observers.remove(observer); 00060 } // detach 00061 00062 void 00063 Pilot::sendBeacon() 00064 { 00065 wns::ldk::CompoundPtr compound(new wns::ldk::Compound(getFUN()->getProxy()->createCommandPool(), wns::ldk::helper::FakePDUPtr())); 00066 00067 activateCommand(compound->getCommandPool()); 00068 00069 if (getConnector()->hasAcceptor(compound)) { 00070 00071 MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName()); 00072 m << " Sending beacon"; 00073 if (delayedSend) m << " (delayed)"; 00074 MESSAGE_END(); 00075 00076 getConnector()->getAcceptor(compound)->sendData(compound); 00077 delayedSend = false; 00078 00079 } else { 00080 MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName()); 00081 m << " Delaying sending of beacon"; 00082 MESSAGE_END(); 00083 delayedSend = true; 00084 } 00085 } // sendBeacon 00086 00087 bool 00088 Pilot::doIsAccepting(const wns::ldk::CompoundPtr&) const 00089 { 00090 return false; 00091 } // doIsAccepting 00092 00093 void 00094 Pilot::doSendData(const wns::ldk::CompoundPtr&) 00095 { 00096 throw wns::Exception("glue::Pilot does not send data."); 00097 } // doSendData 00098 00099 void 00100 Pilot::doWakeup() 00101 { 00102 if (delayedSend) sendBeacon(); 00103 } // doWakeUp 00104 00105 void 00106 Pilot::doOnData(const wns::ldk::CompoundPtr& compound) 00107 { 00108 MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName()); 00109 m << " Received beacon"; 00110 MESSAGE_END(); 00111 00112 notifyObservers(createObserverInformation(compound)); 00113 } // doOnData 00114 00115 void 00116 Pilot::periodically() 00117 { 00118 sendBeacon(); 00119 } // periodically 00120 00121 Pilot::Observer::Information 00122 Pilot::createObserverInformation(const wns::ldk::CompoundPtr& /* compound */) 00123 { 00124 Observer::Information info; 00125 return info; 00126 } // createObserverInformation 00127 00128 void 00129 Pilot::notifyObservers(const Observer::Information& info) 00130 { 00131 for (ObserverList::iterator anObserver = observers.begin(); anObserver != observers.end() ; ++anObserver) 00132 (*anObserver)->receivedBeacon(info); 00133 } // notifyObservers 00134
1.5.5