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_LOST_CONNECTION = -5,
00153
00154
00155 STATUS_EXPIRED = -6,
00156
00157
00158 STATUS_ERROR_COUNT = 6,
00159 };
00160
00170 inline static bool isError(EStatus status)
00171 {
00172 return ((S32)status < 0);
00173 }
00174
00184 inline static bool isSuccess(EStatus status)
00185 {
00186 return ((S32)status >= 0);
00187 }
00188
00195 static std::string lookupStatusString(EStatus status);
00196
00206 EStatus process(
00207 const LLChannelDescriptors& channels,
00208 buffer_ptr_t& buffer,
00209 bool& eos,
00210 LLSD& context,
00211 LLPumpIO* pump);
00212
00229 virtual EStatus handleError(EStatus status, LLPumpIO* pump);
00230
00234 virtual ~LLIOPipe();
00235
00236 protected:
00240 LLIOPipe();
00241
00245 virtual EStatus process_impl(
00246 const LLChannelDescriptors& channels,
00247 buffer_ptr_t& buffer,
00248 bool& eos,
00249 LLSD& context,
00250 LLPumpIO* pump) = 0;
00251
00252 private:
00253 friend void boost::intrusive_ptr_add_ref(LLIOPipe* p);
00254 friend void boost::intrusive_ptr_release(LLIOPipe* p);
00255 U32 mReferenceCount;
00256 };
00257
00258 namespace boost
00259 {
00260 inline void intrusive_ptr_add_ref(LLIOPipe* p)
00261 {
00262 ++p->mReferenceCount;
00263 }
00264 inline void intrusive_ptr_release(LLIOPipe* p)
00265 {
00266 if(p && 0 == --p->mReferenceCount)
00267 {
00268 delete p;
00269 }
00270 }
00271 };
00272
00273
00274 #if 0
00275
00282 class LLIOBoiler : public LLIOPipe
00283 {
00284 public:
00285 LLIOBoiler();
00286 virtual ~LLIOBoiler();
00287
00288 protected:
00289
00290
00292
00295 virtual EStatus process_impl(
00296 const LLChannelDescriptors& channels,
00297 buffer_ptr_t& buffer,
00298 bool& eos,
00299 LLSD& context,
00300 LLPumpIO* pump);
00302 };
00303
00304
00305 LLIOPipe::EStatus process_impl(
00306 const LLChannelDescriptors& channels,
00307 buffer_ptr_t& buffer,
00308 bool& eos,
00309 LLSD& context,
00310 LLPumpIO* pump)
00311 {
00312 return STATUS_NOT_IMPLEMENTED;
00313 }
00314
00315 #endif // #if 0 - use this block as a boilerplate
00316
00317 #endif // LL_LLIOPIPE_H