Back to index

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

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

#include <PayloadFile.h>

Inheritance diagram for ARex::PayloadFile:
Inheritance graph
[legend]
Collaboration diagram for ARex::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.
 PayloadFile (int h, Size_t start, Size_t end)
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 Member Functions

void SetRead (int h, Size_t start, Size_t end)

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

ARex::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 19 of file PayloadFile.cpp.

                                                                     {
  handle_=::open(filename,O_RDONLY);
  SetRead(handle_,start,end);
}

Here is the call graph for this function:

ARex::PayloadFile::PayloadFile ( int  h,
Size_t  start,
Size_t  end 
)

Definition at line 24 of file PayloadFile.cpp.

                                                      {
  SetRead(h,start,end);
}

Here is the call graph for this function:

ARex::PayloadFile::~PayloadFile ( void  ) [virtual]

Creates object associated with file for writing into it.

Use size=-1 for undefined size.

Definition at line 64 of file PayloadFile.cpp.

                              {

#ifndef WIN32 
  if(addr_ != NULL) munmap(addr_,size_);
#endif

  ::close(handle_);
  handle_=-1; size_=0; addr_=NULL;
  return;
}

Member Function Documentation

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

Returns pointer to num'th buffer.

Implements Arc::PayloadRawInterface.

Definition at line 103 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 ARex::PayloadFile::BufferPos ( unsigned int  num) const [virtual]

Returns position of num'th buffer.

Implements Arc::PayloadRawInterface.

Definition at line 116 of file PayloadFile.cpp.

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

Returns length of num'th buffer.

Implements Arc::PayloadRawInterface.

Definition at line 110 of file PayloadFile.cpp.

                                                                {
  if(handle_ == -1) return 0;
  if(num>0) return 0;
  return (end_-start_);
}
char * ARex::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 75 of file PayloadFile.cpp.

                                     {
  if(handle_ == -1) return NULL;
  if(pos >= end_) return NULL;
  if(pos < start_) return NULL;
  return (addr_+pos);
}
char * ARex::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 93 of file PayloadFile.cpp.

                                           {
  // Not supported
  return NULL;
}
char * ARex::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 98 of file PayloadFile.cpp.

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

Definition at line 41 of file PayloadFile.h.

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

Definition at line 42 of file PayloadFile.h.

{ return (handle_ == -1); };
char ARex::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 82 of file PayloadFile.cpp.

                                             {
  if(handle_ == -1) return 0;
  if(pos >= end_) return 0;
  if(pos < start_) return 0;
  return addr_[pos];
}
void ARex::PayloadFile::SetRead ( int  h,
Size_t  start,
Size_t  end 
) [protected]

Definition at line 28 of file PayloadFile.cpp.

                                                       {
  handle_=h;
  start_=start;
  end_=end;
  addr_=NULL;
  size_=0;
  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;
  }

#ifndef WIN32 
  if(size_ > 0) {
    addr_=(char*)mmap(NULL,size_,PROT_READ,MAP_SHARED,handle_,0);
    if(addr_ == MAP_FAILED) goto error;
  }
#else 
  goto error;
#endif

  return;
error:
  perror("PayloadFile");
  if(handle_ != -1) ::close(handle_);
  handle_=-1; size_=0; addr_=NULL;
  return;
}

Here is the caller graph for this function:

PayloadFile::Size_t ARex::PayloadFile::Size ( void  ) const [virtual]

Returns logical size of whole structure.

Implements Arc::PayloadRawInterface.

Definition at line 89 of file PayloadFile.cpp.

                                              {
  return size_;
}
bool ARex::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 121 of file PayloadFile.cpp.

                                   {
  // Not supported
  return false;
}

Member Data Documentation

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

Definition at line 17 of file PayloadFile.h.

size_t ARex::PayloadFile::end_ [protected]

Definition at line 20 of file PayloadFile.h.

int ARex::PayloadFile::handle_ [protected]

Definition at line 16 of file PayloadFile.h.

size_t ARex::PayloadFile::size_ [protected]

Definition at line 18 of file PayloadFile.h.

size_t ARex::PayloadFile::start_ [protected]

Definition at line 19 of file PayloadFile.h.


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