Move the default parameters for methods from Node to Face.
diff --git a/ndn-cpp/face.cpp b/ndn-cpp/face.cpp
index 7b0d3ea..a2503fe 100644
--- a/ndn-cpp/face.cpp
+++ b/ndn-cpp/face.cpp
@@ -9,6 +9,18 @@
namespace ndn {
+void Face::expressInterest(const Name &name, const Interest *interestTemplate, const OnData &onData, const OnTimeout &onTimeout)
+{
+ if (interestTemplate)
+ node_.expressInterest(Interest
+ (name, interestTemplate->getMinSuffixComponents(), interestTemplate->getMaxSuffixComponents(),
+ interestTemplate->getPublisherPublicKeyDigest(), interestTemplate->getExclude(),
+ interestTemplate->getChildSelector(), interestTemplate->getAnswerOriginKind(),
+ interestTemplate->getScope(), interestTemplate->getInterestLifetimeMilliseconds()), onData, onTimeout);
+ else
+ node_.expressInterest(Interest(name, 4000.0), onData, onTimeout);
+}
+
void Face::shutdown()
{
node_.shutdown();
diff --git a/ndn-cpp/face.hpp b/ndn-cpp/face.hpp
index 0b7aa54..9dce469 100644
--- a/ndn-cpp/face.hpp
+++ b/ndn-cpp/face.hpp
@@ -7,6 +7,7 @@
#define NDN_FACE_HPP
#include "node.hpp"
+#include "transport/tcp-transport.hpp"
namespace ndn {
@@ -28,22 +29,14 @@
/**
* Create a new Face for communication with an NDN hub at host:port using the default TcpTransport.
* @param host The host of the NDN hub.
- * @param port The port of the NDN hub.
+ * @param port The port of the NDN hub. If omitted. use 9695.
*/
- Face(const char *host, unsigned short port)
- : node_(host, port)
+ Face(const char *host, unsigned short port = 9695)
+ : node_(ptr_lib::make_shared<TcpTransport>(),
+ ptr_lib::make_shared<TcpTransport::ConnectionInfo>(host, port))
{
}
-
- /**
- * Create a new Face for communication with an NDN hub at host with the default port 9695 and using the default TcpTransport.
- * @param host The host of the NDN hub.
- */
- Face(const char *host)
- : node_(host)
- {
- }
-
+
/**
* Send the Interest through the transport, read the entire response and call onData(interest, data).
* @param interest A reference to the Interest. This copies the Interest.
@@ -52,22 +45,12 @@
* @param onTimeout A function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it.
* This copies the function object, so you may need to use func_lib::ref() as appropriate.
*/
- void expressInterest(const Interest &interest, const OnData &onData, const OnTimeout &onTimeout)
+ void expressInterest(const Interest &interest, const OnData &onData, const OnTimeout &onTimeout = OnTimeout())
{
node_.expressInterest(interest, onData, onTimeout);
}
/**
- * Send the Interest through the transport, read the entire response and call onData(interest, data).
- * @param interest A reference to the Interest. This copies the Interest.
- * @param onData A function object to call when a matching data packet is received. This copies the function object, so you may need to
- * use func_lib::ref() as appropriate.
- */
- void expressInterest(const Interest &interest, const OnData &onData) {
- node_.expressInterest(interest, onData);
- }
-
- /**
* Encode name as an Interest. If interestTemplate is not 0, use its interest selectors.
* Send the interest through the transport, read the entire response and call onData(interest, data).
* @param name A reference to a Name for the interest. This copies the Name.
@@ -77,10 +60,7 @@
* @param onTimeout A function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it.
* This copies the function object, so you may need to use func_lib::ref() as appropriate.
*/
- void expressInterest(const Name &name, const Interest *interestTemplate, const OnData &onData, const OnTimeout &onTimeout)
- {
- node_.expressInterest(name, interestTemplate, onData, onTimeout);
- }
+ void expressInterest(const Name &name, const Interest *interestTemplate, const OnData &onData, const OnTimeout &onTimeout = OnTimeout());
/**
* Encode name as an Interest, using a default interest lifetime.
@@ -91,34 +71,9 @@
* @param onTimeout A function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it.
* This copies the function object, so you may need to use func_lib::ref() as appropriate.
*/
- void expressInterest(const Name &name, const OnData &onData, const OnTimeout &onTimeout)
+ void expressInterest(const Name &name, const OnData &onData, const OnTimeout &onTimeout = OnTimeout())
{
- node_.expressInterest(name, onData, onTimeout);
- }
-
- /**
- * Encode name as an Interest. If interestTemplate is not 0, use its interest selectors.
- * Send the interest through the transport, read the entire response and call onData(interest, data).
- * @param name A reference to a Name for the interest. This copies the Name.
- * @param interestTemplate if not 0, copy interest selectors from the template. This does not keep a pointer to the Interest object.
- * @param onData A function object to call when a matching data packet is received. This copies the function object, so you may need to
- * use func_lib::ref() as appropriate.
- */
- void expressInterest(const Name &name, const Interest *interestTemplate, const OnData &onData)
- {
- node_.expressInterest(name, interestTemplate, onData);
- }
-
- /**
- * Encode name as an Interest, using a default interest lifetime.
- * Send the interest through the transport, read the entire response and call onData(interest, data).
- * @param name A reference to a Name for the interest. This copies the Name.
- * @param onData A function object to call when a matching data packet is received. This copies the function object, so you may need to
- * use func_lib::ref() as appropriate.
- */
- void expressInterest(const Name &name, const OnData &onData)
- {
- node_.expressInterest(name, onData);
+ expressInterest(name, 0, onData, onTimeout);
}
/**
@@ -128,21 +83,10 @@
* use func_lib::ref() as appropriate.
* @param flags The flags for finer control of which interests are forward to the application.
*/
- void registerPrefix(const Name &prefix, const OnInterest &onInterest, int flags)
+ void registerPrefix(const Name &prefix, const OnInterest &onInterest, int flags = 0)
{
node_.registerPrefix(prefix, onInterest, flags);
}
-
- /**
- * Register prefix with the connected NDN hub and call onInterest when a matching interest is received.
- * @param prefix A reference to a Name for the prefix to register. This copies the Name.
- * @param onInterest A function object to call when a matching interest is received. This copies the function object, so you may need to
- * use func_lib::ref() as appropriate.
- */
- void registerPrefix(const Name &prefix, const OnInterest &onInterest)
- {
- node_.registerPrefix(prefix, onInterest);
- }
/**
* Process any data to receive or call timeout callbacks.
diff --git a/ndn-cpp/node.cpp b/ndn-cpp/node.cpp
index 1461dbf..369f3ca 100644
--- a/ndn-cpp/node.cpp
+++ b/ndn-cpp/node.cpp
@@ -21,9 +21,10 @@
return t.tv_sec * 1000.0 + t.tv_usec / 1000.0;
}
-void Node::construct()
+Node::Node(const ptr_lib::shared_ptr<Transport> &transport, const ptr_lib::shared_ptr<const Transport::ConnectionInfo> &connectionInfo)
+: transport_(transport), connectionInfo_(connectionInfo),
+ ndndIdFetcherInterest_(Name("/%C1.M.S.localhost/%C1.M.SRV/ndnd/KEY"), 4000.0)
{
- ndndIdFetcherInterest_ = Interest(Name("/%C1.M.S.localhost/%C1.M.SRV/ndnd/KEY"), 4000.0);
}
void Node::expressInterest(const Interest &interest, const OnData &onData, const OnTimeout &onTimeout)
@@ -40,18 +41,6 @@
transport_->send(*encoding);
}
-void Node::expressInterest(const Name &name, const Interest *interestTemplate, const OnData &onData, const OnTimeout &onTimeout)
-{
- if (interestTemplate)
- expressInterest(Interest
- (name, interestTemplate->getMinSuffixComponents(), interestTemplate->getMaxSuffixComponents(),
- interestTemplate->getPublisherPublicKeyDigest(), interestTemplate->getExclude(),
- interestTemplate->getChildSelector(), interestTemplate->getAnswerOriginKind(),
- interestTemplate->getScope(), interestTemplate->getInterestLifetimeMilliseconds()), onData, onTimeout);
- else
- expressInterest(Interest(name, 4000.0), onData, onTimeout);
-}
-
void Node::registerPrefix(const Name &prefix, const OnInterest &onInterest, int flags)
{
if (ndndId_.size() == 0) {
diff --git a/ndn-cpp/node.hpp b/ndn-cpp/node.hpp
index 54a9a16..8bd59c2 100644
--- a/ndn-cpp/node.hpp
+++ b/ndn-cpp/node.hpp
@@ -38,34 +38,9 @@
* @param transport A shared_ptr to a Transport object used for communication.
* @param transport A shared_ptr to a Transport::ConnectionInfo to be used to connect to the transport.
*/
- Node(const ptr_lib::shared_ptr<Transport> &transport, const ptr_lib::shared_ptr<const Transport::ConnectionInfo> &connectionInfo)
- : transport_(transport), connectionInfo_(connectionInfo)
- {
- construct();
- }
+ Node(const ptr_lib::shared_ptr<Transport> &transport, const ptr_lib::shared_ptr<const Transport::ConnectionInfo> &connectionInfo);
/**
- * Create a new Node for communication with an NDN hub at host:port using the default TcpTransport.
- * @param host The host of the NDN hub.
- * @param port The port of the NDN hub.
- */
- Node(const char *host, unsigned short port)
- : transport_(new TcpTransport()), connectionInfo_(new TcpTransport::ConnectionInfo(host, port))
- {
- construct();
- }
-
- /**
- * Create a new Node for communication with an NDN hub at host with the default port 9695 and using the default TcpTransport.
- * @param host The host of the NDN hub.
- */
- Node(const char *host)
- : transport_(new TcpTransport()), connectionInfo_(new TcpTransport::ConnectionInfo(host, 9695))
- {
- construct();
- }
-
- /**
* Send the Interest through the transport, read the entire response and call onData(interest, data).
* @param interest A reference to the Interest. This copies the Interest.
* @param onData A function object to call when a matching data packet is received. This copies the function object, so you may need to
@@ -74,69 +49,8 @@
* This copies the function object, so you may need to use func_lib::ref() as appropriate.
*/
void expressInterest(const Interest &interest, const OnData &onData, const OnTimeout &onTimeout);
-
- /**
- * Send the Interest through the transport, read the entire response and call onData(interest, data).
- * @param interest A reference to the Interest. This copies the Interest.
- * @param onData A function object to call when a matching data packet is received. This copies the function object, so you may need to
- * use func_lib::ref() as appropriate.
- */
- void expressInterest(const Interest &interest, const OnData &onData) {
- expressInterest(interest, onData, OnTimeout());
- }
-
- /**
- * Encode name as an Interest. If interestTemplate is not 0, use its interest selectors.
- * Send the interest through the transport, read the entire response and call onData(interest, data).
- * @param name A reference to a Name for the interest. This copies the Name.
- * @param interestTemplate if not 0, copy interest selectors from the template. This does not keep a pointer to the Interest object.
- * @param onData A function object to call when a matching data packet is received. This copies the function object, so you may need to
- * use func_lib::ref() as appropriate.
- * @param onTimeout A function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it.
- * This copies the function object, so you may need to use func_lib::ref() as appropriate.
- */
- void expressInterest(const Name &name, const Interest *interestTemplate, const OnData &onData, const OnTimeout &onTimeout);
-
- /**
- * Encode name as an Interest, using a default interest lifetime.
- * Send the interest through the transport, read the entire response and call onData(interest, data).
- * @param name A reference to a Name for the interest. This copies the Name.
- * @param onData A function object to call when a matching data packet is received. This copies the function object, so you may need to
- * use func_lib::ref() as appropriate.
- * @param onTimeout A function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it.
- * This copies the function object, so you may need to use func_lib::ref() as appropriate.
- */
- void expressInterest(const Name &name, const OnData &onData, const OnTimeout &onTimeout)
- {
- expressInterest(name, 0, onData, onTimeout);
- }
/**
- * Encode name as an Interest. If interestTemplate is not 0, use its interest selectors.
- * Send the interest through the transport, read the entire response and call onData(interest, data).
- * @param name A reference to a Name for the interest. This copies the Name.
- * @param interestTemplate if not 0, copy interest selectors from the template. This does not keep a pointer to the Interest object.
- * @param onData A function object to call when a matching data packet is received. This copies the function object, so you may need to
- * use func_lib::ref() as appropriate.
- */
- void expressInterest(const Name &name, const Interest *interestTemplate, const OnData &onData)
- {
- expressInterest(name, interestTemplate, onData, OnTimeout());
- }
-
- /**
- * Encode name as an Interest, using a default interest lifetime.
- * Send the interest through the transport, read the entire response and call onData(interest, data).
- * @param name A reference to a Name for the interest. This copies the Name.
- * @param onData A function object to call when a matching data packet is received. This copies the function object, so you may need to
- * use func_lib::ref() as appropriate.
- */
- void expressInterest(const Name &name, const OnData &onData)
- {
- expressInterest(name, 0, onData);
- }
-
- /**
* Register prefix with the connected NDN hub and call onInterest when a matching interest is received.
* @param prefix A reference to a Name for the prefix to register. This copies the Name.
* @param onInterest A function object to call when a matching interest is received. This copies the function object, so you may need to
@@ -146,17 +60,6 @@
void registerPrefix(const Name &prefix, const OnInterest &onInterest, int flags);
/**
- * Register prefix with the connected NDN hub and call onInterest when a matching interest is received.
- * @param prefix A reference to a Name for the prefix to register. This copies the Name.
- * @param onInterest A function object to call when a matching interest is received. This copies the function object, so you may need to
- * use func_lib::ref() as appropriate.
- */
- void registerPrefix(const Name &prefix, const OnInterest &onInterest)
- {
- registerPrefix(prefix, onInterest, 0);
- }
-
- /**
* Process any data to receive. For each element received, call onReceivedElement.
* This is non-blocking and will return immediately if there is no data to receive.
* You should repeatedly call this from an event loop, with calls to sleep as needed so that the loop doesn't use 100% of the CPU.
@@ -265,11 +168,6 @@
};
/**
- * Finish constructing this object.
- */
- void construct();
-
- /**
* Find the entry from the pit_ where the name conforms to the entry's interest selectors, and
* the entry interest name is the longest that matches name.
* @param name The name to find the interest for (from the incoming data packet).