servlib/bundling/BPQBlockProcessor.cc
changeset 4 c02ca5a6ab82
child 5 1849bf57d910
equal deleted inserted replaced
3:c244287035f5 4:c02ca5a6ab82
       
     1 /*
       
     2  *    Copyright 2006 Intel Corporation
       
     3  * 
       
     4  *    Licensed under the Apache License, Version 2.0 (the "License");
       
     5  *    you may not use this file except in compliance with the License.
       
     6  *    You may obtain a copy of the License at
       
     7  * 
       
     8  *        http://www.apache.org/licenses/LICENSE-2.0
       
     9  * 
       
    10  *    Unless required by applicable law or agreed to in writing, software
       
    11  *    distributed under the License is distributed on an "AS IS" BASIS,
       
    12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    13  *    See the License for the specific language governing permissions and
       
    14  *    limitations under the License.
       
    15  */
       
    16 
       
    17 #ifdef HAVE_CONFIG_H
       
    18 #  include <dtn-config.h>
       
    19 #endif
       
    20 
       
    21 #include "BPQBlockProcessor.h"
       
    22 #include "BPQBlock.h"
       
    23 
       
    24 #include "BlockInfo.h"
       
    25 #include "BundleProtocol.h"
       
    26 
       
    27 namespace dtn {
       
    28 
       
    29 //----------------------------------------------------------------------
       
    30 BPQBlockProcessor::BPQBlockProcessor() :
       
    31         BlockProcessor(BundleProtocol::QUERY_EXTENSION_BLOCK)
       
    32 {
       
    33 }
       
    34 
       
    35 //----------------------------------------------------------------------
       
    36 int
       
    37 BPQBlockProcessor::consume(Bundle* bundle,
       
    38                            BlockInfo* block,
       
    39                            u_char* buf,
       
    40                            size_t len)
       
    41 {
       
    42     (void)bundle;
       
    43     (void)block;
       
    44     (void)buf;
       
    45     (void)len;
       
    46 
       
    47     //static const char* log = "/home/aidan/Desktop/dtn_log";
       
    48     static const char* log = "/dtn/bundle/protocol";
       
    49     log_err_p(log, "BPQ: consume() returning -1");
       
    50 
       
    51     return -1;
       
    52 }
       
    53 
       
    54 //----------------------------------------------------------------------
       
    55 int
       
    56 BPQBlockProcessor::generate(const Bundle*  bundle,
       
    57                             BlockInfoVec*  xmit_blocks,
       
    58                             BlockInfo*     block,
       
    59                             const LinkRef& link,
       
    60                             bool           last)
       
    61 {
       
    62 
       
    63     //static const char* log = "/home/aidan/Desktop/dtn_log";
       
    64     static const char* log = "/dtn/bundle/protocol";
       
    65     log_err_p(log, "BPQ: generate() returning %d", BP_SUCCESS);
       
    66 
       
    67     BPQBlock* bpq_block = new BPQBlock(block);
       
    68 
       
    69 /*
       
    70     for (BlockInfoVec::iterator iter = bundle->recv_blocks().begin();
       
    71          iter != bundle->recv_blocks().end();
       
    72          ++iter)
       
    73     {
       
    74         log_err_p(log,"\n type: 0x%02x ", iter->type());
       
    75         if (iter->data_offset() == 0)
       
    76             log_err_p(log,"(runt)");
       
    77         else {
       
    78             if (!iter->complete())
       
    79                 log_err_p(log,"(incomplete) ");
       
    80             log_err_p(log,"data length: %d", iter->full_length());
       
    81         }
       
    82     }
       
    83 
       
    84 
       
    85 
       
    86 
       
    87 */
       
    88 /*    oasys::StaticStringBuffer<1024> buf;
       
    89     bundle->format_verbose(&buf);
       
    90     log_multiline(oasys::LOG_NOTICE, buf.c_str());
       
    91 
       
    92 */
       
    93     /*oasys::StringBuffer *sb = new oasys::StringBuffer();
       
    94     //char c[10000];
       
    95     bundle->format_verbose(sb);
       
    96     log_err_p(log, "%s", sb->data());
       
    97     */
       
    98 
       
    99 
       
   100 
       
   101     u_int8_t flags = BundleProtocol::BLOCK_FLAG_DISCARD_BUNDLE_ONERROR |
       
   102                      (last ? BundleProtocol::BLOCK_FLAG_LAST_BLOCK : 0);
       
   103 
       
   104     generate_preamble(xmit_blocks,
       
   105                       block,
       
   106                       BundleProtocol::QUERY_EXTENSION_BLOCK,
       
   107                       flags,
       
   108                       1 ); 
       
   109 
       
   110 
       
   111     // source block must include at least a block header, if not actual data
       
   112 //    ASSERT(source->contents().len() != 0);
       
   113 //    ASSERT(source->data_offset() != 0);
       
   114 
       
   115 //    generate_preamble(xmit_blocks, block, source->type(), flags, source->data_length());
       
   116 //    ASSERT(block->data_offset() == source->data_offset());
       
   117 //    ASSERT(block->data_length() == source->data_length());
       
   118 /*
       
   119     BlockInfo::DataBuffer* contents = block->writable_contents();
       
   120     contents->reserve(block->full_length());
       
   121     memcpy(contents->buf()          + block->data_offset(),
       
   122            source->contents().buf() + block->data_offset(),
       
   123            block->data_length());
       
   124     contents->set_len(block->full_length());
       
   125 */
       
   126 
       
   127     return BP_SUCCESS;
       
   128 }
       
   129 
       
   130 } // namespace dtn
       
   131