src/core/model/object.cc
author Josh Pelkey <jpelkey@gatech.edu>
Fri, 13 May 2011 14:52:27 -0400
changeset 7169 358f71a624d8
parent 7003 a0b1500cdaad
child 7399 520706f801e8
permissions -rw-r--r--
core coding style changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2007 INRIA, Gustavo Carneiro
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 *
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * GNU General Public License for more details.
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 *
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Authors: Gustavo Carneiro <gjcarneiro@gmail.com>,
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
 */
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
    21
#include "object.h"
5296
75d258eaccbd Remove and replace object unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4472
diff changeset
    22
#include "object-factory.h"
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
#include "assert.h"
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
#include "singleton.h"
2438
e2ac9f9aeeb9 value.h -> attribute.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
    25
#include "attribute.h"
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1420
diff changeset
    26
#include "log.h"
2502
50d0da37f02f introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2489
diff changeset
    27
#include "string.h"
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
#include <vector>
2372
bf4efb9359c6 attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    29
#include <sstream>
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
    30
#include <stdlib.h>
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
    31
#include <string.h>
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1420
diff changeset
    33
NS_LOG_COMPONENT_DEFINE ("Object");
1374
77468496f7e0 avoid problems with recursive use of Object::DoCollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1372
diff changeset
    34
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
namespace ns3 {
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
2233
b359c83c5fbe add some separation markers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2232
diff changeset
    37
/*********************************************************************
b359c83c5fbe add some separation markers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2232
diff changeset
    38
 *         The Object implementation
b359c83c5fbe add some separation markers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2232
diff changeset
    39
 *********************************************************************/
b359c83c5fbe add some separation markers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2232
diff changeset
    40
2247
56b3591fa3b0 use NS_OBJECT_ENSURE_REGISTERED and fix off-by-one in IidManager::GetRegistered
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2243
diff changeset
    41
NS_OBJECT_ENSURE_REGISTERED (Object);
56b3591fa3b0 use NS_OBJECT_ENSURE_REGISTERED and fix off-by-one in IidManager::GetRegistered
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2243
diff changeset
    42
2937
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    43
Object::AggregateIterator::AggregateIterator ()
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
    44
  : m_object (0),
2937
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    45
    m_current (0)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    46
{
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    47
}
2937
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    48
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    49
bool
2937
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    50
Object::AggregateIterator::HasNext (void) const
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    51
{
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
    52
  return m_current < m_object->m_aggregates->n;
2937
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    53
}
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    54
Ptr<const Object>
2937
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    55
Object::AggregateIterator::Next (void)
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    56
{
5869
67fc4930b470 The iterator needs to actually go forward
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5758
diff changeset
    57
  Object *object = m_object->m_aggregates->buffer[m_current];
67fc4930b470 The iterator needs to actually go forward
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5758
diff changeset
    58
  m_current++;
67fc4930b470 The iterator needs to actually go forward
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5758
diff changeset
    59
  return object;
2937
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    60
}
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
    61
Object::AggregateIterator::AggregateIterator (Ptr<const Object> object)
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
    62
  : m_object (object),
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
    63
    m_current (0)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    64
{
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    65
}
2937
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    66
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
    67
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    68
TypeId
2634
44a92f1d3728 introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2633
diff changeset
    69
Object::GetInstanceTypeId (void) const
44a92f1d3728 introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2633
diff changeset
    70
{
2636
fe664ae9aa8b return the _current_ tid, not the Object tid.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2635
diff changeset
    71
  return m_tid;
2634
44a92f1d3728 introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2633
diff changeset
    72
}
44a92f1d3728 introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2633
diff changeset
    73
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    74
TypeId
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
    75
Object::GetTypeId (void)
2232
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
    76
{
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2636
diff changeset
    77
  static TypeId tid = TypeId ("ns3::Object")
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2636
diff changeset
    78
    .SetParent<ObjectBase> ()
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    79
  ;
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
    80
  return tid;
2232
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
    81
}
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    83
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
    84
Object::Object ()
5486
9bf34ba759a3 Optimization: use a shared reference counter instead of a per-object counter in Object::Ref/Unref
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5479
diff changeset
    85
  : m_tid (Object::GetTypeId ()),
713
c3c745a80610 add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 712
diff changeset
    86
    m_disposed (false),
5524
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5490
diff changeset
    87
    m_started (false),
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    88
    m_aggregates ((struct Aggregates *) malloc (sizeof (struct Aggregates))),
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
    89
    m_getObjectCount (0)
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
    90
{
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
    91
  m_aggregates->n = 1;
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
    92
  m_aggregates->buffer[0] = this;
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
    93
}
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
    94
Object::~Object () 
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
    95
{
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
    96
  // remove this object from the aggregate list
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
    97
  uint32_t n = m_aggregates->n;
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
    98
  for (uint32_t i = 0; i < n; i++)
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
    99
    {
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   100
      Object *current = m_aggregates->buffer[i];
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   101
      if (current == this)
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   102
        {
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   103
          memmove (&m_aggregates->buffer[i], 
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   104
                   &m_aggregates->buffer[i+1],
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   105
                   sizeof (Object *)*(m_aggregates->n - (i+1)));
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   106
          m_aggregates->n--;
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   107
        }
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   108
    }
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   109
  // finally, if all objects have been removed from the list,
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   110
  // delete the aggregate list
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   111
  if (m_aggregates->n == 0)
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   112
    {
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   113
      free (m_aggregates);
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   114
    }
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   115
  m_aggregates = 0;
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   116
}
2667
2324032b8f90 Add an explicit copy constructor. Bug reported by Raj.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2637
diff changeset
   117
Object::Object (const Object &o)
5486
9bf34ba759a3 Optimization: use a shared reference counter instead of a per-object counter in Object::Ref/Unref
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5479
diff changeset
   118
  : m_tid (o.m_tid),
2667
2324032b8f90 Add an explicit copy constructor. Bug reported by Raj.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2637
diff changeset
   119
    m_disposed (false),
5524
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5490
diff changeset
   120
    m_started (false),
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   121
    m_aggregates ((struct Aggregates *) malloc (sizeof (struct Aggregates))),
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   122
    m_getObjectCount (0)
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   123
{
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   124
  m_aggregates->n = 1;
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   125
  m_aggregates->buffer[0] = this;
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   126
}
2372
bf4efb9359c6 attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   127
void
2459
91662d921a83 Attributes -> AttributeList
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2458
diff changeset
   128
Object::Construct (const AttributeList &attributes)
2372
bf4efb9359c6 attempt to perform correctly automatic conversions.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   129
{
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2636
diff changeset
   130
  ConstructSelf (attributes);
2569
d5cff2968984 make Disconnect work with trace contexts.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2542
diff changeset
   131
}
2463
c77e43117673 actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2460
diff changeset
   132
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   133
Ptr<Object>
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   134
Object::DoGetObject (TypeId tid) const
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
{
1534
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   136
  NS_ASSERT (CheckLoose ());
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   137
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   138
  uint32_t n = m_aggregates->n;
3871
c6f693de286d 5% cpu optimization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3397
diff changeset
   139
  TypeId objectTid = Object::GetTypeId ();
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   140
  for (uint32_t i = 0; i < n; i++)
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   141
    {
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   142
      Object *current = m_aggregates->buffer[i];
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   143
      TypeId cur = current->GetInstanceTypeId ();
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   144
      while (cur != tid && cur != objectTid)
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   145
        {
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   146
          cur = cur.GetParent ();
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   147
        }
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   148
      if (cur == tid)
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   149
        {
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   150
          // This is an attempt to 'cache' the result of this lookup.
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   151
          // the idea is that if we perform a lookup for a TypeId on this object,
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   152
          // we are likely to perform the same lookup later so, we make sure
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   153
          // that the aggregate array is sorted by the number of accesses
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   154
          // to each object.
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   155
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   156
          // first, increment the access count
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   157
          current->m_getObjectCount++;
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   158
          // then, update the sort
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   159
          UpdateSortedArray (m_aggregates, i);
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   160
          // finally, return the match
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   161
          return const_cast<Object *> (current);
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   162
        }
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   163
    }
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   164
  return 0;
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   165
}
5524
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5490
diff changeset
   166
void
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5490
diff changeset
   167
Object::Start (void)
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5490
diff changeset
   168
{
5758
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   169
  /**
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   170
   * Note: the code here is a bit tricky because we need to protect ourselves from
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   171
   * modifications in the aggregate array while DoStart is called. The user's
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   172
   * implementation of the DoStart method could call GetObject (which could
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   173
   * reorder the array) and it could call AggregateObject which would add an 
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   174
   * object at the end of the array. To be safe, we restart iteration over the 
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   175
   * array whenever we call some user code, just in case.
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   176
   */
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   177
restart:
5524
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5490
diff changeset
   178
  uint32_t n = m_aggregates->n;
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5490
diff changeset
   179
  for (uint32_t i = 0; i < n; i++)
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5490
diff changeset
   180
    {
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5490
diff changeset
   181
      Object *current = m_aggregates->buffer[i];
5758
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   182
      if (!current->m_started)
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   183
        {
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   184
          current->DoStart ();
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   185
          current->m_started = true;
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   186
          goto restart;
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   187
        }
5524
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5490
diff changeset
   188
    }
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5490
diff changeset
   189
}
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   190
void 
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   191
Object::Dispose (void)
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   192
{
5758
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   193
  /**
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   194
   * Note: the code here is a bit tricky because we need to protect ourselves from
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   195
   * modifications in the aggregate array while DoDispose is called. The user's
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   196
   * DoDispose implementation could call GetObject (which could reorder the array) 
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   197
   * and it could call AggregateObject which would add an object at the end of the array.
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   198
   * So, to be safe, we restart the iteration over the array whenever we call some
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   199
   * user code.
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   200
   */
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   201
restart:
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   202
  uint32_t n = m_aggregates->n;
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   203
  for (uint32_t i = 0; i < n; i++)
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   204
    {
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   205
      Object *current = m_aggregates->buffer[i];
5758
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   206
      if (!current->m_disposed)
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   207
        {
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   208
          current->DoDispose ();
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   209
          current->m_disposed = true;
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   210
          goto restart;
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   211
        }
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   212
    }
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   213
}
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   214
void
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   215
Object::UpdateSortedArray (struct Aggregates *aggregates, uint32_t j) const
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   216
{
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   217
  while (j > 0 && 
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   218
         aggregates->buffer[j]->m_getObjectCount > aggregates->buffer[j-1]->m_getObjectCount)
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   219
    {
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   220
      Object *tmp = aggregates->buffer[j-1];
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   221
      aggregates->buffer[j-1] = aggregates->buffer[j];
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   222
      aggregates->buffer[j] = tmp;
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   223
      j--;
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   224
    }
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   225
}
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   226
void 
2258
666099a753e0 AddInterface -> AggregateObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   227
Object::AggregateObject (Ptr<Object> o)
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   228
{
718
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   229
  NS_ASSERT (!m_disposed);
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   230
  NS_ASSERT (!o->m_disposed);
1534
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   231
  NS_ASSERT (CheckLoose ());
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   232
  NS_ASSERT (o->CheckLoose ());
2902
9c2cfada5e72 make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents: 2717
diff changeset
   233
3397
cad55f67f3fc avoid direct access to Object::m_tid. Use ObjectBase::GetInstanceTypeId instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3394
diff changeset
   234
  if (DoGetObject (o->GetInstanceTypeId ()))
2902
9c2cfada5e72 make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents: 2717
diff changeset
   235
    {
9c2cfada5e72 make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents: 2717
diff changeset
   236
      NS_FATAL_ERROR ("Object::AggregateObject(): "
3397
cad55f67f3fc avoid direct access to Object::m_tid. Use ObjectBase::GetInstanceTypeId instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3394
diff changeset
   237
                      "Multiple aggregation of objects of type " << 
cad55f67f3fc avoid direct access to Object::m_tid. Use ObjectBase::GetInstanceTypeId instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3394
diff changeset
   238
                      o->GetInstanceTypeId ().GetName ());
2902
9c2cfada5e72 make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents: 2717
diff changeset
   239
    }
9c2cfada5e72 make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents: 2717
diff changeset
   240
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   241
  Object *other = PeekPointer (o);
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   242
  // first create the new aggregate buffer.
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   243
  uint32_t total = m_aggregates->n + other->m_aggregates->n;
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   244
  struct Aggregates *aggregates = 
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   245
    (struct Aggregates *)malloc (sizeof(struct Aggregates)+(total-1)*sizeof(Object*));
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   246
  aggregates->n = total;
5758
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   247
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   248
  // copy our buffer to the new buffer
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   249
  memcpy (&aggregates->buffer[0], 
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   250
          &m_aggregates->buffer[0], 
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   251
          m_aggregates->n*sizeof(Object*));
5758
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   252
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   253
  // append the other buffer into the new buffer too
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   254
  for (uint32_t i = 0; i < other->m_aggregates->n; i++)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3871
diff changeset
   255
    {
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   256
      aggregates->buffer[m_aggregates->n+i] = other->m_aggregates->buffer[i];
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   257
      UpdateSortedArray (aggregates, m_aggregates->n + i);
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   258
    }
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   259
5758
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   260
  // keep track of the old aggregate buffers for the iteration
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   261
  // of NotifyNewAggregates
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   262
  struct Aggregates *a = m_aggregates;
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   263
  struct Aggregates *b = other->m_aggregates;
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   264
5758
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   265
  // Then, assign the new aggregation buffer to every object
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   266
  uint32_t n = aggregates->n;
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   267
  for (uint32_t i = 0; i < n; i++)
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   268
    {
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   269
      Object *current = aggregates->buffer[i];
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   270
      current->m_aggregates = aggregates;
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   271
    }
5486
9bf34ba759a3 Optimization: use a shared reference counter instead of a per-object counter in Object::Ref/Unref
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5479
diff changeset
   272
5758
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   273
  // Finally, call NotifyNewAggregate on all the objects aggregates together.
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   274
  // We purposedly use the old aggregate buffers to iterate over the objects
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   275
  // because this allows us to assume that they will not change from under 
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   276
  // our feet, even if our users call AggregateObject from within their
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   277
  // NotifyNewAggregate method.
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   278
  for (uint32_t i = 0; i < a->n; i++)
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   279
    {
5758
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   280
      Object *current = a->buffer[i];
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   281
      current->NotifyNewAggregate ();
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   282
    }
5758
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   283
  for (uint32_t i = 0; i < b->n; i++)
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   284
    {
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   285
      Object *current = b->buffer[i];
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   286
      current->NotifyNewAggregate ();
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   287
    }
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   288
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   289
  // Now that we are done with them, we can free our old aggregate buffers
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   290
  free (a);
bac30d4b6115 Handle recursive calls to GetObject, AggregateObject and Start
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5524
diff changeset
   291
  free (b);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3871
diff changeset
   292
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3871
diff changeset
   293
/**
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3871
diff changeset
   294
 * This function must be implemented in the stack that needs to notify
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3871
diff changeset
   295
 * other stacks connected to the node of their presence in the node.
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3871
diff changeset
   296
 */
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3871
diff changeset
   297
void
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3871
diff changeset
   298
Object::NotifyNewAggregate ()
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3871
diff changeset
   299
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3871
diff changeset
   300
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   301
}
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   302
2937
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
   303
Object::AggregateIterator 
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
   304
Object::GetAggregateIterator (void) const
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
   305
{
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
   306
  return AggregateIterator (this);
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
   307
}
fc048c358357 iterate over aggregated objects dynamically.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2717
diff changeset
   308
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   309
void 
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
   310
Object::SetTypeId (TypeId tid)
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   311
{
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   312
  NS_ASSERT (Check ());
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
   313
  m_tid = tid;
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   314
}
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   315
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   316
void
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   317
Object::DoDispose (void)
713
c3c745a80610 add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 712
diff changeset
   318
{
c3c745a80610 add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 712
diff changeset
   319
  NS_ASSERT (!m_disposed);
c3c745a80610 add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 712
diff changeset
   320
}
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   321
5524
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5490
diff changeset
   322
void
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5490
diff changeset
   323
Object::DoStart (void)
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5490
diff changeset
   324
{
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5490
diff changeset
   325
  NS_ASSERT (!m_started);
efed7493f2c1 Make applications generate traffic within their associated context/node
Guillaume Seguin <guillaume@segu.in>
parents: 5490
diff changeset
   326
}
1336
de5a133ece8a add Object::TraceConnect, TraceDisconnect, and GetTraceResolver methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 732
diff changeset
   327
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   328
bool 
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   329
Object::Check (void) const
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   330
{
5486
9bf34ba759a3 Optimization: use a shared reference counter instead of a per-object counter in Object::Ref/Unref
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5479
diff changeset
   331
  return (GetReferenceCount () > 0);
701
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   332
}
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   333
1534
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   334
/* In some cases, when an event is scheduled against a subclass of
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   335
 * Object, and if no one owns a reference directly to this object, the
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   336
 * object is alive, has a refcount of zero and the method ran when the
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   337
 * event expires runs against the raw pointer which means that we are
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   338
 * manipulating an object with a refcount of zero.  So, instead we
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   339
 * check the aggregate reference count.
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   340
 */
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   341
bool 
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   342
Object::CheckLoose (void) const
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   343
{
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   344
  uint32_t refcount = 0;
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   345
  uint32_t n = m_aggregates->n;
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   346
  for (uint32_t i = 0; i < n; i++)
1534
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   347
    {
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   348
      Object *current = m_aggregates->buffer[i];
5486
9bf34ba759a3 Optimization: use a shared reference counter instead of a per-object counter in Object::Ref/Unref
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5479
diff changeset
   349
      refcount += current->GetReferenceCount ();
1534
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   350
    }
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   351
  return (refcount > 0);
6b7a4e88c422 Make Object::QueryInterface and AddInterface check for the aggregate refcount instead of the object refcount, reason explained in a comment near Object::CheckLoose. Add the same check also to TraceConnect/Disconnect and GetTraceResolver.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   352
}
701
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   353
void
5486
9bf34ba759a3 Optimization: use a shared reference counter instead of a per-object counter in Object::Ref/Unref
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5479
diff changeset
   354
Object::DoDelete (void)
701
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   355
{
5840
c2b3762932e8 get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5758
diff changeset
   356
  // check if we really need to die
c2b3762932e8 get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5758
diff changeset
   357
  for (uint32_t i = 0; i < m_aggregates->n; i++)
c2b3762932e8 get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5758
diff changeset
   358
    {
c2b3762932e8 get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5758
diff changeset
   359
      Object *current = m_aggregates->buffer[i];
c2b3762932e8 get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5758
diff changeset
   360
      if (current->GetReferenceCount () > 0)
c2b3762932e8 get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5758
diff changeset
   361
        {
c2b3762932e8 get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5758
diff changeset
   362
          return;
c2b3762932e8 get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5758
diff changeset
   363
        }
c2b3762932e8 get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5758
diff changeset
   364
    }
c2b3762932e8 get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5758
diff changeset
   365
c2b3762932e8 get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5758
diff changeset
   366
  // Now, we know that we are alone to use this aggregate so, 
c2b3762932e8 get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5758
diff changeset
   367
  // we can dispose and delete everything safely.
c2b3762932e8 get rid of last duplicated reference counting implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5758
diff changeset
   368
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   369
  uint32_t n = m_aggregates->n;
2529
d5f8bee5fcbd ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2523
diff changeset
   370
  // Ensure we are disposed.
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   371
  for (uint32_t i = 0; i < n; i++)
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   372
    {
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   373
      Object *current = m_aggregates->buffer[i];
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   374
      if (!current->m_disposed)
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   375
        {
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   376
          current->DoDispose ();
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   377
        }
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   378
    }
2529
d5f8bee5fcbd ensure that Dispose is invoked at one point.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2523
diff changeset
   379
5490
0883c01e3ed7 delete dead code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5486
diff changeset
   380
  // Now, actually delete all objects
5479
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   381
  struct Aggregates *aggregates = m_aggregates;
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   382
  for (uint32_t i = 0; i < n; i++)
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   383
    {
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   384
      // There is a trick here: each time we call delete below,
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   385
      // the deleted object is removed from the aggregate buffer
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   386
      // in the destructor so, the index of the next element to 
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   387
      // lookup is always zero
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   388
      Object *current = aggregates->buffer[0];
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   389
      delete current;
b1f7a3a87887 Optimize Object::GetObject. Introduce an array of aggregates and sort is by access frequency.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5474
diff changeset
   390
    }
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   391
}
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   392
} // namespace ns3
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   393