The representation of a bundle payload. More...
#include <BundlePayload.h>
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 |
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.
Options for payload location state.
MEMORY | |
DISK |
in memory only (TempBundle) |
NODATA |
on disk |
Definition at line 48 of file BundlePayload.h.
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_.
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] |
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] |
The payload length.
Definition at line 77 of file BundlePayload.h.
References length_.
Referenced by dtn::BundleInfoCache::add_entry(), dtn::FragmentState::check_completed(), dtn::PayloadBlockProcessor::consume(), copy_file(), dtn::FragmentManager::create_fragment(), dtnsim::SimRegistration::deliver_bundle(), dtn::AdminRegistration::deliver_bundle(), dtn::Bundle::durable_size(), dtn::Bundle::format(), dtn::Bundle::format_verbose(), dtn::PayloadBlockProcessor::generate(), dtn::get_payload_str(), dtn::APIClient::handle_recv(), dtnsim::SimLog::log_entry(), dtn::BundleInfoCache::lookup(), dtn::PayloadBlockProcessor::mutate(), dtn::DTLSR::parse_lsa_bundle(), dtn::BundleStatusReport::parse_status_report(), dtn::FragmentManager::proactively_fragment(), dtn::PayloadBlockProcessor::process(), dtn::UDPConvergenceLayer::Receiver::process_data(), dtn::FragmentManager::process_for_reassembly(), dtn::PayloadBlockProcessor::produce(), dtn::FileConvergenceLayer::send_bundle(), dtn::FragmentManager::try_to_convert_to_fragment(), dtn::FragmentManager::try_to_reactively_fragment(), dtn::PayloadBlockProcessor::validate(), and write_data().
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] |
oasys::ScratchBuffer<u_char*>* dtn::BundlePayload::memory_buf | ( | ) | [inline] |
void dtn::BundlePayload::pin_file | ( | ) | const [protected] |
Definition at line 174 of file BundlePayload.cc.
References ASSERT, cur_offset_, DISK, errno, fd, file_, location_, and dtn::BundleStore::payload_fdcache().
Referenced by append_data(), copy_file(), read_data(), truncate(), and write_data().
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 | |||
) |
Copy out a chunk of payload data into the supplied buffer.
Definition at line 419 of file BundlePayload.cc.
References ASSERT, cur_offset_, data_, DISK, file_, length_, location_, lock_, MEMORY, NODATA, pin_file(), and unpin_file().
Referenced by dtn::DTLSRRouter::Reg::deliver_bundle(), dtn::AdminRegistration::deliver_bundle(), dtn::get_payload_str(), dtn::APIClient::handle_recv(), dtn::PayloadBlockProcessor::mutate(), dtn::DTLSR::parse_lsa_bundle(), dtn::BundleStatusReport::parse_status_report(), dtn::PayloadBlockProcessor::process(), dtn::PayloadBlockProcessor::produce(), read_data(), and write_data().
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 | ) |
Set the payload length in preparation for filling in with data.
Definition at line 161 of file BundlePayload.cc.
References data_, length_, location_, lock_, and MEMORY.
Referenced by append_data(), dtn::PayloadBlockProcessor::consume(), dtn::FragmentManager::create_fragment(), dtn::DTLSR::format_lsa_bundle(), replace_with_file(), dtnsim::TrAgent::send_bundle(), set_data(), and dtnsim::SimLink::start_next_bundle().
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] |
Definition at line 204 of file BundlePayload.cc.
References DISK, file_, and location_.
Referenced by append_data(), copy_file(), init(), init_from_store(), read_data(), replace_with_file(), truncate(), and write_data().
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().
size_t dtn::BundlePayload::base_offset_ [protected] |
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] |
file handle
Definition at line 184 of file BundlePayload.h.
Referenced by copy_file(), filename(), init(), init_from_store(), internal_write(), pin_file(), read_data(), replace_with_file(), truncate(), unpin_file(), write_data(), and ~BundlePayload().
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().
location_t dtn::BundlePayload::location_ [protected] |
location of the data
Definition at line 181 of file BundlePayload.h.
Referenced by copy_file(), filename(), init(), init_from_store(), internal_write(), location(), memory_buf(), pin_file(), read_data(), replace_with_file(), set_length(), truncate(), unpin_file(), and ~BundlePayload().
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().
bool dtn::BundlePayload::test_no_remove_ = false [static] |
test: don't rm payload files
Definition at line 174 of file BundlePayload.h.
Referenced by dtn::ParamCommand::ParamCommand(), and ~BundlePayload().