forked from cawka/ndn.cxx
diff --git a/example/.gitignore b/example/.gitignore
new file mode 100644
index 0000000..8ed876c
--- /dev/null
+++ b/example/.gitignore
@@ -0,0 +1,2 @@
+build/
+.waf*
diff --git a/example/client.cc b/example/client.cc
new file mode 100644
index 0000000..279d260
--- /dev/null
+++ b/example/client.cc
@@ -0,0 +1,72 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ * Alexander Afanasyev
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include <ndn.cxx.h>
+#include <iostream>
+
+using namespace std;
+
+const char *FILENAME = NULL;
+ndn::Name InterestBaseName;
+
+// create a global handler
+ndn::Wrapper handler;
+
+void OnData (ndn::Name name, ndn::PcoPtr pco);
+void OnTimeout (ndn::Name name, const ndn::Closure &closure, ndn::InterestPtr origInterest);
+
+void OnData (ndn::Name name, ndn::PcoPtr pco)
+{
+ ndn::BytesPtr content = pco->contentPtr ();
+ cout << string ((char*)ndn::head (*content), content->size ());
+
+ int seqnum = ndn::Name::asSeqNum (*name.rbegin ());
+ if (seqnum >= 10)
+ {
+ return;
+ }
+
+ cerr << ">> C++ " << ndn::Name (InterestBaseName).appendSeqNum (seqnum + 1) << endl; // a shortcut to construct name
+ handler.sendInterest (ndn::Interest ()
+ .setName (ndn::Name (InterestBaseName).appendSeqNum (seqnum + 1))
+ .setScope (ndn::Interest::SCOPE_LOCAL_HOST),
+ ndn::Closure (OnData, OnTimeout));
+}
+
+void OnTimeout (ndn::Name name, const ndn::Closure &closure, ndn::InterestPtr origInterest)
+{
+ // re-express interest
+ handler.sendInterest (*origInterest, closure);
+}
+
+int
+main (int argc, char **argv)
+{
+ if (argc < 2)
+ {
+ std::cerr << "You have to specify filename as an argument" << std::endl;
+ return -1;
+ }
+
+ // this code does not check for most of the bad conditions
+ FILENAME = argv[1];
+
+ InterestBaseName = ndn::Name ("/my-local-prefix/simple-fetch/file");
+ InterestBaseName.append (FILENAME);
+
+ cerr << ">> C++ " << ndn::Name (InterestBaseName).appendSeqNum (0) << endl;
+ handler.sendInterest (ndn::Interest ()
+ .setName (ndn::Name (InterestBaseName).appendSeqNum (0))
+ .setScope (ndn::Interest::SCOPE_LOCAL_HOST),
+ ndn::Closure (OnData, OnTimeout));
+
+ sleep (3);
+ return 0;
+}
diff --git a/example/server.cc b/example/server.cc
new file mode 100644
index 0000000..1a62f20
--- /dev/null
+++ b/example/server.cc
@@ -0,0 +1,45 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ * Alexander Afanasyev
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include <ndn.cxx.h>
+#include <iostream>
+
+using namespace std;
+
+ndn::Name InterestBaseName;
+
+// create a global handler
+ndn::Wrapper handler;
+
+void OnInterest (ndn::InterestPtr interest)
+{
+ cerr << interest->getName () << endl;
+
+ static int COUNTER = 0;
+
+ ostringstream os;
+ os << "C++ LINE #" << (COUNTER++) << endl;
+
+ handler.publishData (interest->getName (), os.str (), 5);
+}
+
+int
+main (int argc, char **argv)
+{
+ InterestBaseName = ndn::Name ("ccnx:/my-local-prefix/simple-fetch/file");
+
+ handler.setInterestFilter (InterestBaseName, OnInterest);
+
+ while (true)
+ {
+ sleep (1);
+ }
+ return 0;
+}
diff --git a/example/waf b/example/waf
new file mode 100755
index 0000000..f26d925
--- /dev/null
+++ b/example/waf
Binary files differ
diff --git a/example/wscript b/example/wscript
new file mode 100644
index 0000000..c617d47
--- /dev/null
+++ b/example/wscript
@@ -0,0 +1,66 @@
+# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+VERSION='0.1'
+APPNAME='test-project'
+
+from waflib import Build, Logs, Utils, Task, TaskGen, Configure
+
+def options(opt):
+ opt.load('compiler_c compiler_cxx boost ccnx')
+
+def configure(conf):
+ conf.load("compiler_c compiler_cxx ccnx")
+
+ conf.add_supported_cxxflags (cxxflags = ['-O0',
+ '-Wall',
+ '-Wno-unused-variable',
+ '-g3',
+ '-Wno-unused-private-field',
+ '-fcolor-diagnostics',
+ '-Qunused-arguments'
+ ])
+
+ if not conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='SSL', mandatory=False):
+ libcrypto = conf.check_cc(lib='crypto',
+ header_name='openssl/crypto.h',
+ define_name='HAVE_SSL',
+ uselib_store='SSL')
+ else:
+ conf.define ("HAVE_SSL", 1)
+ if not conf.get_define ("HAVE_SSL"):
+ conf.fatal ("Cannot find SSL libraries")
+
+ conf.check_ccnx (path=conf.options.ccnx_dir)
+ conf.check_cfg(package='libndn.cxx', args=['--cflags', '--libs'], uselib_store='CCNXCPP', mandatory=True)
+
+ conf.load('boost')
+ conf.check_boost(lib='system test iostreams filesystem thread')
+
+def build (bld):
+ bld (
+ features = ["cxx", "cxxprogram"],
+ target = "client",
+ source = "client.cc",
+ use = 'BOOST BOOST_THREAD CCNX CCNXCPP',
+ )
+
+ bld (
+ features = ["cxx", "cxxprogram"],
+ target = "server",
+ source = "server.cc",
+ use = 'BOOST BOOST_THREAD CCNX CCNXCPP',
+ )
+
+@Configure.conf
+def add_supported_cxxflags(self, cxxflags):
+ """
+ Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
+ """
+ self.start_msg('Checking allowed flags for c++ compiler')
+
+ supportedFlags = []
+ for flag in cxxflags:
+ if self.check_cxx (cxxflags=[flag], mandatory=False):
+ supportedFlags += [flag]
+
+ self.end_msg (' '.join (supportedFlags))
+ self.env.CXXFLAGS += supportedFlags