more refactoring. Tunnel finishes
diff --git a/include/ccnx-closure.h b/include/ccnx-closure.h
new file mode 100644
index 0000000..54306d6
--- /dev/null
+++ b/include/ccnx-closure.h
@@ -0,0 +1,41 @@
+#ifndef CCNX_CLOSURE_H
+#define CCNX_CLOSURE_H
+
+#include "ccnx-common.h"
+
+using namespace std;
+
+namespace Ccnx {
+
+class Closure
+{
+public:
+ typedef boost::function<void (const string &, const Bytes &)> DataCallback;
+
+ typedef enum
+ {
+ RESULT_OK,
+ RESULT_REEXPRESS
+ } TimeoutCallbackReturnValue;
+
+ typedef boost::function<TimeoutCallbackReturnValue (const string &)> TimeoutCallback;
+
+ Closure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback);
+ Closure(const Closure &other);
+ int getRetry() {return m_retry;}
+ void decRetry() { m_retry--;}
+ virtual ~Closure();
+ virtual void
+ runDataCallback(const string &name, const Bytes &content);
+ virtual TimeoutCallbackReturnValue
+ runTimeoutCallback(const string &interest);
+
+protected:
+ int m_retry;
+ TimeoutCallback *m_timeoutCallback;
+ DataCallback *m_dataCallback;
+};
+
+} // Ccnx
+
+#endif
diff --git a/include/ccnx-common.h b/include/ccnx-common.h
new file mode 100644
index 0000000..7394c03
--- /dev/null
+++ b/include/ccnx-common.h
@@ -0,0 +1,24 @@
+#ifndef CCNX_COMMON_H
+#define CCNX_COMMON_H
+
+#include <vector>
+#include <boost/shared_ptr.hpp>
+#include <boost/exception/all.hpp>
+#include <boost/function.hpp>
+#include <string>
+#include <sstream>
+#include <map>
+#include <utility>
+
+using namespace std;
+namespace Ccnx {
+typedef vector<unsigned char> Bytes;
+
+void
+readRaw(Bytes &bytes, const unsigned char *src, size_t len);
+
+const unsigned char *
+head(const Bytes &bytes);
+
+} // Ccnx
+#endif // CCNX_COMMON_H
diff --git a/include/ccnx-pco.h b/include/ccnx-pco.h
index 5b48ccf..1357333 100644
--- a/include/ccnx-pco.h
+++ b/include/ccnx-pco.h
@@ -1,9 +1,8 @@
#ifndef CCNX_CONTENT_OBJECT_H
#define CCNX_CONTENT_OBJECT_H
-#include <boost/exception/all.hpp>
-#include <boost/shared_ptr.hpp>
#include "ccnx-wrapper.h"
+#include "ccnx-common.h"
using namespace std;
diff --git a/include/ccnx-tunnel.h b/include/ccnx-tunnel.h
index c17569d..4e1eade 100644
--- a/include/ccnx-tunnel.h
+++ b/include/ccnx-tunnel.h
@@ -1,13 +1,10 @@
#ifndef CCNX_TUNNEL_H
#define CCNX_TUNNEL_H
-#include <string>
-#include <boost/function.hpp>
#include <boost/variant.hpp>
#include <boost/thread/locks.hpp>
-#include <utility>
-#include <map>
+#include "ccnx-common.h"
#include "ccnx-wrapper.h"
#define _OVERRIDE
@@ -40,10 +37,10 @@
// name is topology-independent
virtual int
- publishData(const string &name, const char *buf, size_t len, int freshness) _OVERRIDE;
+ publishData(const string &name, const unsigned char *buf, size_t len, int freshness) _OVERRIDE;
virtual int
- sendInterest (const std::string &interest, const DataCallback &dataCallback, int retry = 0, const TimeoutCallback &timeoutCallback = TimeoutCallback()) _OVERRIDE;
+ sendInterest (const std::string &interest, Closure *closure);
// prefix is topology-independent
@@ -76,7 +73,7 @@
handleTunneledInterest(const string &tunneldInterest);
void
- handleTunneledData(const string &name, const Bytes &tunneledData, const DataCallback &originalDataCallback);
+ handleTunneledData(const string &name, const Bytes &tunneledData, const Closure::DataCallback &originalDataCallback);
protected:
// need a way to update local prefix, perhaps using macports trick, but eventually we need something more portable
@@ -85,15 +82,17 @@
Lock m_ritLock;
};
-class TunnelClosurePass : public ClosurePass
+class TunnelClosure : public Closure
{
public:
- TunnelClosurePass(int retry, const CcnxWrapper::DataCallback &dataCallback, const CcnxWrapper::TimeoutCallback &timeoutCallback, CcnxTunnel *tunnel, const string &originalInterest);
+ TunnelClosure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback, CcnxTunnel *tunnel, const string &originalInterest);
+
+ TunnelClosure(const Closure *closure, CcnxTunnel *tunnel, const string &originalInterest);
virtual void
runDataCallback(const string &name, const Bytes &content) _OVERRIDE;
- virtual CcnxWrapper::TimeoutCallbackReturnValue
+ virtual TimeoutCallbackReturnValue
runTimeoutCallback(const string &interest) _OVERRIDE;
private:
diff --git a/include/ccnx-wrapper.h b/include/ccnx-wrapper.h
index b4a8536..6ee5749 100644
--- a/include/ccnx-wrapper.h
+++ b/include/ccnx-wrapper.h
@@ -10,38 +10,22 @@
#include <ccn/signing.h>
}
-#include <vector>
-#include <boost/exception/all.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/thread/thread.hpp>
-#include <boost/function.hpp>
-#include <string>
-#include <sstream>
-#include <map>
+
+#include "ccnx-common.h"
+#include "ccnx-closure.h"
using namespace std;
namespace Ccnx {
-typedef vector<unsigned char> Bytes;
-
-void
-readRaw(Bytes &bytes, const unsigned char *src, size_t len);
-
struct CcnxOperationException : virtual boost::exception, virtual exception { };
-class CcnxWrapper {
+class CcnxWrapper
+{
public:
- typedef boost::function<void (const string &, const Bytes &)> DataCallback;
typedef boost::function<void (const string &)> InterestCallback;
- typedef enum
- {
- RESULT_OK,
- RESULT_REEXPRESS
- } TimeoutCallbackReturnValue;
- typedef boost::function<TimeoutCallbackReturnValue (const string &)> TimeoutCallback;
-
-public:
CcnxWrapper();
virtual ~CcnxWrapper();
@@ -53,10 +37,10 @@
clearInterestFilter (const string &prefix);
virtual int
- sendInterest (const string &strInterest, const DataCallback &dataCallback, int retry = 0, const TimeoutCallback &timeoutCallback = TimeoutCallback());
+ sendInterest (const string &strInterest, Closure *closure);
virtual int
- publishData (const string &name, const char *buf, size_t len, int freshness);
+ publishData (const string &name, const unsigned char *buf, size_t len, int freshness);
int
publishData (const string &name, const Bytes &content, int freshness);
@@ -69,7 +53,7 @@
protected:
Bytes
- createContentObject(const string &name, const char *buf, size_t len, int freshness);
+ createContentObject(const string &name, const unsigned char *buf, size_t len, int freshness);
int
putToCcnd (const Bytes &contentObject);
@@ -97,8 +81,6 @@
void
ccnLoop ();
- int
- sendInterest (const string &strInterest, void *dataPass);
/// @endcond
protected:
@@ -116,22 +98,6 @@
typedef boost::shared_ptr<CcnxWrapper> CcnxWrapperPtr;
-class ClosurePass
-{
-public:
- ClosurePass(int retry, const CcnxWrapper::DataCallback &dataCallback, const CcnxWrapper::TimeoutCallback &timeoutCallback);
- int getRetry() {return m_retry;}
- void decRetry() { m_retry--;}
- virtual ~ClosurePass();
- virtual void runDataCallback(const string &name, const Bytes &content);
- virtual CcnxWrapper::TimeoutCallbackReturnValue runTimeoutCallback(const string &interest);
-
-protected:
- int m_retry;
- CcnxWrapper::TimeoutCallback *m_timeoutCallback;
- CcnxWrapper::DataCallback *m_dataCallback;
-};
-
} // Ccnx