APIBlockProcessor.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
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     // there must be a corresponding source block created at the API
00059     const BlockInfo* source = block->source();
00060     ASSERT(source != NULL);
00061     ASSERT(source->owner() == this);
00062 
00063     // source block must include at least a block header, if not actual data
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 } // namespace dtn

Generated on Sat Sep 8 08:43:23 2007 for DTN Reference Implementation by  doxygen 1.5.3