src/core/trace-resolver.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 28 Aug 2007 13:10:18 +0200
changeset 1379 f323d2dcdaf6
parent 1377 2fcc78ee9558
child 1388 7c88861a6f8c
permissions -rw-r--r--
document trace source signatures
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * Copyright (c) 2007 INRIA
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 * All rights reserved.
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License version 2 as
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 * published by the Free Software Foundation;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 * GNU General Public License for more details.
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
 */
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
#include "trace-resolver.h"
1335
d0e45d84f9c6 fix includes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1334
diff changeset
    22
#include "debug.h"
1333
c0d66de933e9 convert TraceResolver * to Ptr<TraceResolver>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1330
diff changeset
    23
c0d66de933e9 convert TraceResolver * to Ptr<TraceResolver>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1330
diff changeset
    24
NS_DEBUG_COMPONENT_DEFINE ("TraceResolver");
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
namespace ns3 {
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
1330
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1329
diff changeset
    28
TraceResolver::TraceResolver ()
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1329
diff changeset
    29
  : m_count (1)
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1329
diff changeset
    30
{}
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
TraceResolver::~TraceResolver ()
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
{}
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
void 
1330
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1329
diff changeset
    36
TraceResolver::Ref (void)
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1329
diff changeset
    37
{
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1329
diff changeset
    38
  m_count++;
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1329
diff changeset
    39
}
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1329
diff changeset
    40
void 
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1329
diff changeset
    41
TraceResolver::Unref (void)
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1329
diff changeset
    42
{
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1329
diff changeset
    43
  m_count--;
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1329
diff changeset
    44
  if (m_count == 0)
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1329
diff changeset
    45
    {
1333
c0d66de933e9 convert TraceResolver * to Ptr<TraceResolver>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1330
diff changeset
    46
      NS_DEBUG ("delete "<<this);
1330
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1329
diff changeset
    47
      delete this;
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1329
diff changeset
    48
    }
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1329
diff changeset
    49
}
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1329
diff changeset
    50
1328
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    51
std::string 
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    52
TraceResolver::GetElement (std::string path)
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    53
{
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    54
  std::string::size_type cur = 1;
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    55
  // check that first char is "/"
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    56
  std::string::size_type next = path.find ("/", cur);
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    57
  std::string id = std::string (path, cur, next-1);
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    58
  return id;
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    59
}
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    60
std::string 
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    61
TraceResolver::GetSubpath (std::string path)
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    62
{
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    63
  std::string::size_type cur = 1;
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    64
  // check that first char is "/"
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    65
  std::string::size_type next = path.find ("/", cur);
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    66
  std::string subpath;
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    67
  if (next != std::string::npos)
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    68
    {
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    69
      subpath = std::string (path, next, std::string::npos);
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    70
    }
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    71
  else
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    72
    {
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    73
      subpath = "";
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    74
    }
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    75
  return subpath;
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    76
}
03f1081c21a7 override Connect from ArrayTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    77
1370
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    78
void 
1379
f323d2dcdaf6 document trace source signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1377
diff changeset
    79
TraceResolver::SourceCollection::AddUnique (std::string path, 
f323d2dcdaf6 document trace source signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1377
diff changeset
    80
                                            const TraceContext &context,
f323d2dcdaf6 document trace source signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1377
diff changeset
    81
                                            const TraceDoc &doc)
1370
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    82
{
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    83
  for (SourceVector::const_iterator i = m_sources.begin (); i != m_sources.end (); i++)
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    84
    {
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    85
      if (i->path == path &&
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    86
          context.IsSimilar (i->context))
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    87
        {
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    88
          return;
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    89
        }
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    90
    }
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    91
  struct Source source;
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    92
  source.path = path;
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    93
  source.context = context;
1379
f323d2dcdaf6 document trace source signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1377
diff changeset
    94
  source.doc = doc;
1370
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    95
  m_sources.push_back (source);
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    96
}
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    97
void 
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    98
TraceResolver::SourceCollection::Print (std::ostream &os) const
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
    99
{
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
   100
  for (SourceVector::const_iterator i = m_sources.begin (); i != m_sources.end (); i++)
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
   101
    {
1372
5967e5b2c737 keep track of trace source help strings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1371
diff changeset
   102
      os << "source=" << i->path << std::endl;
1377
2fcc78ee9558 improve trace list output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   103
      os << "TraceContext=[";
2fcc78ee9558 improve trace list output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   104
      i->context.PrintAvailable (os, ",");
2fcc78ee9558 improve trace list output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   105
      os << "]" << std::endl;
1379
f323d2dcdaf6 document trace source signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1377
diff changeset
   106
      os << "help=\"" << i->doc.GetHelp () << "\"" << std::endl;
f323d2dcdaf6 document trace source signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1377
diff changeset
   107
      os << "const TraceContext &: the trace context associated to the connected trace source." << std::endl;
f323d2dcdaf6 document trace source signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1377
diff changeset
   108
      uint32_t k = 0;
f323d2dcdaf6 document trace source signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1377
diff changeset
   109
      for (TraceDoc::Iterator j = i->doc.ArgsBegin (); j != i->doc.ArgsEnd (); j++)
f323d2dcdaf6 document trace source signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1377
diff changeset
   110
        {
f323d2dcdaf6 document trace source signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1377
diff changeset
   111
          os << "argument " << k << "  --  " << j->first << ": " << j->second << "." << std::endl;
f323d2dcdaf6 document trace source signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1377
diff changeset
   112
          k++;
f323d2dcdaf6 document trace source signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1377
diff changeset
   113
        }
1372
5967e5b2c737 keep track of trace source help strings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1371
diff changeset
   114
      os << std::endl;
1370
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
   115
    }
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
   116
}
d5339e1c95df add TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1363
diff changeset
   117
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   118
}//namespace ns3