Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Types | Public Member Functions | Protected Attributes
Hopi::PayloadFile Class Reference

Implementation of PayloadRawInterface which provides access to ordinary file. More...

#include <PayloadFile.h>

Inheritance diagram for Hopi::PayloadFile:
Inheritance graph
[legend]
Collaboration diagram for Hopi::PayloadFile:
Collaboration graph
[legend]

List of all members.

Public Types

typedef signed long long int Size_t

Public Member Functions

 PayloadFile (const char *filename, Size_t start, Size_t end)
 Creates object associated with file for reading from it.
virtual ~PayloadFile (void)
 Creates object associated with file for writing into it.
virtual char operator[] (Size_t pos) const
 Returns content of byte at specified position.
virtual char * Content (Size_t pos=-1)
 Get pointer to buffer content at global position 'pos'.
virtual Size_t Size (void) const
 Returns logical size of whole structure.
virtual char * Insert (Size_t pos=0, Size_t size=0)
 Create new buffer at global position 'pos' of size 'size'.
virtual char * Insert (const char *s, Size_t pos=0, Size_t size=-1)
 Create new buffer at global position 'pos' of size 'size'.
virtual char * Buffer (unsigned int num)
 Returns pointer to num'th buffer.
virtual Size_t BufferSize (unsigned int num) const
 Returns length of num'th buffer.
virtual Size_t BufferPos (unsigned int num) const
 Returns position of num'th buffer.
virtual bool Truncate (Size_t size)
 Change size of stored information.
 operator bool (void)
bool operator! (void)

Protected Attributes

int handle_
char * addr_
size_t size_
size_t start_
size_t end_

Detailed Description

Implementation of PayloadRawInterface which provides access to ordinary file.

Currently only read-only mode is supported.

Definition at line 13 of file PayloadFile.h.


Member Typedef Documentation

typedef signed long long int Arc::PayloadRawInterface::Size_t [inherited]

Definition at line 19 of file PayloadRaw.h.


Constructor & Destructor Documentation

Hopi::PayloadFile::PayloadFile ( const char *  filename,
Size_t  start,
Size_t  end 
)

Creates object associated with file for reading from it.

Use end=-1 for full size.

Definition at line 21 of file PayloadFile.cpp.

                                                                    :handle_(-1),addr_(NULL),size_(0) {
  start_=start;
  end_=end;
  handle_=open(filename,O_RDONLY);
  if(handle_ == -1) return;
  struct stat st;
  if(fstat(handle_,&st) != 0) goto error;
  size_=st.st_size;
  if(end_ > size_) {
    end_=size_;
  }
  if(start_ >= size_) {
    start_=size_;
    end_=start_;
    return;
  }
  if(size_ > 0) {
    addr_=(char*)mmap(NULL,size_,PROT_READ,MAP_SHARED,handle_,0);
    if(addr_ == MAP_FAILED) goto error;
  }

  return;
error:
  perror("PayloadFile");
  if(handle_ != -1) close(handle_);
  handle_=-1; size_=0; addr_=NULL;
  return;
}
Hopi::PayloadFile::~PayloadFile ( void  ) [virtual]

Creates object associated with file for writing into it.

Use size=-1 for undefined size.

Definition at line 50 of file PayloadFile.cpp.

                              {
  if(addr_ != NULL) munmap(addr_,size_);
  close(handle_);
  handle_=-1; size_=0; addr_=NULL;
  return;
}

Member Function Documentation

char * Hopi::PayloadFile::Buffer ( unsigned int  num) [virtual]

Returns pointer to num'th buffer.

Implements Arc::PayloadRawInterface.

Definition at line 85 of file PayloadFile.cpp.

                                          {
  if(handle_ == -1) return NULL;
  if(num>0) return NULL;
  if(addr_ == NULL) return NULL;
  return addr_+start_;
}
PayloadFile::Size_t Hopi::PayloadFile::BufferPos ( unsigned int  num) const [virtual]

Returns position of num'th buffer.

Implements Arc::PayloadRawInterface.

Definition at line 98 of file PayloadFile.cpp.

                                                               {
  if(num == 0) return start_;
  return end_;
}
PayloadFile::Size_t Hopi::PayloadFile::BufferSize ( unsigned int  num) const [virtual]

Returns length of num'th buffer.

Implements Arc::PayloadRawInterface.

Definition at line 92 of file PayloadFile.cpp.

                                                                {
  if(handle_ == -1) return 0;
  if(num>0) return 0;
  return (end_-start_);
}
char * Hopi::PayloadFile::Content ( Size_t  pos = -1) [virtual]

Get pointer to buffer content at global position 'pos'.

By default to beginning of main buffer whatever that means.

Implements Arc::PayloadRawInterface.

Definition at line 57 of file PayloadFile.cpp.

                                     {
  if(handle_ == -1) return NULL;
  if(pos >= end_) return NULL;
  if(pos < start_) return NULL;
  return (addr_+pos);
}
char * Hopi::PayloadFile::Insert ( Size_t  pos = 0,
Size_t  size = 0 
) [virtual]

Create new buffer at global position 'pos' of size 'size'.

Implements Arc::PayloadRawInterface.

Definition at line 75 of file PayloadFile.cpp.

                                           {
  // Not supported
  return NULL;
}
char * Hopi::PayloadFile::Insert ( const char *  s,
Size_t  pos = 0,
Size_t  size = -1 
) [virtual]

Create new buffer at global position 'pos' of size 'size'.

Created buffer is filled with content of memory at 's'. If 'size' is negative content at 's' is expected to be null-terminated.

Implements Arc::PayloadRawInterface.

Definition at line 80 of file PayloadFile.cpp.

                                                       {
  // Not supported
  return NULL;
}
Hopi::PayloadFile::operator bool ( void  ) [inline]

Definition at line 39 of file PayloadFile.h.

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

Definition at line 40 of file PayloadFile.h.

{ return (handle_ == -1); };
char Hopi::PayloadFile::operator[] ( Size_t  pos) const [virtual]

Returns content of byte at specified position.

Specified position 'pos' is treated as global one and goes through all buffers placed one after another.

Implements Arc::PayloadRawInterface.

Definition at line 64 of file PayloadFile.cpp.

                                             {
  if(handle_ == -1) return 0;
  if(pos >= end_) return 0;
  if(pos < start_) return 0;
  return addr_[pos];
}
PayloadFile::Size_t Hopi::PayloadFile::Size ( void  ) const [virtual]

Returns logical size of whole structure.

Implements Arc::PayloadRawInterface.

Definition at line 71 of file PayloadFile.cpp.

                                              {
  return size_;
}
bool Hopi::PayloadFile::Truncate ( Size_t  size) [virtual]

Change size of stored information.

If size exceeds end of allocated buffer, buffers are not re-allocated, only logical size is extended. Buffers with location behind new size are deallocated.

Implements Arc::PayloadRawInterface.

Definition at line 103 of file PayloadFile.cpp.

                                   {
  // Not supported
  return false;
}

Member Data Documentation

char* Hopi::PayloadFile::addr_ [protected]

Definition at line 17 of file PayloadFile.h.

size_t Hopi::PayloadFile::end_ [protected]

Definition at line 20 of file PayloadFile.h.

int Hopi::PayloadFile::handle_ [protected]

Definition at line 16 of file PayloadFile.h.

size_t Hopi::PayloadFile::size_ [protected]

Definition at line 18 of file PayloadFile.h.

size_t Hopi::PayloadFile::start_ [protected]

Definition at line 19 of file PayloadFile.h.


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