LoggingRegistration.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-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 
00018 #include <oasys/util/StringUtils.h>
00019 
00020 #include "LoggingRegistration.h"
00021 #include "Registration.h"
00022 #include "bundling/Bundle.h"
00023 #include "bundling/BundleEvent.h"
00024 #include "bundling/BundleDaemon.h"
00025 #include "bundling/BundleList.h"
00026 #include "storage/GlobalStore.h"
00027 
00028 namespace dtn {
00029 
00030 LoggingRegistration::LoggingRegistration(const EndpointIDPattern& endpoint)
00031     : Registration(GlobalStore::instance()->next_regid(),
00032                    endpoint, Registration::DEFER, 0)
00033 {
00034     logpathf("/dtn/reg/logging/%d", regid_);
00035     set_active(true);
00036     
00037     log_info("new logging registration on endpoint %s", endpoint.c_str());
00038 }
00039 
00040 void
00041 LoggingRegistration::deliver_bundle(Bundle* b)
00042 {
00043     // use the bundle's builtin verbose formatting function and
00044     // generate the log output for all the header info
00045     oasys::StringBuffer buf;
00046     b->format_verbose(&buf);
00047     log_multiline(oasys::LOG_ALWAYS, buf.c_str());
00048 
00049     // now dump a short chunk of the payload data, either in ascii or
00050     // hexified string output
00051     size_t len = 128;
00052     size_t payload_len = b->payload_.length();
00053     if (payload_len < len) {
00054         len = payload_len;
00055     }
00056 
00057     u_char payload_buf[payload_len];
00058     const u_char* data = b->payload_.read_data(0, len, payload_buf);
00059 
00060     if (oasys::str_isascii(data, len)) {
00061         log_always("        payload (ascii): length %zu '%.*s'",
00062                    payload_len, (int)len, data);
00063     } else {
00064         std::string hex;
00065         oasys::hex2str(&hex, data, len);
00066         len *= 2;
00067         if (len > 128)
00068             len = 128;
00069         log_always("        payload (binary): length %zu %.*s",
00070                  payload_len, (int)len, hex.data());
00071     }
00072 
00073     // post the transmitted event
00074     BundleDaemon::post(new BundleDeliveredEvent(b, this));
00075 }
00076 
00077 } // namespace dtn

Generated on Thu Jun 7 12:54:28 2007 for DTN Reference Implementation by  doxygen 1.5.1