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

(-)a/src/core/model/attribute.cc (+84 lines)
 Lines 108-112   EmptyAttributeValue::DeserializeFromString (std::string value, Ptr<const Attribu 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   public: 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   private: 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 (+13 lines)
 Lines 115-120   public: 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 240-245   public: Link Here 
240
  typedef void (* Int32Callback) (const int32_t  oldValue, const int32_t  newValue);
240
  typedef void (* Int32Callback) (const int32_t  oldValue, const int32_t  newValue);
241
  typedef void (* Uint32Callback)(const uint32_t oldValue, const uint32_t newValue);
241
  typedef void (* Uint32Callback)(const uint32_t oldValue, const uint32_t newValue);
242
  typedef void (* DoubleCallback)(const double   oldValue, const double   newValue);
242
  typedef void (* DoubleCallback)(const double   oldValue, const double   newValue);
243
  typedef void (* VoidCallback)  ();
243
  /**@}*/
244
  /**@}*/
244
245
245
private:
246
private:
(-)a/src/core/model/type-id.cc (-20 / +62 lines)
 Lines 101-117   public: Link Here 
101
                     uint32_t flags,
101
                     uint32_t flags,
102
                     Ptr<const AttributeValue> initialValue,
102
                     Ptr<const AttributeValue> initialValue,
103
                     Ptr<const AttributeAccessor> spec,
103
                     Ptr<const AttributeAccessor> spec,
104
                     Ptr<const AttributeChecker> checker);
104
                     Ptr<const AttributeChecker> checker,
105
                     TypeId::SupportLevel supportLevel = TypeId::ACTIVE,
106
                     const std::string &supportMsg = "");
105
  void SetAttributeInitialValue(uint16_t uid,
107
  void SetAttributeInitialValue(uint16_t uid,
106
                                uint32_t i,
108
                                uint32_t i,
107
                                Ptr<const AttributeValue> initialValue);
109
                                Ptr<const AttributeValue> initialValue);
108
  uint32_t GetAttributeN (uint16_t uid) const;
110
  uint32_t GetAttributeN (uint16_t uid) const;
109
  struct TypeId::AttributeInformation GetAttribute(uint16_t uid, uint32_t i) const;
111
  struct TypeId::AttributeInformation GetAttribute(uint16_t uid, uint32_t i) const;
110
  void AddTraceSource (uint16_t uid,
112
  void AddTraceSource (uint16_t uid,
111
                       std::string name, 
113
                       std::string name,
112
                       std::string help,
114
                       std::string help,
113
                       Ptr<const TraceSourceAccessor> accessor,
115
                       Ptr<const TraceSourceAccessor> accessor,
114
                       std::string callback);
116
                       std::string callback,
117
                       TypeId::SupportLevel supportLevel = TypeId::ACTIVE,
118
                       const std::string &supportMsg = "");
115
  uint32_t GetTraceSourceN (uint16_t uid) const;
119
  uint32_t GetTraceSourceN (uint16_t uid) const;
116
  struct TypeId::TraceSourceInformation GetTraceSource(uint16_t uid, uint32_t i) const;
120
  struct TypeId::TraceSourceInformation GetTraceSource(uint16_t uid, uint32_t i) const;
117
  bool MustHideFromDocumentation (uint16_t uid) const;
121
  bool MustHideFromDocumentation (uint16_t uid) const;
 Lines 411-427   IidManager::HasAttribute (uint16_t uid, Link Here 
411
}
415
}
412
416
413
void 
417
void 
414
IidManager::AddAttribute (uint16_t uid, 
418
IidManager::AddAttribute (uint16_t uid,
415
                          std::string name,
419
                          std::string name,
416
                          std::string help, 
420
                          std::string help,
417
                          uint32_t flags,
421
                          uint32_t flags,
418
                          Ptr<const AttributeValue> initialValue,
422
                          Ptr<const AttributeValue> initialValue,
419
                          Ptr<const AttributeAccessor> accessor,
423
                          Ptr<const AttributeAccessor> accessor,
420
                          Ptr<const AttributeChecker> checker)
424
                          Ptr<const AttributeChecker> checker,
425
                          TypeId::SupportLevel supportLevel,
426
                          const std::string &supportMsg)
421
{
427
{
422
  NS_LOG_FUNCTION (this << uid << name << help << flags << initialValue << accessor << checker);
428
  NS_LOG_FUNCTION (this << uid << name << help << flags << initialValue << accessor << checker);
423
  struct IidInformation *information = LookupInformation (uid);
429
  struct IidInformation *information = LookupInformation (uid);
424
  if (HasAttribute (uid, name))
430
  if (supportLevel == TypeId::ACTIVE && HasAttribute (uid, name))
425
    {
431
    {
426
      NS_FATAL_ERROR ("Attribute \"" << name << "\" already registered on tid=\"" << 
432
      NS_FATAL_ERROR ("Attribute \"" << name << "\" already registered on tid=\"" << 
427
                      information->name << "\"");
433
                      information->name << "\"");
 Lines 434-439   IidManager::AddAttribute (uint16_t uid, Link Here 
434
  info.originalInitialValue = initialValue;
440
  info.originalInitialValue = initialValue;
435
  info.accessor = accessor;
441
  info.accessor = accessor;
436
  info.checker = checker;
442
  info.checker = checker;
443
  info.supportLevel = supportLevel;
444
  info.supportMsg = supportMsg;
437
  information->attributes.push_back (info);
445
  information->attributes.push_back (info);
438
}
446
}
439
void 
447
void 
 Lines 498-508   IidManager::AddTraceSource (uint16_t uid, Link Here 
498
                            std::string name, 
506
                            std::string name, 
499
                            std::string help,
507
                            std::string help,
500
                            Ptr<const TraceSourceAccessor> accessor,
508
                            Ptr<const TraceSourceAccessor> accessor,
501
                            std::string callback)
509
                            std::string callback,
510
                            TypeId::SupportLevel supportLevel,
511
                            const std::string &supportMsg)
502
{
512
{
503
  NS_LOG_FUNCTION (this << uid << name << help << accessor);
513
  NS_LOG_FUNCTION (this << uid << name << help << accessor);
504
  struct IidInformation *information  = LookupInformation (uid);
514
  struct IidInformation *information  = LookupInformation (uid);
505
  if (HasTraceSource (uid, name))
515
  if (supportLevel == TypeId::ACTIVE && HasTraceSource (uid, name))
506
    {
516
    {
507
      NS_FATAL_ERROR ("Trace source \"" << name << "\" already registered on tid=\"" << 
517
      NS_FATAL_ERROR ("Trace source \"" << name << "\" already registered on tid=\"" << 
508
                      information->name << "\"");
518
                      information->name << "\"");
 Lines 512-517   IidManager::AddTraceSource (uint16_t uid, Link Here 
512
  source.help = help;
522
  source.help = help;
513
  source.accessor = accessor;
523
  source.accessor = accessor;
514
  source.callback = callback;
524
  source.callback = callback;
525
  source.supportLevel = supportLevel;
526
  source.supportMsg = supportMsg;
515
  information->traceSources.push_back (source);
527
  information->traceSources.push_back (source);
516
}
528
}
517
uint32_t 
529
uint32_t 
 Lines 625-630   TypeId::LookupAttributeByName (std::string name, struct TypeId::AttributeInforma Link Here 
625
          struct TypeId::AttributeInformation tmp = tid.GetAttribute(i);
637
          struct TypeId::AttributeInformation tmp = tid.GetAttribute(i);
626
          if (tmp.name == name)
638
          if (tmp.name == name)
627
            {
639
            {
640
              if (tmp.supportLevel == TypeId::DEPRECATED)
641
                {
642
                  NS_LOG_UNCOND ("Attribute " << name << " is deprecated: " <<
643
                                 tmp.supportMsg);
644
                  /** should return true or false? */
645
                }
646
              else if (tmp.supportLevel == TypeId::OBSOLETED)
647
                {
648
                  NS_FATAL_ERROR ("Attribute " << name <<
649
                                  " is obsolete, with no fallback: " << tmp.supportMsg);
650
                }
628
              *info = tmp;
651
              *info = tmp;
629
              return true;
652
              return true;
630
            }
653
            }
 Lines 726-752   TypeId::DoAddConstructor (Callback<ObjectBase *> cb) Link Here 
726
}
749
}
727
750
728
TypeId 
751
TypeId 
729
TypeId::AddAttribute (std::string name,
752
TypeId::AddAttribute (std::string name, std::string help,
730
                      std::string help, 
731
                      const AttributeValue &initialValue,
753
                      const AttributeValue &initialValue,
732
                      Ptr<const AttributeAccessor> accessor,
754
                      Ptr<const AttributeAccessor> accessor,
733
                      Ptr<const AttributeChecker> checker)
755
                      Ptr<const AttributeChecker> checker,
756
                      SupportLevel supportLevel,
757
                      const std::string &supportMsg)
734
{
758
{
735
  NS_LOG_FUNCTION (this << name << help << &initialValue << accessor << checker);
759
  NS_LOG_FUNCTION (this << name << help << &initialValue << accessor << checker);
736
  Singleton<IidManager>::Get ()->AddAttribute (m_tid, name, help, ATTR_SGC, initialValue.Copy (), accessor, checker);
760
  Singleton<IidManager>::Get ()->AddAttribute (m_tid, name, help, ATTR_SGC,
761
                                               initialValue.Copy (), accessor,
762
                                               checker, supportLevel, supportMsg);
737
  return *this;
763
  return *this;
738
}
764
}
739
765
740
TypeId 
766
TypeId 
741
TypeId::AddAttribute (std::string name,
767
TypeId::AddAttribute (std::string name, std::string help, uint32_t flags,
742
                      std::string help, 
743
                      uint32_t flags,
744
                      const AttributeValue &initialValue,
768
                      const AttributeValue &initialValue,
745
                      Ptr<const AttributeAccessor> accessor,
769
                      Ptr<const AttributeAccessor> accessor,
746
                      Ptr<const AttributeChecker> checker)
770
                      Ptr<const AttributeChecker> checker,
771
                      SupportLevel supportLevel,
772
                      const std::string &supportMsg)
747
{
773
{
748
  NS_LOG_FUNCTION (this << name << help << flags << &initialValue << accessor << checker);
774
  NS_LOG_FUNCTION (this << name << help << flags << &initialValue << accessor << checker);
749
  Singleton<IidManager>::Get ()->AddAttribute (m_tid, name, help, flags, initialValue.Copy (), accessor, checker);
775
  Singleton<IidManager>::Get ()->AddAttribute (m_tid, name, help, flags,
776
                                               initialValue.Copy (), accessor,
777
                                               checker, supportLevel, supportMsg);
750
  return *this;
778
  return *this;
751
}
779
}
752
780
 Lines 822-831   TypeId Link Here 
822
TypeId::AddTraceSource (std::string name,
850
TypeId::AddTraceSource (std::string name,
823
                        std::string help,
851
                        std::string help,
824
                        Ptr<const TraceSourceAccessor> accessor,
852
                        Ptr<const TraceSourceAccessor> accessor,
825
                        std::string callback)
853
                        std::string callback, SupportLevel supportLevel,
854
                        const std::string &supportMsg)
826
{
855
{
827
  NS_LOG_FUNCTION (this << name << help << accessor);
856
  NS_LOG_FUNCTION (this << name << help << accessor);
828
  Singleton<IidManager>::Get ()->AddTraceSource (m_tid, name, help, accessor, callback);
857
  Singleton<IidManager>::Get ()->AddTraceSource (m_tid, name, help, accessor,
858
                                                 callback, supportLevel,
859
                                                 supportMsg);
829
  return *this;
860
  return *this;
830
}
861
}
831
862
 Lines 851-856   TypeId::LookupTraceSourceByName (std::string name) const Link Here 
851
          struct TypeId::TraceSourceInformation info = tid.GetTraceSource (i);
882
          struct TypeId::TraceSourceInformation info = tid.GetTraceSource (i);
852
          if (info.name == name)
883
          if (info.name == name)
853
            {
884
            {
885
              if (info.supportLevel == TypeId::DEPRECATED)
886
                {
887
                  NS_LOG_UNCOND ("TraceSource " << name << " is deprecated: " <<
888
                                 info.supportMsg);
889
                }
890
              else  if (info.supportLevel == TypeId::OBSOLETED)
891
                {
892
                  NS_FATAL_ERROR ("TraceSource " << name <<
893
                                  " is obsolete, with no fallback: " << info.supportMsg);
894
                }
895
854
              return info.accessor;
896
              return info.accessor;
855
            }
897
            }
856
        }
898
        }
(-)a/src/core/model/type-id.h (-3 / +36 lines)
 Lines 66-71   public: Link Here 
66
    ATTR_CONSTRUCT = 1<<2, /**< The attribute can be written at construction-time */
66
    ATTR_CONSTRUCT = 1<<2, /**< The attribute can be written at construction-time */
67
    ATTR_SGC = ATTR_GET | ATTR_SET | ATTR_CONSTRUCT, /**< The attribute can be read, and written at any time */
67
    ATTR_SGC = ATTR_GET | ATTR_SET | ATTR_CONSTRUCT, /**< The attribute can be read, and written at any time */
68
  };
68
  };
69
  /**
70
   * \brief The level of deprecation of attribute or trace sources
71
   */
72
  enum SupportLevel
73
  {
74
    ACTIVE,      //!< Attribute or trace source is currently used
75
    DEPRECATED,  //!< Attribute or trace source is deprecated; user is warned
76
    OBSOLETED    //!< Attribute or trace source is not used anymore; simulation fails
77
  };
69
  struct AttributeInformation {
78
  struct AttributeInformation {
70
    std::string name;
79
    std::string name;
71
    std::string help;
80
    std::string help;
 Lines 74-85   public: Link Here 
74
    Ptr<const AttributeValue> initialValue;
83
    Ptr<const AttributeValue> initialValue;
75
    Ptr<const AttributeAccessor> accessor;
84
    Ptr<const AttributeAccessor> accessor;
76
    Ptr<const AttributeChecker> checker;
85
    Ptr<const AttributeChecker> checker;
86
    TypeId::SupportLevel supportLevel;
87
    std::string supportMsg;
77
  };
88
  };
78
  struct TraceSourceInformation {
89
  struct TraceSourceInformation {
79
    std::string name;
90
    std::string name;
80
    std::string help;
91
    std::string help;
81
    std::string callback;
92
    std::string callback;
82
    Ptr<const TraceSourceAccessor> accessor;
93
    Ptr<const TraceSourceAccessor> accessor;
94
    TypeId::SupportLevel supportLevel;
95
    std::string supportMsg;
83
  };
96
  };
84
97
85
  /**
98
  /**
 Lines 285-290   public: Link Here 
285
   * \param initialValue the initial value for this attribute.
298
   * \param initialValue the initial value for this attribute.
286
   * \param accessor an instance of the associated AttributeAccessor subclass.
299
   * \param accessor an instance of the associated AttributeAccessor subclass.
287
   * \param checker an instance of the associated AttributeChecker subclass.
300
   * \param checker an instance of the associated AttributeChecker subclass.
301
   * \param supportLevel deprecation status of the attribute
302
   * \param supportMsg in case of deprecation, the message should indicate how
303
   *        to refactor user code to the current facilities. The name of the
304
   *        deprecated Attribute is already printed.
288
   * \returns this TypeId instance
305
   * \returns this TypeId instance
289
   *
306
   *
290
   * Record in this TypeId the fact that a new attribute exists.
307
   * Record in this TypeId the fact that a new attribute exists.
 Lines 293-299   public: Link Here 
293
                       std::string help, 
310
                       std::string help, 
294
                       const AttributeValue &initialValue,
311
                       const AttributeValue &initialValue,
295
                       Ptr<const AttributeAccessor> accessor,
312
                       Ptr<const AttributeAccessor> accessor,
296
                       Ptr<const AttributeChecker> checker);
313
                       Ptr<const AttributeChecker> checker,
314
                       SupportLevel supportLevel = ACTIVE,
315
                       const std::string &supportMsg = "");
297
316
298
  /**
317
  /**
299
   * \param i the attribute to manipulate
318
   * \param i the attribute to manipulate
 Lines 311-316   public: Link Here 
311
   * \param initialValue the initial value for this attribute.
330
   * \param initialValue the initial value for this attribute.
312
   * \param accessor an instance of the associated AttributeAccessor subclass.
331
   * \param accessor an instance of the associated AttributeAccessor subclass.
313
   * \param checker an instance of the associated AttributeChecker subclass.
332
   * \param checker an instance of the associated AttributeChecker subclass.
333
   * \param supportLevel deprecation status of the attribute
334
   * \param supportMsg if the support level of the Attribute is DEPRECATED or
335
   *                   OBSOLETED, this message should indicate how
336
   *                   to refactor user code to the current facilities. The name
337
   *                   of the deprecated Attribute is already printed.
314
   * \returns this TypeId instance
338
   * \returns this TypeId instance
315
   *
339
   *
316
   * Record in this TypeId the fact that a new attribute exists.
340
   * Record in this TypeId the fact that a new attribute exists.
 Lines 320-326   public: Link Here 
320
                       uint32_t flags,
344
                       uint32_t flags,
321
                       const AttributeValue &initialValue,
345
                       const AttributeValue &initialValue,
322
                       Ptr<const AttributeAccessor> accessor,
346
                       Ptr<const AttributeAccessor> accessor,
323
                       Ptr<const AttributeChecker> checker);
347
                       Ptr<const AttributeChecker> checker,
348
                       SupportLevel supportLevel = ACTIVE,
349
                       const std::string &supportMsg = "");
324
350
325
  /**
351
  /**
326
   * \param name the name of the new trace source
352
   * \param name the name of the new trace source
 Lines 345-356   public: Link Here 
345
   *        used to connect/disconnect sinks to this trace source.
371
   *        used to connect/disconnect sinks to this trace source.
346
   * \param callback fully qualified typedef name for the callback signature.
372
   * \param callback fully qualified typedef name for the callback signature.
347
   *        Generally this should begin with the "ns3::" namespace qualifier.
373
   *        Generally this should begin with the "ns3::" namespace qualifier.
374
   * \param supportLevel deprecation status of the trace source
375
   * \param supportMsg if the support level of the TraceSource is DEPRECATED or
376
   *                   OBSOLETED, this message should indicate how
377
   *                   to refactor user code to the current facilities. The name
378
   *                   of the deprecated TraceSource is already printed.
348
   * \returns this TypeId instance.
379
   * \returns this TypeId instance.
349
   */
380
   */
350
  TypeId AddTraceSource (std::string name,
381
  TypeId AddTraceSource (std::string name,
351
                         std::string help,
382
                         std::string help,
352
                         Ptr<const TraceSourceAccessor> accessor,
383
                         Ptr<const TraceSourceAccessor> accessor,
353
                         std::string callback);
384
                         std::string callback,
385
                         SupportLevel supportLevel = ACTIVE,
386
                         const std::string &supportMsg = "");
354
387
355
  TypeId HideFromDocumentation (void);
388
  TypeId HideFromDocumentation (void);
356
389

Return to bug 2149