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                 // This means we could not connect to a remote host.
00152                 STATUS_EXPIRED = -5,
00153 
00154                 // Keep track of the count of codes here.
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         /* @name LLIOPipe virtual implementations
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 // virtual
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

Generated on Thu Jul 1 06:08:47 2010 for Second Life Viewer by  doxygen 1.4.7