get rid of publisher and fetcher
modify SyncAppSocket API
modify SyncLogic API
Tweak SeqNo
diff --git a/ccnx/sync-app-socket.cc b/ccnx/sync-app-socket.cc
index 848a6d0..ce65674 100644
--- a/ccnx/sync-app-socket.cc
+++ b/ccnx/sync-app-socket.cc
@@ -28,13 +28,12 @@
namespace Sync
{
-SyncAppSocket::SyncAppSocket (const string &syncPrefix, CcnxWrapper::DataCallback dataCallback)
- : m_appHandle (new CcnxWrapper())
- , m_fetcher (m_appHandle, dataCallback)
- , m_publisher (m_appHandle)
+SyncAppSocket::SyncAppSocket (const string &syncPrefix, NewDataCallback dataCallback, RemoveCallback rmCallback )
+ : m_ccnxHandle (new CcnxWrapper())
+ , m_newDataCallback(dataCallback)
, m_syncLogic (syncPrefix,
- bind (&AppDataFetch::onUpdate, m_fetcher, _1, _2, _3),
- bind (&AppDataFetch::onRemove, m_fetcher, _1))
+ bind(&SyncAppSocket::passCallback, this, _1),
+ rmCallback)
{
}
@@ -42,10 +41,62 @@
{
}
-bool SyncAppSocket::publish (const string &prefix, uint32_t session, const string &dataBuffer, int freshness)
+bool
+SyncAppSocket::publishString (const string &prefix, uint32_t session, const string &dataBuffer, int freshness)
{
- uint32_t sequence = m_publisher.publishData (prefix, session, dataBuffer, freshness);
+ uint32_t sequence = getNextSeq(prefix, session);
+ ostringstream contentNameWithSeqno;
+ contentNameWithSeqno << prefix << "/" << session << "/" << sequence;
+ m_ccnxHandle->publishStringData (contentNameWithSeqno.str (), dataBuffer, freshness);
+
+ SeqNo s(session, sequence + 1);
+ m_sequenceLog[prefix] = s;
+
m_syncLogic.addLocalNames (prefix, session, sequence);
}
+bool
+SyncAppSocket::publishRaw(const std::string &prefix, uint32_t session, const char *buf, size_t len, int freshness)
+{
+ uint32_t sequence = getNextSeq(prefix, session);
+ ostringstream contentNameWithSeqno;
+ contentNameWithSeqno << prefix << "/" << session << "/" << sequence;
+ m_ccnxHandle->publishRawData (contentNameWithSeqno.str (), buf, len, freshness);
+
+ SeqNo s(session, sequence + 1);
+ m_sequenceLog[prefix] = s;
+ m_syncLogic.addLocalNames (prefix, session, sequence);
+}
+
+
+void
+SyncAppSocket::fetchString(const std::string &prefix, const SeqNo &seq, CcnxWrapper::StringDataCallback callback, int retry)
+{
+ ostringstream interestName;
+ interestName << prefix << "/" << seq.getSession() << "/" << seq.getSeq();
+ m_ccnxHandle->sendInterestForString(interestName.str(), callback, retry);
+}
+
+void
+SyncAppSocket::fetchRaw(const std::string &prefix, const SeqNo &seq, CcnxWrapper::RawDataCallback callback, int retry)
+{
+ ostringstream interestName;
+ interestName << prefix << "/" << seq.getSession() << "/" << seq.getSeq();
+ m_ccnxHandle->sendInterest(interestName.str(), callback, retry);
+}
+
+uint32_t
+SyncAppSocket::getNextSeq (const string &prefix, uint32_t session)
+{
+ SequenceLog::iterator i = m_sequenceLog.find (prefix);
+
+ if (i != m_sequenceLog.end ())
+ {
+ SeqNo s = i->second;
+ if (s.getSession() == session)
+ return s.getSeq();
+ }
+ return 0;
+}
+
}