dtn::BundlePayload Class Reference

The representation of a bundle payload. More...

#include <BundlePayload.h>

List of all members.

Public Types

enum  location_t { MEMORY = 1, DISK = 2, NODATA = 3 }
 

Options for payload location state.

More...

Public Member Functions

 BundlePayload (oasys::SpinLock *lock)
virtual ~BundlePayload ()
void init (int bundleid, location_t location=DISK)
 Actual payload initialization function.
void init_from_store (int bundleid)
 Initialization when re-reading the database.
void set_length (size_t len)
 Set the payload length in preparation for filling in with data.
void truncate (size_t len)
 Truncate the payload.
size_t length () const
 The payload length.
location_t location () const
 The payload location.
void set_data (const u_char *bp, size_t len)
 Set the payload data and length.
void set_data (const std::string &data)
 Set the payload data and length.
void append_data (const u_char *bp, size_t len)
 Append a chunk of payload data, extending the length to accomodate the new data.
void write_data (const u_char *bp, size_t offset, size_t len)
 Write a chunk of payload data at the specified offset.
void write_data (const BundlePayload &src, size_t src_offset, size_t len, size_t dst_offset)
 Writes len bytes of payload data from from another payload at the given src_offset to the given dst_offset.
void copy_file (oasys::FileIOClient *dst) const
 Copy (or link) the payload to the given file client object.
bool replace_with_file (const char *path)
 Replace the underlying file with a hard link to the given path or a copy of the file contents if the link can't be created.
const std::string & filename () const
 Return the filename.
oasys::ScratchBuffer< u_char * > * memory_buf ()
 Get a pointer to the in-memory scratch buffer.
const oasys::ScratchBuffer
< u_char * > * 
memory_buf () const
 Get a pointer to the in-memory scratch buffer (const variant.
const u_char * read_data (size_t offset, size_t len, u_char *buf)
 Copy out a chunk of payload data into the supplied buffer.
const u_char * read_data (size_t offset, size_t len, u_char *buf) const
 Since read_data doesn't really change anything of substance in the payload class (just the internal bookkeeping fields), we define a "const" variant that just casts itself away and calls the normal variant.
virtual void serialize (oasys::SerializeAction *a)
 Virtual from SerializableObject.

Static Public Attributes

static bool test_no_remove_ = false
 test: don't rm payload files

Protected Member Functions

void pin_file () const
void unpin_file () const
void internal_write (const u_char *bp, size_t offset, size_t len)

Protected Attributes

location_t location_
 location of the data
oasys::ScratchBuffer< u_char * > data_
 payload data if in memory
size_t length_
 the payload length
oasys::FileIOClient file_
 file handle
size_t cur_offset_
 cache of current fd position
size_t base_offset_
 for fragments, offset into the file (todo)
oasys::SpinLock * lock_
 the lock for the given bundle

Detailed Description

The representation of a bundle payload.

This is abstracted into a separate class to allow the daemon to separately manage the serialization of header information from the payload.

Note that this implementation doesn't support payloads larger than 4GB. XXX/demmer fix this.

Definition at line 40 of file BundlePayload.h.


Member Enumeration Documentation

Options for payload location state.

Enumerator:
MEMORY 
DISK 

in memory only (TempBundle)

NODATA 

on disk

Definition at line 48 of file BundlePayload.h.


Constructor & Destructor Documentation

dtn::BundlePayload::BundlePayload ( oasys::SpinLock *  lock  ) 

Definition at line 39 of file BundlePayload.cc.

dtn::BundlePayload::~BundlePayload (  )  [virtual]

Definition at line 138 of file BundlePayload.cc.

References DISK, file_, location_, and test_no_remove_.


Member Function Documentation

void dtn::BundlePayload::append_data ( const u_char *  bp,
size_t  len 
)

Append a chunk of payload data, extending the length to accomodate the new data.

Definition at line 364 of file BundlePayload.cc.

References internal_write(), length_, lock_, pin_file(), set_length(), and unpin_file().

void dtn::BundlePayload::copy_file ( oasys::FileIOClient *  dst  )  const

Copy (or link) the payload to the given file client object.

Definition at line 239 of file BundlePayload.cc.

References ASSERT, DISK, file_, length(), location_, pin_file(), and unpin_file().

Referenced by dtn::APIClient::handle_recv().

const std::string& dtn::BundlePayload::filename (  )  const [inline]

Return the filename.

Definition at line 127 of file BundlePayload.h.

References ASSERT, DISK, file_, and location_.

void dtn::BundlePayload::init ( int  bundleid,
location_t  location = DISK 
)

Actual payload initialization function.

Definition at line 48 of file BundlePayload.cc.

References errno, fd, file_, location_, MEMORY, NODATA, dtn::BundleStore::payload_dir(), dtn::BundleStore::payload_fdcache(), and unpin_file().

void dtn::BundlePayload::init_from_store ( int  bundleid  ) 

Initialization when re-reading the database.

Definition at line 108 of file BundlePayload.cc.

References DISK, errno, fd, file_, location_, NODATA, dtn::BundleStore::payload_dir(), dtn::BundleStore::payload_fdcache(), and unpin_file().

Referenced by dtn::Bundle::serialize().

void dtn::BundlePayload::internal_write ( const u_char *  bp,
size_t  offset,
size_t  len 
) [protected]

Definition at line 320 of file BundlePayload.cc.

References ASSERT, cur_offset_, data_, DISK, file_, length_, location_, lock_, MEMORY, and NODATA.

Referenced by append_data(), and write_data().

size_t dtn::BundlePayload::length (  )  const [inline]
location_t dtn::BundlePayload::location (  )  const [inline]

The payload location.

Definition at line 82 of file BundlePayload.h.

References location_.

Referenced by dtn::PayloadBlockProcessor::consume().

const oasys::ScratchBuffer<u_char*>* dtn::BundlePayload::memory_buf (  )  const [inline]

Get a pointer to the in-memory scratch buffer (const variant.

Definition at line 145 of file BundlePayload.h.

References ASSERT, data_, location_, and MEMORY.

oasys::ScratchBuffer<u_char*>* dtn::BundlePayload::memory_buf (  )  [inline]

Get a pointer to the in-memory scratch buffer.

Definition at line 136 of file BundlePayload.h.

References ASSERT, data_, location_, and MEMORY.

void dtn::BundlePayload::pin_file (  )  const [protected]
const u_char* dtn::BundlePayload::read_data ( size_t  offset,
size_t  len,
u_char *  buf 
) const [inline]

Since read_data doesn't really change anything of substance in the payload class (just the internal bookkeeping fields), we define a "const" variant that just casts itself away and calls the normal variant.

Definition at line 163 of file BundlePayload.h.

References read_data().

const u_char * dtn::BundlePayload::read_data ( size_t  offset,
size_t  len,
u_char *  buf 
)
bool dtn::BundlePayload::replace_with_file ( const char *  path  ) 

Replace the underlying file with a hard link to the given path or a copy of the file contents if the link can't be created.

Definition at line 250 of file BundlePayload.cc.

References ASSERT, DISK, errno, fd, file_, location_, lock_, dtn::BundleStore::payload_fdcache(), set_length(), src, and unpin_file().

void dtn::BundlePayload::serialize ( oasys::SerializeAction *  a  )  [virtual]

Virtual from SerializableObject.

Definition at line 153 of file BundlePayload.cc.

References base_offset_, and length_.

void dtn::BundlePayload::set_data ( const std::string &  data  ) 

Set the payload data and length.

Definition at line 357 of file BundlePayload.cc.

References set_data().

void dtn::BundlePayload::set_data ( const u_char *  bp,
size_t  len 
)

Set the payload data and length.

Definition at line 349 of file BundlePayload.cc.

References set_length(), and write_data().

Referenced by dtn::CustodySignal::create_custody_signal(), dtn::BundleStatusReport::create_status_report(), and set_data().

void dtn::BundlePayload::set_length ( size_t  len  ) 
void dtn::BundlePayload::truncate ( size_t  len  ) 

Truncate the payload.

Used for reactive fragmentation.

Definition at line 215 of file BundlePayload.cc.

References ASSERT, cur_offset_, data_, DISK, file_, length_, location_, lock_, MEMORY, NODATA, pin_file(), and unpin_file().

Referenced by dtn::FragmentManager::try_to_convert_to_fragment().

void dtn::BundlePayload::unpin_file (  )  const [protected]
void dtn::BundlePayload::write_data ( const BundlePayload src,
size_t  src_offset,
size_t  len,
size_t  dst_offset 
)

Writes len bytes of payload data from from another payload at the given src_offset to the given dst_offset.

Definition at line 390 of file BundlePayload.cc.

References ASSERT, buf, file_, internal_write(), length(), length_, lock_, pin_file(), read_data(), and unpin_file().

void dtn::BundlePayload::write_data ( const u_char *  bp,
size_t  offset,
size_t  len 
)

Write a chunk of payload data at the specified offset.

The length must have been previously set to at least offset + len.

Definition at line 378 of file BundlePayload.cc.

References ASSERT, internal_write(), length_, lock_, pin_file(), and unpin_file().

Referenced by dtn::PayloadBlockProcessor::consume(), dtn::FragmentManager::create_fragment(), dtn::DTLSR::format_lsa_bundle(), and set_data().


Member Data Documentation

for fragments, offset into the file (todo)

Definition at line 186 of file BundlePayload.h.

Referenced by serialize().

size_t dtn::BundlePayload::cur_offset_ [mutable, protected]

cache of current fd position

Definition at line 185 of file BundlePayload.h.

Referenced by internal_write(), pin_file(), read_data(), and truncate().

oasys::ScratchBuffer<u_char*> dtn::BundlePayload::data_ [protected]

payload data if in memory

Definition at line 182 of file BundlePayload.h.

Referenced by internal_write(), memory_buf(), read_data(), set_length(), and truncate().

oasys::FileIOClient dtn::BundlePayload::file_ [mutable, protected]
size_t dtn::BundlePayload::length_ [protected]

the payload length

Definition at line 183 of file BundlePayload.h.

Referenced by append_data(), internal_write(), length(), read_data(), serialize(), set_length(), truncate(), and write_data().

oasys::SpinLock* dtn::BundlePayload::lock_ [protected]

the lock for the given bundle

Definition at line 187 of file BundlePayload.h.

Referenced by append_data(), internal_write(), read_data(), replace_with_file(), set_length(), truncate(), and write_data().

test: don't rm payload files

Definition at line 174 of file BundlePayload.h.

Referenced by dtn::ParamCommand::ParamCommand(), and ~BundlePayload().


The documentation for this class was generated from the following files:
Generated on Sun Nov 21 13:21:13 2010 for DTN Reference Implementation by  doxygen 1.6.3