Upgrade the underlying NFD to version 0.5.0
Change-Id: I61eb240cb982eb5e675a63aece0c373290c59129
Refs: #3839
diff --git a/app/src/main/jni/ndn-cxx-android/ndn-cxx-config.hpp b/app/src/main/jni/ndn-cxx-android/ndn-cxx-config.hpp
index 92a02e8..f669a93 100644
--- a/app/src/main/jni/ndn-cxx-android/ndn-cxx-config.hpp
+++ b/app/src/main/jni/ndn-cxx-android/ndn-cxx-config.hpp
@@ -1,16 +1,17 @@
#ifndef W_SRC_NDN_CXX_CONFIG_HPP_WAF
#define W_SRC_NDN_CXX_CONFIG_HPP_WAF
+#define NDN_CXX_HAVE_STD_TO_STRING 1
+#define NDN_CXX_HAVE_VECTOR_INSERT_ERASE_CONST_ITERATOR 1
#define NDN_CXX_HAVE_IS_DEFAULT_CONSTRUCTIBLE 1
#define NDN_CXX_HAVE_IS_NOTHROW_MOVE_CONSTRUCTIBLE 1
#define NDN_CXX_HAVE_IS_NOTHROW_MOVE_ASSIGNABLE 1
-#define NDN_CXX_HAVE_CXX_FRIEND_TYPENAME 1
-#define NDN_CXX_HAVE_CXX_OVERRIDE_FINAL 1
-#define NDN_CXX_NDN_CXX_HAVE_VECTOR_INSERT_ERASE_CONST_ITERATOR 1
-#define NDN_CXX_HAVE_PTHREAD 1
#define NDN_CXX_HAVE_RT
+#define NDN_CXX_HAVE_PTHREAD 1
#define NDN_CXX_HAVE_SQLITE3 1
-#define NDN_CXX_HAVE_CRYPTOPP_CONFIG_H 1
#define NDN_CXX_SYSCONFDIR "./etc"
+#define NDN_CXX_NDEBUG 1
+#define NDEBUG 1
+#define HAVE_NDN_CXX_CUSTOM_LOGGER 1
#endif /* W_SRC_NDN_CXX_CONFIG_HPP_WAF */
diff --git a/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logger.cpp b/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logger.cpp
new file mode 100644
index 0000000..41cae15
--- /dev/null
+++ b/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logger.cpp
@@ -0,0 +1,88 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2016 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "ndn-cxx-custom-logger.hpp"
+#include "ndn-cxx-custom-logging.hpp"
+
+#include <cinttypes>
+#include <stdio.h>
+#include <type_traits>
+
+namespace ndn {
+namespace util {
+
+std::ostream&
+operator<<(std::ostream& os, LogLevel level)
+{
+ switch (level) {
+ case LogLevel::FATAL:
+ return os << "FATAL";
+ case LogLevel::NONE:
+ return os << "NONE";
+ case LogLevel::ERROR:
+ return os << "ERROR";
+ case LogLevel::WARN:
+ return os << "WARN";
+ case LogLevel::INFO:
+ return os << "INFO";
+ case LogLevel::DEBUG:
+ return os << "DEBUG";
+ case LogLevel::TRACE:
+ return os << "TRACE";
+ case LogLevel::ALL:
+ return os << "ALL";
+ }
+
+ BOOST_THROW_EXCEPTION(std::invalid_argument("unknown log level " + to_string(static_cast<int>(level))));
+}
+
+LogLevel
+parseLogLevel(const std::string& s)
+{
+ if (s == "FATAL")
+ return LogLevel::FATAL;
+ else if (s == "NONE")
+ return LogLevel::NONE;
+ else if (s == "ERROR")
+ return LogLevel::ERROR;
+ else if (s == "WARN")
+ return LogLevel::WARN;
+ else if (s == "INFO")
+ return LogLevel::INFO;
+ else if (s == "DEBUG")
+ return LogLevel::DEBUG;
+ else if (s == "TRACE")
+ return LogLevel::TRACE;
+ else if (s == "ALL")
+ return LogLevel::ALL;
+
+ BOOST_THROW_EXCEPTION(std::invalid_argument("unrecognized log level '" + s + "'"));
+}
+
+Logger::Logger(const std::string& name)
+ : m_moduleName(name)
+{
+ this->setLevel(LogLevel::NONE);
+ Logging::addLogger(*this);
+}
+
+} // namespace util
+} // namespace ndn
diff --git a/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logger.hpp b/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logger.hpp
new file mode 100644
index 0000000..892c1d5
--- /dev/null
+++ b/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logger.hpp
@@ -0,0 +1,121 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2016 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#ifndef NFD_ANDROID_NDN_CXX_ANDROID_NDN_CXX_CUSTOM_LOGGER_HPP
+#define NFD_ANDROID_NDN_CXX_ANDROID_NDN_CXX_CUSTOM_LOGGER_HPP
+
+#include "common.hpp"
+#include <atomic>
+#include <android/log.h>
+
+namespace ndn {
+namespace util {
+
+/** \brief indicates the severity level of a log message
+ */
+enum class LogLevel {
+ FATAL = -1, ///< fatal (will be logged unconditionally)
+ NONE = 0, ///< no messages
+ ERROR = 1, ///< serious error messages
+ WARN = 2, ///< warning messages
+ INFO = 3, ///< informational messages
+ DEBUG = 4, ///< debug messages
+ TRACE = 5, ///< trace messages (most verbose)
+ ALL = 255 ///< all messages
+};
+
+/** \brief output LogLevel as string
+ * \throw std::invalid_argument unknown \p level
+ */
+std::ostream&
+operator<<(std::ostream& os, LogLevel level);
+
+/** \brief parse LogLevel from string
+ * \throw std::invalid_argument unknown level name
+ */
+LogLevel
+parseLogLevel(const std::string& s);
+
+/** \brief represents a logger in logging facility
+ * \note User should declare a new logger with \p NDN_LOG_INIT macro.
+ */
+class Logger
+{
+public:
+ explicit
+ Logger(const std::string& name);
+
+ const std::string&
+ getModuleName() const
+ {
+ return m_moduleName;
+ }
+
+ bool
+ isLevelEnabled(LogLevel level) const
+ {
+ return m_currentLevel.load(std::memory_order_relaxed) >= level;
+ }
+
+ void
+ setLevel(LogLevel level)
+ {
+ m_currentLevel.store(level, std::memory_order_relaxed);
+ }
+
+private:
+ const std::string m_moduleName;
+ std::atomic<LogLevel> m_currentLevel;
+};
+
+/** \brief declare a log module
+ */
+#define NDN_LOG_INIT(name) \
+ namespace { \
+ inline ::ndn::util::Logger& getNdnCxxLogger() \
+ { \
+ static ::ndn::util::Logger logger(BOOST_STRINGIZE(name)); \
+ return logger; \
+ } \
+ } \
+ struct ndn_cxx__allow_trailing_semicolon
+
+#define NDN_LOG(level, androidLevel, msg, expression) \
+ do { \
+ if (getNdnCxxLogger().isLevelEnabled(::ndn::util::LogLevel::level)) { \
+ std::ostringstream os; \
+ os << expression; \
+ __android_log_print(ANDROID_LOG_##androidLevel, \
+ getNdnCxxLogger().getModuleName().c_str(), "%s", os.str().c_str()); \
+ } \
+ } while (false)
+
+#define NDN_LOG_TRACE(expression) NDN_LOG(TRACE, VERBOSE, TRACE, expression)
+#define NDN_LOG_DEBUG(expression) NDN_LOG(DEBUG, DEBUG, DEBUG, expression)
+#define NDN_LOG_INFO(expression) NDN_LOG(INFO, INFO, INFO, expression)
+#define NDN_LOG_WARN(expression) NDN_LOG(WARN, WARN, WARNING, expression)
+#define NDN_LOG_ERROR(expression) NDN_LOG(ERROR, ERROR, ERROR, expression)
+#define NDN_LOG_FATAL(expression) NDN_LOG(FATAL, FATAL, FATAL, expression)
+
+} // namespace util
+} // namespace ndn
+
+#endif // NFD_ANDROID_NDN_CXX_ANDROID_NDN_CXX_CUSTOM_LOGGER_HPP
diff --git a/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logging.cpp b/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logging.cpp
new file mode 100644
index 0000000..845d412
--- /dev/null
+++ b/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logging.cpp
@@ -0,0 +1,109 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2016 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "ndn-cxx-custom-logging.hpp"
+#include "ndn-cxx-custom-logger.hpp"
+
+#include <cstdlib>
+#include <sstream>
+
+namespace ndn {
+namespace util {
+
+static const LogLevel INITIAL_DEFAULT_LEVEL = LogLevel::NONE;
+
+Logging&
+Logging::get()
+{
+ // Initialization of block-scope variables with static storage duration is thread-safe.
+ // See ISO C++ standard [stmt.dcl]/4
+ static Logging instance;
+ return instance;
+}
+
+Logging::Logging()
+{
+}
+
+void
+Logging::addLoggerImpl(Logger& logger)
+{
+ std::lock_guard<std::mutex> lock(m_mutex);
+
+ const std::string& moduleName = logger.getModuleName();
+ m_loggers.insert({moduleName, &logger});
+
+ auto levelIt = m_enabledLevel.find(moduleName);
+ if (levelIt == m_enabledLevel.end()) {
+ levelIt = m_enabledLevel.find("*");
+ }
+ LogLevel level = levelIt == m_enabledLevel.end() ? INITIAL_DEFAULT_LEVEL : levelIt->second;
+ logger.setLevel(level);
+}
+
+void
+Logging::setLevelImpl(const std::string& moduleName, LogLevel level)
+{
+ std::lock_guard<std::mutex> lock(m_mutex);
+
+ if (moduleName == "*") {
+ this->setDefaultLevel(level);
+ return;
+ }
+
+ m_enabledLevel[moduleName] = level;
+ auto range = m_loggers.equal_range(moduleName);
+ for (auto i = range.first; i != range.second; ++i) {
+ i->second->setLevel(level);
+ }
+}
+
+void
+Logging::setDefaultLevel(LogLevel level)
+{
+ m_enabledLevel.clear();
+ m_enabledLevel["*"] = level;
+
+ for (auto i = m_loggers.begin(); i != m_loggers.end(); ++i) {
+ i->second->setLevel(level);
+ }
+}
+
+void
+Logging::setLevelImpl(const std::string& config)
+{
+ std::stringstream ss(config);
+ std::string configModule;
+ while (std::getline(ss, configModule, ':')) {
+ size_t ind = configModule.find('=');
+ if (ind == std::string::npos) {
+ BOOST_THROW_EXCEPTION(std::invalid_argument("malformed logging config: '=' is missing"));
+ }
+
+ std::string moduleName = configModule.substr(0, ind);
+ LogLevel level = parseLogLevel(configModule.substr(ind+1));
+
+ this->setLevelImpl(moduleName, level);
+ }
+}
+
+} // namespace util
+} // namespace ndn
diff --git a/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logging.hpp b/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logging.hpp
new file mode 100644
index 0000000..b59b927
--- /dev/null
+++ b/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logging.hpp
@@ -0,0 +1,126 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2016 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#ifndef NFD_ANDROID_NDN_CXX_ANDROID_NDN_CXX_CUSTOM_LOGGING_HPP
+#define NFD_ANDROID_NDN_CXX_ANDROID_NDN_CXX_CUSTOM_LOGGING_HPP
+
+#include "common.hpp"
+
+#include <mutex>
+#include <unordered_map>
+
+namespace ndn {
+namespace util {
+
+enum class LogLevel;
+class Logger;
+
+/** \brief controls the logging facility
+ *
+ * \note Public static methods are thread safe.
+ * Non-public methods are not guaranteed to be thread safe.
+ */
+class Logging : noncopyable
+{
+public:
+ /** \brief register a new logger
+ * \note App should declare a new logger with \p NDN_LOG_INIT macro.
+ */
+ static void
+ addLogger(Logger& logger);
+
+ /** \brief set severity level
+ * \param moduleName logger name, or "*" for default level
+ * \param level minimum severity level
+ *
+ * Log messages are output only if its severity is greater than the set minimum severity level.
+ * Initial default severity level is \p LogLevel::NONE which enables FATAL only.
+ *
+ * Changing the default level overwrites individual settings.
+ */
+ static void
+ setLevel(const std::string& moduleName, LogLevel level);
+
+ /** \brief set severity levels with a config string
+ * \param config colon-separate key=value pairs
+ * \throw std::invalid_argument config string is malformed
+ *
+ * \code
+ * Logging::setSeverityLevels("*=INFO:Face=DEBUG:NfdController=WARN");
+ * \endcode
+ * is equivalent to
+ * \code
+ * Logging::setSeverityLevel("*", LogLevel::INFO);
+ * Logging::setSeverityLevel("Face", LogLevel::DEBUG);
+ * Logging::setSeverityLevel("NfdController", LogLevel::WARN);
+ * \endcode
+ */
+ static void
+ setLevel(const std::string& config);
+
+private:
+ Logging();
+
+ void
+ addLoggerImpl(Logger& logger);
+
+ void
+ setLevelImpl(const std::string& moduleName, LogLevel level);
+
+ void
+ setDefaultLevel(LogLevel level);
+
+ void
+ setLevelImpl(const std::string& config);
+
+NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
+ static Logging&
+ get();
+
+private:
+ std::mutex m_mutex;
+ std::unordered_map<std::string, LogLevel> m_enabledLevel; ///< moduleName => minimum level
+ std::unordered_multimap<std::string, Logger*> m_loggers; ///< moduleName => logger
+};
+
+inline void
+Logging::addLogger(Logger& logger)
+{
+ get().addLoggerImpl(logger);
+}
+
+inline void
+Logging::setLevel(const std::string& moduleName, LogLevel level)
+{
+ get().setLevelImpl(moduleName, level);
+}
+
+inline void
+Logging::setLevel(const std::string& config)
+{
+ get().setLevelImpl(config);
+}
+
+
+} // namespace util
+} // namespace ndn
+
+#endif // NFD_ANDROID_NDN_CXX_ANDROID_NDN_CXX_CUSTOM_LOGGING_HPP