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

(-)a/src/core/model/attribute.cc (+84 lines)
 Lines 108-112    Link Here 
108
  return true;
108
  return true;
109
}
109
}
110
110
111
EmptyAttributeAccessor::EmptyAttributeAccessor () : AttributeAccessor ()
112
{
113
}
114
115
EmptyAttributeAccessor::~EmptyAttributeAccessor ()
116
{
117
}
118
119
bool
120
EmptyAttributeAccessor::Set (ObjectBase * object, const AttributeValue &value) const
121
{
122
  (void) object;
123
  (void) value;
124
  return true;
125
}
126
127
bool
128
EmptyAttributeAccessor::Get (const ObjectBase * object, AttributeValue &attribute) const
129
{
130
  (void) object;
131
  (void) attribute;
132
  return true;
133
}
134
135
bool
136
EmptyAttributeAccessor::HasGetter (void) const
137
{
138
  return false;
139
}
140
141
bool
142
EmptyAttributeAccessor::HasSetter (void) const
143
{
144
  return false;
145
}
146
147
EmptyAttributeChecker::EmptyAttributeChecker () : AttributeChecker ()
148
{
149
}
150
151
EmptyAttributeChecker::~EmptyAttributeChecker ()
152
{
153
}
154
155
bool
156
EmptyAttributeChecker::Check (const AttributeValue &value) const
157
{
158
  (void) value;
159
  return true;
160
}
161
162
std::string
163
EmptyAttributeChecker::GetValueTypeName (void) const
164
{
165
  return "EmptyAttribute";
166
}
167
168
bool
169
EmptyAttributeChecker::HasUnderlyingTypeInformation (void) const
170
{
171
  return false;
172
}
173
174
std::string
175
EmptyAttributeChecker::GetUnderlyingTypeInformation (void) const
176
{
177
  return "";
178
}
179
180
Ptr<AttributeValue>
181
EmptyAttributeChecker::Create (void) const
182
{
183
  static EmptyAttributeValue t;
184
  return Ptr<AttributeValue> (&t, false);
185
}
186
187
bool
188
EmptyAttributeChecker::Copy (const AttributeValue &source, AttributeValue &destination) const
189
{
190
  (void) source;
191
  (void) destination;
192
  return true;
193
}
194
111
195
112
} // namespace ns3
196
} // namespace ns3
(-)a/src/core/model/attribute.h (-2 / +47 lines)
 Lines 222-229    Link Here 
222
   * \return true if copy was successful
222
   * \return true if copy was successful
223
   */
223
   */
224
  virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const = 0;
224
  virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const = 0;
225
226
  
227
};
225
};
228
226
229
/**
227
/**
 Lines 259-264    Link Here 
259
  virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker);
257
  virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker);
260
};
258
};
261
259
260
/**
261
 * \brief An accessor for EmptyAttributeValue
262
 *
263
 * Does nothing, since every EmptyAttributeValue is the same.
264
 */
265
class EmptyAttributeAccessor : public AttributeAccessor
266
{
267
public:
268
  EmptyAttributeAccessor ();
269
  ~EmptyAttributeAccessor ();
270
  virtual bool Set (ObjectBase * object, const AttributeValue &value) const;
271
  virtual bool Get (const ObjectBase * object, AttributeValue &attribute) const;
272
  virtual bool HasGetter (void) const;
273
  virtual bool HasSetter (void) const;
274
};
275
276
static inline Ptr<const AttributeAccessor>
277
MakeEmptyAttributeAccessor ()
278
{
279
  return Ptr<const AttributeAccessor> (new EmptyAttributeAccessor (), false);
280
}
281
282
/**
283
 * \brief A checker for EmptyAttributeValue
284
 *
285
 * Does nothing, since every EmptyAttributeValue does not contain anything and
286
 * is, of course, valid.
287
 */
288
class EmptyAttributeChecker : public AttributeChecker
289
{
290
public:
291
  EmptyAttributeChecker ();
292
  ~EmptyAttributeChecker ();
293
  virtual bool Check (const AttributeValue &value) const;
294
  virtual std::string GetValueTypeName (void) const;
295
  virtual bool HasUnderlyingTypeInformation (void) const;
296
  virtual std::string GetUnderlyingTypeInformation (void) const;
297
  virtual Ptr<AttributeValue> Create (void) const;
298
  virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const;
299
};
300
301
static inline Ptr<AttributeChecker>
302
MakeEmptyAttributeChecker ()
303
{
304
  return Ptr<AttributeChecker> (new EmptyAttributeChecker (), false);
305
}
306
262
} // namespace ns3
307
} // namespace ns3
263
308
264
#endif /* ATTRIBUTE_H */
309
#endif /* ATTRIBUTE_H */
(-)a/src/core/model/trace-source-accessor.h (-1 / +14 lines)
 Lines 107-113    Link Here 
107
 * type implements a statically-polymorphic set of Connect and Disconnect
107
 * type implements a statically-polymorphic set of Connect and Disconnect
108
 * methods and creates a dynamic-polymorphic class to wrap the underlying
108
 * methods and creates a dynamic-polymorphic class to wrap the underlying
109
 * static-polymorphic class.  This functionality is typically provided
109
 * static-polymorphic class.  This functionality is typically provided
110
 * by wrapping an object data member in a TracedCallback.
110
 * by wrapping an object data member in a TracedCallback or TracedValue.
111
 *
111
 *
112
 * \param [in] a The trace source
112
 * \param [in] a The trace source
113
 * \returns The TraceSourceAccessor
113
 * \returns The TraceSourceAccessor
 Lines 115-120    Link Here 
115
template <typename T>
115
template <typename T>
116
Ptr<const TraceSourceAccessor> MakeTraceSourceAccessor (T a);
116
Ptr<const TraceSourceAccessor> MakeTraceSourceAccessor (T a);
117
117
118
/**
119
 * \ingroup tracing
120
 *
121
 * Create an empty TraceSourceAccessor.
122
 *
123
 * \returns The empty TraceSourceAccessor (runtime exception if used)
124
 */
125
static inline
126
Ptr<const TraceSourceAccessor> MakeEmptyTraceSourceAccessor ()
127
{
128
  return Ptr<const TraceSourceAccessor> (0);
129
}
130
118
} // namespace ns3
131
} // namespace ns3
119
132
120
133
(-)a/src/core/model/traced-value.h (+1 lines)
 Lines 87-92    Link Here 
87
  typedef void (* Int32) (int32_t  oldValue, int32_t  newValue);
87
  typedef void (* Int32) (int32_t  oldValue, int32_t  newValue);
88
  typedef void (* Uint32)(uint32_t oldValue, uint32_t newValue);
88
  typedef void (* Uint32)(uint32_t oldValue, uint32_t newValue);
89
  typedef void (* Double)(double   oldValue, double   newValue);
89
  typedef void (* Double)(double   oldValue, double   newValue);
90
  typedef void (* Void)  (void);
90
  /**@}*/
91
  /**@}*/
91
}  // namespace TracedValueCallback
92
}  // namespace TracedValueCallback
92
93
(-)a/src/core/model/type-id.cc (-20 / +95 lines)
 Lines 195-200    Link Here 
195
   *             subclass.
195
   *             subclass.
196
   * \param [in] checker An instance of the associated AttributeChecker
196
   * \param [in] checker An instance of the associated AttributeChecker
197
   *             subclass.
197
   *             subclass.
198
   * \param [in] supportLevel The support/deprecation status for this attribute.
199
   * \param [in] supportMsg Upgrade hint if this attribute is no longer supported.
198
   */
200
   */
199
  void AddAttribute (uint16_t uid,
201
  void AddAttribute (uint16_t uid,
200
                     std::string name,
202
                     std::string name,
 Lines 202-208    Link Here 
202
                     uint32_t flags,
204
                     uint32_t flags,
203
                     Ptr<const AttributeValue> initialValue,
205
                     Ptr<const AttributeValue> initialValue,
204
                     Ptr<const AttributeAccessor> accessor,
206
                     Ptr<const AttributeAccessor> accessor,
205
                     Ptr<const AttributeChecker> checker);
207
                     Ptr<const AttributeChecker> checker,
208
                     TypeId::SupportLevel supportLevel = TypeId::SUPPORTED,
209
                     const std::string &supportMsg = "");
206
  /**
210
  /**
207
   * Set the initial value of an Attribute.
211
   * Set the initial value of an Attribute.
208
   * \param [in] uid The id.
212
   * \param [in] uid The id.
 Lines 236-248    Link Here 
236
   * \param [in] callback Fully qualified typedef name for the callback
240
   * \param [in] callback Fully qualified typedef name for the callback
237
   *             signature.  Generally this should begin with the
241
   *             signature.  Generally this should begin with the
238
   *             "ns3::" namespace qualifier.  
242
   *             "ns3::" namespace qualifier.  
243
   * \param [in] supportLevel The support/deprecation status for this attribute.
244
   * \param [in] supportMsg Upgrade hint if this attribute is no longer supported.
239
   * \returns This TypeId instance.
245
   * \returns This TypeId instance.
240
   */
246
   */
241
  void AddTraceSource (uint16_t uid,
247
  void AddTraceSource (uint16_t uid,
242
                       std::string name, 
248
                       std::string name, 
243
                       std::string help,
249
                       std::string help,
244
                       Ptr<const TraceSourceAccessor> accessor,
250
                       Ptr<const TraceSourceAccessor> accessor,
245
                       std::string callback);
251
                       std::string callback,
252
                       TypeId::SupportLevel supportLevel = TypeId::SUPPORTED,
253
                       const std::string &supportMsg = "");
246
  /**
254
  /**
247
   * Get the number of Trace sources.
255
   * Get the number of Trace sources.
248
   * \param [in] uid The id.
256
   * \param [in] uid The id.
 Lines 307-312    Link Here 
307
    std::vector<struct TypeId::AttributeInformation> attributes;
315
    std::vector<struct TypeId::AttributeInformation> attributes;
308
    /** The container of TraceSources. */
316
    /** The container of TraceSources. */
309
    std::vector<struct TypeId::TraceSourceInformation> traceSources;
317
    std::vector<struct TypeId::TraceSourceInformation> traceSources;
318
    /** Support level/deprecation. */
319
    TypeId::SupportLevel supportLevel;
320
    /** Support message. */
321
    std::string supportMsg;
310
  };
322
  };
311
  /** Iterator type. */
323
  /** Iterator type. */
312
  typedef std::vector<struct IidInformation>::const_iterator Iterator;
324
  typedef std::vector<struct IidInformation>::const_iterator Iterator;
 Lines 617-631    Link Here 
617
}
629
}
618
630
619
void 
631
void 
620
IidManager::AddAttribute (uint16_t uid, 
632
IidManager::AddAttribute (uint16_t uid,
621
                          std::string name,
633
                          std::string name,
622
                          std::string help, 
634
                          std::string help,
623
                          uint32_t flags,
635
                          uint32_t flags,
624
                          Ptr<const AttributeValue> initialValue,
636
                          Ptr<const AttributeValue> initialValue,
625
                          Ptr<const AttributeAccessor> accessor,
637
                          Ptr<const AttributeAccessor> accessor,
626
                          Ptr<const AttributeChecker> checker)
638
                          Ptr<const AttributeChecker> checker,
639
                          TypeId::SupportLevel supportLevel,
640
                          const std::string &supportMsg)
627
{
641
{
628
  NS_LOG_FUNCTION (this << uid << name << help << flags << initialValue << accessor << checker);
642
  NS_LOG_FUNCTION (IID << uid << name << help << flags
643
                   << initialValue << accessor << checker
644
                   << supportLevel << supportMsg);
629
  struct IidInformation *information = LookupInformation (uid);
645
  struct IidInformation *information = LookupInformation (uid);
630
  if (HasAttribute (uid, name))
646
  if (HasAttribute (uid, name))
631
    {
647
    {
 Lines 640-645    Link Here 
640
  info.originalInitialValue = initialValue;
656
  info.originalInitialValue = initialValue;
641
  info.accessor = accessor;
657
  info.accessor = accessor;
642
  info.checker = checker;
658
  info.checker = checker;
659
  info.supportLevel = supportLevel;
660
  info.supportMsg = supportMsg;
643
  information->attributes.push_back (info);
661
  information->attributes.push_back (info);
644
  NS_LOG_LOGIC (IIDL << information->attributes.size () - 1);
662
  NS_LOG_LOGIC (IIDL << information->attributes.size () - 1);
645
}
663
}
 Lines 711-719    Link Here 
711
                            std::string name, 
729
                            std::string name, 
712
                            std::string help,
730
                            std::string help,
713
                            Ptr<const TraceSourceAccessor> accessor,
731
                            Ptr<const TraceSourceAccessor> accessor,
714
                            std::string callback)
732
                            std::string callback,
733
                            TypeId::SupportLevel supportLevel,
734
                            const std::string &supportMsg)
715
{
735
{
716
  NS_LOG_FUNCTION (this << uid << name << help << accessor);
736
  NS_LOG_FUNCTION (IID << uid << name << help
737
                   << accessor << callback
738
                   << supportLevel << supportMsg);
717
  struct IidInformation *information  = LookupInformation (uid);
739
  struct IidInformation *information  = LookupInformation (uid);
718
  if (HasTraceSource (uid, name))
740
  if (HasTraceSource (uid, name))
719
    {
741
    {
 Lines 725-730    Link Here 
725
  source.help = help;
747
  source.help = help;
726
  source.accessor = accessor;
748
  source.accessor = accessor;
727
  source.callback = callback;
749
  source.callback = callback;
750
  source.supportLevel = supportLevel;
751
  source.supportMsg = supportMsg;
728
  information->traceSources.push_back (source);
752
  information->traceSources.push_back (source);
729
  NS_LOG_LOGIC (IIDL << information->traceSources.size () - 1);
753
  NS_LOG_LOGIC (IIDL << information->traceSources.size () - 1);
730
}
754
}
 Lines 845-852    Link Here 
845
          struct TypeId::AttributeInformation tmp = tid.GetAttribute(i);
869
          struct TypeId::AttributeInformation tmp = tid.GetAttribute(i);
846
          if (tmp.name == name)
870
          if (tmp.name == name)
847
            {
871
            {
848
              *info = tmp;
872
              if (tmp.supportLevel == TypeId::SUPPORTED)
849
              return true;
873
                {
874
                  *info = tmp;
875
                  return true;
876
                }
877
              else if (tmp.supportLevel == TypeId::DEPRECATED)
878
                {
879
                  NS_LOG_UNCOND ("Attribute '" << name << "' is deprecated: "
880
                                 << tmp.supportMsg);
881
                  *info = tmp;
882
                  return true;
883
                }
884
              else if (tmp.supportLevel == TypeId::OBSOLETE)
885
                {
886
                  NS_FATAL_ERROR ("Attribute '" << name
887
                                  << "' is obsolete, with no fallback: "
888
                                  << tmp.supportMsg);
889
                }
850
            }
890
            }
851
        }
891
        }
852
      nextTid = tid.GetParent ();
892
      nextTid = tid.GetParent ();
 Lines 950-959    Link Here 
950
                      std::string help, 
990
                      std::string help, 
951
                      const AttributeValue &initialValue,
991
                      const AttributeValue &initialValue,
952
                      Ptr<const AttributeAccessor> accessor,
992
                      Ptr<const AttributeAccessor> accessor,
953
                      Ptr<const AttributeChecker> checker)
993
                      Ptr<const AttributeChecker> checker,
994
                      SupportLevel supportLevel,
995
                      const std::string &supportMsg)
954
{
996
{
955
  NS_LOG_FUNCTION (this << name << help << &initialValue << accessor << checker);
997
  NS_LOG_FUNCTION (this << name << help
956
  IidManager::Get ()->AddAttribute (m_tid, name, help, ATTR_SGC, initialValue.Copy (), accessor, checker);
998
                   << &initialValue << accessor << checker
999
                   << supportLevel << supportMsg);
1000
  IidManager::Get ()->AddAttribute (m_tid, name, help, ATTR_SGC,
1001
                                    initialValue.Copy (), accessor, checker,
1002
                                    supportLevel, supportMsg);
957
  return *this;
1003
  return *this;
958
}
1004
}
959
1005
 Lines 963-972    Link Here 
963
                      uint32_t flags,
1009
                      uint32_t flags,
964
                      const AttributeValue &initialValue,
1010
                      const AttributeValue &initialValue,
965
                      Ptr<const AttributeAccessor> accessor,
1011
                      Ptr<const AttributeAccessor> accessor,
966
                      Ptr<const AttributeChecker> checker)
1012
                      Ptr<const AttributeChecker> checker,
1013
                      SupportLevel supportLevel,
1014
                      const std::string &supportMsg)
967
{
1015
{
968
  NS_LOG_FUNCTION (this << name << help << flags << &initialValue << accessor << checker);
1016
  NS_LOG_FUNCTION (this << name << help << flags
969
  IidManager::Get ()->AddAttribute (m_tid, name, help, flags, initialValue.Copy (), accessor, checker);
1017
                   << &initialValue << accessor << checker
1018
                   << supportLevel << supportMsg);
1019
  IidManager::Get ()->AddAttribute (m_tid, name, help, flags,
1020
                                    initialValue.Copy (), accessor, checker,
1021
                                    supportLevel, supportMsg);
970
  return *this;
1022
  return *this;
971
}
1023
}
972
1024
 Lines 1042-1051    Link Here 
1042
TypeId::AddTraceSource (std::string name,
1094
TypeId::AddTraceSource (std::string name,
1043
                        std::string help,
1095
                        std::string help,
1044
                        Ptr<const TraceSourceAccessor> accessor,
1096
                        Ptr<const TraceSourceAccessor> accessor,
1045
                        std::string callback)
1097
                        std::string callback,
1098
                        SupportLevel supportLevel,
1099
                        const std::string &supportMsg)
1046
{
1100
{
1047
  NS_LOG_FUNCTION (this << name << help << accessor);
1101
  NS_LOG_FUNCTION (this << name << help
1048
  IidManager::Get ()->AddTraceSource (m_tid, name, help, accessor, callback);
1102
                   << accessor << callback
1103
                   << supportLevel << supportMsg);
1104
  IidManager::Get ()->AddTraceSource (m_tid, name, help,
1105
                                      accessor, callback,
1106
                                      supportLevel, supportMsg);
1049
  return *this;
1107
  return *this;
1050
}
1108
}
1051
1109
 Lines 1071-1077    Link Here 
1071
          struct TypeId::TraceSourceInformation tmp = tid.GetTraceSource (i);
1129
          struct TypeId::TraceSourceInformation tmp = tid.GetTraceSource (i);
1072
          if (tmp.name == name)
1130
          if (tmp.name == name)
1073
            {
1131
            {
1074
              return info.accessor;
1132
              if (tmp.supportLevel == TypeId::SUPPORTED)
1133
                {
1134
                  *info = tmp;
1135
                  return tmp.accessor;
1136
                }
1137
              else if (tmp.supportLevel == TypeId::DEPRECATED)
1138
                {
1139
                  NS_LOG_UNCOND ("TraceSource '" << name << "' is deprecated: "
1140
                                 << tmp.supportMsg);
1141
                  *info = tmp;
1142
                  return tmp.accessor;
1143
                }
1144
              else  if (tmp.supportLevel == TypeId::OBSOLETE)
1145
                {
1146
                  NS_FATAL_ERROR ("TraceSource '" << name
1147
                                  << "' is obsolete, with no fallback: "
1148
                                  << tmp.supportMsg);
1149
                }
1075
            }
1150
            }
1076
        }
1151
        }
1077
      nextTid = tid.GetParent ();
1152
      nextTid = tid.GetParent ();
(-)a/src/core/model/type-id.h (-3 / +50 lines)
 Lines 65-70    Link Here 
65
    ATTR_CONSTRUCT = 1<<2, /**< The attribute can be written at construction-time */
65
    ATTR_CONSTRUCT = 1<<2, /**< The attribute can be written at construction-time */
66
    ATTR_SGC = ATTR_GET | ATTR_SET | ATTR_CONSTRUCT, /**< The attribute can be read, and written at any time */
66
    ATTR_SGC = ATTR_GET | ATTR_SET | ATTR_CONSTRUCT, /**< The attribute can be read, and written at any time */
67
  };
67
  };
68
  /** The level of support or deprecation for attributes or trace sources. */
69
  enum SupportLevel
70
  {
71
    SUPPORTED,   /**< Attribute or trace source is currently used. */
72
    DEPRECATED,  /**< Attribute or trace source is deprecated; user is warned. */
73
    OBSOLETE     /**< Attribute or trace source is not used anymore; simulation fails. */
74
  };
68
  /** Attribute implementation. */
75
  /** Attribute implementation. */
69
  struct AttributeInformation {
76
  struct AttributeInformation {
70
    /** Attribute name. */
77
    /** Attribute name. */
 Lines 81-86    Link Here 
81
    Ptr<const AttributeAccessor> accessor;
88
    Ptr<const AttributeAccessor> accessor;
82
    /** Checker object. */
89
    /** Checker object. */
83
    Ptr<const AttributeChecker> checker;
90
    Ptr<const AttributeChecker> checker;
91
    /** Support level/deprecation. */
92
    TypeId::SupportLevel supportLevel;
93
    /** Support message. */
94
    std::string supportMsg;
84
  };
95
  };
85
  /** TraceSource implementation. */
96
  /** TraceSource implementation. */
86
  struct TraceSourceInformation {
97
  struct TraceSourceInformation {
 Lines 92-97    Link Here 
92
    std::string callback;
103
    std::string callback;
93
    /** Trace accessor. */
104
    /** Trace accessor. */
94
    Ptr<const TraceSourceAccessor> accessor;
105
    Ptr<const TraceSourceAccessor> accessor;
106
    /** Support level/deprecation. */
107
    TypeId::SupportLevel supportLevel;
108
    /** Support message. */
109
    std::string supportMsg;
95
  };
110
  };
96
111
97
  /** Type of hash values. */
112
  /** Type of hash values. */
 Lines 349-361    Link Here 
349
   *             subclass.
364
   *             subclass.
350
   * \param [in] checker An instance of the associated AttributeChecker
365
   * \param [in] checker An instance of the associated AttributeChecker
351
   *             subclass.
366
   *             subclass.
367
   * \param [in] supportLevel Support/deprecation status of the attribute.
368
   * \param [in] supportMsg Upgrade hint if this attribute is no longer
369
   *             supported.  If the attribute is \c DEPRECATED the attribute
370
   *             behavior still exists, but user code should be updated
371
   *             following guidance in the hint..
372
   *             If the attribute is \c OBSOLETE, the hint should indicate
373
   *             which class the attribute functional has been moved to,
374
   *             or that the functionality is no longer supported.
375
   *             See \file type-id-test-case.cc for examples.
352
   * \returns This TypeId instance
376
   * \returns This TypeId instance
353
   */
377
   */
354
  TypeId AddAttribute (std::string name,
378
  TypeId AddAttribute (std::string name,
355
                       std::string help, 
379
                       std::string help, 
356
                       const AttributeValue &initialValue,
380
                       const AttributeValue &initialValue,
357
                       Ptr<const AttributeAccessor> accessor,
381
                       Ptr<const AttributeAccessor> accessor,
358
                       Ptr<const AttributeChecker> checker);
382
                       Ptr<const AttributeChecker> checker,
383
                       SupportLevel supportLevel = SUPPORTED,
384
                       const std::string &supportMsg = "");
359
385
360
  /**
386
  /**
361
   * Set the initial value of an Attribute.
387
   * Set the initial value of an Attribute.
 Lines 379-384    Link Here 
379
   *             subclass.
405
   *             subclass.
380
   * \param [in] checker An instance of the associated AttributeChecker
406
   * \param [in] checker An instance of the associated AttributeChecker
381
   *             subclass.
407
   *             subclass.
408
   * \param [in] supportLevel Support/deprecation status of the attribute.
409
   * \param [in] supportMsg Upgrade hint if this attribute is no longer
410
   *             supported.  If the attribute is \c DEPRECATED the attribute
411
   *             behavior still exists, but user code should be updated
412
   *             following guidance in the hint..
413
   *             If the attribute is \c OBSOLETE, the hint should indicate
414
   *             which class the attribute functional has been moved to,
415
   *             or that the functionality is no longer supported.
382
   * \returns This TypeId instance
416
   * \returns This TypeId instance
383
   */
417
   */
384
  TypeId AddAttribute (std::string name,
418
  TypeId AddAttribute (std::string name,
 Lines 386-392    Link Here 
386
                       uint32_t flags,
420
                       uint32_t flags,
387
                       const AttributeValue &initialValue,
421
                       const AttributeValue &initialValue,
388
                       Ptr<const AttributeAccessor> accessor,
422
                       Ptr<const AttributeAccessor> accessor,
389
                       Ptr<const AttributeChecker> checker);
423
                       Ptr<const AttributeChecker> checker,
424
                       SupportLevel supportLevel = SUPPORTED,
425
                       const std::string &supportMsg = "");
390
426
391
  /**
427
  /**
392
   * Record a new TraceSource.
428
   * Record a new TraceSource.
 Lines 415-426    Link Here 
415
   * \param [in] callback Fully qualified typedef name for the callback
451
   * \param [in] callback Fully qualified typedef name for the callback
416
   *             signature.  Generally this should begin with the
452
   *             signature.  Generally this should begin with the
417
   *             "ns3::" namespace qualifier.
453
   *             "ns3::" namespace qualifier.
454
   * \param [in] supportLevel Support/deprecation status of the attribute.
455
   * \param [in] supportMsg Upgrade hint if this attribute is no longer
456
   *             supported.  If the attribute is \c DEPRECATED the attribute
457
   *             behavior still exists, but user code should be updated
458
   *             following guidance in the hint..
459
   *             If the attribute is \c OBSOLETE, the hint should indicate
460
   *             which class the attribute functional has been moved to,
461
   *             or that the functionality is no longer supported.
462
   *             See \file type-id-test-case.cc for examples.
418
   * \returns This TypeId instance.
463
   * \returns This TypeId instance.
419
   */
464
   */
420
  TypeId AddTraceSource (std::string name,
465
  TypeId AddTraceSource (std::string name,
421
                         std::string help,
466
                         std::string help,
422
                         Ptr<const TraceSourceAccessor> accessor,
467
                         Ptr<const TraceSourceAccessor> accessor,
423
                         std::string callback);
468
                         std::string callback,
469
                         SupportLevel supportLevel = SUPPORTED,
470
                         const std::string &supportMsg = "");
424
471
425
  /**
472
  /**
426
   * Hide this TypeId from documentation.
473
   * Hide this TypeId from documentation.
(-)a/src/core/test/type-id-test-suite.cc (+138 lines)
 Lines 22-27    Link Here 
22
#include <iomanip>
22
#include <iomanip>
23
#include <ctime>
23
#include <ctime>
24
24
25
#include "ns3/integer.h"
26
#include "ns3/double.h"
27
#include "ns3/object.h"
28
#include "ns3/traced-value.h"
25
#include "ns3/type-id.h"
29
#include "ns3/type-id.h"
26
#include "ns3/test.h"
30
#include "ns3/test.h"
27
#include "ns3/log.h"
31
#include "ns3/log.h"
 Lines 186-192    Link Here 
186
   */
190
   */
187
  
191
  
188
}
192
}
193
194
195
//----------------------------
196
//
197
// Deprecated Attribute test
198
199
class DeprecatedAttribute : public Object
200
{
201
private:
202
  // float m_obsAttr;  // this is obsolete, no trivial forwarding
203
  // int m_oldAttr;  // this has become m_attr
204
  int m_attr;
205
206
  // TracedValue<int> m_obsTrace;  // this is obsolete, no trivial forwarding
207
  // TracedValue<double> m_oldTrace;  // this has become m_trace
208
  TracedValue<double> m_trace;
209
210
public:
211
212
  virtual ~DeprecatedAttribute () { };
213
214
  // Register a type with a deprecated Attribute and TraceSource
215
  static TypeId GetTypeId (void)
216
  {
217
    static TypeId tid = TypeId ("DeprecatedAttribute")
218
      .SetParent<Object> ()
219
      
220
      // The new attribute
221
      .AddAttribute ("attribute",
222
                     "the Attribute",
223
                     IntegerValue (1),
224
                     MakeIntegerAccessor (&DeprecatedAttribute::m_attr),
225
                     MakeIntegerChecker<int> ())
226
      // The old deprecated attribute
227
      .AddAttribute ("oldAttribute",
228
                     "the old attribute",
229
                     IntegerValue (1),
230
                     MakeIntegerAccessor (&DeprecatedAttribute::m_attr),
231
                     MakeIntegerChecker<int> (),
232
                     TypeId::DEPRECATED,
233
                     "use 'attribute' instead")
234
      // Obsolete attribute, as an example
235
      .AddAttribute ("obsoleteAttribute",
236
                     "the obsolete attribute",
237
                     EmptyAttributeValue (),
238
                     MakeEmptyAttributeAccessor (),
239
                     MakeEmptyAttributeChecker (),
240
                     TypeId::OBSOLETE,
241
                     "refactor to use 'attribute'")
242
243
      // The new trace source
244
      .AddTraceSource ("trace",
245
                       "the TraceSource",
246
                       MakeTraceSourceAccessor (&DeprecatedAttribute::m_trace),
247
                       "ns3::TracedValueCallback::Double")
248
      // The old trace source
249
      .AddTraceSource ("oldTrace",
250
                       "the old trace source",
251
                       MakeTraceSourceAccessor (&DeprecatedAttribute::m_trace),
252
                       "ns3::TracedValueCallback::Double",
253
                       TypeId::DEPRECATED,
254
                       "use 'trace' instead")
255
      // Obsolete trace source, as an example
256
      .AddTraceSource ("obsoleteTraceSource",
257
                       "the obsolete trace source",
258
                       MakeEmptyTraceSourceAccessor (),
259
                       "ns3::TracedValueCallback::Void",
260
                       TypeId::OBSOLETE,
261
                       "refactor to use 'trace'");
262
    
263
    return tid;
264
  }
265
266
};
267
268
269
class DeprecatedAttributeTestCase : public TestCase
270
{
271
public:
272
  DeprecatedAttributeTestCase ();
273
  virtual ~DeprecatedAttributeTestCase ();
274
private:
275
  virtual void DoRun (void);
276
277
};
278
279
DeprecatedAttributeTestCase::DeprecatedAttributeTestCase ()
280
  : TestCase ("Check deprecated Attributes and TraceSources")
281
{
282
}
283
284
DeprecatedAttributeTestCase::~DeprecatedAttributeTestCase ()
285
{
286
}
287
288
void
289
DeprecatedAttributeTestCase::DoRun (void)
290
{
291
  cerr << suite << endl;
292
  cerr << suite << GetName () << endl;
293
294
  TypeId tid = DeprecatedAttribute::GetTypeId ();
295
  cerr << suite << "DeprecatedAttribute TypeId: " << tid.GetUid () << endl;
189
  
296
  
297
  //  Try the lookups
298
  struct TypeId::AttributeInformation ainfo;
299
  NS_TEST_ASSERT_MSG_EQ (tid.LookupAttributeByName ("attribute", &ainfo), true,
300
                      "lookup new attribute");
301
  cerr << suite << "lookup new attribute:"
302
       << (ainfo.supportLevel == TypeId::SUPPORTED ? "supported" : "error")
303
       << endl;
304
305
  NS_TEST_ASSERT_MSG_EQ (tid.LookupAttributeByName ("oldAttribute", &ainfo), true,
306
                      "lookup old attribute");
307
  cerr << suite << "lookup old attribute:"
308
       << (ainfo.supportLevel == TypeId::DEPRECATED ? "deprecated" : "error")
309
       << endl;
310
311
312
  struct TypeId::TraceSourceInformation tinfo;
313
  Ptr<const TraceSourceAccessor> acc;
314
  acc = tid.LookupTraceSourceByName ("trace", &tinfo);
315
  NS_TEST_ASSERT_MSG_NE (acc, 0, "lookup new trace source");
316
  cerr << suite << "lookup new trace source:"
317
       << (tinfo.supportLevel == TypeId::SUPPORTED ? "supported" : "error")
318
       << endl;
319
320
  acc = tid.LookupTraceSourceByName ("oldTrace", &tinfo);
321
  NS_TEST_ASSERT_MSG_NE (acc, 0, "lookup old trace source");
322
  cerr << suite << "lookup old trace source:"
323
       << (tinfo.supportLevel == TypeId::DEPRECATED ? "deprecated" : "error")
324
       << endl;
325
}
326
190
  
327
  
191
//----------------------------
328
//----------------------------
192
//
329
//
 Lines 298-303    Link Here 
298
  // as chained.
435
  // as chained.
299
  AddTestCase (new UniqueTypeIdTestCase, QUICK);
436
  AddTestCase (new UniqueTypeIdTestCase, QUICK);
300
  AddTestCase (new CollisionTestCase, QUICK);
437
  AddTestCase (new CollisionTestCase, QUICK);
438
  AddTestCase (new DeprecatedAttributeTestCase, QUICK);
301
}
439
}
302
440
303
static TypeIdTestSuite g_TypeIdTestSuite;  
441
static TypeIdTestSuite g_TypeIdTestSuite;  

Return to bug 2149