X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Scheduler%2FReadHelper.ct;h=3ac3df5f55a0d3e8364cddb878ad158ec1a2da52;hb=9a988902090d28007578e93bffd809f6bd913155;hp=16d2850617a484bdc5b6cd45e9178dc2f4fdef84;hpb=c5ab87643518405aa5171ed4602f7234873a4900;p=senf.git diff --git a/Scheduler/ReadHelper.ct b/Scheduler/ReadHelper.ct index 16d2850..3ac3df5 100644 --- a/Scheduler/ReadHelper.ct +++ b/Scheduler/ReadHelper.ct @@ -1,8 +1,25 @@ // $Id$ // -// Copyright (C) 2006 +// Copyright (C) 2006 Stefan Bund +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// Copyright (C) 2006 -// Definition of non-inline template functions +/** \file + \brief ReadHelper non-inline template implementation */ #include "ReadHelper.ih" @@ -16,32 +33,32 @@ ///////////////////////////////ct.p//////////////////////////////////////// template -prefix_ satcom::lib::ReadHelper::ReadHelper(Handle handle, std::string::size_type maxSize, +prefix_ senf::ReadHelper::ReadHelper(Handle handle, std::string::size_type maxSize, InternalPredicate * predicate, Callback cb) - : handle_(handle), maxSize_(maxSize), predicate_(predicate), callback_(cb), + : handle_(handle), maxSize_(maxSize), predicate_(predicate), callback_(cb), errno_(0), complete_(false) { // Here we add a *static* member taking a *smart* pointer as first // argumnet instead of a simple bound-member as callback to the // scheduler. This ensures, that the refcount is at least 1 as // long as the helper is registered with the scheduler. - satcom::lib::Scheduler::instance() - .add(handle,boost::bind(&ReadHelper::dispatchProcess,ptr(this),_1,_2), - satcom::lib::Scheduler::EV_READ); + senf::Scheduler::instance() + .add(handle,boost::bind(&ReadHelper::dispatchProcess,ptr(this),_1,_2), + senf::Scheduler::EV_READ); } template -prefix_ void satcom::lib::ReadHelper::revoke() +prefix_ void senf::ReadHelper::revoke() { ptr guard (this); // To ensure, 'this' is deleted only after this method terminates ... - satcom::lib::Scheduler::instance() - .remove(handle_,satcom::lib::Scheduler::EV_READ); + senf::Scheduler::instance() + .remove(handle_,senf::Scheduler::EV_READ); } template prefix_ void -satcom::lib::ReadHelper::dispatchProcess(ptr helper, Handle handle, - satcom::lib::Scheduler::EventId event) +senf::ReadHelper::dispatchProcess(ptr helper, Handle handle, + senf::Scheduler::EventId event) { // since we have a 'ptr' argument, the instance cannot be deleted // before this method returns @@ -49,32 +66,33 @@ satcom::lib::ReadHelper::dispatchProcess(ptr helper, Handle handle, } template -prefix_ void satcom::lib::ReadHelper::process(Handle handle, - satcom::lib::Scheduler::EventId event) +prefix_ void senf::ReadHelper::process(Handle handle, + senf::Scheduler::EventId event) { + /** \fixme Move the done() calls to outside the try/catch block */ try { - if (event != satcom::lib::Scheduler::EV_READ) - throw SystemException(EPIPE); - std::string rcv (handle.read(maxSize_ - data_.size())); - data_.append(rcv); - std::string::size_type n = predicate_ ? (*predicate_)(data_) : std::string::npos; - if (n != std::string::npos || data_.size() >= maxSize_ || rcv.size() == 0) { - complete_ = true; - if (n < data_.size()) { - tail_.assign(data_,n,std::string::npos); - data_.erase(n); - } - done(); - } + if (event != senf::Scheduler::EV_READ) + throw SystemException(EPIPE); + std::string rcv (handle.read(maxSize_ - data_.size())); + data_.append(rcv); + std::string::size_type n = predicate_ ? (*predicate_)(data_) : std::string::npos; + if (n != std::string::npos || data_.size() >= maxSize_ || rcv.size() == 0) { + complete_ = true; + if (n < data_.size()) { + tail_.assign(data_,n,std::string::npos); + data_.erase(n); + } + done(); + } } - catch (satcom::lib::SystemException const & ex) { - errno_ = ex.err; - done(); + catch (senf::SystemException const & ex) { + errno_ = ex.err; + done(); } } template -prefix_ void satcom::lib::ReadHelper::done() +prefix_ void senf::ReadHelper::done() { revoke(); callback_(ptr(this)); @@ -83,7 +101,7 @@ prefix_ void satcom::lib::ReadHelper::done() template template prefix_ std::string::size_type -satcom::lib::ReadHelper::InternalPredicate::Dispatcher:: +senf::ReadHelper::InternalPredicate::Dispatcher:: operator()(std::string const & data) { return predicate(data); @@ -95,4 +113,8 @@ operator()(std::string const & data) // Local Variables: // mode: c++ +// fill-column: 100 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" // End: