00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "APIBlockProcessor.h"
00018
00019 #include "BlockInfo.h"
00020 #include "BundleProtocol.h"
00021
00022 namespace dtn {
00023
00024 template <> APIBlockProcessor*
00025 oasys::Singleton<APIBlockProcessor>::instance_ = NULL;
00026
00027
00028 APIBlockProcessor::APIBlockProcessor() :
00029 BlockProcessor(BundleProtocol::API_EXTENSION_BLOCK)
00030 {
00031 }
00032
00033
00034 int
00035 APIBlockProcessor::consume(Bundle* bundle,
00036 BlockInfo* block,
00037 u_char* buf,
00038 size_t len)
00039 {
00040 (void)bundle;
00041 (void)block;
00042 (void)buf;
00043 (void)len;
00044
00045 return -1;
00046 }
00047
00048
00049 void
00050 APIBlockProcessor::generate(const Bundle* bundle,
00051 Link* link,
00052 BlockInfo* block,
00053 bool last)
00054 {
00055 (void)bundle;
00056 (void)link;
00057
00058
00059 const BlockInfo* source = block->source();
00060 ASSERT(source != NULL);
00061 ASSERT(source->owner() == this);
00062
00063
00064 ASSERT(source->contents().len() != 0);
00065 ASSERT(source->data_offset() != 0);
00066
00067 u_int8_t flags = source->flags();
00068 if (last) {
00069 flags |= BundleProtocol::BLOCK_FLAG_LAST_BLOCK;
00070 } else {
00071 flags &= ~BundleProtocol::BLOCK_FLAG_LAST_BLOCK;
00072 }
00073
00074 generate_preamble(block, source->type(), flags, source->data_length());
00075 ASSERT(block->data_offset() == source->data_offset());
00076 ASSERT(block->data_length() == source->data_length());
00077
00078 BlockInfo::DataBuffer* contents = block->writable_contents();
00079 memcpy(contents->buf() + block->data_offset(),
00080 source->contents().buf() + block->data_offset(),
00081 block->data_length());
00082 contents->set_len(block->full_length());
00083 }
00084
00085 }