Tracing a private attribute

42 views
Skip to first unread message

Amin Dorostanian

unread,
Dec 22, 2015, 3:55:43 AM12/22/15
to ns-3-users
Hi all,

I am trying to trace an atrribute inside YansWifiModel but I can not cast my own object type to ns3 model. Any help would be appreciated.
This is my code:

class MyYansWifiPhy : public YansWifiPhy
{

public:
  static TypeId GetTypeId (void)
  {
    static TypeId tid = TypeId ("MyYansWifiPhy")
      .SetParent<ns3::YansWifiPhy> ()
      .AddConstructor<MyYansWifiPhy> ()
      .AddTraceSource ("ChannelWidth",
                       "Trace channel width.",
                       MakeTraceSourceAccessor (&MyYansWifiPhy::m_channelWidth),
                       "ns3::TracedValueCallback::uint32_t")
    ;
    return tid;
  }

  MyYansWifiPhy () {}
  TracedValue<uint32_t> m_channelWidth;
};

void
ChannelWidthTrace (uint32_t oldValue, uint32_t newValue)
{
  std::cout << "Traced Channel Width " << oldValue << " to " << newValue << std::endl;
}
 And here I want to get my object:
   ObjectPtrContainerValue phy_list ;
    my_channel->GetAttribute("PhyList",phy_list);
    // * First Path
    ns3::Ptr<ns3::Object> tmp_phy_0 = phy_list.Get(0);
    Ptr<MyYansWifiPhy> phy_0 = tmp_phy_0->GetObject<MyYansWifiPhy>();


Thanks in advance,

Amin



Konstantinos

unread,
Dec 22, 2015, 6:20:44 AM12/22/15
to ns-3-users
Hi Amin,

The problem is here 

ns3::Ptr<ns3::Object> tmp_phy_0 = phy_list.Get(0);
Ptr<MyYansWifiPhy> phy_0 = tmp_phy_0->GetObject<MyYansWifiPhy>();

In order to GetObject() A from a class B, you have to have A aggregated to B. 
And that's not the case in you.
What you actually want is a DynamicCast of the Object you get from the phy_list to a MyYansWifiPhy object. 

Regards,
K.

Amin Dorostanian

unread,
Dec 25, 2015, 7:05:07 AM12/25/15
to ns-3-users
Dear Konstantinos,

Thanks for your answer, could you please help me with writing this down casting?  
I tried to solve this with dynamic_cast but it returned 0x0 pointer. 

Thanks in advance,
Reply all
Reply to author
Forward
0 new messages