Added test-publish-async.cpp
diff --git a/Makefile.am b/Makefile.am
index 10297a0..c882616 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -11,7 +11,7 @@
lib_LTLIBRARIES = libndn-c.la libndn-cpp.la
-bin_PROGRAMS = bin/test-encode-decode-interest bin/test-encode-decode-data bin/test-get-async
+bin_PROGRAMS = bin/test-encode-decode-interest bin/test-encode-decode-data bin/test-get-async bin/test-publish-async
libndn_c_la_SOURCES = \
config.h \
@@ -71,4 +71,7 @@
bin_test_get_async_SOURCES = tests/test-get-async.cpp
bin_test_get_async_LDADD = libndn-cpp.la libndn-c.la
+bin_test_publish_async_SOURCES = tests/test-publish-async.cpp
+bin_test_publish_async_LDADD = libndn-cpp.la libndn-c.la
+
dist_noinst_SCRIPTS = autogen.sh
diff --git a/Makefile.in b/Makefile.in
index f7d87d4..f594d19 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -89,7 +89,7 @@
config.guess config.sub install-sh missing ltmain.sh
bin_PROGRAMS = bin/test-encode-decode-interest$(EXEEXT) \
bin/test-encode-decode-data$(EXEEXT) \
- bin/test-get-async$(EXEEXT)
+ bin/test-get-async$(EXEEXT) bin/test-publish-async$(EXEEXT)
subdir = .
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
@@ -177,6 +177,10 @@
am_bin_test_get_async_OBJECTS = tests/test-get-async.$(OBJEXT)
bin_test_get_async_OBJECTS = $(am_bin_test_get_async_OBJECTS)
bin_test_get_async_DEPENDENCIES = libndn-cpp.la libndn-c.la
+am_bin_test_publish_async_OBJECTS = \
+ tests/test-publish-async.$(OBJEXT)
+bin_test_publish_async_OBJECTS = $(am_bin_test_publish_async_OBJECTS)
+bin_test_publish_async_DEPENDENCIES = libndn-cpp.la libndn-c.la
SCRIPTS = $(dist_noinst_SCRIPTS)
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -233,11 +237,13 @@
SOURCES = $(libndn_c_la_SOURCES) $(libndn_cpp_la_SOURCES) \
$(bin_test_encode_decode_data_SOURCES) \
$(bin_test_encode_decode_interest_SOURCES) \
- $(bin_test_get_async_SOURCES)
+ $(bin_test_get_async_SOURCES) \
+ $(bin_test_publish_async_SOURCES)
DIST_SOURCES = $(libndn_c_la_SOURCES) $(libndn_cpp_la_SOURCES) \
$(bin_test_encode_decode_data_SOURCES) \
$(bin_test_encode_decode_interest_SOURCES) \
- $(bin_test_get_async_SOURCES)
+ $(bin_test_get_async_SOURCES) \
+ $(bin_test_publish_async_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
@@ -509,6 +515,8 @@
bin_test_encode_decode_data_LDADD = libndn-cpp.la libndn-c.la
bin_test_get_async_SOURCES = tests/test-get-async.cpp
bin_test_get_async_LDADD = libndn-cpp.la libndn-c.la
+bin_test_publish_async_SOURCES = tests/test-publish-async.cpp
+bin_test_publish_async_LDADD = libndn-cpp.la libndn-c.la
dist_noinst_SCRIPTS = autogen.sh
all: config.h
$(MAKE) $(AM_MAKEFLAGS) all-am
@@ -806,6 +814,12 @@
bin/test-get-async$(EXEEXT): $(bin_test_get_async_OBJECTS) $(bin_test_get_async_DEPENDENCIES) $(EXTRA_bin_test_get_async_DEPENDENCIES) bin/$(am__dirstamp)
@rm -f bin/test-get-async$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(bin_test_get_async_OBJECTS) $(bin_test_get_async_LDADD) $(LIBS)
+tests/test-publish-async.$(OBJEXT): tests/$(am__dirstamp) \
+ tests/$(DEPDIR)/$(am__dirstamp)
+
+bin/test-publish-async$(EXEEXT): $(bin_test_publish_async_OBJECTS) $(bin_test_publish_async_DEPENDENCIES) $(EXTRA_bin_test_publish_async_DEPENDENCIES) bin/$(am__dirstamp)
+ @rm -f bin/test-publish-async$(EXEEXT)
+ $(AM_V_CXXLD)$(CXXLINK) $(bin_test_publish_async_OBJECTS) $(bin_test_publish_async_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
@@ -865,6 +879,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/test-encode-decode-data.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/test-encode-decode-interest.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/test-get-async.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/test-publish-async.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
diff --git a/tests/test-publish-async.cpp b/tests/test-publish-async.cpp
new file mode 100644
index 0000000..a7ba291
--- /dev/null
+++ b/tests/test-publish-async.cpp
@@ -0,0 +1,61 @@
+/**
+ * @author: Jeff Thompson
+ * See COPYING for copyright and distribution information.
+ */
+
+#include <cstdlib>
+#include <sstream>
+#include <iostream>
+#include <time.h>
+#include "../ndn-cpp/face.hpp"
+#include "../ndn-cpp/key-chain.hpp"
+
+using namespace std;
+using namespace ndn;
+using namespace ptr_lib;
+using namespace func_lib;
+
+class Echo {
+public:
+ Echo()
+ {
+ interestCount_ = 0;
+ }
+
+ void operator()(const ptr_lib::shared_ptr<const Name> &prefix, const ptr_lib::shared_ptr<const Interest> &interest) {
+ ++interestCount_;
+
+ // Make and sign a Data packet.
+ Data data(interest->getName());
+ string content(string("Echo ") + interest->getName().toUri());
+ data.setContent((const unsigned char*)&content[0], sizeof(content));
+ data.getSignedInfo().setTimestampMilliseconds(time(NULL) * 1000.0);
+ KeyChain::defaultSign(data);
+
+ // TODO: Need to put the Data.
+ }
+
+ int interestCount_;
+};
+
+int main(int argc, char** argv)
+{
+ try {
+ Face face("localhost");
+
+ Echo echo;
+ Name prefix("/testecho");
+ cout << "Register prefix " << prefix.toUri() << endl;
+ face.registerPrefix(prefix, ref(echo));
+
+ // The main event loop.
+ while (echo.interestCount_ < 1) {
+ face.processEvents();
+ // We need to sleep for a few milliseconds so we don't use 100% of the CPU.
+ usleep(10000);
+ }
+ } catch (std::exception &e) {
+ cout << "exception: " << e.what() << endl;
+ }
+ return 0;
+}