From f9a13fdbfd69e2b85ff0f717afab7582604e1073 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 4 Sep 2006 13:40:02 +0200 Subject: [PATCH] remove packet logger. replace it with more generic callback logger --- samples/main-trace.cc | 12 ++++---- src/common/packet-logger.cc | 42 --------------------------- src/common/packet-logger.h | 53 ----------------------------------- src/common/trace-container.cc | 31 -------------------- src/common/trace-container.h | 22 +-------------- 5 files changed, 7 insertions(+), 153 deletions(-) delete mode 100644 src/common/packet-logger.cc delete mode 100644 src/common/packet-logger.h diff --git a/samples/main-trace.cc b/samples/main-trace.cc index 545f8e729..ffda24001 100644 --- a/samples/main-trace.cc +++ b/samples/main-trace.cc @@ -1,14 +1,14 @@ /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ #include "ns3/trace-container.h" #include "ns3/ui-traced-variable.tcc" -#include "ns3/packet-logger.h" #include "ns3/trace-stream.h" #include "ns3/pcap-writer.h" +#include "ns3/packet.h" #include using namespace ns3; -PacketLogger a; +CallbackLogger a; UiTracedVariable b; TraceStream c; CallbackLogger d; @@ -16,7 +16,7 @@ CallbackLogger d; void register_all_trace_sources (TraceContainer *container) { - container->register_packet_logger ("source-a", &a); + container->register_callback ("source-a", &a); container->register_ui_variable ("source-b", &b); container->register_stream ("source-c", &c); container->register_callback ("source-d", &d); @@ -25,7 +25,7 @@ void generate_trace_events (void) { // log en empty packet - a.log (Packet ()); + a (Packet ()); b = 10; b += 100; b += 50; @@ -50,8 +50,8 @@ int main (int argc, char *argv[]) PcapWriter pcap; pcap.open ("trace-test.log"); pcap.write_header_ethernet (); - traces.set_packet_logger_callback ("source-a", - make_callback (&PcapWriter::write_packet, &pcap)); + traces.set_callback ("source-a", + make_callback (&PcapWriter::write_packet, &pcap)); traces.set_ui_variable_callback ("source-b", make_callback (&variable_event)); traces.set_stream ("source-c", &std::cout); traces.set_callback ("source-d", make_callback (&callback_event)); diff --git a/src/common/packet-logger.cc b/src/common/packet-logger.cc deleted file mode 100644 index 0942d0a2c..000000000 --- a/src/common/packet-logger.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ -/* - * Copyright (c) 2006 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ - -#include "packet-logger.h" - -namespace ns3 { - -PacketLogger::PacketLogger () -{} -void -PacketLogger::log (Packet const packet) -{ - if (!m_callback.is_null ()) { - m_callback (packet); - } -} -void -PacketLogger::set_callback (PacketLoggerCallback callback) -{ - m_callback = callback; -} - -}; // namespace ns3 - diff --git a/src/common/packet-logger.h b/src/common/packet-logger.h deleted file mode 100644 index 7b71b14c4..000000000 --- a/src/common/packet-logger.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ -/* - * Copyright (c) 2006 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ - -#ifndef PACKET_LOGGER_H -#define PACKET_LOGGER_H - -#include "ns3/callback.h" -#include "packet.h" - -namespace ns3 { - -/** - * \brief log packets - */ -class PacketLogger { -public: - typedef Callback PacketLoggerCallback; - PacketLogger (); - /** - * \param packet to log - * If a non-null callback was set, the packet - * is forwarded to that callback. - */ - void log (Packet const packet); - /** - * \param callback callback to store - */ - void set_callback (PacketLoggerCallback callback); -private: - PacketLoggerCallback m_callback; -}; - -}; // namespace ns3 - -#endif /* PACKET_LOGGER_H */ diff --git a/src/common/trace-container.cc b/src/common/trace-container.cc index 9faadbf85..32cfe2924 100644 --- a/src/common/trace-container.cc +++ b/src/common/trace-container.cc @@ -20,7 +20,6 @@ */ #include "trace-container.h" -#include "packet-logger.h" #include "trace-stream.h" #include #include @@ -64,17 +63,6 @@ TraceContainer::set_f_variable_callback (char const *name, Callback callback) -{ - for (PacketLoggerListI i = m_packet_logger_list.begin (); i != m_packet_logger_list.end (); i++) { - if ((*i).second == name) { - (*i).first->set_callback (callback); - return; - } - } - assert (false); -} -void TraceContainer::set_stream (char const *name, std::ostream *os) { for (TraceStreamListI i = m_trace_stream_list.begin (); i != m_trace_stream_list.end (); i++) { @@ -116,19 +104,6 @@ TraceContainer::register_f_variable (char const *name, FTracedVariableBase *var) assert (false); } -void -TraceContainer::register_packet_logger (char const *name, PacketLogger *logger) -{ - // ensure unicity - for (PacketLoggerListI i = m_packet_logger_list.begin (); i != m_packet_logger_list.end (); i++) { - if (i->second == name) { - m_packet_logger_list.erase (i); - break; - } - } - m_packet_logger_list.push_back (std::make_pair (logger, name)); -} - void TraceContainer::register_stream (char const *name, TraceStream *stream) { @@ -182,12 +157,6 @@ ns3::TraceContainer::print_debug (void) std::cout << " \"" << (*i).second << "\""< #include namespace ns3 { -class PacketLogger; class TraceStream; /** @@ -45,9 +43,8 @@ class TraceStream; * model trace event sources. * * TraceContainer can be used to register the following event sources: - * - ns3::PacketLogger : can be connected to ns3::PcapWriter * - ns3::TraceStream : can be connected to any std::ostream - * - ns3::CallbackLogger: can be connected to ns3::Callback + * - ns3::CallbackLogger: can be connected to any ns3::Callback * - ns3::UiTracedVariable * - ns3::SiTracedVariable * - ns3::FTracedVariable @@ -88,13 +85,6 @@ public: * This method targets only event sources which are variables of any double type. */ void set_f_variable_callback (char const *name, Callback callback); - /** - * \param name the name of the target event source - * \param callback the callback being connected to the target event source - * - * This method targets only event sources which are of type PacketLogger. - */ - void set_packet_logger_callback (char const *name, Callback callback); /** * \param name the name of the target event source * \param os the output stream being connected to the source trace stream @@ -165,13 +155,6 @@ public: * This method registers only event sources of type "double". */ void register_f_variable (char const *name, FTracedVariableBase *var); - /** - * \param name the name of the registered event source - * \param logger the event source being registered - * - * This method registers only event sources of type PacketLogger. - */ - void register_packet_logger (char const *name, PacketLogger *logger); /** * \param name the name of the registered event source * \param stream the event source being registered @@ -199,8 +182,6 @@ private: typedef std::list >::iterator SiListI; typedef std::list > FList; typedef std::list >::iterator FListI; - typedef std::list > PacketLoggerList; - typedef std::list >::iterator PacketLoggerListI; typedef std::list > TraceStreamList; typedef std::list >::iterator TraceStreamListI; typedef std::list > CallbackList; @@ -209,7 +190,6 @@ private: UiList m_ui_list; SiList m_si_list; FList m_f_list; - PacketLoggerList m_packet_logger_list; TraceStreamList m_trace_stream_list; CallbackList m_callback_list; };