Renamed namespaces satcom::lib and satcom::pkf to senf
[senf.git] / Scheduler / WriteHelper.hh
1 // $Id$
2 //
3 // Copyright (C) 2006 
4
5 #ifndef HH_WriteHelper_
6 #define HH_WriteHelper_ 1
7
8 // Custom includes
9 #include <string>
10 #include <boost/intrusive_ptr.hpp>
11 #include <boost/function.hpp>
12 #include "Utils/intrusive_refcount.hh"
13 #include "Scheduler.hh"
14
15 //#include "WriteHelper.mpp"
16 ///////////////////////////////hh.p////////////////////////////////////////
17
18 namespace senf {
19
20
21     template <class Handle>
22     class WriteHelper
23         : public senf::intrusive_refcount
24     {
25     public:
26         ///////////////////////////////////////////////////////////////////////////
27         // Types
28
29         typedef boost::intrusive_ptr<WriteHelper> ptr;
30         typedef boost::function<void (ptr)> Callback;
31
32         ///////////////////////////////////////////////////////////////////////////
33         ///\name Structors and default members
34         ///@{
35
36         static ptr dispatch(Handle handle, std::string data, Callback callback);
37
38         ///@}
39         ///////////////////////////////////////////////////////////////////////////
40
41         Handle handle() const;
42
43         std::string const & data() const;
44
45         bool complete() const;
46         bool error() const;
47         void throw_error() const;
48
49         void revoke();
50
51     protected:
52
53     private:
54         WriteHelper(Handle handle, std::string data, Callback callback);
55
56         static void dispatchProcess(ptr helper, Handle handle, senf::Scheduler::EventId event);
57         void process(Handle handle, senf::Scheduler::EventId event);
58         void done();
59
60         Handle handle_;
61         mutable std::string data_;
62         Callback callback_;
63
64         mutable std::string::size_type offset_;
65         int errno_;
66     };
67
68
69 }
70
71 ///////////////////////////////hh.e////////////////////////////////////////
72 //#include "WriteHelper.cci"
73 #include "WriteHelper.ct"
74 #include "WriteHelper.cti"
75 //#include "WriteHelper.mpp"
76 #endif
77
78 \f
79 // Local Variables:
80 // mode: c++
81 // End: