00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _BUNDLE_PAYLOAD_H_
00018 #define _BUNDLE_PAYLOAD_H_
00019
00020 #include <string>
00021 #include <oasys/serialize/Serialize.h>
00022 #include <oasys/debug/DebugUtils.h>
00023 #include <oasys/io/FileIOClient.h>
00024
00025 namespace dtn {
00026
00027 class BundleStore;
00028
00040 class BundlePayload : public oasys::SerializableObject, public oasys::Logger {
00041 public:
00042 BundlePayload(oasys::SpinLock* lock);
00043 virtual ~BundlePayload();
00044
00048 typedef enum {
00049 MEMORY = 1,
00050 DISK = 2,
00051 NODATA = 3,
00052 } location_t;
00053
00057 void init(int bundleid, location_t location = DISK);
00058
00062 void init_from_store(int bundleid);
00063
00067 void set_length(size_t len);
00068
00072 void truncate(size_t len);
00073
00077 size_t length() const { return length_; }
00078
00082 location_t location() const { return location_; }
00083
00087 void set_data(const u_char* bp, size_t len);
00088
00092 void set_data(const std::string& data);
00093
00098 void append_data(const u_char* bp, size_t len);
00099
00104 void write_data(const u_char* bp, size_t offset, size_t len);
00105
00110 void write_data(const BundlePayload& src, size_t src_offset,
00111 size_t len, size_t dst_offset);
00112
00116 void copy_file(oasys::FileIOClient* dst) const;
00117
00122 bool replace_with_file(const char* path);
00123
00127 const std::string& filename() const
00128 {
00129 ASSERT(location_ == DISK);
00130 return file_.path_str();
00131 }
00132
00136 oasys::ScratchBuffer<u_char*>* memory_buf()
00137 {
00138 ASSERT(location_ == MEMORY);
00139 return &data_;
00140 }
00141
00145 const oasys::ScratchBuffer<u_char*>* memory_buf() const
00146 {
00147 ASSERT(location_ == MEMORY);
00148 return &data_;
00149 }
00150
00155 const u_char* read_data(size_t offset, size_t len, u_char* buf);
00156
00163 const u_char* read_data(size_t offset, size_t len, u_char* buf) const
00164 {
00165 return const_cast<BundlePayload*>(this)->
00166 read_data(offset, len, buf);
00167 }
00168
00172 virtual void serialize(oasys::SerializeAction* a);
00173
00174 static bool test_no_remove_;
00175
00176 protected:
00177 void pin_file() const;
00178 void unpin_file() const;
00179 void internal_write(const u_char* bp, size_t offset, size_t len);
00180
00181 location_t location_;
00182 oasys::ScratchBuffer<u_char*> data_;
00183 size_t length_;
00184 mutable oasys::FileIOClient file_;
00185 mutable size_t cur_offset_;
00186 size_t base_offset_;
00187 oasys::SpinLock* lock_;
00188 };
00189
00190 }
00191
00192 #endif