View | Details | Raw Unified | Return to bug 127
Collapse All | Expand All

(-)a/src/core/callback-trace-source.h (-2 / +15 lines)
 Lines 23-34    Link Here 
23
#define CALLBACK_TRACE_H
23
#define CALLBACK_TRACE_H
24
24
25
#include <list>
25
#include <list>
26
#include <typeinfo>
26
#include "callback.h"
27
#include "callback.h"
27
#include "fatal-error.h"
28
#include "fatal-error.h"
28
#include "trace-context.h"
29
#include "trace-context.h"
29
#include "trace-source.h"
30
#include "trace-source.h"
30
31
31
namespace ns3 {
32
namespace ns3 {
33
34
class CallbackTraceSourceBase : public TraceSource
35
{
36
public:
37
  virtual const std::type_info& GetCallbackType () const = 0;
38
};
32
39
33
/**
40
/**
34
 * \brief log arbitrary number of parameters to a matching ns3::Callback
41
 * \brief log arbitrary number of parameters to a matching ns3::Callback
 Lines 39-50   namespace ns3 { Link Here 
39
 */
46
 */
40
template<typename T1 = empty, typename T2 = empty, 
47
template<typename T1 = empty, typename T2 = empty, 
41
         typename T3 = empty, typename T4 = empty>
48
         typename T3 = empty, typename T4 = empty>
42
class CallbackTraceSource : public TraceSource {
49
class CallbackTraceSource : public CallbackTraceSourceBase {
43
public:
50
public:
51
52
  typedef Callback<void,TraceContext const &,T1,T2,T3,T4> CallbackType;
53
44
  CallbackTraceSource ();
54
  CallbackTraceSource ();
45
  virtual void AddCallback (CallbackBase const & callback, TraceContext const & context);
55
  virtual void AddCallback (CallbackBase const & callback, TraceContext const & context);
46
  virtual void RemoveCallback (CallbackBase const & callback);
56
  virtual void RemoveCallback (CallbackBase const & callback);
47
  virtual void ConnectPrinter (std::ostream &os, const TraceContext &context);
57
  virtual void ConnectPrinter (std::ostream &os, const TraceContext &context);
58
  virtual const std::type_info& GetCallbackType () const {
59
    return typeid (CallbackType);
60
  }
48
  void operator() (void) const;
61
  void operator() (void) const;
49
  void operator() (T1 a1) const;
62
  void operator() (T1 a1) const;
50
  void operator() (T1 a1, T2 a2) const;
63
  void operator() (T1 a1, T2 a2) const;
 Lines 52-58   public: Link Here 
52
  void operator() (T1 a1, T2 a2, T3 a3, T4 a4) const;
65
  void operator() (T1 a1, T2 a2, T3 a3, T4 a4) const;
53
66
54
private:
67
private:
55
  typedef std::list<Callback<void,TraceContext const &,T1,T2,T3,T4> > CallbackList;
68
  typedef std::list<CallbackType> CallbackList;
56
  TraceContext m_context;
69
  TraceContext m_context;
57
  CallbackList m_callbackList;
70
  CallbackList m_callbackList;
58
};
71
};
(-)a/src/core/composite-trace-resolver.cc (-15 / +47 lines)
 Lines 105-111   CompositeTraceResolver::DoAddSource (std Link Here 
105
      path.append (this->name);
105
      path.append (this->name);
106
      TraceContext ctx = context;
106
      TraceContext ctx = context;
107
      ctx.Union (this->context);
107
      ctx.Union (this->context);
108
      collection->AddUnique (path, ctx, this->doc);
108
      collection->AddUnique (path, ctx, this->doc, GetCallbackType ());
109
    }
109
    }
110
    virtual void TraceAll (std::ostream &os, const TraceContext &context)
110
    virtual void TraceAll (std::ostream &os, const TraceContext &context)
111
    {
111
    {
 Lines 115-120   CompositeTraceResolver::DoAddSource (std Link Here 
115
    }
115
    }
116
    TraceSource *trace;
116
    TraceSource *trace;
117
    TraceDoc doc;
117
    TraceDoc doc;
118
119
    const std::type_info* GetCallbackType ()
120
    {
121
      const CallbackTraceSourceBase *callbackSource =
122
        dynamic_cast<const CallbackTraceSourceBase *> (trace);
123
      if (callbackSource == NULL)
124
        {
125
          return NULL;
126
        }
127
      else
128
        {
129
          return &callbackSource->GetCallbackType ();
130
        }
131
    }
118
  } *item = new SourceResolveItem ();
132
  } *item = new SourceResolveItem ();
119
  item->name = name;
133
  item->name = name;
120
  item->context = context;
134
  item->context = context;
 Lines 438-444   bool Link Here 
438
bool 
452
bool 
439
CompositeTraceResolverTest::RunTests (void)
453
CompositeTraceResolverTest::RunTests (void)
440
{
454
{
441
  bool ok = true;
455
  bool result = true;
442
456
443
  CallbackTraceSource<double> traceDoubleA;
457
  CallbackTraceSource<double> traceDoubleA;
444
  CallbackTraceSource<double> traceDoubleB;
458
  CallbackTraceSource<double> traceDoubleB;
 Lines 453-471   CompositeTraceResolverTest::RunTests (vo Link Here 
453
467
454
  resolver.Connect ("/*", MakeCallback (&CompositeTraceResolverTest::TraceDouble, this), TraceContext ());
468
  resolver.Connect ("/*", MakeCallback (&CompositeTraceResolverTest::TraceDouble, this), TraceContext ());
455
469
470
  {
471
    TraceResolver::SourceCollection collection;
472
    resolver.CollectSources ("/*", context, &collection);
473
474
    int numSources = 0;
475
    for (TraceResolver::SourceCollection::Iterator source = collection.Begin ();
476
         source != collection.End (); source++)
477
      {
478
        NS_TEST_ASSERT (source->callbackType != NULL);
479
        if (source->callbackType != NULL)
480
          {
481
            numSources++;
482
            NS_TEST_ASSERT (*source->callbackType == typeid (Callback<void, TraceContext const &, double>));
483
          }
484
      }
485
    NS_TEST_ASSERT (numSources > 0);
486
  }
487
456
  m_gotDoubleA = false;
488
  m_gotDoubleA = false;
457
  m_gotDoubleB = false;
489
  m_gotDoubleB = false;
458
  traceDoubleA (0);
490
  traceDoubleA (0);
459
  if (!m_gotDoubleA || m_gotDoubleB)
491
  if (!m_gotDoubleA || m_gotDoubleB)
460
    {
492
    {
461
      ok = false;
493
      result = false;
462
    }
494
    }
463
  m_gotDoubleA = false;
495
  m_gotDoubleA = false;
464
  traceDoubleA (0);
496
  traceDoubleA (0);
465
  traceDoubleB (0);
497
  traceDoubleB (0);
466
  if (!m_gotDoubleA || !m_gotDoubleB)
498
  if (!m_gotDoubleA || !m_gotDoubleB)
467
    {
499
    {
468
      ok = false;
500
      result = false;
469
    }
501
    }
470
  m_gotDoubleA = false;
502
  m_gotDoubleA = false;
471
  m_gotDoubleB = false;
503
  m_gotDoubleB = false;
 Lines 478-484   CompositeTraceResolverTest::RunTests (vo Link Here 
478
  traceDoubleB (0);
510
  traceDoubleB (0);
479
  if (m_gotDoubleA || m_gotDoubleB)
511
  if (m_gotDoubleA || m_gotDoubleB)
480
    {
512
    {
481
      ok = false;
513
      result = false;
482
    }
514
    }
483
515
484
  resolver.Connect ("/trace-double-a", 
516
  resolver.Connect ("/trace-double-a", 
 Lines 489-495   CompositeTraceResolverTest::RunTests (vo Link Here 
489
  traceDoubleB (0);
521
  traceDoubleB (0);
490
  if (!m_gotDoubleA || m_gotDoubleB)
522
  if (!m_gotDoubleA || m_gotDoubleB)
491
    {
523
    {
492
      ok = false;
524
      result = false;
493
    }
525
    }
494
  resolver.Disconnect ("/trace-double-a", 
526
  resolver.Disconnect ("/trace-double-a", 
495
		       MakeCallback (&CompositeTraceResolverTest::TraceDouble, this));
527
		       MakeCallback (&CompositeTraceResolverTest::TraceDouble, this));
 Lines 502-508   CompositeTraceResolverTest::RunTests (vo Link Here 
502
  traceDoubleB (0);
534
  traceDoubleB (0);
503
  if (!m_gotDoubleA || m_gotDoubleB)
535
  if (!m_gotDoubleA || m_gotDoubleB)
504
    {
536
    {
505
      ok = false;
537
      result = false;
506
    }
538
    }
507
  resolver.Disconnect ("/trace-double-a", 
539
  resolver.Disconnect ("/trace-double-a", 
508
		       MakeCallback (&CompositeTraceResolverTest::TraceDouble, this));
540
		       MakeCallback (&CompositeTraceResolverTest::TraceDouble, this));
 Lines 515-521   CompositeTraceResolverTest::RunTests (vo Link Here 
515
  traceDoubleB (0);
547
  traceDoubleB (0);
516
  if (!m_gotDoubleA || !m_gotDoubleB)
548
  if (!m_gotDoubleA || !m_gotDoubleB)
517
    {
549
    {
518
      ok = false;
550
      result = false;
519
    }
551
    }
520
  resolver.Disconnect ("/trace-double-a", 
552
  resolver.Disconnect ("/trace-double-a", 
521
		       MakeCallback (&CompositeTraceResolverTest::TraceDouble, this));
553
		       MakeCallback (&CompositeTraceResolverTest::TraceDouble, this));
 Lines 525-531   CompositeTraceResolverTest::RunTests (vo Link Here 
525
  traceDoubleB (0);
557
  traceDoubleB (0);
526
  if (m_gotDoubleA || !m_gotDoubleB)
558
  if (m_gotDoubleA || !m_gotDoubleB)
527
    {
559
    {
528
      ok = false;
560
      result = false;
529
    }
561
    }
530
562
531
563
 Lines 537-543   CompositeTraceResolverTest::RunTests (vo Link Here 
537
  traceDoubleB (0);
569
  traceDoubleB (0);
538
  if (m_gotDoubleA || m_gotDoubleB)
570
  if (m_gotDoubleA || m_gotDoubleB)
539
    {
571
    {
540
      ok = false;
572
      result = false;
541
    }
573
    }
542
574
543
  resolver.Add ("subresolver", 
575
  resolver.Add ("subresolver", 
 Lines 549-555   CompositeTraceResolverTest::RunTests (vo Link Here 
549
  m_traceInt (1);
581
  m_traceInt (1);
550
  if (!m_gotInt)
582
  if (!m_gotInt)
551
    {
583
    {
552
      ok = false;
584
      result = false;
553
    }
585
    }
554
586
555
  resolver.Disconnect ("/subresolver/trace-int", 
587
  resolver.Disconnect ("/subresolver/trace-int", 
 Lines 558-564   CompositeTraceResolverTest::RunTests (vo Link Here 
558
  m_traceInt (1);
590
  m_traceInt (1);
559
  if (m_gotInt)
591
  if (m_gotInt)
560
    {
592
    {
561
      ok = false;
593
      result = false;
562
    }
594
    }
563
595
564
  resolver.Connect ("/*/trace-int", 
596
  resolver.Connect ("/*/trace-int", 
 Lines 567-573   CompositeTraceResolverTest::RunTests (vo Link Here 
567
  m_traceInt (1);
599
  m_traceInt (1);
568
  if (!m_gotInt)
600
  if (!m_gotInt)
569
    {
601
    {
570
      ok = false;
602
      result = false;
571
    }
603
    }
572
604
573
  resolver.Disconnect ("/subresolver/trace-int", 
605
  resolver.Disconnect ("/subresolver/trace-int", 
 Lines 576-582   CompositeTraceResolverTest::RunTests (vo Link Here 
576
  m_traceInt (1);
608
  m_traceInt (1);
577
  if (m_gotInt)
609
  if (m_gotInt)
578
    {
610
    {
579
      ok = false;
611
      result = false;
580
    }
612
    }
581
613
582
  SVTraceSource<uint16_t> source;
614
  SVTraceSource<uint16_t> source;
 Lines 584-590   CompositeTraceResolverTest::RunTests (vo Link Here 
584
  resolver.AddSource ("uint16_t", TraceDoc ("test source"), source, TraceSourceTest (TraceSourceTest::UINT16_T));
616
  resolver.AddSource ("uint16_t", TraceDoc ("test source"), source, TraceSourceTest (TraceSourceTest::UINT16_T));
585
  
617
  
586
618
587
  return ok;
619
  return result;
588
}
620
}
589
621
590
static CompositeTraceResolverTest g_compositeTraceResolverTest;
622
static CompositeTraceResolverTest g_compositeTraceResolverTest;
(-)a/src/core/trace-resolver.cc (-1 / +3 lines)
 Lines 78-84   void Link Here 
78
void 
78
void 
79
TraceResolver::SourceCollection::AddUnique (std::string path, 
79
TraceResolver::SourceCollection::AddUnique (std::string path, 
80
                                            const TraceContext &context,
80
                                            const TraceContext &context,
81
                                            const TraceDoc &doc)
81
                                            const TraceDoc &doc,
82
                                            const std::type_info *callbackType)
82
{
83
{
83
  for (SourceVector::const_iterator i = m_sources.begin (); i != m_sources.end (); i++)
84
  for (SourceVector::const_iterator i = m_sources.begin (); i != m_sources.end (); i++)
84
    {
85
    {
 Lines 92-97   TraceResolver::SourceCollection::AddUniq Link Here 
92
  source.path = path;
93
  source.path = path;
93
  source.context = context;
94
  source.context = context;
94
  source.doc = doc;
95
  source.doc = doc;
96
  source.callbackType = callbackType;
95
  m_sources.push_back (source);
97
  m_sources.push_back (source);
96
}
98
}
97
TraceResolver::SourceCollection::Iterator
99
TraceResolver::SourceCollection::Iterator
(-)a/src/core/trace-resolver.h (-1 / +7 lines)
 Lines 23-28    Link Here 
23
23
24
#include <string>
24
#include <string>
25
#include <list>
25
#include <list>
26
#include <typeinfo>
26
#include "trace-context.h"
27
#include "trace-context.h"
27
#include "trace-doc.h"
28
#include "trace-doc.h"
28
29
 Lines 93-103   public: Link Here 
93
       * Document the signature of this trace source
94
       * Document the signature of this trace source
94
       */
95
       */
95
      TraceDoc doc;
96
      TraceDoc doc;
97
      /**
98
       * Type info of the Callback, or NULL if it's not a callback source
99
       */
100
      const std::type_info *callbackType;
96
    };
101
    };
97
    typedef std::vector<struct Source>::const_iterator Iterator;
102
    typedef std::vector<struct Source>::const_iterator Iterator;
98
    void AddUnique (std::string path, 
103
    void AddUnique (std::string path, 
99
                    const TraceContext &context,
104
                    const TraceContext &context,
100
                    const TraceDoc &doc);
105
                    const TraceDoc &doc,
106
                    const std::type_info *callbackType);
101
107
102
    /**
108
    /**
103
     * \returns an iterator which points to the first element of the set of
109
     * \returns an iterator which points to the first element of the set of

Return to bug 127