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