servlib/bundling/BPQResponse.cc
changeset 5 1849bf57d910
child 6 d1f220643814
equal deleted inserted replaced
4:c02ca5a6ab82 5:1849bf57d910
       
     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 "BPQResponse.h"
       
    22 //#include <oasys/util/ScratchBuffer.h>
       
    23 //#include "SDNV.h"
       
    24 
       
    25 namespace dtn {
       
    26 
       
    27 // Setup our logging information
       
    28 static const char* LOG = "/dtn/bundle/extblock/bpq";
       
    29 
       
    30 //----------------------------------------------------------------------
       
    31 bool
       
    32 BPQResponse::create_bpq_response(Bundle*      new_response,
       
    33                                  Bundle*      query,
       
    34                                  Bundle*      cached_response,
       
    35                                  EndpointID&  local_eid)
       
    36 {
       
    37     log_debug_p(LOG, "BPQResponse::create_bpq_response");
       
    38 
       
    39     // init metadata
       
    40     cached_response->copy_metadata(new_response);
       
    41 
       
    42     // set EIDs
       
    43     new_response->mutable_source()->assign(local_eid);
       
    44     new_response->mutable_dest()->assign(query->source());
       
    45     new_response->mutable_replyto()->assign(query->dest());
       
    46 
       
    47     // set expiry
       
    48     new_response->set_expiration(query->expiration());      // TODO: check this is ok
       
    49 
       
    50     // set payload
       
    51     log_debug_p(LOG, "Copy response payload");
       
    52     new_response->mutable_payload()->
       
    53         replace_with_file(cached_response->payload().filename().c_str());
       
    54 
       
    55     // copy API blocks
       
    56     BlockInfoVec* api_blocks = cached_response->api_blocks();
       
    57 
       
    58     for (BlockInfoVec::iterator iter = api_blocks->begin();
       
    59          iter != api_blocks->end();
       
    60          ++iter)
       
    61     {
       
    62         BlockInfo current = *iter;    
       
    63 
       
    64         BlockInfo* new_bi = new BlockInfo(current);
       
    65         new_bi->set_flag(current.flags());
       
    66 
       
    67         new_response->api_blocks()->append_block(current.owner(), new_bi);
       
    68 
       
    69         if (new_bi->type()==200){
       
    70             log_debug_p(LOG, "_FOO_ new_bi->contents(): watch %p",&(new_bi->contents()));
       
    71         }
       
    72     }
       
    73 
       
    74     // copy RECV blocks
       
    75     BlockInfoVec* recv_blocks = cached_response->mutable_recv_blocks();
       
    76 
       
    77     for (BlockInfoVec::iterator iter = recv_blocks->begin();
       
    78          iter != recv_blocks->end();
       
    79          ++iter)
       
    80     {
       
    81         BlockInfo current = *iter;       
       
    82 
       
    83         BlockInfo* new_bi = new BlockInfo(current);
       
    84         new_bi->set_flag(current.flags());
       
    85 
       
    86         new_response->mutable_recv_blocks()->append_block(current.owner(), new_bi);
       
    87 
       
    88         if (new_bi->type()==200){
       
    89             log_debug_p(LOG, "_FOO_ new_bi->contents(): watch %p",&(new_bi->contents()));
       
    90         }
       
    91 
       
    92     }
       
    93     
       
    94    return true;
       
    95 }
       
    96 
       
    97 } // namespace dtn