User Manual, Developers Guide and API Documentation

Producer.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 WNS_LDK_TOOLS_PRODUCER_HPP
00029 #define WNS_LDK_TOOLS_PRODUCER_HPP
00030 
00031 #include <WNS/ldk/fun/FUN.hpp>
00032 
00033 #include <WNS/ldk/CommandTypeSpecifier.hpp>
00034 #include <WNS/ldk/HasReceptor.hpp>
00035 #include <WNS/ldk/HasConnector.hpp>
00036 #include <WNS/ldk/HasDeliverer.hpp>
00037 
00038 #include <WNS/pyconfig/View.hpp>
00039 
00040 #include <list>
00041 
00042 namespace wns { namespace ldk { namespace tools {
00043 
00059     class Producer :
00060         public virtual FunctionalUnit,
00061         public CommandTypeSpecifier<>,
00062         public HasReceptor<>,
00063         public HasConnector<>,
00064         public HasDeliverer<>,
00065         public Cloneable<Producer>
00066     {
00067     public:
00068         typedef std::list<CompoundPtr> ContainerType;
00069 
00070         Producer(fun::FUN* fuNet) :
00071                 CommandTypeSpecifier<>(fuNet),
00072                 HasReceptor<>(),
00073                 HasConnector<>(),
00074                 HasDeliverer<>(),
00075                 Cloneable<Producer>(),
00076 
00077                 sent(),
00078                 buffer()
00079             {
00080                 allocate();
00081             }
00082 
00083         ~Producer()
00084             {
00085             }
00086 
00087         virtual void
00088         doSendData(const CompoundPtr& /* compound */)
00089         {
00090             assure(false, "sendData of Producer called");
00091         } // doSendData
00092 
00093 
00094         virtual void
00095         doOnData(const CompoundPtr& compound)
00096         {
00097             getDeliverer()->getAcceptor(compound)->onData(compound);
00098             wakeup();
00099         } // doOnData
00100 
00101         unsigned long int sent;
00102 
00103     private:
00104         //
00105         // compound handler interface
00106         //
00107         virtual bool
00108         doIsAccepting(const CompoundPtr& /* compound */) const
00109         {
00110             return false;
00111         } // isAccepting
00112 
00113         virtual void
00114         doWakeup()
00115         {
00116             while(getConnector()->hasAcceptor(buffer)) {
00117                 CompoundPtr it = buffer;
00118                 allocate();
00119                 getConnector()->getAcceptor(it)->sendData(it);
00120                 ++sent;
00121             }
00122         } // wakeup
00123 
00124         void allocate()
00125         {
00126             buffer = getFUN()->createCompound();
00127         } // allocate
00128 
00129         CompoundPtr buffer;
00130     };
00131 
00132 }}}
00133 
00134 
00135 #endif // NOT defined WNS_LDK_TOOLS_PRODUCER_HPP
00136 
00137 

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