ndn.cxx: Expressing interests and publishing data use event scheduling, instead of directly calling the callback
Also in this commit is extension, allowing expression of multiple
interests for the same name with different callbacks. For example, if
user expresses two exactly the same interests, when data arrives or
interest times out, callbacks from the individual call will be invoked.
Another small change is that if interest is "collapsed" in ApiFace, it
is not further propagated to the NDN stack.
diff --git a/ndn.cxx/ndn-api-face.cc b/ndn.cxx/ndn-api-face.cc
index 4be4162..4d522fa 100644
--- a/ndn.cxx/ndn-api-face.cc
+++ b/ndn.cxx/ndn-api-face.cc
@@ -107,6 +107,7 @@
}
// Record the callback
+ bool needToActuallyExpressInterest = false;
PendingInterestContainer::iterator entry = m_this->m_pendingInterests.find_exact (interest->GetName ());
if (entry == m_this->m_pendingInterests.end ())
{
@@ -114,10 +115,15 @@
m_this->m_pendingInterests.insert (interest->GetName (), Create <PendingInterestEntry> (interest));
entry = status.first;
+
+ needToActuallyExpressInterest = true;
}
entry->payload ()->AddCallbacks (onData, onTimeout);
- ReceiveInterest (interest);
+ if (needToActuallyExpressInterest)
+ {
+ Simulator::ScheduleNow (&Face::ReceiveInterest, this, interest);
+ }
}
void
@@ -158,12 +164,10 @@
{
NS_LOG_INFO (">> D " << data->GetName ());
- ReceiveData (data);
+ Simulator::ScheduleNow (&Face::ReceiveData, this, data);
}
-
-
///////////////////////////////////////////////
// private stuff
@@ -197,8 +201,7 @@
{
// data has been send out from NDN stack towards the application
NS_LOG_DEBUG ("<< D " << data->GetName ());
-
- NS_LOG_FUNCTION (this << data);
+ // NS_LOG_FUNCTION (this << data);
if (!IsUp ())
{
@@ -213,8 +216,7 @@
while (entry != m_this->m_pendingInterests.end ())
{
- if (!entry->payload ()->m_dataCallback.IsNull ())
- entry->payload ()->m_dataCallback (entry->payload ()->GetInterest (), data);
+ entry->payload ()->ProcessOnData (entry->payload ()->GetInterest (), data);
m_this->m_pendingInterests.erase (entry);
entry = m_this->m_pendingInterests.longest_prefix_match (data->GetName ());