remove packet logger. replace it with more generic callback logger
This commit is contained in:
@@ -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 <iostream>
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
PacketLogger a;
|
||||
CallbackLogger<Packet> a;
|
||||
UiTracedVariable<unsigned short> b;
|
||||
TraceStream c;
|
||||
CallbackLogger<double, int> d;
|
||||
@@ -16,7 +16,7 @@ CallbackLogger<double, int> 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));
|
||||
|
||||
@@ -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 <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
|
||||
#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
|
||||
|
||||
@@ -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 <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
|
||||
#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<void,Packet const> 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 */
|
||||
@@ -20,7 +20,6 @@
|
||||
*/
|
||||
|
||||
#include "trace-container.h"
|
||||
#include "packet-logger.h"
|
||||
#include "trace-stream.h"
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
@@ -64,17 +63,6 @@ TraceContainer::set_f_variable_callback (char const *name, Callback<void,double,
|
||||
assert (false);
|
||||
}
|
||||
void
|
||||
TraceContainer::set_packet_logger_callback (char const *name, Callback<void,Packet const> 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 << "\""<<std::endl;
|
||||
}
|
||||
}
|
||||
if (!m_packet_logger_list.empty ()) {
|
||||
std::cout << "packet logger: " << std::endl;
|
||||
for (PacketLoggerListI i = m_packet_logger_list.begin (); i != m_packet_logger_list.end (); i++) {
|
||||
std::cout << " \"" << (*i).second << "\""<<std::endl;
|
||||
}
|
||||
}
|
||||
if (!m_callback_list.empty ()) {
|
||||
std::cout << "callback list: "<<std::endl;
|
||||
for (CallbackListI i = m_callback_list.begin (); i != m_callback_list.end (); i++) {
|
||||
|
||||
@@ -27,13 +27,11 @@
|
||||
#include "f-traced-variable.tcc"
|
||||
#include "callback-logger.h"
|
||||
#include "ns3/callback.h"
|
||||
#include "packet.h"
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
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<void,double, double> 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<void,Packet const> 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<std::pair<SiTracedVariableBase *, std::string> >::iterator SiListI;
|
||||
typedef std::list<std::pair<FTracedVariableBase *, std::string> > FList;
|
||||
typedef std::list<std::pair<FTracedVariableBase *, std::string> >::iterator FListI;
|
||||
typedef std::list<std::pair<PacketLogger *, std::string> > PacketLoggerList;
|
||||
typedef std::list<std::pair<PacketLogger *, std::string> >::iterator PacketLoggerListI;
|
||||
typedef std::list<std::pair<TraceStream *, std::string> > TraceStreamList;
|
||||
typedef std::list<std::pair<TraceStream *, std::string> >::iterator TraceStreamListI;
|
||||
typedef std::list<std::pair<CallbackLoggerBase *, std::string> > 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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user