00001 #ifndef __OFS_HANDLE__
00002 #define __OFS_HANDLE__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdlib.h>
00020
00021 #include "XrdOuc/XrdOucCRC.hh"
00022 #include "XrdSys/XrdSysPthread.hh"
00023
00024
00025
00026
00027
00028 class XrdOfsHanKey
00029 {
00030 public:
00031
00032 const char *Val;
00033 unsigned int Hash;
00034 short Len;
00035 unsigned short Links;
00036
00037 inline XrdOfsHanKey& operator=(const XrdOfsHanKey &rhs)
00038 {Val = strdup(rhs.Val); Hash = rhs.Hash;
00039 Len = rhs.Len;
00040 return *this;
00041 }
00042
00043 inline int operator==(const XrdOfsHanKey &oth)
00044 {return Hash == oth.Hash && Len == oth.Len
00045 && !strcmp(Val, oth.Val);
00046 }
00047
00048 inline int operator!=(const XrdOfsHanKey &oth)
00049 {return Hash != oth.Hash || Len != oth.Len
00050 || strcmp(Val, oth.Val);
00051 }
00052
00053 XrdOfsHanKey(const char *key=0, int kln=0)
00054 : Val(key), Len(kln), Links(0)
00055 {Hash = (key && kln ?
00056 XrdOucCRC::CRC32((const unsigned char *)key,kln) : 0);
00057 }
00058
00059 ~XrdOfsHanKey() {};
00060 };
00061
00062
00063
00064
00065
00066 class XrdOfsHandle;
00067
00068 class XrdOfsHanTab
00069 {
00070 public:
00071 void Add(XrdOfsHandle *hP);
00072
00073 XrdOfsHandle *Find(XrdOfsHanKey &Key);
00074
00075 int Remove(XrdOfsHandle *rip);
00076
00077
00078
00079
00080
00081 XrdOfsHanTab(int psize = 987, int size = 1597);
00082 ~XrdOfsHanTab() {}
00083
00084 private:
00085
00086 static const int LoadMax = 80;
00087
00088 void Expand();
00089
00090 XrdOfsHandle **nashtable;
00091 int prevtablesize;
00092 int nashtablesize;
00093 int nashnum;
00094 int Threshold;
00095 };
00096
00097
00098
00099
00100
00101 class XrdOssDF;
00102 class XrdOfsHanCB;
00103 class XrdOfsHanPsc;
00104
00105 class XrdOfsHandle
00106 {
00107 friend class XrdOfsHanTab;
00108 friend class XrdOfsHanXpr;
00109 public:
00110
00111 char isPending;
00112 char isChanged;
00113 char isCompressed;
00114 char isRW;
00115
00116 void Activate(XrdOssDF *ssP) {ssi = ssP;}
00117
00118 static const int opRW = 1;
00119 static const int opPC = 3;
00120
00121 static int Alloc(const char *thePath,int Opts,XrdOfsHandle **Handle);
00122 static int Alloc( XrdOfsHandle **Handle);
00123
00124 static void Hide(const char *thePath);
00125
00126 inline int Inactive() {return (ssi == ossDF);}
00127
00128 inline const char *Name() {return Path.Val;}
00129
00130 int PoscGet(short &Mode, int Done=0);
00131
00132 int PoscSet(const char *User, int Unum, short Mode);
00133
00134 const char *PoscUsr();
00135
00136 int Retire(long long *retsz=0, char *buff=0, int blen=0);
00137
00138 int Retire(XrdOfsHanCB *, int DSec);
00139
00140 XrdOssDF &Select(void) {return *ssi;}
00141
00142 static int StartXpr(int Init=0);
00143
00144 int Usage() {return Path.Links;}
00145
00146 inline void Lock() {hMutex.Lock();}
00147 inline void UnLock() {hMutex.UnLock();}
00148
00149 XrdOfsHandle() : Path(0,0) {}
00150
00151 ~XrdOfsHandle() {Retire();}
00152
00153 private:
00154 static int Alloc(XrdOfsHanKey, int Opts, XrdOfsHandle **Handle);
00155 int WaitLock(void);
00156
00157 static const int LockTries = 3;
00158 static const int LockWait = 333;
00159 static const int nolokDelay= 3;
00160 static const int nomemDelay= 15;
00161
00162 static XrdSysMutex myMutex;
00163 static XrdOfsHanTab roTable;
00164 static XrdOfsHanTab rwTable;
00165 static XrdOssDF *ossDF;
00166 static XrdOfsHandle *Free;
00167
00168 XrdSysMutex hMutex;
00169 XrdOssDF *ssi;
00170 XrdOfsHandle *Next;
00171 XrdOfsHanKey Path;
00172 XrdOfsHanPsc *Posc;
00173 };
00174
00175
00176
00177
00178
00179 class XrdOfsHanCB
00180 {
00181 public:
00182
00183 virtual void Retired(XrdOfsHandle *) = 0;
00184
00185 XrdOfsHanCB() {}
00186 virtual ~XrdOfsHanCB() {}
00187 };
00188 #endif