add doxygen comments
diff --git a/model/sync-app-data-fetch.h b/model/sync-app-data-fetch.h
index 1bba3a6..3816e4e 100644
--- a/model/sync-app-data-fetch.h
+++ b/model/sync-app-data-fetch.h
@@ -36,10 +36,22 @@
class AppDataFetch
{
public:
+ /**
+ * @param dataCallback the callback function to process data
+ */
AppDataFetch(boost::function<void (boost::shared_ptr<DataBuffer>)>
dataCallback);
+
void setDataCallback(boost::function<void (boost::shared_ptr<DataBuffer>)>
dataCallback) {m_dataCallback = dataCallback;}
+
+ /**
+ * @breif fetch data for a certain name prefix
+ *
+ * @param prefix the prefix for the data
+ * @param startSeq the start of sequence number range (inclusive)
+ * @param endSeq the end of sequence number range (inclusive)
+ */
void fetch(string prefix, long startSeq, long endSeq);
private:
diff --git a/model/sync-app-data-publish.h b/model/sync-app-data-publish.h
index 3859153..162abf5 100644
--- a/model/sync-app-data-publish.h
+++ b/model/sync-app-data-publish.h
@@ -34,19 +34,47 @@
/**
* \ingroup sync
- * @brief publishes application data and keeps track of most recently published
- * data
+ * @brief publishes application data using incrementing sequence number (for
+ * each sequence namber and keeps track of most recently published data for
+ * each name prefix
*/
class AppDataPublish
{
public:
- std::pair<std::string, boost::shared_ptr<const DataBuffer> > getRecentData();
+ AppDataPublish();
+ ~AppDataPublish() {};
+
+ /**
+ * @brief get the name (including sequence number) and the content
+ * (unencoded, just XML stanza) of the most recent published data
+ *
+ * @param prefix the name prefix to look for
+ * @return the pair of name and content
+ */
+ std::pair<std::string, boost::shared_ptr<const DataBuffer> >
+ getRecentData(std::string prefix);
+
+ /**
+ * brief get the most recent sequence number for a name prefix
+ */
+ long getHighestSeq(std:string prefix);
+
+ /**
+ * @brief publish data for a name prefix, updates the corresponding
+ * sequence number and recent data
+ *
+ * @param name data prefix
+ * @param dataBuffer the data itself
+ * @param freshness the freshness for the data object
+ * @return whether the publish succeeded
+ */
bool publishData(std::string name, boost::shared_ptr<DataBufer> dataBuffer,
int freshness);
private:
- boost::shared_ptr<CcnxWrapper> ccnxHandle;
- std::pair<std::string, boost::shared_ptr<DataBuffer> > recentData;
+ boost::unordered_map<string, long> m_sequenceLog;
+ boost::shared_ptr<CcnxWrapper> m_ccnxHandle;
+ std::pair<std::string, boost::shared_ptr<DataBuffer> > m_recentData;
};
} // Sync
diff --git a/model/sync-app-socket.h b/model/sync-app-socket.h
index 5e44617..e4b6133 100644
--- a/model/sync-app-socket.h
+++ b/model/sync-app-socket.h
@@ -33,11 +33,32 @@
class SyncAppSocket
{
public:
+ /**
+ * @brief the constructor for SyncAppSocket; the parameter syncPrefix
+ * should be passed to the constructor of m_syncAppWrapper; the other
+ * parameter should be passed to the constructor of m_fetcher; furthermore,
+ * the fetch function of m_fetcher should be a second paramter passed to
+ * the constructor of m_syncAppWrapper, so that m_syncAppWrapper can tell
+ * m_fetcher to fetch the actual app data after it learns the names
+ *
+ * @param syncPrefix the name prefix for Sync Interest
+ * @param dataCallback the callback to process data
+ */
SyncAppSocket(std::string syncPrefix, boost::function<void
- (boost::shared_ptr<DataBuffer>)>);
+ (boost::shared_ptr<DataBuffer>)> dataCallback);
+
~SyncAppSocket();
- bool publishData(std::string prefix, boost::shared_ptr<DataBuffer>
- dataBuffer);
+
+ /**
+ * @brief publish data from local client and tell SyncAppWrapper to update
+ * the sync tree by adding the local names
+ *
+ * @param prefix the name prefix for the data
+ * @param dataBuffer the data itself
+ * @param freshness the freshness time for the data (in seconds)
+ */
+ bool publish(std::string prefix, boost::shared_ptr<DataBuffer>
+ dataBuffer, int freshness);
private:
boost::shared_ptr<AppDataFetch> m_fetcher;
boost::shared_ptr<AppDataPublish> m_publisher;
diff --git a/model/sync-app-wrapper.h b/model/sync-app-wrapper.h
index 97137ac..e9490e7 100644
--- a/model/sync-app-wrapper.h
+++ b/model/sync-app-wrapper.h
@@ -40,15 +40,32 @@
class SyncAppWrapper
{
public:
+ /**
+ * @brief constructor for this class;
+ * @param syncPrefix the name prefix to use for the Sync Interest
+ * @param fetch the fetch function, which will be called to actually fetch
+ * the app data when new remote names are learned
+ */
SyncAppWrapper(std::string syncPrefix, boost::function<void (string, long,
long)> fetch);
+
~SyncAppWrapper();
/**
* a wrapper for the same func in SyncApp
*/
void addLocalNames(std::string prefix, long seq);
+
+ /**
+ * @brief respond to the Sync Interest; a lot of logic needs to go in here
+ * @param interest the Sync Interest in string format
+ */
void respondSyncInterest(std::string interest);
- void processSyncData(boost::shared_ptr<DataBuffer> databuffer);
+
+ /**
+ * @brief process the fetched sync data
+ * @param dataBuffer the sync data
+ */
+ void processSyncData(boost::shared_ptr<DataBuffer> dataBuffer);
private:
sendSyncInterest();
diff --git a/model/sync-ccnx-wrapper.h b/model/sync-ccnx-wrapper.h
index eaa86cf..4153606 100644
--- a/model/sync-ccnx-wrapper.h
+++ b/model/sync-ccnx-wrapper.h
@@ -31,7 +31,8 @@
#include <ccn/bloom.h>
}
-#include <boost/thread.hpp>
+#include <boost/thread/recursive_mutex.hpp>
+#include <boost/thread/thread.hpp>
#include <boost/shared_ptr.hpp>
#include <string>
#include "sync-data-buffer.h"
@@ -52,7 +53,8 @@
ccn* m_handle;
ccn_keystore *m_keyStore;
ccn_charbuf *m_keyLoactor;
- boost::mutex m_mutex;
+ // to lock, use "boost::recursive_mutex::scoped_lock scoped_lock(mutex);
+ boost::recursive_mutex m_mutex;
boost::shared_ptr<boos::thread> m_thread;
private:
@@ -65,19 +67,43 @@
public:
-
+ /**
+ * @brief initialize the wrapper; a lot of things needs to be done. 1) init
+ * keystore 2) init keylocator 3) start a thread to hold a loop of ccn_run
+ *
+ */
CcnxWrapper();
~CcnxWrapper();
+
/**
- * @brief send Interest
+ * @brief send Interest; need to grab lock m_mutex first
*
* @param strInterest the Interest name
- * @param callback the callback function to deal with the returned data
+ * @param dataCallback the callback function to deal with the returned data
+ * @return the return code of ccn_express_interest
*/
int sendInterest(std::string strInterest, boost::function<void
- (boost::shared_ptr<DataBuffer>)> processData);
+ (boost::shared_ptr<DataBuffer>)> dataCallback);
+
+ /**
+ * @brief set Interest filter (specify what interest you want to receive
+ *
+ * @param prefix the prefix of Interest
+ * @param interestCallback the callback function to deal with the returned data
+ * @return the return code of ccn_set_interest_filter
+ */
int sendInterestFilter(std::string prefix, boost::function<void (std::string)>
- processInterest);
+ interestCallback);
+
+ /**
+ * @brief publish data and put it to local ccn content store; need to grab
+ * lock m_mutex first
+ *
+ * @param name the name for the data object
+ * @param dataBuffer the data to be published
+ * @param freshness the freshness time for the data object
+ * @return code generated by ccnx library calls, >0 if success
+ */
int publishData(std::string name, boost::shared_ptr<DataBuffer> dataBuffer,
int freshness);
diff --git a/model/sync-data-buffer.h b/model/sync-data-buffer.h
index 269b379..4b6fe3e 100644
--- a/model/sync-data-buffer.h
+++ b/model/sync-data-buffer.h
@@ -38,7 +38,8 @@
/**
* \ingroup sync
- * @brief DataBuffer Interface
+ * @brief DataBuffer Interface to be used by CcnxWrapper and all other data
+ * publish/request/processing related functions
*/
class DataBuffer {
public:
@@ -59,10 +60,15 @@
AppDataBuffer(const unsigned char *buffer, size_t len);
AppDataBuffer(const DataBuffer *DataBuffer);
AppDataBuffer &operator=(const DataBuffer *DataBuffer);
+
+ /**
+ * @brief reset the buffer and len
+ */
virtual void setBufferAndLength(const unsigned char *buffer, size_t len);
- virtual ~DataBuffer();
- virtual size_t length() {return len;}
- virtual const unsigned char *buffer() { return const_cast<const unsigned char *> (buffer); }
+ virtual ~AppDataBuffer();
+ virtual size_t length() {return m_len;}
+ virtual const unsigned char *buffer() { return const_cast<const unsigned
+ char *> (m_buffer); }
private:
unsigned char *m_buffer;
@@ -77,6 +83,10 @@
*/
class SyncDataBuffer : DataBuffer{
public:
+ /**
+ * @brief decorates some object that implements DataBuffer interface
+ * primary usage here is to decorate AppDataBuffer
+ */
SyncDataBuffer(DataBuffer *dataBuffer) { m_dataBuffer = dataBuffer;}
virtual ~SyncDataBuffer(){};
virtual size_t length() {m_dataBuffer->length();}