Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Directories
  • File List
  • File Members

Joins.cc

Go to the documentation of this file.
00001 // $Id: Joins.cc 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2007
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #include "Joins.hh"
00027 //#include "Joins.ih"
00028 
00029 // Custom includes
00030 #include <algorithm>
00031 #include <boost/bind.hpp>
00032 #include <boost/lambda/lambda.hpp>
00033 #include <boost/lambda/bind.hpp>
00034 
00035 //#include "Joins.mpp"
00036 #define prefix_
00037 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00038 
00039 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00040 // senf::ppi::module::PassiveJoin
00041 
00042 prefix_ senf::ppi::module::PassiveJoin::PassiveJoin()
00043 {
00044     noroute(output);
00045     output.onThrottle(&PassiveJoin::onThrottle);
00046     output.onUnthrottle(&PassiveJoin::onUnthrottle);
00047 }
00048 
00049 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00050 // private members
00051 
00052 prefix_ void senf::ppi::module::PassiveJoin::connectorSetup(connector::PassiveInput<> & conn)
00053 {
00054     noroute(conn);
00055     conn.onRequest(boost::bind(&PassiveJoin::request,this,boost::ref(conn)));
00056     conn.qdisc( QueueingDiscipline::NONE);
00057 }
00058 
00059 prefix_ void senf::ppi::module::PassiveJoin::onThrottle()
00060 {
00061     using boost::lambda::_1;
00062     using boost::lambda::bind;
00063     std::for_each(connectors().begin(), connectors().end(),
00064                   bind(&connector::GenericPassiveInput::throttle, _1));
00065 }
00066 
00067 prefix_ void senf::ppi::module::PassiveJoin::onUnthrottle()
00068 {
00069     using boost::lambda::_1;
00070     using boost::lambda::bind;
00071     std::for_each(connectors().begin(), connectors().end(),
00072                   bind(&connector::GenericPassiveInput::unthrottle, _1));
00073 }
00074 
00075 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00076 // senf::ppi::module::PriorityJoin
00077 
00078 prefix_ senf::ppi::module::PriorityJoin::PriorityJoin()
00079 {
00080     noroute(output);
00081     output.onRequest(&PriorityJoin::request);
00082 }
00083 
00084 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00085 // private members
00086 
00087 prefix_ void
00088 senf::ppi::module::PriorityJoin::connectorSetup(PriorityJoin::ConnectorType & conn,
00089                                                 int priority)
00090 {
00091     noroute(conn);
00092     conn.onThrottle(&PriorityJoin::onThrottle);
00093     conn.onUnthrottle(&PriorityJoin::onUnthrottle);
00094 
00095     if (priority < 0) {
00096         priority = connectors().size() + priority;
00097         if (priority < 0)
00098             priority = 0;
00099     }
00100     if (priority >= int(connectors().size())-1)
00101         return;
00102 
00103     connectors().insert(connectors().begin()+priority, connectors().pop_back().release());
00104 }
00105 
00106 prefix_ void senf::ppi::module::PriorityJoin::request()
00107 {
00108     using boost::lambda::_1;
00109     using boost::lambda::bind;
00110     PriorityJoin::ContainerType::iterator i (
00111         std::find_if(connectors().begin(), connectors().end(),
00112                      ! bind(&connector::GenericActiveInput::throttled, _1)));
00113     if (i != connectors().end())
00114         output((*i)());
00115 }
00116 
00117 prefix_ void senf::ppi::module::PriorityJoin::onThrottle()
00118 {
00119     if (std::find_if(connectors().begin(), connectors().end(),
00120                      ! bind(&connector::GenericActiveInput::throttled, _1)) == connectors().end())
00121         output.throttle();
00122 }
00123 
00124 prefix_ void senf::ppi::module::PriorityJoin::onUnthrottle()
00125 {
00126     output.unthrottle();
00127 }
00128 
00129 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00130 #undef prefix_
00131 //#include "Joins.mpp"
00132 
00133 
00134 // Local Variables:
00135 // mode: c++
00136 // fill-column: 100
00137 // comment-column: 40
00138 // c-file-style: "senf"
00139 // indent-tabs-mode: nil
00140 // ispell-local-dictionary: "american"
00141 // compile-command: "scons -u test"
00142 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research