src/core/trace-resolver.cc
author Craig Dowell <craigdo@ee.washington.edu>
Thu, 13 Sep 2007 17:47:42 -0700
changeset 1504 36ecc970ba96
parent 1399 5945e92014e2
child 2332 200875532591
permissions -rw-r--r--
checkpoint debug to log
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"
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1399
diff changeset
    22
#include "log.h"
1333
c0d66de933e9 convert TraceResolver * to Ptr<TraceResolver>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1330
diff changeset
    23
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1399
diff changeset
    24
NS_LOG_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
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1399
diff changeset
    46
      NS_LOG_LOGIC ("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
}
1399
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1397
diff changeset
    97
TraceResolver::SourceCollection::Iterator
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1397
diff changeset
    98
TraceResolver::SourceCollection::Begin (void) const
1397
fdc239ba72a7 add PrintDoxygen method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1390
diff changeset
    99
{
1399
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1397
diff changeset
   100
  return m_sources.begin ();
1397
fdc239ba72a7 add PrintDoxygen method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1390
diff changeset
   101
}
1399
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1397
diff changeset
   102
TraceResolver::SourceCollection::Iterator
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1397
diff changeset
   103
TraceResolver::SourceCollection::End (void) const
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1397
diff changeset
   104
{
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1397
diff changeset
   105
  return m_sources.end ();
5945e92014e2 move printing to client code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1397
diff changeset
   106
}
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   107
}//namespace ns3