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

QueueingSocketSink.cc

Go to the documentation of this file.
00001 // $Id: QueueingSocketSink.cc 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2010
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Thorsten Horstmann <tho@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 //
00023 
00027 #include "QueueingSocketSink.hh"
00028 //#include "QueueingSocketSink.ih"
00029 
00030 // Custom includes
00031 #include <senf/Utils/Console/Variables.hh>
00032 
00033 #define prefix_
00034 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00035 
00036 SENF_PPI_REGISTER_QALGORITHM( "FIFOQueueingAlgorithm", senf::ppi::FIFOQueueingAlgorithm);
00037 
00038 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00039 // senf::ppi::QueueingAlgorithm
00040 
00041 prefix_ senf::ppi::QueueingAlgorithm::QueueingAlgorithm()
00042     : dir_(this)
00043 {
00044     namespace fty = console::factory;
00045     dir_.add("size", fty::Command( &QueueingAlgorithm::size, this));
00046     dir_.add("clear", fty::Command( &QueueingAlgorithm::clear, this));
00047 }
00048 
00049 prefix_ senf::console::DirectoryNode & senf::ppi::QueueingAlgorithm::consoleDir()
00050 {
00051     return dir_;
00052 }
00053 
00054 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00055 // senf::ppi::QueueingAlgorithmRegistry
00056 
00057 prefix_ void senf::ppi::QueueingAlgorithmRegistry::dump(std::ostream & os)
00058     const
00059 {
00060     for (QAlgoMap::const_iterator i = qAlgoMap_.begin(); i != qAlgoMap_.end(); ++i) {
00061         os << i->first << std::endl;
00062     }
00063 }
00064 
00065 prefix_ senf::ppi::QueueingAlgorithm::ptr senf::ppi::QueueingAlgorithmRegistry::createQAlgorithm(std::string const & key)
00066     const
00067 {
00068     QAlgoMap::const_iterator i (qAlgoMap_.find( key));
00069     if (i != qAlgoMap_.end())
00070         return i->second->create();
00071     else
00072         throw Exception("QueueingAlgorithm not registered: ") << key;
00073 }
00074 
00075 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00076 // senf::ppi::FIFOQueueingAlgorithm
00077 
00078 prefix_ senf::ppi::FIFOQueueingAlgorithm::FIFOQueueingAlgorithm()
00079     : max_size_( 64)
00080 {
00081     consoleDir().add("max-size", console::factory::Variable(max_size_) );
00082 }
00083 
00084 prefix_ senf::Packet senf::ppi::FIFOQueueingAlgorithm::v_dequeue()
00085 {
00086     if (queue_.size() > 0) {
00087         Packet p (queue_.front());
00088         queue_.pop();
00089         return p;
00090     }
00091     return Packet();
00092 }
00093 
00094 prefix_ bool senf::ppi::FIFOQueueingAlgorithm::v_enqueue(Packet const & packet)
00095 {
00096     if (queue_.size() >= max_size_)
00097         queue_.pop();
00098     queue_.push( packet);
00099     return true;
00100 }
00101 
00102 prefix_ void senf::ppi::FIFOQueueingAlgorithm::v_clear()
00103 {
00104     while (! queue_.empty())
00105         queue_.pop();
00106 }
00107 
00108 prefix_ senf::ppi::QueueingAlgorithm::ptr senf::ppi::FIFOQueueingAlgorithm::create()
00109 {
00110     return new FIFOQueueingAlgorithm();
00111 }
00112 
00113 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00114 #undef prefix_

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