use Name everywhere
diff --git a/include/ccnx-closure.h b/include/ccnx-closure.h
index 01358c4..a2c8b7d 100644
--- a/include/ccnx-closure.h
+++ b/include/ccnx-closure.h
@@ -2,6 +2,7 @@
#define CCNX_CLOSURE_H
#include "ccnx-common.h"
+#include "ccnx-name.h"
using namespace std;
@@ -10,7 +11,7 @@
class Closure
{
public:
- typedef boost::function<void (const string &, const Bytes &)> DataCallback;
+ typedef boost::function<void (const Name &, const Bytes &)> DataCallback;
typedef enum
{
@@ -18,7 +19,7 @@
RESULT_REEXPRESS
} TimeoutCallbackReturnValue;
- typedef boost::function<TimeoutCallbackReturnValue (const string &)> TimeoutCallback;
+ typedef boost::function<TimeoutCallbackReturnValue (const Name &)> TimeoutCallback;
Closure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback);
Closure(const Closure &other);
@@ -26,9 +27,9 @@
void decRetry() { m_retry--;}
virtual ~Closure();
virtual void
- runDataCallback(const string &name, const Bytes &content);
+ runDataCallback(const Name &name, const Bytes &content);
virtual TimeoutCallbackReturnValue
- runTimeoutCallback(const string &interest);
+ runTimeoutCallback(const Name &interest);
protected:
int m_retry;
diff --git a/include/ccnx-name.h b/include/ccnx-name.h
index 84c045f..59e34a5 100644
--- a/include/ccnx-name.h
+++ b/include/ccnx-name.h
@@ -5,6 +5,9 @@
namespace Ccnx {
+class CcnxCharbuf;
+typedef boost::shared_ptr<CcnxCharbuf> CcnxCharbufPtr;
+
// This class is mostly used in CcnxWrapper; users should not be directly using this class
// The main purpose of this class to is avoid manually create and destroy charbuf everytime
class CcnxCharbuf
@@ -17,15 +20,16 @@
// expose internal data structure, use with caution!!
ccn_charbuf *
getBuf() { return m_buf; }
+ static CcnxCharbufPtr Null;
protected:
ccn_charbuf *m_buf;
};
-typedef boost::shared_ptr<CcnxCharbuf> CcnxCharbufPtr;
struct NameException:
virtual boost::exception, virtual exception {};
+
class Name
{
public:
@@ -58,8 +62,22 @@
getCompAsString(int index) const;
Name
- getPartialName(int start, int n) const;
+ getPartialName(int start, int n = -1) const;
+ string
+ toString() const;
+
+ Name &
+ operator=(const Name &other);
+
+ bool
+ operator==(const string &str);
+
+ bool
+ operator!=(const string &str);
+
+ friend Name
+ operator+(const Name &n1, const Name &n2);
protected:
vector<Bytes> m_comps;
@@ -68,6 +86,16 @@
ostream&
operator <<(ostream &os, const Name &name);
+bool
+operator ==(const Name &n1, const Name &n2);
+
+bool
+operator !=(const Name &n1, const Name &n2);
+
+bool
+operator <(const Name &n1, const Name &n2);
+
+
struct InterestSelectorException:
virtual boost::exception, virtual exception {};
@@ -117,7 +145,13 @@
publisherPublicKeyDigest(const Bytes &digest) {m_publisherPublicKeyDigest = digest; return *this;}
CcnxCharbufPtr
- toCcnxCharbuf();
+ toCcnxCharbuf() const;
+
+ bool
+ isEmpty() const;
+
+ bool
+ operator==(const Selectors &other);
private:
int m_maxSuffixComps;
diff --git a/include/ccnx-pco.h b/include/ccnx-pco.h
index 829e0cc..72a7289 100644
--- a/include/ccnx-pco.h
+++ b/include/ccnx-pco.h
@@ -3,6 +3,7 @@
#include "ccnx-wrapper.h"
#include "ccnx-common.h"
+#include "ccnx-name.h"
using namespace std;
@@ -21,7 +22,7 @@
Bytes
content() const;
- string
+ Name
name() const;
protected:
diff --git a/include/ccnx-tunnel.h b/include/ccnx-tunnel.h
index 15d5223..732370d 100644
--- a/include/ccnx-tunnel.h
+++ b/include/ccnx-tunnel.h
@@ -5,6 +5,7 @@
#include "ccnx-common.h"
#include "ccnx-wrapper.h"
+#include "ccnx-name.h"
#define _OVERRIDE
#ifdef __GNUC__
@@ -24,8 +25,8 @@
class CcnxTunnel : public CcnxWrapper
{
public:
- typedef multimap<string, InterestCallback> RegisteredInterestTable;
- typedef multimap<string, InterestCallback>::iterator RitIter;
+ typedef multimap<Name, InterestCallback> RegisteredInterestTable;
+ typedef multimap<Name, InterestCallback>::iterator RitIter;
CcnxTunnel();
@@ -33,50 +34,50 @@
// name is topology-independent
virtual int
- publishData(const string &name, const unsigned char *buf, size_t len, int freshness) _OVERRIDE;
+ publishData(const Name &name, const unsigned char *buf, size_t len, int freshness) _OVERRIDE;
int
- publishContentObject(const string &name, const Bytes &contentObject, int freshness);
+ publishContentObject(const Name &name, const Bytes &contentObject, int freshness);
virtual int
- sendInterest (const string &interest, Closure *closure);
+ sendInterest (const Name &interest, Closure *closure, const Selectors &selectors = Selectors());
// prefix is topology-independent
virtual int
- setInterestFilter(const string &prefix, const InterestCallback &interestCallback) _OVERRIDE;
+ setInterestFilter(const Name &prefix, const InterestCallback &interestCallback) _OVERRIDE;
// prefix is topology-independent
// this clears all entries with key equal to prefix
virtual void
- clearInterestFilter(const string &prefix) _OVERRIDE;
+ clearInterestFilter(const Name &prefix) _OVERRIDE;
// subclass should provide translation service from topology-independent name
// to routable name
- virtual string
- queryRoutableName(const string &name) = 0;
+ virtual Name
+ queryRoutableName(const Name &name) = 0;
// subclass should implement the function to store ContentObject with topoloy-independent
// name to the permanent storage; default does nothing
virtual void
- storeContentObject(const string &name, const Bytes &content) {}
+ storeContentObject(const Name &name, const Bytes &content) {}
// should be called when connect to a different network
void
refreshLocalPrefix();
static bool
- isPrefix(const string &prefix, const string &name);
+ isPrefix(const Name &prefix, const Name &name);
void
- handleTunneledInterest(const string &tunneldInterest);
+ handleTunneledInterest(const Name &tunneldInterest);
void
- handleTunneledData(const string &name, const Bytes &tunneledData, const Closure::DataCallback &originalDataCallback);
+ handleTunneledData(const Name &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
- string m_localPrefix;
+ Name m_localPrefix;
RegisteredInterestTable m_rit;
Lock m_ritLock;
};
@@ -84,19 +85,19 @@
class TunnelClosure : public Closure
{
public:
- TunnelClosure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback, CcnxTunnel *tunnel, const string &originalInterest);
+ TunnelClosure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback, CcnxTunnel *tunnel, const Name &originalInterest);
- TunnelClosure(const Closure *closure, CcnxTunnel *tunnel, const string &originalInterest);
+ TunnelClosure(const Closure *closure, CcnxTunnel *tunnel, const Name &originalInterest);
virtual void
- runDataCallback(const string &name, const Bytes &content) _OVERRIDE;
+ runDataCallback(const Name &name, const Bytes &content) _OVERRIDE;
virtual TimeoutCallbackReturnValue
- runTimeoutCallback(const string &interest) _OVERRIDE;
+ runTimeoutCallback(const Name &interest) _OVERRIDE;
private:
CcnxTunnel *m_tunnel;
- string m_originalInterest;
+ Name m_originalInterest;
};
};
diff --git a/include/ccnx-wrapper.h b/include/ccnx-wrapper.h
index 90089e7..77246ce 100644
--- a/include/ccnx-wrapper.h
+++ b/include/ccnx-wrapper.h
@@ -25,35 +25,32 @@
typedef boost::recursive_mutex RecLock;
typedef boost::unique_lock<RecLock> UniqueRecLock;
- typedef boost::function<void (const string &)> InterestCallback;
+ typedef boost::function<void (const Name &)> InterestCallback;
CcnxWrapper();
virtual ~CcnxWrapper();
virtual int
- setInterestFilter (const string &prefix, const InterestCallback &interestCallback);
+ setInterestFilter (const Name &prefix, const InterestCallback &interestCallback);
virtual void
- clearInterestFilter (const string &prefix);
+ clearInterestFilter (const Name &prefix);
virtual int
- sendInterest (const string &interest, Closure *closure);
+ sendInterest (const Name &interest, Closure *closure, const Selectors &selector = Selectors());
virtual int
- publishData (const string &name, const unsigned char *buf, size_t len, int freshness);
+ publishData (const Name &name, const unsigned char *buf, size_t len, int freshness);
int
- publishData (const string &name, const Bytes &content, int freshness);
+ publishData (const Name &name, const Bytes &content, int freshness);
- static string
+ static Name
getLocalPrefix ();
- static string
- extractName(const unsigned char *data, const ccn_indexbuf *comps);
-
protected:
Bytes
- createContentObject(const string &name, const unsigned char *buf, size_t len, int freshness);
+ createContentObject(const Name &name, const unsigned char *buf, size_t len, int freshness);
int
putToCcnd (const Bytes &contentObject);
@@ -92,8 +89,7 @@
boost::thread m_thread;
bool m_running;
bool m_connected;
- map<string, InterestCallback> m_registeredInterests;
- // std::list< std::pair<std::string, InterestCallback> > m_registeredInterests;
+ map<Name, InterestCallback> m_registeredInterests;
};
typedef boost::shared_ptr<CcnxWrapper> CcnxWrapperPtr;