implement sync-app-socket and change appwrapper to logic
diff --git a/model/sync-app-socket.cc b/model/sync-app-socket.cc
index 2680859..8f11c97 100644
--- a/model/sync-app-socket.cc
+++ b/model/sync-app-socket.cc
@@ -19,3 +19,36 @@
  *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
  *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
  */
+
+#include "sync-app-socket.h"
+
+using namespace std;
+using namespace boost;
+
+namespace Sync
+{
+
+SyncAppSocket::SyncAppSocket(string syncPrefix, function<void (string)> dataCallback)
+{
+  m_ccnxHandle.reset(new CcnxWrapper());
+  m_fetcher = new AppDataFetch(m_ccnxHandle, dataCallback);
+  m_publisher = new AppDataPublish(m_ccnxHandle);
+
+  function<void (string, uint32_t, uint32_t)> f(bind(&AppDataFetch::fetch, m_fetcher, _1, _2, _3));
+  m_syncLogic = new SyncLogic(syncPrefix, f, m_ccnxHandle);
+}
+
+SyncAppSocket::~SyncAppSocket()
+{
+  delete m_syncLogic;
+  delete m_fetcher;
+  delete m_publisher;
+}
+
+bool SyncAppSocket::publish(string prefix, string dataBuffer, int freshness)
+{
+  m_publisher->publishData(prefix, dataBuffer, freshness);
+  m_syncLogic->addLocalNames(prefix, m_publisher->getHighestSeq(prefix));
+}
+
+}
\ No newline at end of file
diff --git a/model/sync-app-socket.h b/model/sync-app-socket.h
index 4c86f2d..d94d4db 100644
--- a/model/sync-app-socket.h
+++ b/model/sync-app-socket.h
@@ -22,6 +22,10 @@
 
 #ifndef SYNC_APP_SOCKET_H
 #define SYNC_APP_SOCKET_H
+
+#include "sync-logic.h"
+#include "sync-app-data-fetch.h"
+#include "sync-app-data-publish.h"
 #include <boost/function.hpp>
 
 namespace Sync {
@@ -44,25 +48,26 @@
 	 * @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>)> dataCallback);
+	SyncAppSocket(std::string syncPrefix, boost::function<void (std::string)>
+	dataCallback);
 
 	~SyncAppSocket();
 
 	/**
-	 * @brief publish data from local client and tell SyncAppWrapper to update
+	 * @brief publish data from local client and tell SyncLogic 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);
+	bool publish(std::string prefix, std::string dataBuffer, int freshness);
+
 private:
-	boost::shared_ptr<AppDataFetch> m_fetcher;
-	boost::shared_ptr<AppDataPublish> m_publisher;
-	boost::shared_ptr<SyncAppWrapper> m_syncAppWrapper;
+	AppDataFetch *m_fetcher;
+	AppDataPublish *m_publisher;
+	SyncLogic *m_syncLogic;
+	boost::shared_ptr<CcnxWrapper> m_ccnxHandle;
 };
 
 } // Sync
diff --git a/model/sync-ccnx-wrapper.cc b/model/sync-ccnx-wrapper.cc
index be6f203..741a143 100644
--- a/model/sync-ccnx-wrapper.cc
+++ b/model/sync-ccnx-wrapper.cc
@@ -101,7 +101,7 @@
       int ret = poll(pfds, 1, 100);
       if (ret >= 0)
       {
-	boost::recursive_mutex::scoped_lock lock(m_mutex);
+	recursive_mutex::scoped_lock lock(m_mutex);
 	res = ccn_run(m_handle, 0);
       }
     }
@@ -126,6 +126,7 @@
   ccn_encode_ContentObject(content, pname, signed_info,
 			   dataBuffer.c_str(), dataBuffer.length(),
 			   NULL, getPrivateKey());
+  recursive_mutex::scoped_lock lock(m_mutex);
   ccn_put(m_handle, content->buf, content->length);
 
   ccn_charbuf_destroy(&pname);
@@ -144,7 +145,7 @@
   switch (kind)
   {
     case CCN_UPCALL_FINAL:
-      free(selfp);
+      delete selfp;
       return CCN_UPCALL_RESULT_OK;
 
     case CCN_UPCALL_INTEREST:
@@ -177,7 +178,7 @@
   switch (kind)
   {
     case CCN_UPCALL_FINAL:
-      free(selfp);
+      delete selfp;
       return CCN_UPCALL_RESULT_OK;
 
     case CCN_UPCALL_CONTENT:
@@ -191,6 +192,7 @@
   size_t len;
   ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E], info->pco, (const unsigned char **)&pcontent, &len);
   f((string)pcontent);
+  return CCN_UPCALL_RESULT_OK;
 }
 
 int CcnxWrapper::sendInterest(string strInterest, function<void (string)> dataCallback)
@@ -200,9 +202,10 @@
   function<void (string)> *f = new function<void (string)>(dataCallback);
 
   ccn_name_from_uri(pname, strInterest.c_str());
-  ccn_express_interest(m_handle, pname, dataClosure, NULL);
   dataClosure->data = f;
   dataClosure->p = &incomingData;
+  recursive_mutex::scoped_lock lock(m_mutex);
+  ccn_express_interest(m_handle, pname, dataClosure, NULL);
 
   ccn_charbuf_destroy(&pname);
 }
diff --git a/model/sync-app-wrapper.cc b/model/sync-logic.cc
similarity index 78%
rename from model/sync-app-wrapper.cc
rename to model/sync-logic.cc
index b06de1d..5d6703a 100644
--- a/model/sync-app-wrapper.cc
+++ b/model/sync-logic.cc
@@ -20,7 +20,7 @@
  *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
  */
 
-#include "sync-app-wrapper.h"
+#include "sync-logic.h"
 
 using namespace std;
 using namespace boost;
@@ -28,7 +28,7 @@
 namespace Sync
 {
 
-SyncAppWrapper::SyncAppWrapper(string syncPrefix,
+SyncLogic::SyncLogic(string syncPrefix,
 			       function<void (string, uint32_t, uint32_t)> fetch,
 			       shared_ptr<CcnxWrapper> ccnxHandle)
 {
@@ -37,27 +37,27 @@
   m_ccnxHandle = ccnxHandle;
 }
 
-SyncAppWrapper::~SyncAppWrapper()
+SyncLogic::~SyncLogic()
 {
 
 }
 
-void SyncAppWrapper::processSyncData(string dataBuffer)
+void SyncLogic::processSyncData(string dataBuffer)
 {
 
 }
 
-void SyncAppWrapper::addLocalNames(string prefix, uint32_t seq)
+void SyncLogic::addLocalNames(string prefix, uint32_t seq)
 {
 
 }
 
-void SyncAppWrapper::respondSyncInterest(string interest)
+void SyncLogic::respondSyncInterest(string interest)
 {
 
 }
 
-void SyncAppWrapper::sendSyncInterest()
+void SyncLogic::sendSyncInterest()
 {
 
 }
diff --git a/model/sync-app-wrapper.h b/model/sync-logic.h
similarity index 92%
rename from model/sync-app-wrapper.h
rename to model/sync-logic.h
index 72202ce..6fe589c 100644
--- a/model/sync-app-wrapper.h
+++ b/model/sync-logic.h
@@ -20,8 +20,8 @@
  *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
  */
 
-#ifndef SYNC_APP_WRAPPER_H
-#define SYNC_APP_WRAPPER_H
+#ifndef SYNC_LOGIC_H
+#define SYNC_LOGIC_H
 #include <boost/shared_ptr.hpp>
 #include <boost/function.hpp>
 #include "sync-ccnx-wrapper.h"
@@ -37,7 +37,7 @@
  * @brief A wrapper for SyncApp, which handles ccnx related things (process
  * interests and data)
  */
-class SyncAppWrapper
+class SyncLogic
 {
 public:
 	/**
@@ -46,10 +46,10 @@
 	 * @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 (std::string,
+	SyncLogic(std::string syncPrefix, boost::function<void (std::string,
 	uint32_t, uint32_t)> fetch, boost::shared_ptr<CcnxWrapper> ccnxHandle);
 
-	~SyncAppWrapper();
+	~SyncLogic();
 	/**
 	 * a wrapper for the same func in SyncApp
 	 */