callback scheduler

29 views
Skip to first unread message

abdelwahed berguiga

unread,
Aug 11, 2014, 7:15:24 AM8/11/14
to ns-3-...@googlegroups.com
Dear all,
i have created a callback to a function and i need to schedule this callback on my ns-3 simulation script.

Callback<void, Mac16Address, Mac16Address, uint8_t> m_newNodeCallback;

m_newNodeCallback (hdr.GetSrcAddr() , hdr.GetDstAddr() , 4);

MyRoutingProtocolNotifier::HandleNewNode (Mac16Address from, Mac16Address to, uint8_t att)
{
 .
 ..
 ...
 ....
}


the HandleNewNode function is declared at the src/model directory.
Any one have an idea how to call this callback?

Many Thanks.

pdbarnes

unread,
Aug 13, 2014, 5:57:31 PM8/13/14
to ns-3-...@googlegroups.com

To set the callback, you need a function like Socket::SetSendCallback (), which just does:
120 Socket::SetSendCallback (Callback<void, Ptr<Socket>, uint32_t> sendCb)
121 {
122  NS_LOG_FUNCTION (this << &sendCb);
123  m_sendCb = sendCb;
124 }
Presumably your function would be called SetNewNodeCallback ()

To set HandleNewNode as your callback handler, you invoke your SetNewNodeCallback with a helper:
SetNewNodeCallback (MakeCallback (&MyRoutingProtocolNotifier::HandleNewNode, this);


To invoke the callback, in your code do something like Socket::NotifySend does:
297  if (!m_sendCb.IsNull ())
298  {
299  m_sendCb (this, spaceAvailable);
300  }

On Monday, August 11, 2014 4:15:24 AM UTC-7, abdelwahed berguiga wrote:
Callback<void, Mac16Address, Mac16Address, uint8_t> m_newNodeCallback;

m_newNodeCallback (hdr.GetSrcAddr() , hdr.GetDstAddr() , 4);

MyRoutingProtocolNotifier::HandleNewNode (Mac16Address from, Mac16Address to, uint8_t att)
{}


Reply all
Reply to author
Forward
0 new messages