implementing getLocalPrefix method
diff --git a/ccnx/sync-ccnx-wrapper.cc b/ccnx/sync-ccnx-wrapper.cc
index 4759903..c27aeb3 100644
--- a/ccnx/sync-ccnx-wrapper.cc
+++ b/ccnx/sync-ccnx-wrapper.cc
@@ -21,6 +21,11 @@
*/
#include "sync-ccnx-wrapper.h"
+
+extern "C" {
+#include <ccn/fetch.h>
+}
+
#include "sync-log.h"
#include <poll.h>
#include <boost/throw_exception.hpp>
@@ -455,6 +460,76 @@
ccn_charbuf_destroy(&pname);
}
+string
+CcnxWrapper::getLocalPrefix ()
+{
+ recursive_mutex::scoped_lock lock(m_mutex);
+
+ string retval = "";
+
+ struct ccn_charbuf *templ = ccn_charbuf_create();
+ ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
+ ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
+ ccn_charbuf_append_closer(templ); /* </Name> */
+ // XXX - use pubid if possible
+ ccn_charbuf_append_tt(templ, CCN_DTAG_MaxSuffixComponents, CCN_DTAG);
+ ccnb_append_number(templ, 1);
+ ccn_charbuf_append_closer(templ); /* </MaxSuffixComponents> */
+ ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", 2);
+ ccn_charbuf_append_closer(templ); /* </Interest> */
+
+ struct ccn_charbuf *name = ccn_charbuf_create ();
+ int res = ccn_name_from_uri (name, "/local/ndn/prefix");
+ if (res < 0) {
+ _LOG_ERROR ("Something wrong with `ccn_name_from_uri` call");
+ }
+ else
+ {
+ struct ccn_fetch *fetch = ccn_fetch_new (m_handle);
+
+ struct ccn_fetch_stream *stream = ccn_fetch_open (fetch, name, "/local/ndn/prefix",
+ templ, 4, CCN_V_HIGHEST, 0);
+ if (stream == NULL) {
+ _LOG_ERROR ("Cannot create ccn_fetch_stream");
+ }
+ else
+ {
+ ostringstream os;
+
+ char buf[256];
+ while ((res = ccn_fetch_read (stream, buf, sizeof(buf))) != 0) {
+ if (res > 0) {
+ os << string(buf, res);
+ } else if (res == CCN_FETCH_READ_NONE) {
+ fflush(stdout);
+ if (ccn_run (m_handle, 1000) < 0) {
+ _LOG_ERROR ("error during ccn_run");
+ break;
+ }
+ } else if (res == CCN_FETCH_READ_END) {
+ break;
+ } else if (res == CCN_FETCH_READ_TIMEOUT) {
+ break;
+ } else {
+ _LOG_ERROR ("fatal error. should be reported");
+ break;
+ }
+ }
+ retval = os.str ();
+ stream = ccn_fetch_close(stream);
+ }
+ fetch = ccn_fetch_destroy(fetch);
+ }
+
+ ccn_charbuf_destroy (&name);
+
+ return retval;
+}
+
+
+
+
+
DataClosurePass::DataClosurePass (CallbackType type, int retry, const CcnxWrapper::StringDataCallback &strDataCallback): ClosurePass(type, retry), m_callback(NULL)
{
m_callback = new CcnxWrapper::StringDataCallback (strDataCallback);