XrdSutPFEntry.cc

Go to the documentation of this file.
00001 // $Id: XrdSutPFEntry.cc 30949 2009-11-02 16:37:58Z ganis $
00002 
00003 const char *XrdSutPFEntryCVSID = "$Id: XrdSutPFEntry.cc 30949 2009-11-02 16:37:58Z ganis $";
00004 #include <stdio.h>
00005 #include <string.h>
00006 #include <time.h>
00007 
00008 #include "XrdSutAux.hh"
00009 #include "XrdSutPFEntry.hh"
00010 
00011 //__________________________________________________________________
00012 XrdSutPFBuf::XrdSutPFBuf(char *b, kXR_int32 l)
00013 {
00014    // Constructor
00015 
00016    len = 0;
00017    buf = 0; 
00018    if (b) { 
00019       buf = b;
00020       len = l;
00021    }
00022 }
00023 
00024 //__________________________________________________________________
00025 XrdSutPFBuf::XrdSutPFBuf(const XrdSutPFBuf &b)
00026 {
00027    //Copy constructor
00028 
00029    buf = 0;
00030    len = 0; 
00031    if (b.buf) {
00032       buf = new char[b.len];
00033       if (buf) {
00034          memcpy(buf,b.buf,b.len);
00035          len = b.len;
00036       }
00037    }
00038 }
00039 
00040 //__________________________________________________________________
00041 void XrdSutPFBuf::SetBuf(const char *b, kXR_int32 l)
00042 {
00043    // Set the buffer
00044 
00045    len = 0;
00046    if (buf) {
00047       delete[] buf;
00048       buf = 0; 
00049    }
00050    if (b && l > 0) {
00051       buf = new char[l];
00052       if (buf) {
00053          memcpy(buf,b,l);
00054          len = l;
00055       }
00056    }
00057 }
00058 
00059 //____________________________________________________________________
00060 XrdSutPFEntry::XrdSutPFEntry(const char *n, short st, short cn,
00061                              kXR_int32 mt)
00062 {
00063    // Constructor
00064 
00065    name = 0;
00066    status = st;
00067    cnt    = cn;
00068    mtime  = (mt > 0) ? mt : (kXR_int32)time(0);
00069    if (n) { 
00070       name = new char[strlen(n)+1];
00071       if (name)
00072          strcpy(name,n);
00073    }
00074 }
00075 
00076 //_____________________________________________________________________
00077 XrdSutPFEntry::XrdSutPFEntry(const XrdSutPFEntry &e) : buf1(e.buf1),
00078                      buf2(e.buf2), buf3(e.buf3), buf4(e.buf4)
00079 {
00080    // Copy constructor
00081 
00082    name = 0;
00083    status = e.status;
00084    cnt    = e.cnt;
00085    mtime  = e.mtime;
00086    if (e.name) {
00087       name = new char[strlen(e.name)+1];
00088       if (name)
00089          strcpy(name,e.name);
00090    }
00091 }
00092 
00093 //____________________________________________________________________
00094 void XrdSutPFEntry::Reset()
00095 {
00096    // Resetting entry
00097 
00098    if (name)
00099       delete[] name;
00100    name = 0;
00101    status = 0;
00102    cnt    = 0;
00103    mtime  = (kXR_int32)time(0);
00104    buf1.SetBuf();
00105    buf2.SetBuf();
00106    buf3.SetBuf();
00107    buf4.SetBuf();
00108 }
00109 
00110 //_____________________________________________________________________
00111 void XrdSutPFEntry::SetName(const char *n)
00112 {
00113    // Set the name
00114 
00115    if (name) { 
00116       delete[] name;
00117       name = 0;
00118    }
00119    if (n) {
00120       name = new char[strlen(n)+1];
00121       if (name)
00122          strcpy(name,n);
00123    }
00124 }
00125 
00126 //_____________________________________________________________________
00127 char *XrdSutPFEntry::AsString() const
00128 {
00129    // Return a string with serialized information
00130    // For print purposes
00131    // The output string points to a static buffer, so it must
00132    // not be deleted by the caller
00133    static char pbuf[2048];
00134 
00135    char smt[20] = {0};
00136    XrdSutTimeString(mtime,smt);
00137 
00138    sprintf(pbuf,"st:%d cn:%d  buf:%d,%d,%d,%d modified:%s name:%s",
00139            status,cnt,buf1.len,buf2.len,buf3.len,buf4.len,smt,name);
00140  
00141    return pbuf;
00142 }
00143 
00144 //______________________________________________________________________________
00145 XrdSutPFEntry& XrdSutPFEntry::operator=(const XrdSutPFEntry &e)
00146 {
00147    // Assign entry e to local entry.
00148 
00149    SetName(name);
00150    status = e.status;
00151    cnt    = e.cnt;            // counter
00152    mtime  = e.mtime;          // time of last modification / creation
00153    buf1.SetBuf(e.buf1.buf);
00154    buf2.SetBuf(e.buf2.buf);
00155    buf3.SetBuf(e.buf3.buf);
00156    buf4.SetBuf(e.buf4.buf);
00157 
00158    return (*this);
00159 }

Generated on Tue Jul 5 14:47:02 2011 for ROOT_528-00b_version by  doxygen 1.5.1