hack to avoid using vector in callback for python binding
diff --git a/include/sync-logic.h b/include/sync-logic.h
index 7108054..7daede2 100644
--- a/include/sync-logic.h
+++ b/include/sync-logic.h
@@ -62,6 +62,7 @@
* @brief A wrapper for SyncApp, which handles ccnx related things (process
* interests and data)
*/
+
class SyncLogic
#ifdef NS3_MODULE
: public ns3::Application
@@ -71,6 +72,7 @@
//typedef boost::function< void ( const std::string &/*prefix*/, const SeqNo &/*newSeq*/, const SeqNo &/*oldSeq*/ ) > LogicUpdateCallback;
typedef boost::function< void (const std::vector<MissingDataInfo> & ) > LogicUpdateCallback;
typedef boost::function< void ( const std::string &/*prefix*/ ) > LogicRemoveCallback;
+ typedef boost::function< void (const std::string &)> LogicPerBranchCallback;
/**
* @brief Constructor
@@ -84,6 +86,9 @@
LogicUpdateCallback onUpdate,
LogicRemoveCallback onRemove);
+ SyncLogic (const std::string &syncPrefix,
+ LogicPerBranchCallback onUpdateBranch);
+
~SyncLogic ();
/**
@@ -179,6 +184,8 @@
std::string m_syncPrefix;
LogicUpdateCallback m_onUpdate;
LogicRemoveCallback m_onRemove;
+ LogicPerBranchCallback m_onUpdateBranch;
+ bool m_perBranch;
CcnxWrapperPtr m_ccnxHandle;
Scheduler m_scheduler;
diff --git a/model/sync-logic.cc b/model/sync-logic.cc
index 234f059..a060b0f 100644
--- a/model/sync-logic.cc
+++ b/model/sync-logic.cc
@@ -64,6 +64,7 @@
, m_syncInterestTable (TIME_SECONDS (m_syncInterestReexpress))
, m_syncPrefix (syncPrefix)
, m_onUpdate (onUpdate)
+ , m_perBranch (false)
, m_onRemove (onRemove)
, m_ccnxHandle(CcnxWrapper::Create ())
, m_recoveryRetransmissionInterval (m_defaultRecoveryRetransmitInterval)
@@ -88,6 +89,36 @@
#endif
}
+SyncLogic::SyncLogic (const std::string &syncPrefix,
+ LogicPerBranchCallback onUpdateBranch)
+ : m_state (new FullState)
+ , m_syncInterestTable (TIME_SECONDS (m_syncInterestReexpress))
+ , m_syncPrefix (syncPrefix)
+ , m_onUpdateBranch (onUpdateBranch)
+ , m_perBranch(true)
+ , m_ccnxHandle(CcnxWrapper::Create ())
+ , m_recoveryRetransmissionInterval (m_defaultRecoveryRetransmitInterval)
+#ifndef NS3_MODULE
+ , m_randomGenerator (static_cast<unsigned int> (std::time (0)))
+ , m_rangeUniformRandom (m_randomGenerator, uniform_int<> (200,1000))
+ , m_reexpressionJitter (m_randomGenerator, uniform_int<> (100,500))
+#else
+ , m_rangeUniformRandom (200,1000)
+ , m_reexpressionJitter (10,500)
+#endif
+{
+#ifndef NS3_MODULE
+ // In NS3 module these functions are moved to StartApplication method
+
+ m_ccnxHandle->setInterestFilter (m_syncPrefix,
+ bind (&SyncLogic::respondSyncInterest, this, _1));
+
+ m_scheduler.schedule (TIME_SECONDS (0), // no need to add jitter
+ bind (&SyncLogic::sendSyncInterest, this),
+ REEXPRESSING_INTEREST);
+#endif
+}
+
SyncLogic::~SyncLogic ()
{
m_ccnxHandle->clearInterestFilter (m_syncPrefix);
@@ -309,7 +340,6 @@
if (inserted || updated)
{
diffLog->update (info, seq);
- //m_onUpdate (info->toString (), seq, oldSeq);
if (!oldSeq.isValid())
{
oldSeq = SeqNo(seq.getSession(), 0);
@@ -322,7 +352,16 @@
if (info->toString() != forwarderPrefix)
{
MissingDataInfo mdi = {info->toString(), oldSeq, seq};
- v.push_back(mdi);
+ if (m_perBranch)
+ {
+ ostringstream interestName;
+ interestName << mdi.prefix << "/" << mdi.high.getSession() << "/" << mdi.high.getSeq();
+ m_onUpdateBranch(interestName.str());
+ }
+ else
+ {
+ v.push_back(mdi);
+ }
}
}
}
@@ -331,7 +370,10 @@
if (m_state->remove (info))
{
diffLog->remove (info);
- m_onRemove (info->toString ());
+ if (!m_perBranch)
+ {
+ m_onRemove (info->toString ());
+ }
}
}
else
@@ -341,7 +383,10 @@
if (!v.empty())
{
- m_onUpdate(v);
+ if (!m_perBranch)
+ {
+ m_onUpdate(v);
+ }
}
insertToDiffLog (diffLog);