Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Static Public Member Functions | Private Attributes
Hopi::HopiFile Class Reference
Collaboration diagram for Hopi::HopiFile:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 HopiFile (const std::string &path, bool for_read, bool slave)
 ~HopiFile (void)
int Write (void *buf, off_t offset, int size)
int Read (void *buf, off_t offset, int size)
int Write (off_t offset, int size)
int Read (off_t offset, int size)
void Size (off_t size)
off_t Size (void)
 operator bool (void)
bool operator! (void)
void Destroy (void)

Static Public Member Functions

static void DestroyStuck (void)
static void DestroyAll (void)

Private Attributes

int handle
std::string path
bool for_read
bool slave
HopiFileChunkschunks

Detailed Description

Definition at line 197 of file hopi.cpp.


Constructor & Destructor Documentation

Hopi::HopiFile::HopiFile ( const std::string &  path,
bool  for_read,
bool  slave 
)

Definition at line 219 of file hopi.cpp.

                                                                :handle(-1),chunks(HopiFileChunks::Get(path)) {
  HopiFile::for_read=for_read;
  HopiFile::slave=slave;
  HopiFile::path=path;
  if(for_read) {
    handle=open(path.c_str(),O_RDONLY);
  } else {
    if(slave) {
      handle=open(path.c_str(),O_WRONLY);
      if(handle == -1) {
        if(errno == ENOENT) {
          Hopi::logger.msg(Arc::ERROR, "Hopi SlaveMode is active, PUT is only allowed to existing files");
        }
      }
    } else {
      handle=open(path.c_str(),O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
    }
  }
  if(handle == -1) {
    Hopi::logger.msg(Arc::ERROR, Arc::StrError(errno));
  }
}

Here is the call graph for this function:

Definition at line 242 of file hopi.cpp.

                        {
  if(handle != -1) {
    close(handle);
    if(!for_read) {
      if(chunks.Complete()) {
        if(slave) {
          Hopi::logger.msg(Arc::VERBOSE, "Removing complete file in slave mode");
          ::unlink(path.c_str());
        }
        chunks.Remove();
        return;
      }
    }
  }
  chunks.Release();
}

Here is the call graph for this function:


Member Function Documentation

void Hopi::HopiFile::Destroy ( void  )

Definition at line 259 of file hopi.cpp.

                           {
  if(handle != -1) close(handle);
  handle=-1;
  ::unlink(path.c_str());
  chunks.Remove();
}

Here is the call graph for this function:

void Hopi::HopiFile::DestroyAll ( void  ) [static]

Definition at line 283 of file hopi.cpp.

                              {
  std::string prev_path;
  for(;;) {
    HopiFileChunks* first_chunks = HopiFileChunks::GetFirst();
    if(!first_chunks) return;
    std::string first_path = first_chunks->Path();
    if(first_path == prev_path) {
      // This may happen if other thread just started accessing this file
      first_chunks->Release();
      return;
    }
    ::unlink(first_path.c_str());
    first_chunks->Remove();
    prev_path=first_path;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Hopi::HopiFile::DestroyStuck ( void  ) [static]

Definition at line 266 of file hopi.cpp.

                                {
  std::string prev_path;
  for(;;) {
    HopiFileChunks* stuck_chunks = HopiFileChunks::GetStuck();
    if(!stuck_chunks) return;
    std::string stuck_path = stuck_chunks->Path();
    if(stuck_path == prev_path) {
      // This may happen if other thread just started accessing this file
      stuck_chunks->Release();
      return;
    }
    ::unlink(stuck_path.c_str());
    stuck_chunks->Remove();
    prev_path=stuck_path;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Hopi::HopiFile::operator bool ( void  ) [inline]

Definition at line 212 of file hopi.cpp.

{ return (handle != -1); };
bool Hopi::HopiFile::operator! ( void  ) [inline]

Definition at line 213 of file hopi.cpp.

{ return (handle == -1); };
int Hopi::HopiFile::Read ( void *  buf,
off_t  offset,
int  size 
)

Definition at line 323 of file hopi.cpp.

                                                  {
  if(handle == -1) return -1;
  if(!for_read) return -1;
  if(lseek(handle,offset,SEEK_SET) != offset) return 0;
  return read(handle,buf,size);
}
int Hopi::HopiFile::Read ( off_t  offset,
int  size 
)

Definition at line 330 of file hopi.cpp.

                                        {
  if(handle == -1) return -1;
  if(!for_read) return -1;
  return size;
}
void Hopi::HopiFile::Size ( off_t  size) [inline]

Definition at line 210 of file hopi.cpp.

{ chunks.Size(size); };

Here is the call graph for this function:

off_t Hopi::HopiFile::Size ( void  ) [inline]

Definition at line 211 of file hopi.cpp.

{ return chunks.Size(); };

Here is the call graph for this function:

int Hopi::HopiFile::Write ( void *  buf,
off_t  offset,
int  size 
)

Definition at line 300 of file hopi.cpp.

                                                   {
  if(handle == -1) return -1;
  if(for_read) return -1;
  int s = size;
  if(lseek(handle,offset,SEEK_SET) != offset) return 0;
  for(;s>0;) {
    ssize_t l = write(handle,buf,s);
    if(l == -1) return -1;
    chunks.Add(offset,offset+l);
    chunks.Print();
    s-=l; buf=((char*)buf)+l; offset+=l;
  }
  return size;
}

Here is the call graph for this function:

int Hopi::HopiFile::Write ( off_t  offset,
int  size 
)

Definition at line 315 of file hopi.cpp.

                                         {
  if(handle == -1) return -1;
  if(for_read) return -1;
  chunks.Add(offset,offset+size);
  chunks.Print();
  return size;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 202 of file hopi.cpp.

bool Hopi::HopiFile::for_read [private]

Definition at line 200 of file hopi.cpp.

int Hopi::HopiFile::handle [private]

Definition at line 198 of file hopi.cpp.

std::string Hopi::HopiFile::path [private]

Definition at line 199 of file hopi.cpp.

bool Hopi::HopiFile::slave [private]

Definition at line 201 of file hopi.cpp.


The documentation for this class was generated from the following file: