utils/print-trace-sources.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 30 Aug 2007 14:25:09 +0200
changeset 1400 382b2a36384c
parent 1399 5945e92014e2
child 1538 7f18d8c94d10
permissions -rw-r--r--
rewrite the TraceContext::SourceCollection::Iterator class
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1368
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
#include "ns3/internet-node.h"
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
#include "ns3/ptr.h"
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
#include "ns3/trace-resolver.h"
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
#include "ns3/node-list.h"
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
#include "ns3/point-to-point-net-device.h"
1376
ad7e61edfb9d merge with trunk
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1375
diff changeset
     6
#include "ns3/csma-net-device.h"
1368
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
#include "ns3/queue.h"
1375
4f45bec005b8 document also mobility model notifier
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1371
diff changeset
     8
#include "ns3/mobility-model-notifier.h"
1368
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
using namespace ns3;
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
1399
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    12
void
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    13
PrintSimpleText (const TraceResolver::SourceCollection *sources, std::ostream &os)
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    14
{
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    15
  for (TraceResolver::SourceCollection::Iterator i = sources->Begin (); i != sources->End (); i++)
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    16
    {
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    17
      os << "source=" << i->path << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    18
      os << "TraceContext=[";
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    19
      i->context.PrintAvailable (os, ",");
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    20
      os << "]" << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    21
      os << "help=\"" << i->doc.GetHelp () << "\"" << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    22
      os << "void TraceSinkCallback (const TraceContext &";
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    23
      for (TraceDoc::Iterator k = i->doc.ArgsBegin (); k != i->doc.ArgsEnd (); k++)
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    24
        {
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    25
          os << ", " << k->first;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    26
        }
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    27
      os << ")" << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    28
      os << "argument 1  --  the trace context associated to the connected trace source." << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    29
      uint32_t k = 2;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    30
      for (TraceDoc::Iterator j = i->doc.ArgsBegin (); j != i->doc.ArgsEnd (); j++)
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    31
        {
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    32
          os << "argument " << k << "  --  " << j->second << "." << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    33
          k++;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    34
        }
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    35
      os << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    36
    }
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    37
}
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    38
void
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    39
PrintDoxygenText (const TraceResolver::SourceCollection *sources, std::ostream &os)
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    40
{
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    41
  uint32_t z = 0;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    42
  for (TraceResolver::SourceCollection::Iterator i = sources->Begin (); i != sources->End (); i++)
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    43
    {
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    44
      os << "///" << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    45
      os << "/// \\ingroup TraceSourceList" << std::endl; 
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    46
      os << "/// \\brief " << i->doc.GetHelp () << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    47
      os << "/// \\param arg1 the trace context associated to the connected trace source." << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    48
      uint32_t j = 2;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    49
      for (TraceDoc::Iterator l = i->doc.ArgsBegin (); l != i->doc.ArgsEnd (); l++)
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    50
        {
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    51
          os << "/// \\param arg" << j << " " << l->second << "." << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    52
          j++;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    53
        }
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    54
      os << "///" << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    55
      os << "///" << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    56
      os << "/// The path to this trace source is: " << i->path << "." << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    57
      os << "///" << std::endl;
1400
382b2a36384c rewrite the TraceContext::SourceCollection::Iterator class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1399
diff changeset
    58
      if (i->context.Begin ().IsLast ())
1399
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    59
        {
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    60
          os << "/// No data can be extracted from \\p arg1 with ns3::TraceContext::GetElement." << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    61
        }
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    62
      else
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    63
        {
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    64
          os << "/// The following classes can be extracted from \\p arg1 with " << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    65
          os << "/// ns3::TraceContext::GetElement:" << std::endl;
1400
382b2a36384c rewrite the TraceContext::SourceCollection::Iterator class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1399
diff changeset
    66
          for (TraceContext::Iterator m = i->context.Begin (); !m.IsLast (); m.Next ())
1399
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    67
            {
1400
382b2a36384c rewrite the TraceContext::SourceCollection::Iterator class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1399
diff changeset
    68
              os << "///  - " << m.Get () << std::endl;
1399
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    69
            }
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    70
        }
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    71
      os << "void TraceSinkCallback" << z << " (const TraceContext & arg1" ;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    72
      j = 2;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    73
      for (TraceDoc::Iterator k = i->doc.ArgsBegin (); k != i->doc.ArgsEnd (); k++)
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    74
        {
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    75
          os << ", " << k->first << " arg" << j;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    76
          j++;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    77
        }
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    78
      os << ");" << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    79
      os << std::endl;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    80
      z++;
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    81
    }
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    82
}
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    83
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    84
1368
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
int main (int argc, char *argv[])
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
{
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
  Ptr<Node> node = Create<InternetNode> ();
1375
4f45bec005b8 document also mobility model notifier
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1371
diff changeset
    88
  node->AddInterface (Create<MobilityModelNotifier> ());
1368
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
  Ptr<PointToPointNetDevice> p2p = Create<PointToPointNetDevice> (node);
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
  p2p->AddQueue (Queue::CreateDefault ());
1376
ad7e61edfb9d merge with trunk
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1375
diff changeset
    92
  Ptr<CsmaNetDevice> csma = Create<CsmaNetDevice> (node);
1368
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
  csma->AddQueue (Queue::CreateDefault ());
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    94
1371
bebf690257c9 replace TraceResolver::PrintAvailable with TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1368
diff changeset
    95
  TraceResolver::SourceCollection collection;
bebf690257c9 replace TraceResolver::PrintAvailable with TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1368
diff changeset
    96
  NodeList::GetTraceResolver ()->CollectSources ("", TraceContext (), &collection);
1399
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1376
diff changeset
    97
  PrintDoxygenText (&collection, std::cout);
1368
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    98
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    99
  return 0;
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
}