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