lliopipe.h

Go to the documentation of this file.
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 // Debugging schmutz for deadlocks
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                 // Processing occurred normally, future calls will be accepted.
00113                 STATUS_OK = 0,
00114 
00115                 // Processing occured normally, but stop unsolicited calls to
00116                 // process.
00117                 STATUS_STOP = 1,
00118 
00119                 // This pipe is done with the processing. Future calls to
00120                 // process will be accepted as long as new data is available.
00121                 STATUS_DONE = 2,
00122 
00123                 // This pipe is requesting that it become the head in a process.
00124                 STATUS_BREAK = 3,
00125 
00126                 // This pipe is requesting that it become the head in a process.
00127                 STATUS_NEED_PROCESS = 4,
00128 
00129                 // Keep track of the highest number of success codes here.
00130                 STATUS_SUCCESS_COUNT = 5,
00131 
00132                 // A generic error code.
00133                 STATUS_ERROR = -1,
00134 
00135                 // This method has not yet been implemented. This usually
00136                 // indicates the programmer working on the pipe is not yet
00137                 // done.
00138                 STATUS_NOT_IMPLEMENTED = -2,
00139 
00140                 // This indicates that a pipe precondition was not met. For
00141                 // example, many pipes require an element to appear after them
00142                 // in a chain (ie, mNext is not null) and will return this in
00143                 // response to method calls. To recover from this, it will
00144                 // require the caller to adjust the pipe state or may require
00145                 // a dev to adjust the code to satisfy the preconditions.
00146                 STATUS_PRECONDITION_NOT_MET = -3,
00147 
00148                 // This means we could not connect to a remote host.
00149                 STATUS_NO_CONNECTION = -4,
00150 
00151                 // The connection was lost.
00152                 STATUS_LOST_CONNECTION = -5,
00153 
00154                 // The totoal process time has exceeded the timeout.
00155                 STATUS_EXPIRED = -6,
00156 
00157                 // Keep track of the count of codes here.
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         /* @name LLIOPipe virtual implementations
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 // virtual
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

Generated on Fri May 16 08:32:26 2008 for SecondLife by  doxygen 1.5.5