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
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ReadHelper.hh

Go to the documentation of this file.
00001 // $Id: ReadHelper.hh 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2006 Stefan Bund <g0dil@berlios.de>
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the
00017 // Free Software Foundation, Inc.,
00018 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 // Copyright (C) 2006
00020 
00024 #ifndef HH_SENF_Scheduler_ReadHelper_
00025 #define HH_SENF_Scheduler_ReadHelper_ 1
00026 
00027 // Custom includes
00028 #include <string>
00029 #include <boost/function.hpp>
00030 #include <boost/intrusive_ptr.hpp>
00031 #include <boost/scoped_ptr.hpp>
00032 
00033 #include <senf/Utils/intrusive_refcount.hh>
00034 #include "FdEvent.hh"
00035 
00036 //#include "ReadHelper.mpp"
00037 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00038 
00039 namespace senf {
00040 
00041 
00068     template <class Handle>
00069     class ReadHelper
00070         : public senf::intrusive_refcount
00071     {
00072     public:
00073         //-////////////////////////////////////////////////////////////////////////
00074         // Types
00075 
00076         typedef boost::intrusive_ptr<ReadHelper> ptr; 
00077         typedef boost::function<void (ptr)> Callback; 
00078 
00079         //-////////////////////////////////////////////////////////////////////////
00081         //\{
00082 
00083         static ptr dispatch(Handle handle, std::string::size_type maxSize,
00084                             Callback callback); 
00085 
00096         template <class Predicate>
00097         static ptr dispatch(Handle handle, std::string::size_type maxSize, Predicate const & predicate,
00098                             Callback callback); 
00099 
00112         //\}
00113         //-////////////////////////////////////////////////////////////////////////
00114 
00115         Handle handle() const;          
00116         std::string::size_type maxSize() const; 
00117 
00118         std::string const & data() const; 
00119         std::string const & tail() const; 
00120 
00121         bool complete() const;          
00122         bool error() const;             
00123         void throw_error() const;       
00124 
00125         void revoke();                  
00126 
00127     protected:
00128 
00129     private:
00130         struct InternalPredicate;
00131 
00132         ReadHelper(Handle handle, std::string::size_type maxSize,
00133                    InternalPredicate * predicate, Callback cb);
00134 
00135         static void dispatchProcess(ptr helper, Handle handle, int event);
00136         void process(Handle handle, int event);
00137         void done();
00138 
00139         Handle handle_;
00140         scheduler::FdEvent fde_;
00141         std::string::size_type maxSize_;
00142         boost::scoped_ptr<InternalPredicate> predicate_;
00143         Callback callback_;
00144 
00145         std::string data_;
00146         std::string tail_;
00147         int errno_;
00148         bool complete_;
00149     };
00150 
00159     struct ReadUntil
00160     {
00161         ReadUntil(std::string const & target);
00162         std::string::size_type operator()(std::string const & data);
00163         std::string target;
00164     };
00165 
00166 }
00167 
00168 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00169 #include "ReadHelper.cci"
00170 #include "ReadHelper.ct"
00171 #include "ReadHelper.cti"
00172 //#include "ReadHelper.mpp"
00173 #endif
00174 
00175 
00176 // Local Variables:
00177 // mode: c++
00178 // fill-column: 100
00179 // c-file-style: "senf"
00180 // indent-tabs-mode: nil
00181 // ispell-local-dictionary: "american"
00182 // compile-command: "scons -u test"
00183 // comment-column: 40
00184 // End:

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