forked from cawka/ndn.cxx
diff --git a/ndn-cpp/interest.h b/ndn-cpp/interest.h
new file mode 100644
index 0000000..d929efa
--- /dev/null
+++ b/ndn-cpp/interest.h
@@ -0,0 +1,461 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ *                     Alexander Afanasyev
+ *                     Zhenkai Zhu
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ *         Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ */
+
+#ifndef NDN_INTEREST_H
+#define NDN_INTEREST_H
+
+#include <ndn-cpp/common.h>
+#include <ndn-cpp/fields/name.h>
+#include <ndn-cpp/fields/exclude.h>
+#include <ndn-cpp/helpers/hash.h>
+
+namespace ndn {
+
+/**
+ * @brief Class abstracting operations with Interests (constructing and getting access to Interest fields)
+ */
+class Interest
+{
+public:
+  /**
+   * @brief Default constructor, creates an interest for / prefix without any selectors
+   */
+  Interest ();
+
+  /**
+   * @brief Create an interest for the name
+   * @param name name of the data to request
+   */
+  Interest (const Name &name);
+
+  /**
+   * @brief Copy constructor
+   * @param interest interest to copy
+   */
+  Interest (const Interest &interest);
+
+  /**
+   * @brief Create an interest based on ccn_parsed_interest data structure
+   * @param interest pointer to ccn_parsed_interest data structure
+   *
+   * This method will create an interest with empty name, since ccn_parsed_interest structure
+   * has limited amount of information
+   */
+  Interest (const ccn_parsed_interest *interest);
+
+  /**
+   * @brief Set interest name
+   * @param name name of the interest
+   * @return reference to self (to allow method chaining)
+   *
+   * In some cases, a direct access to and manipulation of name using getName is more efficient
+   */
+  inline Interest &
+  setName (const Name &name);
+
+  /**
+   * @brief Get interest name (const reference)
+   * @returns name of the interest
+   */
+  inline const Name &
+  getName () const;
+
+  /**
+   * @brief Get interest name (reference)
+   * @returns name of the interest
+   */
+  inline Name &
+  getName ();
+
+  /**
+   * @brief Set interest lifetime (time_duration)
+   * @param interestLifetime interest lifetime specified as a time_duration value.
+   *        Negative value means that InterestLifetime is not set.
+   * @return reference to self (to allow method chaining)
+   */
+  inline Interest &
+  setInterestLifetime (const TimeInterval &interestLifetime);
+
+  /**
+   * @brief Set interest lifetime (double)
+   * @param interestLifetime interest lifetime expressed in seconds, with possible fractional seconds (double).
+   *        Negative value means that InterestLifetime is not set.
+   * @return reference to self (to allow method chaining)
+   */
+  inline Interest &
+  setInterestLifetime (double interestLifetimeSeconds);
+
+  /**
+   * @brief Get interest lifetime
+   * @return TimeInterval representing lifetime of the interest.
+   *         Use time_duration::total_seconds () or time_duration::total_microseconds (),
+   *         if you need interest lifetime as a plain number.
+   *         @see http://www.boost.org/doc/libs/1_53_0/doc/html/date_time/posix_time.html
+   */
+  inline const TimeInterval &
+  getInterestLifetime () const;
+
+  /**
+   * @brief Set intended interest scope
+   * @param scope requested scope of the interest @see Scope
+   * @return reference to self (to allow method chaining)
+   */
+  inline Interest &
+  setScope (uint8_t scope);
+
+  /**
+   * @brief Get intended interest scope
+   * @return intended interest scope @see Scope
+   */
+  inline uint8_t
+  getScope () const;
+
+  ///////////////////////////////////////////////////////////////////////
+  //                          SELECTORS                                //
+  ///////////////////////////////////////////////////////////////////////
+
+  /**
+   * @brief Enum defining constants for AnswerOriginKind selector field
+   */
+  enum AnswerOriginKind
+  {
+    AOK_CS = 0x1,      ///< @brief request item from the content store
+    AOK_NEW = 0x2,     ///< @brief request item from the original producer
+    AOK_DEFAULT = 0x3, ///< @brief default: either from content store or original producer
+    AOK_STALE = 0x4,   ///< @brief Allow stale data
+    AOK_EXPIRE = 0x10  ///< @brief Allow expired data (?)
+  };
+
+  /**
+   * @brief Enum defining constants for ChildSelector field
+   */
+  enum ChildSelector
+    {
+      CHILD_LEFT = 0,   ///< @brief request left child
+      CHILD_RIGHT = 1,  ///< @brief request right child
+      CHILD_DEFAULT = 2 ///< @brief do not specify which child is requested
+    };
+
+  /**
+   * @brief Enum defining constants for Scope field
+   */
+  enum Scope
+    {
+      NO_SCOPE = 255,        ///< @brief Interest scope is not defined
+      SCOPE_LOCAL_CCND = 0,  ///< @brief Interest scope is only toward local NDN daemon
+      SCOPE_LOCAL_HOST = 1,  ///< @brief Interest scope is within local host (any local application only)
+      SCOPE_NEXT_HOST = 2    ///< @brief Interest scope is within local host and immediate neighboring node
+    };
+
+  /**
+   * @brief Set interest selector for maximum suffix components
+   * @param maxSuffixComponents maximum number of suffix components. If Interest::ncomps, then not restricted
+   * @return reference to self (to allow method chaining)
+   */
+  inline Interest &
+  setMaxSuffixComponents (uint32_t maxSuffixComponents);
+
+  /**
+   * \brief Get interest selector for maximum suffix components
+   *
+   * MaxSuffixComponents refer to the number of name components beyond those in the prefix,
+   * and counting the implicit digest, that may occur in the matching ContentObject.
+   * For more information, see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html
+   **/
+  inline uint32_t
+  getMaxSuffixComponents () const;
+
+  /**
+   * @brief Set interest selector for minimum suffix components
+   * @param minSuffixComponents minimum number of suffix components. If Interest::ncomps, then not restricted
+   * @return reference to self (to allow method chaining)
+   */
+  inline Interest &
+  setMinSuffixComponents (uint32_t minSuffixComponents);
+
+  /**
+   * \brief Get interest selector for minimum suffix components
+   *
+   * MinSuffixComponents refer to the number of name components beyond those in the prefix,
+   * and counting the implicit digest, that may occur in the matching ContentObject.
+   * For more information, see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html
+   **/
+  inline uint32_t
+  getMinSuffixComponents () const;
+
+  /**
+   * @brief Set interest selector for answer origin kind
+   * @param answerOriginKind type of answer @see AnswerOriginKind
+   * @return reference to self (to allow method chaining)
+   */
+  inline Interest &
+  setAnswerOriginKind (uint32_t answerOriginKind);
+
+  /**
+   * @brief Get interest selector for answer origin kind
+   */
+  inline uint32_t
+  getAnswerOriginKind () const;
+
+  /**
+   * @brief Set interest selector for child selector
+   * @param child child selector @see ChildSelector
+   * @return reference to self (to allow method chaining)
+   *
+   * Often a given interest will match more than one ContentObject within a given content store.
+   * The ChildSelector provides a way of expressing a preference for which of these should be returned.
+   * If the value is false, the leftmost child is preferred. If true, the rightmost child is preferred.
+   * \see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html for more information.
+   */
+  inline Interest &
+  setChildSelector (uint8_t child);
+
+  /**
+   * @brief Get interest selector for child selector
+   */
+  inline uint8_t
+  getChildSelector () const;
+
+  /**
+   * @brief Set interest selector for publisher public key digest
+   * @param digest publisher public key digest
+   * @return reference to self (to allow method chaining)
+   *
+   * Currently, this method has no effect
+   * @todo Implement PublisherPublicKeyDigest
+   */
+  inline Interest &
+  setPublisherPublicKeyDigest(const Hash &digest);
+
+  /**
+   * @brief Get interest selector for publisher public key digest
+   *
+   * @todo Implement
+   */
+  inline const Hash&
+  getPublisherPublicKeyDigest () const;
+
+  /**
+   * @brief Set exclude filter
+   * @param exclude An exclude filter to set
+   *
+   * In some cases, a direct access to and manipulation of exclude filter using getExclude is more efficient
+   */
+  inline void
+  setExclude (const Exclude &exclude);
+
+  /**
+   * @brief Get exclude filter (const reference)
+   */
+  inline const Exclude &
+  getExclude () const;
+
+  /**
+   * @brief Get exclude filter (reference)
+   */
+  inline Exclude &
+  getExclude ();
+
+  ///////////////////////////////////////////////////////////////////////
+  //                           HELPERS                                 //
+  ///////////////////////////////////////////////////////////////////////
+
+  /**
+   * @brief Compare equality of two interests
+   */
+  bool
+  operator== (const Interest &interest);
+
+public:
+  // Data Members (public):
+  /// @brief Value indicating that number of components parameter is invalid
+  const static uint32_t ncomps = static_cast<uint32_t> (-1);
+
+private:
+  Name m_name;
+  uint32_t m_maxSuffixComponents;
+  uint32_t m_minSuffixComponents;
+  uint32_t m_answerOriginKind;
+  TimeInterval m_interestLifetime; // lifetime in seconds
+
+  uint8_t m_scope;
+  uint8_t m_childSelector;
+  // not used now
+  Hash m_publisherPublicKeyDigest;
+  Exclude m_exclude;
+
+  Ptr<Blob> m_wire;
+};
+
+typedef boost::shared_ptr<Interest> InterestPtr;
+
+namespace Error
+{
+/**
+ * @brief Exception that is thrown in case of error during interest construction or parsing
+ */
+struct Interest:
+    virtual boost::exception, virtual std::exception {};
+}
+
+
+
+inline Interest &
+Interest::setName (const Name &name)
+{
+  m_name = name;
+  return *this;
+}
+
+inline const Name &
+Interest::getName () const
+{
+  return m_name;
+}
+
+inline Name &
+Interest::getName ()
+{
+  return m_name;
+}
+
+inline Interest &
+Interest::setInterestLifetime (const TimeInterval &interestLifetime)
+{
+  m_interestLifetime = interestLifetime;
+  return *this;
+}
+
+inline Interest &
+Interest::setInterestLifetime (double interestLifetimeSeconds)
+{
+  m_interestLifetime = time::Seconds (interestLifetimeSeconds);
+  return *this;
+}
+
+inline const TimeInterval &
+Interest::getInterestLifetime () const
+{
+  return m_interestLifetime;
+}
+
+inline Interest &
+Interest::setScope (uint8_t scope)
+{
+  m_scope = scope;
+  return *this;
+}
+
+inline uint8_t
+Interest::getScope () const
+{
+  return m_scope;
+}
+
+///////////////////////////////////////////////////////////////////////
+//                          SELECTORS                                //
+///////////////////////////////////////////////////////////////////////
+
+
+inline Interest &
+Interest::setMaxSuffixComponents (uint32_t maxSuffixComponents)
+{
+  m_maxSuffixComponents = maxSuffixComponents;
+  return *this;
+}
+
+inline uint32_t
+Interest::getMaxSuffixComponents () const
+{
+  return m_maxSuffixComponents;
+}
+
+inline Interest &
+Interest::setMinSuffixComponents (uint32_t minSuffixComponents)
+{
+  m_minSuffixComponents = minSuffixComponents;
+  return *this;
+}
+
+inline uint32_t
+Interest::getMinSuffixComponents () const
+{
+  return m_minSuffixComponents;
+}
+
+inline Interest &
+Interest::setAnswerOriginKind (uint32_t answerOriginKind)
+{
+  m_answerOriginKind = answerOriginKind;
+  return *this;
+}
+
+inline uint32_t
+Interest::getAnswerOriginKind () const
+{
+  return m_answerOriginKind;
+}
+
+inline Interest &
+Interest::setChildSelector (uint8_t childSelector)
+{
+  m_childSelector = childSelector;
+  return *this;
+}
+
+inline uint8_t
+Interest::getChildSelector () const
+{
+  return m_childSelector;
+}
+
+inline Interest &
+Interest::setPublisherPublicKeyDigest(const Hash &publisherPublicKeyDigest)
+{
+  m_publisherPublicKeyDigest = publisherPublicKeyDigest;
+  return *this;
+}
+
+inline const Hash&
+Interest::getPublisherPublicKeyDigest () const
+{
+  return m_publisherPublicKeyDigest;
+}
+
+inline void
+Interest::setExclude (const Exclude &exclude)
+{
+  m_exclude = exclude;
+}
+
+/**
+ * @brief Get exclude filter (const reference)
+ */
+inline const Exclude &
+Interest::getExclude () const
+{
+  return m_exclude;
+}
+
+/**
+ * @brief Get exclude filter (reference)
+ */
+inline Exclude &
+Interest::getExclude ()
+{
+  return m_exclude;
+}
+
+
+} // ndn
+
+#endif // NDN_INTEREST_H