llapr.h

Go to the documentation of this file.
00001 
00034 #ifndef LL_LLAPR_H
00035 #define LL_LLAPR_H
00036 
00037 #if LL_LINUX || LL_SOLARIS
00038 #include <sys/param.h>  // Need PATH_MAX in APR headers...
00039 #endif
00040 
00041 #include <boost/noncopyable.hpp>
00042 
00043 #include "apr-1/apr_thread_proc.h"
00044 #include "apr-1/apr_thread_mutex.h"
00045 #include "apr-1/apr_getopt.h"
00046 #include "apr-1/apr_signal.h"
00047 #include "apr-1/apr_atomic.h"
00048 #include "llstring.h"
00049 
00050 extern apr_thread_mutex_t* gLogMutexp;
00051 
00056 void ll_init_apr();
00057 
00061 void ll_cleanup_apr();
00062 
00072 class LLScopedLock : private boost::noncopyable
00073 {
00074 public:
00081         LLScopedLock(apr_thread_mutex_t* mutex);
00082 
00086         ~LLScopedLock();
00087 
00091         bool isLocked() const { return mLocked; }
00092 
00096         void unlock();
00097 
00098 protected:
00099         bool mLocked;
00100         apr_thread_mutex_t* mMutex;
00101 };
00102 
00103 template <typename Type> class LLAtomic32
00104 {
00105 public:
00106         LLAtomic32<Type>() {};
00107         LLAtomic32<Type>(Type x) {apr_atomic_set32(&mData, apr_uint32_t(x)); };
00108         ~LLAtomic32<Type>() {};
00109 
00110         operator const Type() { apr_uint32_t data = apr_atomic_read32(&mData); return Type(data); }
00111         Type operator =(const Type& x) { apr_atomic_set32(&mData, apr_uint32_t(x)); return Type(mData); }
00112         void operator -=(Type x) { apr_atomic_sub32(&mData, apr_uint32_t(x)); }
00113         void operator +=(Type x) { apr_atomic_add32(&mData, apr_uint32_t(x)); }
00114         Type operator ++(int) { return apr_atomic_inc32(&mData); } // Type++
00115         Type operator --(int) { return apr_atomic_dec32(&mData); } // Type--
00116         
00117 private:
00118         apr_uint32_t mData;
00119 };
00120 
00121 typedef LLAtomic32<U32> LLAtomicU32;
00122 typedef LLAtomic32<S32> LLAtomicS32;
00123 
00124 // File IO convenience functions.
00125 // Returns NULL if the file fails to openm sets *sizep to file size of not NULL
00126 // abbreviated flags
00127 #define LL_APR_R (APR_READ) // "r"
00128 #define LL_APR_W (APR_CREATE|APR_TRUNCATE|APR_WRITE) // "w"
00129 #define LL_APR_RB (APR_READ|APR_BINARY) // "rb"
00130 #define LL_APR_WB (APR_CREATE|APR_TRUNCATE|APR_WRITE|APR_BINARY) // "wb"
00131 #define LL_APR_RPB (APR_READ|APR_WRITE|APR_BINARY) // "r+b"
00132 #define LL_APR_WPB (APR_CREATE|APR_TRUNCATE|APR_READ|APR_WRITE|APR_BINARY) // "w+b"
00133 apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags, S32* sizep, apr_pool_t* pool);
00134 apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags, S32* sizep);
00135 apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags, apr_pool_t* pool);
00136 apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags);
00137 // Returns actual offset, -1 if seek fails
00138 S32 ll_apr_file_seek(apr_file_t* apr_file, apr_seek_where_t where, S32 offset);
00139 // Returns bytes read/written, 0 if read/write fails:
00140 S32 ll_apr_file_read(apr_file_t* apr_file, void* buf, S32 nbytes);
00141 S32 ll_apr_file_read_ex(const LLString& filename, apr_pool_t* pool, void *buf, S32 offset, S32 nbytes);
00142 S32 ll_apr_file_write(apr_file_t* apr_file, const void* buf, S32 nbytes);
00143 S32 ll_apr_file_write_ex(const LLString& filename, apr_pool_t* pool, void *buf, S32 offset, S32 nbytes);
00144 // returns false if failure:
00145 bool ll_apr_file_remove(const LLString& filename, apr_pool_t* pool = NULL);
00146 bool ll_apr_file_rename(const LLString& filename, const LLString& newname, apr_pool_t* pool = NULL);
00147 bool ll_apr_file_exists(const LLString& filename, apr_pool_t* pool = NULL);
00148 S32 ll_apr_file_size(const LLString& filename, apr_pool_t* pool = NULL);
00149 bool ll_apr_dir_make(const LLString& dirname, apr_pool_t* pool = NULL);
00150 bool ll_apr_dir_remove(const LLString& dirname, apr_pool_t* pool = NULL);
00151 
00157 bool ll_apr_warn_status(apr_status_t status);
00158 
00159 void ll_apr_assert_status(apr_status_t status);
00160 
00161 extern "C" apr_pool_t* gAPRPoolp; // Global APR memory pool
00162 
00163 #endif // LL_LLAPR_H

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