separate selectors
diff --git a/include/ccnx-name.h b/include/ccnx-name.h
index 8b8be4a..5f5a5c0 100644
--- a/include/ccnx-name.h
+++ b/include/ccnx-name.h
@@ -132,73 +132,6 @@
operator <(const Name &n1, const Name &n2);
-struct InterestSelectorException:
- virtual boost::exception, virtual exception {};
-
-class Selectors
-{
-public:
- Selectors();
- Selectors(const Selectors &other);
- ~Selectors(){};
-
- typedef enum
- {
- AOK_CS = 0x1,
- AOK_NEW = 0x2,
- AOK_DEFAULT = 0x3, // (AOK_CS | AOK_NEW)
- AOK_STALE = 0x4,
- AOK_EXPIRE = 0x10
- } AOK;
-
- typedef enum
- {
- LEFT = 0,
- RIGHT = 1,
- DEFAULT = 2
- } CHILD_SELECTOR;
-
- inline Selectors &
- maxSuffixComps(int maxSCs) {m_maxSuffixComps = maxSCs; return *this;}
-
- inline Selectors &
- minSuffixComps(int minSCs) {m_minSuffixComps = minSCs; return *this;}
-
- inline Selectors &
- answerOriginKind(AOK kind) {m_answerOriginKind = kind; return *this;}
-
- inline Selectors &
- interestLifetime(int lifetime) {m_interestLifetime = lifetime; return *this;}
-
- inline Selectors &
- scope(int scope) {m_scope = scope; return *this;}
-
- inline Selectors &
- childSelector(CHILD_SELECTOR child) {m_childSelector = child; return *this;}
-
- // this has no effect now
- inline Selectors &
- publisherPublicKeyDigest(const Bytes &digest) {m_publisherPublicKeyDigest = digest; return *this;}
-
- CcnxCharbufPtr
- toCcnxCharbuf() const;
-
- bool
- isEmpty() const;
-
- bool
- operator==(const Selectors &other);
-
-private:
- int m_maxSuffixComps;
- int m_minSuffixComps;
- AOK m_answerOriginKind;
- double m_interestLifetime;
- int m_scope;
- CHILD_SELECTOR m_childSelector;
- // not used now
- Bytes m_publisherPublicKeyDigest;
-};
} // Ccnx
#endif
diff --git a/include/ccnx-selectors.h b/include/ccnx-selectors.h
new file mode 100644
index 0000000..1275217
--- /dev/null
+++ b/include/ccnx-selectors.h
@@ -0,0 +1,99 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012-2013 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>
+ * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+#ifndef CCNX_SELECTORS_H
+#define CCNX_SELECTORS_H
+
+#include "ccnx-common.h"
+#include "ccnx-name.h"
+
+namespace Ccnx {
+
+struct InterestSelectorException:
+ virtual boost::exception, virtual exception {};
+
+class Selectors
+{
+public:
+ Selectors();
+ Selectors(const Selectors &other);
+ ~Selectors(){};
+
+ typedef enum
+ {
+ AOK_CS = 0x1,
+ AOK_NEW = 0x2,
+ AOK_DEFAULT = 0x3, // (AOK_CS | AOK_NEW)
+ AOK_STALE = 0x4,
+ AOK_EXPIRE = 0x10
+ } AOK;
+
+ typedef enum
+ {
+ LEFT = 0,
+ RIGHT = 1,
+ DEFAULT = 2
+ } CHILD_SELECTOR;
+
+ inline Selectors &
+ maxSuffixComps(int maxSCs) {m_maxSuffixComps = maxSCs; return *this;}
+
+ inline Selectors &
+ minSuffixComps(int minSCs) {m_minSuffixComps = minSCs; return *this;}
+
+ inline Selectors &
+ answerOriginKind(AOK kind) {m_answerOriginKind = kind; return *this;}
+
+ inline Selectors &
+ interestLifetime(int lifetime) {m_interestLifetime = lifetime; return *this;}
+
+ inline Selectors &
+ scope(int scope) {m_scope = scope; return *this;}
+
+ inline Selectors &
+ childSelector(CHILD_SELECTOR child) {m_childSelector = child; return *this;}
+
+ // this has no effect now
+ inline Selectors &
+ publisherPublicKeyDigest(const Bytes &digest) {m_publisherPublicKeyDigest = digest; return *this;}
+
+ CcnxCharbufPtr
+ toCcnxCharbuf() const;
+
+ bool
+ isEmpty() const;
+
+ bool
+ operator==(const Selectors &other);
+
+private:
+ int m_maxSuffixComps;
+ int m_minSuffixComps;
+ AOK m_answerOriginKind;
+ double m_interestLifetime;
+ int m_scope;
+ CHILD_SELECTOR m_childSelector;
+ // not used now
+ Bytes m_publisherPublicKeyDigest;
+};
+
+} // Ccnx
+
+#endif
diff --git a/include/ccnx-tunnel.h b/include/ccnx-tunnel.h
index bc13f9a..104c7cf 100644
--- a/include/ccnx-tunnel.h
+++ b/include/ccnx-tunnel.h
@@ -6,6 +6,7 @@
#include "ccnx-common.h"
#include "ccnx-wrapper.h"
#include "ccnx-name.h"
+#include "ccnx-selectors.h"
#define _OVERRIDE
#ifdef __GNUC__
diff --git a/include/ccnx-wrapper.h b/include/ccnx-wrapper.h
index 6e8e595..667d4be 100644
--- a/include/ccnx-wrapper.h
+++ b/include/ccnx-wrapper.h
@@ -7,6 +7,7 @@
#include "ccnx-common.h"
#include "ccnx-name.h"
+#include "ccnx-selectors.h"
#include "ccnx-closure.h"
using namespace std;
diff --git a/src/ccnx-name.cpp b/src/ccnx-name.cpp
index 9bc2663..3803987 100644
--- a/src/ccnx-name.cpp
+++ b/src/ccnx-name.cpp
@@ -274,117 +274,5 @@
return ss1.str() < ss2.str();
}
-Selectors::Selectors()
- : m_maxSuffixComps(-1)
- , m_minSuffixComps(-1)
- , m_answerOriginKind(AOK_DEFAULT)
- , m_interestLifetime(-1.0)
- , m_scope(-1)
- , m_childSelector(DEFAULT)
-{
-}
-
-Selectors::Selectors(const Selectors &other)
-{
- m_maxSuffixComps = other.m_maxSuffixComps;
- m_minSuffixComps = other.m_minSuffixComps;
- m_answerOriginKind = other.m_answerOriginKind;
- m_interestLifetime = other.m_interestLifetime;
- m_scope = other.m_scope;
- m_childSelector = other.m_childSelector;
- m_publisherPublicKeyDigest = other.m_publisherPublicKeyDigest;
-}
-
-bool
-Selectors::operator == (const Selectors &other)
-{
- return m_maxSuffixComps == other.m_maxSuffixComps
- && m_minSuffixComps == other.m_minSuffixComps
- && m_answerOriginKind == other.m_answerOriginKind
- && (m_interestLifetime - other.m_interestLifetime) < 10e-4
- && m_scope == other.m_scope
- && m_childSelector == other.m_childSelector;
-}
-
-bool
-Selectors::isEmpty() const
-{
- return m_maxSuffixComps == -1
- && m_minSuffixComps == -1
- && m_answerOriginKind == AOK_DEFAULT
- && (m_interestLifetime - (-1.0)) < 10e-4
- && m_scope == -1
- && m_childSelector == DEFAULT;
-}
-
-
-CcnxCharbufPtr
-Selectors::toCcnxCharbuf() const
-{
- if (isEmpty())
- {
- return CcnxCharbuf::Null;
- }
- CcnxCharbufPtr ptr(new CcnxCharbuf());
- ccn_charbuf *cbuf = ptr->getBuf();
- ccn_charbuf_append_tt(cbuf, CCN_DTAG_Interest, CCN_DTAG);
- ccn_charbuf_append_tt(cbuf, CCN_DTAG_Name, CCN_DTAG);
- ccn_charbuf_append_closer(cbuf); // </Name>
-
- if (m_maxSuffixComps < m_minSuffixComps)
- {
- boost::throw_exception(InterestSelectorException() << error_info_str("MaxSuffixComps = " + boost::lexical_cast<string>(m_maxSuffixComps) + " is smaller than MinSuffixComps = " + boost::lexical_cast<string>(m_minSuffixComps)));
- }
-
- if (m_maxSuffixComps > 0)
- {
- ccnb_tagged_putf(cbuf, CCN_DTAG_MaxSuffixComponents, "%d", m_maxSuffixComps);
- }
-
- if (m_minSuffixComps > 0)
- {
- ccnb_tagged_putf(cbuf, CCN_DTAG_MinSuffixComponents, "%d", m_minSuffixComps);
- }
-
- if (m_answerOriginKind != AOK_DEFAULT)
- {
- // it was not using "ccnb_tagged_putf" in ccnx c code, no idea why
- ccn_charbuf_append_tt(cbuf, CCN_DTAG_AnswerOriginKind, CCN_DTAG);
- ccnb_append_number(cbuf, m_answerOriginKind);
- ccn_charbuf_append_closer(cbuf); // <AnswerOriginKind>
- }
-
- if (m_scope != -1)
- {
- ccnb_tagged_putf(cbuf, CCN_DTAG_Scope, "%d", m_scope);
- }
-
- if (m_interestLifetime > 0.0)
- {
- // Ccnx timestamp unit is weird 1/4096 second
- // this is from their code
- unsigned lifetime = 4096 * (m_interestLifetime + 1.0/8192.0);
- if (lifetime == 0 || lifetime > (30 << 12))
- {
- boost::throw_exception(InterestSelectorException() << error_info_str("Ccnx requires 0 < lifetime < 30.0. lifetime= " + boost::lexical_cast<string>(m_interestLifetime)));
- }
- unsigned char buf[3] = {0};
- for (int i = sizeof(buf) - 1; i >= 0; i--, lifetime >>= 8)
- {
- buf[i] = lifetime & 0xff;
- }
- ccnb_append_tagged_blob(cbuf, CCN_DTAG_InterestLifetime, buf, sizeof(buf));
- }
-
- if (m_childSelector != DEFAULT)
- {
- ccnb_tagged_putf(cbuf, CCN_DTAG_ChildSelector, "%d", m_childSelector);
- }
-
-
- ccn_charbuf_append_closer(cbuf); // </Interest>
-
- return ptr;
-}
} // Ccnx
diff --git a/src/ccnx-selectors.cpp b/src/ccnx-selectors.cpp
new file mode 100644
index 0000000..001c1b7
--- /dev/null
+++ b/src/ccnx-selectors.cpp
@@ -0,0 +1,120 @@
+#include "ccnx-selectors.h"
+#include "ccnx-common.h"
+#include <boost/lexical_cast.hpp>
+
+namespace Ccnx {
+
+Selectors::Selectors()
+ : m_maxSuffixComps(-1)
+ , m_minSuffixComps(-1)
+ , m_answerOriginKind(AOK_DEFAULT)
+ , m_interestLifetime(-1.0)
+ , m_scope(-1)
+ , m_childSelector(DEFAULT)
+{
+}
+
+Selectors::Selectors(const Selectors &other)
+{
+ m_maxSuffixComps = other.m_maxSuffixComps;
+ m_minSuffixComps = other.m_minSuffixComps;
+ m_answerOriginKind = other.m_answerOriginKind;
+ m_interestLifetime = other.m_interestLifetime;
+ m_scope = other.m_scope;
+ m_childSelector = other.m_childSelector;
+ m_publisherPublicKeyDigest = other.m_publisherPublicKeyDigest;
+}
+
+bool
+Selectors::operator == (const Selectors &other)
+{
+ return m_maxSuffixComps == other.m_maxSuffixComps
+ && m_minSuffixComps == other.m_minSuffixComps
+ && m_answerOriginKind == other.m_answerOriginKind
+ && (m_interestLifetime - other.m_interestLifetime) < 10e-4
+ && m_scope == other.m_scope
+ && m_childSelector == other.m_childSelector;
+}
+
+bool
+Selectors::isEmpty() const
+{
+ return m_maxSuffixComps == -1
+ && m_minSuffixComps == -1
+ && m_answerOriginKind == AOK_DEFAULT
+ && (m_interestLifetime - (-1.0)) < 10e-4
+ && m_scope == -1
+ && m_childSelector == DEFAULT;
+}
+
+
+CcnxCharbufPtr
+Selectors::toCcnxCharbuf() const
+{
+ if (isEmpty())
+ {
+ return CcnxCharbuf::Null;
+ }
+ CcnxCharbufPtr ptr(new CcnxCharbuf());
+ ccn_charbuf *cbuf = ptr->getBuf();
+ ccn_charbuf_append_tt(cbuf, CCN_DTAG_Interest, CCN_DTAG);
+ ccn_charbuf_append_tt(cbuf, CCN_DTAG_Name, CCN_DTAG);
+ ccn_charbuf_append_closer(cbuf); // </Name>
+
+ if (m_maxSuffixComps < m_minSuffixComps)
+ {
+ boost::throw_exception(InterestSelectorException() << error_info_str("MaxSuffixComps = " + boost::lexical_cast<string>(m_maxSuffixComps) + " is smaller than MinSuffixComps = " + boost::lexical_cast<string>(m_minSuffixComps)));
+ }
+
+ if (m_maxSuffixComps > 0)
+ {
+ ccnb_tagged_putf(cbuf, CCN_DTAG_MaxSuffixComponents, "%d", m_maxSuffixComps);
+ }
+
+ if (m_minSuffixComps > 0)
+ {
+ ccnb_tagged_putf(cbuf, CCN_DTAG_MinSuffixComponents, "%d", m_minSuffixComps);
+ }
+
+ if (m_answerOriginKind != AOK_DEFAULT)
+ {
+ // it was not using "ccnb_tagged_putf" in ccnx c code, no idea why
+ ccn_charbuf_append_tt(cbuf, CCN_DTAG_AnswerOriginKind, CCN_DTAG);
+ ccnb_append_number(cbuf, m_answerOriginKind);
+ ccn_charbuf_append_closer(cbuf); // <AnswerOriginKind>
+ }
+
+ if (m_scope != -1)
+ {
+ ccnb_tagged_putf(cbuf, CCN_DTAG_Scope, "%d", m_scope);
+ }
+
+ if (m_interestLifetime > 0.0)
+ {
+ // Ccnx timestamp unit is weird 1/4096 second
+ // this is from their code
+ unsigned lifetime = 4096 * (m_interestLifetime + 1.0/8192.0);
+ if (lifetime == 0 || lifetime > (30 << 12))
+ {
+ boost::throw_exception(InterestSelectorException() << error_info_str("Ccnx requires 0 < lifetime < 30.0. lifetime= " + boost::lexical_cast<string>(m_interestLifetime)));
+ }
+ unsigned char buf[3] = {0};
+ for (int i = sizeof(buf) - 1; i >= 0; i--, lifetime >>= 8)
+ {
+ buf[i] = lifetime & 0xff;
+ }
+ ccnb_append_tagged_blob(cbuf, CCN_DTAG_InterestLifetime, buf, sizeof(buf));
+ }
+
+ if (m_childSelector != DEFAULT)
+ {
+ ccnb_tagged_putf(cbuf, CCN_DTAG_ChildSelector, "%d", m_childSelector);
+ }
+
+
+ ccn_charbuf_append_closer(cbuf); // </Interest>
+
+ return ptr;
+}
+
+} // Ccnx
diff --git a/test/test-ccnx-name.cc b/test/test-ccnx-name.cc
index 5084246..f617397 100644
--- a/test/test-ccnx-name.cc
+++ b/test/test-ccnx-name.cc
@@ -33,10 +33,4 @@
// Charbuf related stuff will be checked in other place
}
-BOOST_AUTO_TEST_CASE (SelectorsTest)
-{
- Selectors s;
- BOOST_CHECK(s.isEmpty());
-}
-
BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/test-ccnx-wrapper.cc b/test/test-ccnx-wrapper.cc
index 58d8d24..7c010ec 100644
--- a/test/test-ccnx-wrapper.cc
+++ b/test/test-ccnx-wrapper.cc
@@ -1,6 +1,7 @@
#include "ccnx-wrapper.h"
#include "ccnx-closure.h"
#include "ccnx-name.h"
+#include "ccnx-selectors.h"
#include "ccnx-pco.h"
#include <unistd.h>
diff --git a/wscript b/wscript
index e18214a..609f64d 100644
--- a/wscript
+++ b/wscript
@@ -67,6 +67,7 @@
'src/ccnx-tunnel.cpp',
'src/object-db-file.cpp',
'src/ccnx-name.cpp',
+ 'src/ccnx-selectors.cpp',
],
use = 'BOOST BOOST_THREAD SSL CCNX',
includes = ['include', ],