Files
unison/samples/main-trace.cc

62 lines
1.5 KiB
C++
Raw Normal View History

2006-09-05 13:18:11 +02:00
/* -*- Mode:C++; c-basic-offset:4; tab-width:4; indent-tabs-mode:f -*- */
2006-08-29 17:51:04 +02:00
#include "ns3/trace-container.h"
2006-09-04 15:09:58 +02:00
#include "ns3/ui-variable-tracer.h"
#include "ns3/callback-tracer.h"
2006-09-04 14:10:34 +02:00
#include "ns3/stream-tracer.h"
2006-08-29 17:51:04 +02:00
#include "ns3/pcap-writer.h"
#include "ns3/packet.h"
2006-08-29 17:47:17 +02:00
#include <iostream>
2006-08-29 17:55:34 +02:00
using namespace ns3;
2006-08-29 17:47:17 +02:00
CallbackTracer<Packet> a;
UiVariableTracer<unsigned short> b;
2006-09-04 14:10:34 +02:00
StreamTracer c;
CallbackTracer<double, int> d;
2006-08-29 17:47:17 +02:00
void
registerAllTraceSources (TraceContainer *container)
2006-08-29 17:47:17 +02:00
{
2006-09-05 13:18:11 +02:00
container->registerCallback ("source-a", &a);
container->registerUiVariable ("source-b", &b);
container->registerStream ("source-c", &c);
container->registerCallback ("source-d", &d);
2006-08-29 17:47:17 +02:00
}
void
generateTraceEvents (void)
2006-08-29 17:47:17 +02:00
{
2006-09-05 13:18:11 +02:00
// log en empty packet
a (Packet ());
b = 10;
b += 100;
b += 50;
b = (unsigned short) -20;
c << "this is a simple test b=" << b << std::endl;
d (3.1415, 3);
2006-08-29 17:47:17 +02:00
}
void
variableEvent (uint64_t old, uint64_t cur)
2006-08-29 17:47:17 +02:00
{}
void
callbackEvent (double a, int b)
2006-08-29 17:47:17 +02:00
{}
int main (int argc, char *argv[])
{
2006-09-05 13:18:11 +02:00
TraceContainer traces;
registerAllTraceSources (&traces);
PcapWriter pcap;
pcap.open ("trace-test.log");
pcap.writeHeaderEthernet ();
traces.setCallback ("source-a",
makeCallback (&PcapWriter::writePacket, &pcap));
traces.setUiVariableCallback ("source-b", makeCallback (&variableEvent));
traces.setStream ("source-c", &std::cout);
traces.setCallback ("source-d", makeCallback (&callbackEvent));
generateTraceEvents ();
return 0;
2006-08-29 17:47:17 +02:00
}