remove sync-data-buffer, use string instead; change ccnx-wrapper
accordingly
diff --git a/model/sync-ccnx-wrapper.cc b/model/sync-ccnx-wrapper.cc
index a7936a3..88c65d9 100644
--- a/model/sync-ccnx-wrapper.cc
+++ b/model/sync-ccnx-wrapper.cc
@@ -108,7 +108,7 @@
}
}
-int CcnxWrapper::publishData(string name, shared_ptr< DataBuffer > dataBuffer, int freshness)
+int CcnxWrapper::publishData(string name, string dataBuffer, int freshness)
{
ccn_charbuf *pname = ccn_charbuf_create();
ccn_charbuf *signed_info = ccn_charbuf_create();
@@ -124,7 +124,7 @@
NULL,
m_keyLoactor);
ccn_encode_ContentObject(content, pname, signed_info,
- dataBuffer->buffer(), dataBuffer->length(),
+ dataBuffer.c_str(), dataBuffer.length(),
NULL, getPrivateKey());
ccn_put(m_handle, content->buf, content->length);
@@ -154,10 +154,16 @@
return CCN_UPCALL_RESULT_OK;
}
- char *comp;
- size_t size;
- ccn_name_comp_get(info->content_ccnb, info->content_comps, info->content_comps->n - 3, (const unsigned char **)&comp, &size);
- f((string)comp);
+ string interest;
+ for (int i = 0; i < info->content_comps->n - 1; i++)
+ {
+ char *comp;
+ size_t size;
+ ccn_name_comp_get(info->content_ccnb, info->content_comps, i, (const unsigned char **)&comp, &size);
+ interest += comp;
+ }
+ f(interest);
+ return CCN_UPCALL_RESULT_OK;
}
static ccn_upcall_res incomingData(
@@ -165,7 +171,7 @@
ccn_upcall_kind kind,
ccn_upcall_info *info)
{
- function<void (shared_ptr<DataBuffer>)> f = *(function<void (shared_ptr<DataBuffer>)> *)selfp->data;
+ function<void (string)> f = *(function<void (string)> *)selfp->data;
switch (kind)
{
@@ -183,15 +189,14 @@
char *pcontent;
size_t len;
ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E], info->pco, (const unsigned char **)&pcontent, &len);
- shared_ptr<DataBuffer> data(new DataBufferImpl((const unsigned char*)pcontent, len));
- f(data);
+ f((string)pcontent);
}
-int CcnxWrapper::sendInterest(string strInterest, function< void (shared_ptr< DataBuffer >) > dataCallback)
+int CcnxWrapper::sendInterest(string strInterest, function<void (string)> dataCallback)
{
ccn_charbuf *pname = ccn_charbuf_create();
ccn_closure *dataClosure = new ccn_closure;
- function<void (shared_ptr< DataBuffer >)> *f = new function<void (shared_ptr< DataBuffer >)>(dataCallback);
+ 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);
@@ -201,7 +206,7 @@
ccn_charbuf_destroy(&pname);
}
-int CcnxWrapper::setInterestFilter(string prefix, function< void (string) > interestCallback)
+int CcnxWrapper::setInterestFilter(string prefix, function<void (string)> interestCallback)
{
ccn_charbuf *pname = ccn_charbuf_create();
ccn_closure *interestClosure = new ccn_closure;
diff --git a/model/sync-ccnx-wrapper.h b/model/sync-ccnx-wrapper.h
index fa1356b..037d2d2 100644
--- a/model/sync-ccnx-wrapper.h
+++ b/model/sync-ccnx-wrapper.h
@@ -36,7 +36,7 @@
#include <boost/thread/thread.hpp>
#include <boost/function.hpp>
#include <string>
-#include "sync-data-buffer.h"
+
/**
* \defgroup sync SYNC protocol
*
@@ -84,8 +84,8 @@
* @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>)> dataCallback);
+ int sendInterest(std::string strInterest, boost::function<void (std::string)>
+ dataCallback);
/**
* @brief set Interest filter (specify what interest you want to receive
@@ -106,8 +106,7 @@
* @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);
+ int publishData(std::string name, std::string dataBuffer, int freshness);
};
diff --git a/model/sync-data-buffer.cc b/model/sync-data-buffer.cc
deleted file mode 100644
index 2680859..0000000
--- a/model/sync-data-buffer.cc
+++ /dev/null
@@ -1,21 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012 University of California, Los Angeles
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
- * 卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
diff --git a/model/sync-data-buffer.h b/model/sync-data-buffer.h
deleted file mode 100644
index 8706188..0000000
--- a/model/sync-data-buffer.h
+++ /dev/null
@@ -1,128 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012 University of California, Los Angeles
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
- * 卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef SYNC_DATA_BUFFER_H
-#define SYNC_DATA_BUFFER_H
-
-#include <tinyxml.h>
-#include <boost/shared_ptr.hpp>
-#include <boost/exception/all.hpp>
-#include "sync-diff-state.h"
-#include "sync-full-state.h"
-
-
-/**
- * \defgroup sync SYNC protocol
- *
- * Implementation of SYNC protocol
- */
-namespace Sync {
-
-/**
- * \ingroup sync
- * @brief DataBuffer Interface to be used by CcnxWrapper and all other data
- * publish/request/processing related functions
- */
-class DataBuffer {
-public:
- virtual ~DataBuffer() = 0;
- virtual size_t length() = 0;
- virtual const unsigned char *buffer() = 0;
- virtual void setBufferAndLength(const unsigned char *buffer, size_t len) =
- 0;
-};
-
-/**
- * \ingroup sync
- * @brief general Data Buffer class, implments DataBuffer interface mainly works for app data
- */
-class DataBufferImpl : public DataBuffer {
-public:
- DataBufferImpl() {m_buffer = NULL; m_len = 0;}
- DataBufferImpl(const unsigned char *buffer, size_t len);
- DataBufferImpl(const DataBuffer *DataBuffer);
- DataBufferImpl &operator=(const DataBuffer *DataBuffer);
-
- /**
- * @brief reset the buffer and len
- */
- virtual void setBufferAndLength(const unsigned char *buffer, size_t len);
- virtual ~DataBufferImpl();
- 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;
- size_t m_len;
-};
-
-
-
-/**
- * \ingroup sync
- * @brief decorator class, wrapper for sync data; converts to and from states
- */
-class SyncDataBuffer : DataBuffer{
-public:
- /**
- * @brief decorates some object that implements DataBuffer interface
- * primary usage here is to decorate AppDataBuffer
- */
- SyncDataBuffer(boost::shared_ptr<DataBuffer> dataBuffer) { m_dataBuffer = dataBuffer;}
- virtual ~SyncDataBuffer(){};
- virtual size_t length() {m_dataBuffer->length();}
- virtual const unsigned char *buffer() {m_dataBuffer->buffer();}
- virtual void setBufferAndLength(const unsigned char *buffer, size_t len)
- {m_dataBuffer->setBufferAndLength(buffer, len); }
-
- /**
- * @brief convert from FullState to SyncDataBuffer
- */
- SyncDataBuffer &operator<<(FullState &fs);
-
- /**
- * @brief convert from DiffState to SyncDataBuffer
- */
- SyncDataBuffer &operator<<(DiffState &ds);
-
- /**
- * @brief convert from SyncDataBuffer to FullState, throws
- * SyncDataBufferConvertException if convert fails
- */
- SyncDataBuffer &operator>>(FullState &fs);
-
- /**
- * @brief convert from SyncDataBuffer to DiffState, throws
- * SyncDataBufferConvertException if convert fails
- */
- SyncDataBuffer &operator>>(DiffState &ds);
-
-private:
- boost::shared_ptr<DataBuffer> m_dataBuffer;
-};
-
-struct SyncDataBufferConvertException : virtual boost::exception {};
-
-} // Sync
-
-#endif // SYNC_DATA_BUFFER_H