src/core/object.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 28 Aug 2007 13:14:43 +0200
changeset 1380 799617173a45
parent 1374 77468496f7e0
child 1383 12f30b7defb4
permissions -rw-r--r--
api doxygen for Object base class
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
#ifndef OBJECT_H
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
    22
#define OBJECT_H
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
#include <stdint.h>
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
#include <string>
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
#include "ptr.h"
1371
bebf690257c9 replace TraceResolver::PrintAvailable with TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1368
diff changeset
    27
#include "trace-resolver.h"
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
namespace ns3 {
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
1340
a8d774560c2b remove const keyword and add a TraceConnect method which takes a TraceContext argument
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1336
diff changeset
    31
class TraceContext;
1336
de5a133ece8a add Object::TraceConnect, TraceDisconnect, and GetTraceResolver methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1330
diff changeset
    32
class CallbackBase;
de5a133ece8a add Object::TraceConnect, TraceDisconnect, and GetTraceResolver methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1330
diff changeset
    33
718
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    34
/**
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    35
 * \brief a unique identifier for an interface.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    36
 *
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    37
 * Instances of this class can be created only through
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    38
 * calls to ns3::MakeInterfaceId.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    39
 *
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    40
 * Note: This class is quite similar to COM's UUIDs.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    41
 */
708
e8cac905d541 port ComponentManager to Object from Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 706
diff changeset
    42
class InterfaceId
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
{
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
public:
718
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    45
  /**
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    46
   * \param name the name of the requested interface
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    47
   * \returns the unique id associated with the requested
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    48
   *          name. 
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    49
   *
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    50
   * This method cannot fail: it will crash if the input 
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    51
   * name is not a valid interface name.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    52
   */
708
e8cac905d541 port ComponentManager to Object from Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 706
diff changeset
    53
  static InterfaceId LookupByName (std::string name);
718
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    54
  /**
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    55
   * \param iid a unique id 
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    56
   * \returns the parent of the requested id, as registered
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    57
   *          by ns3::MakeInterfaceId.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    58
   *
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    59
   * This method cannot fail: it will crash if the input
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    60
   * id is not a valid interface id.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    61
   */
708
e8cac905d541 port ComponentManager to Object from Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 706
diff changeset
    62
  static InterfaceId LookupParent (InterfaceId iid);
1371
bebf690257c9 replace TraceResolver::PrintAvailable with TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1368
diff changeset
    63
bebf690257c9 replace TraceResolver::PrintAvailable with TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1368
diff changeset
    64
  /**
bebf690257c9 replace TraceResolver::PrintAvailable with TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1368
diff changeset
    65
   * \returns the name of this interface.
bebf690257c9 replace TraceResolver::PrintAvailable with TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1368
diff changeset
    66
   */
bebf690257c9 replace TraceResolver::PrintAvailable with TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1368
diff changeset
    67
  std::string GetName (void) const;
708
e8cac905d541 port ComponentManager to Object from Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 706
diff changeset
    68
  ~InterfaceId ();
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
private:
712
0708bee3dbf3 use a 16 bit interface id
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 709
diff changeset
    70
  InterfaceId (uint16_t iid);
708
e8cac905d541 port ComponentManager to Object from Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 706
diff changeset
    71
  friend InterfaceId MakeInterfaceId (std::string name, const InterfaceId &parent);
e8cac905d541 port ComponentManager to Object from Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 706
diff changeset
    72
  friend InterfaceId MakeObjectInterfaceId (void);
e8cac905d541 port ComponentManager to Object from Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 706
diff changeset
    73
  friend bool operator == (const InterfaceId &a, const InterfaceId &b);
e8cac905d541 port ComponentManager to Object from Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 706
diff changeset
    74
  friend bool operator != (const InterfaceId &a, const InterfaceId &b);
712
0708bee3dbf3 use a 16 bit interface id
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 709
diff changeset
    75
  uint16_t m_iid;
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
};
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
718
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    78
/**
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    79
 * \param name of the new InterfaceId to create.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    80
 * \param parent the "parent" of the InterfaceId to create.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    81
 * \returns a new InterfaceId
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    82
 * \relates InterfaceId
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    83
 *
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    84
 * Every InterfaceId is a child of another InterfaceId. The
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    85
 * top-most InterfaceId is Object::iid and its parent is 
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    86
 * itself.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    87
 */
708
e8cac905d541 port ComponentManager to Object from Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 706
diff changeset
    88
InterfaceId
e8cac905d541 port ComponentManager to Object from Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 706
diff changeset
    89
MakeInterfaceId (std::string name, const InterfaceId &parent);
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
718
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    91
/**
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    92
 * \brief a base class which provides memory management and object aggregation
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    93
 *
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    94
 * Note: This base class is quite similar in spirit to IUnknown in COM or
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    95
 * BonoboObject in Bonobo: it provides three main methods: Ref, Unref and
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    96
 * QueryInterface.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
    97
 */
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
    98
class Object
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    99
{
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
public:
708
e8cac905d541 port ComponentManager to Object from Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 706
diff changeset
   101
  static const InterfaceId iid;
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   103
  Object ();
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   104
  virtual ~Object ();
718
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   105
  /**
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   106
   * Increment the reference count. This method should not be called
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   107
   * by user code. Object instances are expected to be used in conjunction
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   108
   * of the Ptr template which would make calling Ref unecessary and 
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   109
   * dangerous.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   110
   */
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   111
  inline void Ref (void) const;
718
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   112
  /**
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   113
   * Decrement the reference count. This method should not be called
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   114
   * by user code. Object instances are expected to be used in conjunction
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   115
   * of the Ptr template which would make calling Ref unecessary and 
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   116
   * dangerous.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   117
   */
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   118
  inline void Unref (void) const;
718
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   119
  /**
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   120
   * \param iid the interface requested
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   121
   * \returns a pointer to the requested interface or zero if it could not be found.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   122
   * 
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   123
   */
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   124
  template <typename T>
709
b5c7825babf3 make QueryInterface const
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 708
diff changeset
   125
  Ptr<T> QueryInterface (InterfaceId iid) const;
718
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   126
  /**
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   127
   * Run the DoDispose methods of this object and all the
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   128
   * objects aggregated to it.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   129
   * After calling this method, the object is expected to be
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   130
   * totally unusable except for the Ref and Unref methods.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   131
   * It is an error to call Dispose twice on the same object 
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   132
   * instance
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   133
   */
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   134
  void Dispose (void);
718
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   135
  /**
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   136
   * \param other another object pointer
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   137
   *
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   138
   * This method aggregates the two objects together: after this
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   139
   * method returns, it becomes possible to call QueryInterface
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   140
   * on one to get the other, and vice-versa. 
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   141
   */
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   142
  void AddInterface (Ptr<Object> other);
1330
d67fce6d56f8 add refcounting to TraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 718
diff changeset
   143
1380
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   144
  /**
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   145
   * \param path the path to match for the callback
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   146
   * \param cb callback to connect
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   147
   *
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   148
   * Connect the input callback to all trace sources which
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   149
   * match the input path.
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   150
   *
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   151
   */
1336
de5a133ece8a add Object::TraceConnect, TraceDisconnect, and GetTraceResolver methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1330
diff changeset
   152
  void TraceConnect (std::string path, const CallbackBase &cb);
1380
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   153
  /**
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   154
   * \param path the path to match for the callback
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   155
   * \param cb callback to disconnect
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   156
   *
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   157
   * Disconnect the input callback from all trace sources which
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   158
   * match the input path.
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   159
   */
1336
de5a133ece8a add Object::TraceConnect, TraceDisconnect, and GetTraceResolver methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1330
diff changeset
   160
  void TraceDisconnect (std::string path, const CallbackBase &cb);
1380
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   161
  /**
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   162
   * \returns the trace resolver associated to this object.
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   163
   *
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   164
   * This method should be rarely called by users.
799617173a45 api doxygen for Object base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1374
diff changeset
   165
   */
1368
e75dc1a2a5fb add TraceResolver::PrintAvailable method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1340
diff changeset
   166
  virtual Ptr<TraceResolver> GetTraceResolver (void);
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   167
protected:
718
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   168
  /**
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   169
   * \param iid an InterfaceId
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   170
   *
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   171
   * Every subclass which defines a new InterfaceId for itself
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   172
   * should register this InterfaceId by calling this method
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   173
   * from its constructor.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   174
   */
708
e8cac905d541 port ComponentManager to Object from Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 706
diff changeset
   175
  void SetInterfaceId (InterfaceId iid);
718
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   176
  /**
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   177
   * This method is called by Object::Dispose.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   178
   * Subclasses are expected to override this method and chain
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   179
   * up to their parent's implementation once they are done.
b32ae2809deb add dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 713
diff changeset
   180
   */
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   181
  virtual void DoDispose (void);
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   182
private:
1371
bebf690257c9 replace TraceResolver::PrintAvailable with TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1368
diff changeset
   183
  friend class InterfaceIdTraceResolver;
709
b5c7825babf3 make QueryInterface const
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 708
diff changeset
   184
  Ptr<Object> DoQueryInterface (InterfaceId iid) const;
1371
bebf690257c9 replace TraceResolver::PrintAvailable with TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1368
diff changeset
   185
  void DoCollectSources (std::string path, const TraceContext &context, 
bebf690257c9 replace TraceResolver::PrintAvailable with TraceResolver::CollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1368
diff changeset
   186
                         TraceResolver::SourceCollection *collection);
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   187
  bool Check (void) const;
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   188
  void MaybeDelete (void) const;
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   189
  mutable uint32_t m_count;
708
e8cac905d541 port ComponentManager to Object from Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 706
diff changeset
   190
  InterfaceId m_iid;
713
c3c745a80610 add a m_disposed field and check it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 712
diff changeset
   191
  bool m_disposed;
1374
77468496f7e0 avoid problems with recursive use of Object::DoCollectSources
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1371
diff changeset
   192
  bool m_collecting;
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   193
  Object *m_next;
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   194
};
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   195
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   196
} // namespace ns3
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   197
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   198
namespace ns3 {
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   199
701
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   200
void
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   201
Object::Ref (void) const
701
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   202
{
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   203
  m_count++;
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   204
}
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   205
void
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   206
Object::Unref (void) const
701
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   207
{
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   208
  NS_ASSERT (Check ());
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   209
  m_count--;
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   210
  if (m_count == 0)
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   211
    {
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   212
      MaybeDelete ();
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   213
    }
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   214
}
aa179c876b22 optimization suggested by gustavo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 699
diff changeset
   215
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   216
template <typename T>
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   217
Ptr<T> 
709
b5c7825babf3 make QueryInterface const
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 708
diff changeset
   218
Object::QueryInterface (InterfaceId iid) const
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   219
{
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   220
  Ptr<Object> found = DoQueryInterface (iid);
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   221
  if (found != 0)
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   222
    {
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   223
      return Ptr<T> (dynamic_cast<T *> (PeekPointer (found)));
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   224
    }
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   225
  return 0;
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   226
}
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   227
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   228
} // namespace ns3
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   229
706
8b0bf4623c9d rename InterfaceObject to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 703
diff changeset
   230
#endif /* OBJECT_H */
699
956a76f5fd56 a replacement for the Interface base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   231