src/core/traced-callback.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 31 Mar 2008 14:56:41 -0700
changeset 2834 1aab57845b07
parent 2594 a8f89acd17a1
permissions -rw-r--r--
remove 'All rigts reserved' keyword per tom's suggestion
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
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 * 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
     6
 * 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
     7
 * 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
     8
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 * 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
    10
 * 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
    11
 * 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
    12
 * 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
    13
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 * 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
    15
 * 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
    16
 * 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
    17
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
 * 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
    19
 */
2482
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2466
diff changeset
    20
#include "traced-callback.h"
1419
ac2a81821ab5 add support for NodeList::ConnectPrinterToAll
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1350
diff changeset
    21
ac2a81821ab5 add support for NodeList::ConnectPrinterToAll
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1350
diff changeset
    22
#ifdef RUN_SELF_TESTS
ac2a81821ab5 add support for NodeList::ConnectPrinterToAll
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1350
diff changeset
    23
1335
d0e45d84f9c6 fix includes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1334
diff changeset
    24
#include "test.h"
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
2482
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2466
diff changeset
    28
class TracedCallbackTest : public Test 
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
{
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
public:
2482
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2466
diff changeset
    31
  TracedCallbackTest ();
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2466
diff changeset
    32
  virtual ~TracedCallbackTest ();
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
  virtual bool RunTests (void);
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
private:
2462
93028d4474ba add an IntegerTraceSource which behaves just like an Integer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1419
diff changeset
    35
  void CbOne (uint8_t a, double b);
93028d4474ba add an IntegerTraceSource which behaves just like an Integer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1419
diff changeset
    36
  void CbTwo (uint8_t a, double b);
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
  bool m_one;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
  bool m_two;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
};
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
2482
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2466
diff changeset
    42
TracedCallbackTest::TracedCallbackTest ()
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2466
diff changeset
    43
  : Test ("TracedCallback")
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
{}
2482
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2466
diff changeset
    45
TracedCallbackTest::~TracedCallbackTest ()
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    46
{}
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
void
2482
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2466
diff changeset
    48
TracedCallbackTest::CbOne (uint8_t a, double b)
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
{
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    50
  m_one = true;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
}
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
void
2482
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2466
diff changeset
    53
TracedCallbackTest::CbTwo (uint8_t a, double b)
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
{
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
  m_two = true;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
}
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
bool 
2482
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2466
diff changeset
    58
TracedCallbackTest::RunTests (void)
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
{
1350
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    60
  bool result = true;
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    61
2482
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2466
diff changeset
    62
  TracedCallback<uint8_t,double> trace;
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2482
diff changeset
    63
  trace.ConnectWithoutContext (MakeCallback (&TracedCallbackTest::CbOne, this));
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2482
diff changeset
    64
  trace.ConnectWithoutContext (MakeCallback (&TracedCallbackTest::CbTwo, this));
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
  m_one = false;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
  m_two = false;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
  trace (1, 2);
1350
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    68
  NS_TEST_ASSERT (m_one);
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    69
  NS_TEST_ASSERT (m_two);
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    70
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2482
diff changeset
    71
  trace.DisconnectWithoutContext (MakeCallback (&TracedCallbackTest::CbOne, this));
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
  m_one = false;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
  m_two = false;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
  trace (1, 2);
1350
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    75
  NS_TEST_ASSERT (!m_one);
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    76
  NS_TEST_ASSERT (m_two);
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2482
diff changeset
    77
  trace.DisconnectWithoutContext (MakeCallback (&TracedCallbackTest::CbTwo, this));
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
  m_one = false;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
  m_two = false;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    80
  trace (1, 2);
1350
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    81
  NS_TEST_ASSERT (!m_one);
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    82
  NS_TEST_ASSERT (!m_two);
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2482
diff changeset
    84
  trace.ConnectWithoutContext (MakeCallback (&TracedCallbackTest::CbOne, this));
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2482
diff changeset
    85
  trace.ConnectWithoutContext (MakeCallback (&TracedCallbackTest::CbTwo, this));
1350
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    86
  m_one = false;
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    87
  m_two = false;
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    88
  trace (1, 2);
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    89
  NS_TEST_ASSERT (m_one);
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    90
  NS_TEST_ASSERT (m_two);
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    91
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    92
  return result;
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    93
}
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
2482
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2466
diff changeset
    95
static TracedCallbackTest g_eventTraceTest;
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    96
1419
ac2a81821ab5 add support for NodeList::ConnectPrinterToAll
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1350
diff changeset
    97
}//namespace ns3
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    98
1419
ac2a81821ab5 add support for NodeList::ConnectPrinterToAll
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1350
diff changeset
    99
#endif /* RUN_SELF_TESTS */