diff -r c02ca5a6ab82 -r 1849bf57d910 servlib/bundling/BPQResponse.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/servlib/bundling/BPQResponse.cc Fri May 27 18:33:25 2011 +0100 @@ -0,0 +1,97 @@ +/* + * Copyright 2006 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "BPQResponse.h" +//#include +//#include "SDNV.h" + +namespace dtn { + +// Setup our logging information +static const char* LOG = "/dtn/bundle/extblock/bpq"; + +//---------------------------------------------------------------------- +bool +BPQResponse::create_bpq_response(Bundle* new_response, + Bundle* query, + Bundle* cached_response, + EndpointID& local_eid) +{ + log_debug_p(LOG, "BPQResponse::create_bpq_response"); + + // init metadata + cached_response->copy_metadata(new_response); + + // set EIDs + new_response->mutable_source()->assign(local_eid); + new_response->mutable_dest()->assign(query->source()); + new_response->mutable_replyto()->assign(query->dest()); + + // set expiry + new_response->set_expiration(query->expiration()); // TODO: check this is ok + + // set payload + log_debug_p(LOG, "Copy response payload"); + new_response->mutable_payload()-> + replace_with_file(cached_response->payload().filename().c_str()); + + // copy API blocks + BlockInfoVec* api_blocks = cached_response->api_blocks(); + + for (BlockInfoVec::iterator iter = api_blocks->begin(); + iter != api_blocks->end(); + ++iter) + { + BlockInfo current = *iter; + + BlockInfo* new_bi = new BlockInfo(current); + new_bi->set_flag(current.flags()); + + new_response->api_blocks()->append_block(current.owner(), new_bi); + + if (new_bi->type()==200){ + log_debug_p(LOG, "_FOO_ new_bi->contents(): watch %p",&(new_bi->contents())); + } + } + + // copy RECV blocks + BlockInfoVec* recv_blocks = cached_response->mutable_recv_blocks(); + + for (BlockInfoVec::iterator iter = recv_blocks->begin(); + iter != recv_blocks->end(); + ++iter) + { + BlockInfo current = *iter; + + BlockInfo* new_bi = new BlockInfo(current); + new_bi->set_flag(current.flags()); + + new_response->mutable_recv_blocks()->append_block(current.owner(), new_bi); + + if (new_bi->type()==200){ + log_debug_p(LOG, "_FOO_ new_bi->contents(): watch %p",&(new_bi->contents())); + } + + } + + return true; +} + +} // namespace dtn