00001 
00034 #ifndef LL_LLIOPIPE_H
00035 #define LL_LLIOPIPE_H
00036 
00037 #include <boost/intrusive_ptr.hpp>
00038 #include <boost/shared_ptr.hpp>
00039 #include "apr-1/apr_poll.h"
00040 
00041 #include "llsd.h"
00042 
00043 class LLIOPipe;
00044 class LLPumpIO;
00045 class LLBufferArray;
00046 class LLChannelDescriptors;
00047 
00048 
00049 #define LL_DEBUG_PUMPS
00050 #ifdef LL_DEBUG_PUMPS
00051 void pump_debug(const char *file, S32 line);
00052 #define PUMP_DEBUG pump_debug(__FILE__, __LINE__);
00053 #define END_PUMP_DEBUG pump_debug("none", 0);
00054 #endif
00055 
00056 
00060 namespace boost
00061 {
00062         void intrusive_ptr_add_ref(LLIOPipe* p);
00063         void intrusive_ptr_release(LLIOPipe* p);
00064 };
00065 
00082 class LLIOPipe
00083 {
00084 public:
00091         typedef boost::intrusive_ptr<LLIOPipe> ptr_t;
00092 
00096         typedef boost::shared_ptr<LLBufferArray> buffer_ptr_t;
00097 
00110         enum EStatus
00111         {
00112                 
00113                 STATUS_OK = 0,
00114 
00115                 
00116                 
00117                 STATUS_STOP = 1,
00118 
00119                 
00120                 
00121                 STATUS_DONE = 2,
00122 
00123                 
00124                 STATUS_BREAK = 3,
00125 
00126                 
00127                 STATUS_NEED_PROCESS = 4,
00128 
00129                 
00130                 STATUS_SUCCESS_COUNT = 5,
00131 
00132                 
00133                 STATUS_ERROR = -1,
00134 
00135                 
00136                 
00137                 
00138                 STATUS_NOT_IMPLEMENTED = -2,
00139 
00140                 
00141                 
00142                 
00143                 
00144                 
00145                 
00146                 STATUS_PRECONDITION_NOT_MET = -3,
00147 
00148                 
00149                 STATUS_NO_CONNECTION = -4,
00150 
00151                 
00152                 STATUS_EXPIRED = -5,
00153 
00154                 
00155                 STATUS_ERROR_COUNT = 5,
00156         };
00157 
00167         inline static bool isError(EStatus status)
00168         {
00169                 return ((S32)status < 0);
00170         }
00171 
00181         inline static bool isSuccess(EStatus status)
00182         {
00183                 return ((S32)status >= 0);
00184         }
00185 
00192         static std::string lookupStatusString(EStatus status);
00193 
00203         EStatus process(
00204                 const LLChannelDescriptors& channels,
00205                 buffer_ptr_t& buffer,
00206                 bool& eos,
00207                 LLSD& context,
00208                 LLPumpIO* pump);
00209 
00226         virtual EStatus handleError(EStatus status, LLPumpIO* pump);
00227 
00231         virtual ~LLIOPipe();
00232 
00233 protected:
00237         LLIOPipe();
00238 
00242         virtual EStatus process_impl(
00243                 const LLChannelDescriptors& channels,
00244                 buffer_ptr_t& buffer,
00245                 bool& eos,
00246                 LLSD& context,
00247                 LLPumpIO* pump) = 0;
00248 
00249 private:
00250         friend void boost::intrusive_ptr_add_ref(LLIOPipe* p);
00251         friend void boost::intrusive_ptr_release(LLIOPipe* p);
00252         U32 mReferenceCount;
00253 };
00254 
00255 namespace boost
00256 {
00257         inline void intrusive_ptr_add_ref(LLIOPipe* p)
00258         {
00259                 ++p->mReferenceCount;
00260         }
00261         inline void intrusive_ptr_release(LLIOPipe* p)
00262         {
00263                 if(p && 0 == --p->mReferenceCount)
00264                 {
00265                         delete p;
00266                 }
00267         }
00268 };
00269 
00270 
00271 #if 0
00272 
00279 class LLIOBoiler : public LLIOPipe
00280 {
00281 public:
00282         LLIOBoiler();
00283         virtual ~LLIOBoiler();
00284 
00285 protected:
00286         
00287 
00289 
00292         virtual EStatus process_impl(
00293                 const LLChannelDescriptors& channels,
00294                 buffer_ptr_t& buffer,
00295                 bool& eos,
00296                 LLSD& context,
00297                 LLPumpIO* pump);
00299 };
00300 
00301 
00302 LLIOPipe::EStatus process_impl(
00303         const LLChannelDescriptors& channels,
00304         buffer_ptr_t& buffer,
00305         bool& eos,
00306         LLSD& context,
00307         LLPumpIO* pump)
00308 {
00309         return STATUS_NOT_IMPLEMENTED;
00310 }
00311 
00312 #endif // #if 0 - use this block as a boilerplate
00313 
00314 #endif // LL_LLIOPIPE_H