Added Node class, and move most functionality from Face to Node. Make connect take a Node, not a Face.
diff --git a/ndn-cpp/face.hpp b/ndn-cpp/face.hpp
index 64d835c..c98932c 100644
--- a/ndn-cpp/face.hpp
+++ b/ndn-cpp/face.hpp
@@ -6,19 +6,14 @@
#ifndef NDN_FACE_HPP
#define NDN_FACE_HPP
-#include "closure.hpp"
-#include "interest.hpp"
-#include "transport/udp-transport.hpp"
-#include "encoding/binary-xml-element-reader.hpp"
-
-using namespace std;
+#include "node.hpp"
namespace ndn {
/**
* The Face class provides the main methods for NDN communication.
*/
-class Face : public ElementListener {
+class Face {
public:
/**
* Create a new Face for communication with an NDN hub at host:port with the given Transport object.
@@ -27,7 +22,7 @@
* @param transport A pointer to a Transport object used for communication.
*/
Face(const char *host, unsigned short port, const ptr_lib::shared_ptr<Transport> &transport)
- : host_(host), port_(port), transport_(transport), tempClosure_(0)
+ : node_(host, port, transport)
{
}
@@ -37,7 +32,7 @@
* @param port The port of the NDN hub.
*/
Face(const char *host, unsigned short port)
- : host_(host), port_(port), transport_(new UdpTransport()), tempClosure_(0)
+ : node_(host, port)
{
}
@@ -46,7 +41,7 @@
* @param host The host of the NDN hub.
*/
Face(const char *host)
- : host_(host), port_(9695), transport_(new UdpTransport()), tempClosure_(0)
+ : node_(host)
{
}
@@ -59,37 +54,36 @@
* @param closure a pointer for the Closure. The caller must manage the memory for the Closure. This will not try to delete it.
* @param interestTemplate if not 0, copy interest selectors from the template. This does not keep a pointer to the Interest object.
*/
- void expressInterest(const Name &name, Closure *closure, const Interest *interestTemplate);
+ void expressInterest(const Name &name, Closure *closure, const Interest *interestTemplate)
+ {
+ node_.expressInterest(name, closure, interestTemplate);
+ }
void expressInterest(const Name &name, Closure *closure)
{
- expressInterest(name, closure, 0);
+ node_.expressInterest(name, closure);
}
/**
- * Process any data to receive. For each element received, call face.onReceivedElement.
+ * Process any data to receive or call timeout callbacks.
* 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.
* @throw This may throw an exception for reading data or in the callback for processing the data. If you
* call this from an main event loop, you may want to catch and log/disregard all exceptions.
*/
- void processEvents();
+ void processEvents()
+ {
+ // Just call Node's processEvents.
+ node_.processEvents();
+ }
+ /**
+ * Shut down and disconnect this Face.
+ */
void shutdown();
- const char *getHost() const { return host_.c_str(); }
-
- unsigned short getPort() const { return port_; }
-
- const ptr_lib::shared_ptr<Transport> &getTransport() { return transport_; }
-
- virtual void onReceivedElement(unsigned char *element, unsigned int elementLength);
-
private:
- ptr_lib::shared_ptr<Transport> transport_;
- string host_;
- unsigned short port_;
- Closure *tempClosure_;
+ Node node_;
};
}