Added initial expressInterest
diff --git a/ndn-cpp/NDN.cpp b/ndn-cpp/NDN.cpp
index cafa4c6..4f7be39 100644
--- a/ndn-cpp/NDN.cpp
+++ b/ndn-cpp/NDN.cpp
@@ -12,6 +12,16 @@
namespace ndn {
+void NDN::expressInterest(const Name &name, const ptr_lib::shared_ptr<Closure> &closure, const Interest *interestTemplate)
+{
+ Interest interest(name);
+ vector<unsigned char> encoding;
+ interest.encode(encoding);
+
+ transport_->connect((char *)"E.hub.ndn.ucla.edu", 9695);
+ transport_->send(&encoding[0], encoding.size());
+}
+
void NDN::onReceivedElement(unsigned char *element, unsigned int elementLength)
{
BinaryXMLDecoder decoder(element, elementLength);
@@ -22,7 +32,7 @@
ptr_lib::shared_ptr<Interest> dummyInterest;
UpcallInfo upcallInfo(this, dummyInterest, 0, contentObject);
- closure_->upcall(UPCALL_CONTENT, upcallInfo);
+ tempClosure_->upcall(UPCALL_CONTENT, upcallInfo);
}
}
diff --git a/ndn-cpp/NDN.hpp b/ndn-cpp/NDN.hpp
index 9c8c691..09dfad2 100644
--- a/ndn-cpp/NDN.hpp
+++ b/ndn-cpp/NDN.hpp
@@ -7,21 +7,38 @@
#define NDN_NDN_HPP
#include "Closure.hpp"
+#include "Interest.hpp"
+#include "transport/Transport.hpp"
#include "encoding/BinaryXMLElementReader.hpp"
namespace ndn {
class NDN : public ElementListener {
public:
- NDN(Closure *closure)
+ NDN(const ptr_lib::shared_ptr<Transport> &transport, const ptr_lib::shared_ptr<Closure> &tempClosure)
{
- closure_ = closure;
+ transport_ = transport;
+ tempClosure_ = tempClosure;
}
+ /**
+ * 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
+ * closure->upcall(UPCALL_CONTENT (or UPCALL_CONTENT_UNVERIFIED),
+ * UpcallInfo(this, interest, 0, contentObject)).
+ * @param name reference to a Name for the interest. This does not keep a pointer to the Name object.
+ * @param closure a shared_ptr for the Closure. This uses shared_ptr to take another reference to the object.
+ * @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, const ptr_lib::shared_ptr<Closure> &closure, const Interest *interestTemplate);
+
+ Transport &tempGetTransport() { return *transport_; }
+
virtual void onReceivedElement(unsigned char *element, unsigned int elementLength);
private:
- Closure *closure_;
+ ptr_lib::shared_ptr<Transport> transport_;
+ ptr_lib::shared_ptr<Closure> tempClosure_;
};
}
diff --git a/tests/test-get-async.cpp b/tests/test-get-async.cpp
index 011c28f..8965c54 100644
--- a/tests/test-get-async.cpp
+++ b/tests/test-get-async.cpp
@@ -35,23 +35,14 @@
int main(int argc, char** argv)
{
try {
- Interest interest;
- interest.getName() = Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt/level2/%FD%05%0B%16%7D%95%0E");
- vector<unsigned char> encoding;
- interest.encode(encoding);
-
- TcpTransport transport;
- transport.connect((char *)"E.hub.ndn.ucla.edu", 9695);
- transport.send(&encoding[0], encoding.size());
-
- MyClosure closure;
- NDN ndn(&closure);
+ NDN ndn(ptr_lib::make_shared<TcpTransport>(), ptr_lib::make_shared<MyClosure>());
+ ndn.expressInterest(Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt/level2/%FD%05%0B%16%7D%95%0E"), ptr_lib::make_shared<MyClosure>(), 0);
ndn_BinaryXMLElementReader elementReader;
ndn_BinaryXMLElementReader_init(&elementReader, (struct ndn_ElementListener *)&ndn);
unsigned char buffer[8000];
- unsigned int nBytes = transport.receive(buffer, sizeof(buffer));
+ unsigned int nBytes = ndn.tempGetTransport().receive(buffer, sizeof(buffer));
ndn_BinaryXMLElementReader_onReceivedData(&elementReader, buffer, nBytes);
} catch (exception &e) {
cout << "exception: " << e.what() << endl;