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