New Qt5-based implementation
Change-Id: I1a165aacd8c8254a250a14a2024fecf50c986abe
diff --git a/qt/Resources/emblem-dropbox-unsyncable.png b/qt4/Resources/emblem-dropbox-unsyncable.png
similarity index 100%
rename from qt/Resources/emblem-dropbox-unsyncable.png
rename to qt4/Resources/emblem-dropbox-unsyncable.png
Binary files differ
diff --git a/qt/Resources/emblem-system.png b/qt4/Resources/emblem-system.png
similarity index 100%
rename from qt/Resources/emblem-system.png
rename to qt4/Resources/emblem-system.png
Binary files differ
diff --git a/qt/Resources/emblem-web.png b/qt4/Resources/emblem-web.png
similarity index 100%
rename from qt/Resources/emblem-web.png
rename to qt4/Resources/emblem-web.png
Binary files differ
diff --git a/qt/Resources/gnome-system.png b/qt4/Resources/gnome-system.png
similarity index 100%
rename from qt/Resources/gnome-system.png
rename to qt4/Resources/gnome-system.png
Binary files differ
diff --git a/qt/Resources/icon-connected-white.png b/qt4/Resources/icon-connected-white.png
similarity index 100%
rename from qt/Resources/icon-connected-white.png
rename to qt4/Resources/icon-connected-white.png
Binary files differ
diff --git a/qt/Resources/icon-disconnected-white.png b/qt4/Resources/icon-disconnected-white.png
similarity index 100%
rename from qt/Resources/icon-disconnected-white.png
rename to qt4/Resources/icon-disconnected-white.png
Binary files differ
diff --git a/qt/Resources/mail-send-receive.png b/qt4/Resources/mail-send-receive.png
similarity index 100%
rename from qt/Resources/mail-send-receive.png
rename to qt4/Resources/mail-send-receive.png
Binary files differ
diff --git a/qt/Resources/ndnx-main.png b/qt4/Resources/ndnx-main.png
similarity index 100%
rename from qt/Resources/ndnx-main.png
rename to qt4/Resources/ndnx-main.png
Binary files differ
diff --git a/qt/Resources/ndnx-main.xpm b/qt4/Resources/ndnx-main.xpm
similarity index 100%
rename from qt/Resources/ndnx-main.xpm
rename to qt4/Resources/ndnx-main.xpm
diff --git a/qt/Resources/preferences-desktop.png b/qt4/Resources/preferences-desktop.png
similarity index 100%
rename from qt/Resources/preferences-desktop.png
rename to qt4/Resources/preferences-desktop.png
Binary files differ
diff --git a/qt/Resources/status-to-fib.xslt b/qt4/Resources/status-to-fib.xslt
similarity index 100%
rename from qt/Resources/status-to-fib.xslt
rename to qt4/Resources/status-to-fib.xslt
diff --git a/qt/Resources/status.xslt b/qt4/Resources/status.xslt
similarity index 100%
rename from qt/Resources/status.xslt
rename to qt4/Resources/status.xslt
diff --git a/qt/Resources/system-run.png b/qt4/Resources/system-run.png
similarity index 100%
rename from qt/Resources/system-run.png
rename to qt4/Resources/system-run.png
Binary files differ
diff --git a/qt/disabled/fib-input-dialog.cpp b/qt4/disabled/fib-input-dialog.cpp
similarity index 100%
rename from qt/disabled/fib-input-dialog.cpp
rename to qt4/disabled/fib-input-dialog.cpp
diff --git a/qt/disabled/fib-input-dialog.hpp b/qt4/disabled/fib-input-dialog.hpp
similarity index 100%
rename from qt/disabled/fib-input-dialog.hpp
rename to qt4/disabled/fib-input-dialog.hpp
diff --git a/qt/main.cpp b/qt4/main.cpp
similarity index 100%
rename from qt/main.cpp
rename to qt4/main.cpp
diff --git a/qt/network-manager.cpp b/qt4/network-manager.cpp
similarity index 100%
rename from qt/network-manager.cpp
rename to qt4/network-manager.cpp
diff --git a/qt/network-manager.hpp b/qt4/network-manager.hpp
similarity index 100%
rename from qt/network-manager.hpp
rename to qt4/network-manager.hpp
diff --git a/qt/nfd-control-center.desktop.in b/qt4/nfd-control-center.desktop.in
similarity index 100%
rename from qt/nfd-control-center.desktop.in
rename to qt4/nfd-control-center.desktop.in
diff --git a/qt/quit-dialog.cpp b/qt4/quit-dialog.cpp
similarity index 100%
rename from qt/quit-dialog.cpp
rename to qt4/quit-dialog.cpp
diff --git a/qt/quit-dialog.hpp b/qt4/quit-dialog.hpp
similarity index 100%
rename from qt/quit-dialog.hpp
rename to qt4/quit-dialog.hpp
diff --git a/qt/resource.qrc b/qt4/resource.qrc
similarity index 100%
rename from qt/resource.qrc
rename to qt4/resource.qrc
diff --git a/qt/tray-menu.cpp b/qt4/tray-menu.cpp
similarity index 100%
rename from qt/tray-menu.cpp
rename to qt4/tray-menu.cpp
diff --git a/qt/tray-menu.hpp b/qt4/tray-menu.hpp
similarity index 100%
rename from qt/tray-menu.hpp
rename to qt4/tray-menu.hpp
diff --git a/qt/traymenu.ui b/qt4/traymenu.ui
similarity index 100%
rename from qt/traymenu.ui
rename to qt4/traymenu.ui
diff --git a/qt/wscript b/qt4/wscript
similarity index 100%
rename from qt/wscript
rename to qt4/wscript
diff --git a/qt5/app.icns b/qt5/app.icns
new file mode 100644
index 0000000..ececc16
--- /dev/null
+++ b/qt5/app.icns
Binary files differ
diff --git a/qt5/fib-status.cpp b/qt5/fib-status.cpp
new file mode 100644
index 0000000..eaae8af
--- /dev/null
+++ b/qt5/fib-status.cpp
@@ -0,0 +1,170 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014, Regents of the University of California,
+ *
+ * This file is part of NFD Control Center. See AUTHORS.md for complete list of NFD
+ * authors and contributors.
+ *
+ * NFD Control Center is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD Control Center 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NFD
+ * Control Center, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "fib-status.hpp"
+
+#ifdef WAF
+#include "fib-status.moc"
+// #include "fib-status.cpp.moc"
+#endif
+
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/name.hpp>
+#include <ndn-cxx/interest.hpp>
+#include <ndn-cxx/encoding/buffer-stream.hpp>
+#include <ndn-cxx/management/nfd-fib-entry.hpp>
+#include <ndn-cxx/management/nfd-face-status.hpp>
+#include <ndn-cxx/management/nfd-forwarder-status.hpp>
+
+namespace ndn {
+
+FibStatusModel::FibStatusModel(Face& face, QObject *parent/* = 0*/)
+ : QAbstractListModel(parent)
+ , m_face(face)
+{
+}
+
+int
+FibStatusModel::rowCount(const QModelIndex &parent/* = QModelIndex()*/) const
+{
+ return m_items.count();
+}
+
+void
+FibStatusModel::addItem(const FibStatusItem &item)
+{
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ m_items << item;
+ endInsertRows();
+}
+
+QVariant
+FibStatusModel::data(const QModelIndex & index, int role) const
+{
+ if (index.row() < 0 || index.row() >= m_items.count()) {
+ return QVariant();
+ }
+
+ const FibStatusItem &item = m_items.at(index.row());
+ if (role == PrefixRole) {
+ return item.prefix();
+ } else if (role == FaceIdRole) {
+ return item.faceId();
+ } else if (role == CostRole) {
+ return item.cost();
+ }
+
+ return QVariant();
+}
+
+QHash<int, QByteArray>
+FibStatusModel::roleNames() const
+{
+ QHash<int, QByteArray> roles;
+ roles[PrefixRole] = "prefix";
+ roles[FaceIdRole] = "faceId";
+ roles[CostRole] = "cost";
+ return roles;
+}
+
+void
+FibStatusModel::clear()
+{
+ beginResetModel();
+ m_items.clear();
+ endResetModel();
+}
+
+Q_INVOKABLE void
+FibStatusModel::fetchFibInformation()
+{
+ // m_buffer = make_shared<OBufferStream>();
+
+ // Interest interest("/localhost/nfd/fib/list");
+ // interest.setChildSelector(1);
+ // interest.setMustBeFresh(true);
+ // m_face.expressInterest(interest,
+ // bind(&FibStatusModel::fetchSegments, this, _2,
+ // &FibStatusModel::afterFetchedFibEnumerationInformation),
+ // bind(&FibStatusModel::onTimeout, this));
+ // try {
+ // m_face.processEvents();
+ // } catch (Tlv::Error e) {
+ // std::cerr << e.what() << std::endl;
+ // clear();
+ // }
+}
+
+void
+FibStatusModel::afterFetchedFibEnumerationInformation()
+{
+// beginResetModel();
+// m_items.clear();
+// ConstBufferPtr buf = m_buffer->buf();
+
+// Block block;
+// size_t offset = 0;
+// while (offset < buf->size()) {
+// bool ok = Block::fromBuffer(buf, offset, block);
+// if (!ok) {
+// std::cerr << "ERROR: cannot decode FibEntry TLV" << std::endl;
+// break;
+// }
+// offset += block.size();
+
+// nfd::FibEntry fibEntry(block);
+
+// for (std::list<nfd::NextHopRecord>::const_iterator
+// nextHop = fibEntry.getNextHopRecords().begin();
+// nextHop != fibEntry.getNextHopRecords().end();
+// ++nextHop) {
+// addItem(FibStatusItem(QString::fromStdString(fibEntry.getPrefix().toUri()),
+// nextHop->getFaceId(), nextHop->getCost()));
+// }
+// }
+// endResetModel();
+}
+
+
+void
+FibStatusModel::fetchSegments(const Data& data, void (FibStatusModel::*onDone)())
+{
+ // m_buffer->write(reinterpret_cast<const char*>(data.getContent().value()),
+ // data.getContent().value_size());
+
+ // uint64_t currentSegment = data.getName().get(-1).toSegment();
+
+ // const name::Component& finalBlockId = data.getMetaInfo().getFinalBlockId();
+ // if (finalBlockId.empty() ||
+ // finalBlockId.toSegment() > currentSegment) {
+ // m_face.expressInterest(data.getName().getPrefix(-1).appendSegment(currentSegment+1),
+ // bind(&FibStatusModel::fetchSegments, this, _2, onDone),
+ // bind(&FibStatusModel::onTimeout, this));
+ // } else {
+ // return (this->*onDone)();
+ // }
+}
+
+void
+FibStatusModel::onTimeout()
+{
+ std::cerr << "Request timed out" << std::endl;
+}
+
+} // namespace ndn
diff --git a/qt5/fib-status.hpp b/qt5/fib-status.hpp
new file mode 100644
index 0000000..0ebd80e
--- /dev/null
+++ b/qt5/fib-status.hpp
@@ -0,0 +1,113 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014, Regents of the University of California,
+ *
+ * This file is part of NFD Control Center. See AUTHORS.md for complete list of NFD
+ * authors and contributors.
+ *
+ * NFD Control Center is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD Control Center 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NFD
+ * Control Center, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NCC_FIB_STATUS_HPP
+#define NCC_FIB_STATUS_HPP
+
+#include <QtCore/QAbstractListModel>
+#include <QtCore/QStringList>
+
+namespace ndn {
+class Face;
+class Data;
+
+class FibStatusItem
+{
+public:
+ FibStatusItem(const QString &prefix, uint64_t faceId, uint64_t cost)
+ : m_prefix(prefix)
+ , m_faceId(faceId)
+ , m_cost(cost)
+ {
+ }
+
+ const QString&
+ prefix() const
+ {
+ return m_prefix;
+ }
+
+ uint64_t
+ faceId() const
+ {
+ return m_faceId;
+ }
+
+ uint64_t
+ cost() const
+ {
+ return m_cost;
+ }
+
+private:
+ QString m_prefix;
+ uint64_t m_faceId;
+ uint64_t m_cost;
+};
+
+class FibStatusModel : public QAbstractListModel
+{
+ Q_OBJECT
+
+public:
+ enum FibStatusRoles {
+ PrefixRole = Qt::UserRole + 1,
+ FaceIdRole,
+ CostRole
+ };
+
+ explicit
+ FibStatusModel(Face& face, QObject *parent = 0);
+
+ int
+ rowCount(const QModelIndex &parent = QModelIndex()) const;
+
+ void
+ addItem(const FibStatusItem &item);
+
+ QVariant
+ data(const QModelIndex & index, int role) const;
+
+ QHash<int, QByteArray>
+ roleNames() const;
+
+ void
+ clear();
+
+ Q_INVOKABLE void
+ fetchFibInformation();
+
+ void
+ afterFetchedFibEnumerationInformation();
+
+ void
+ fetchSegments(const Data& data, void (FibStatusModel::*onDone)());
+
+ void
+ onTimeout();
+
+private:
+ Face& m_face;
+ QList<FibStatusItem> m_items;
+ // shared_ptr<OBufferStream> m_buffer;
+};
+
+} // namespace ndn
+
+#endif // NCC_FIB_STATUS_HPP
diff --git a/qt5/forwarder-status.cpp b/qt5/forwarder-status.cpp
new file mode 100644
index 0000000..300c29e
--- /dev/null
+++ b/qt5/forwarder-status.cpp
@@ -0,0 +1,135 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014, Regents of the University of California,
+ *
+ * This file is part of NFD Control Center. See AUTHORS.md for complete list of NFD
+ * authors and contributors.
+ *
+ * NFD Control Center is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD Control Center 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NFD
+ * Control Center, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "forwarder-status.hpp"
+
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/name.hpp>
+#include <ndn-cxx/interest.hpp>
+#include <ndn-cxx/management/nfd-fib-entry.hpp>
+#include <ndn-cxx/management/nfd-face-status.hpp>
+#include <ndn-cxx/management/nfd-forwarder-status.hpp>
+
+#ifdef WAF
+#include "forwarder-status.moc"
+// #include "forwarder-status.cpp.moc"
+#endif
+
+namespace ndn {
+
+ForwarderStatusModel::ForwarderStatusModel(Face& face, QObject* parent/* = 0*/)
+ : QAbstractListModel(parent)
+ , m_face(face)
+{
+ connect(this, SIGNAL(onDataReceived(ndn::shared_ptr<const ndn::Data>)), this,
+ SLOT(updateStatus(ndn::shared_ptr<const ndn::Data>)));
+}
+
+int
+ForwarderStatusModel::rowCount(const QModelIndex& parent/* = QModelIndex()*/) const
+{
+ return m_items.count();
+}
+
+void
+ForwarderStatusModel::addItem(const ForwarderStatusItem& item)
+{
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ m_items << item;
+ endInsertRows();
+}
+
+QVariant
+ForwarderStatusModel::data(const QModelIndex& index, int role) const
+{
+ if (index.row() < 0 || index.row() >= m_items.count()) {
+ return QVariant();
+ }
+
+ const ForwarderStatusItem& item = m_items.at(index.row());
+ if (role == TypeRole) {
+ return item.type();
+ }
+ else if (role == ValueRole) {
+ return item.value();
+ }
+ return QVariant();
+}
+
+QHash<int, QByteArray>
+ForwarderStatusModel::roleNames() const
+{
+ QHash<int, QByteArray> roles;
+ roles[TypeRole] = "type";
+ roles[ValueRole] = "value";
+ return roles;
+}
+
+Q_INVOKABLE void
+ForwarderStatusModel::fetchVersionInformation()
+{
+ Interest interest("/localhost/nfd/status");
+ interest.setMustBeFresh(true);
+ m_face.expressInterest(interest,
+ bind(&ForwarderStatusModel::afterFetchedVersionInformation, this, _2),
+ bind(&ForwarderStatusModel::onTimeout, this, _1));
+}
+
+void
+ForwarderStatusModel::clear()
+{
+ beginResetModel();
+ m_items.clear();
+ endResetModel ();
+}
+
+void
+ForwarderStatusModel::afterFetchedVersionInformation(const Data& data)
+{
+ emit onDataReceived(data.shared_from_this());
+}
+
+void
+ForwarderStatusModel::updateStatus(shared_ptr<const Data> data)
+{
+ beginResetModel();
+ m_items.clear();
+ nfd::ForwarderStatus status(data->getContent());
+ addItem(ForwarderStatusItem("version", QString::number(status.getNfdVersion())));
+ addItem(ForwarderStatusItem("startTime", QString::fromStdString(time::toIsoString(status.getStartTimestamp()))));
+ addItem(ForwarderStatusItem("currentTime", QString::fromStdString(time::toIsoString(status.getCurrentTimestamp()))));
+ addItem(ForwarderStatusItem("nNameTreeEntries", QString::number(status.getNNameTreeEntries())));
+ addItem(ForwarderStatusItem("nFibEntries", QString::number(status.getNFibEntries())));
+ addItem(ForwarderStatusItem("nPitEntries", QString::number(status.getNPitEntries())));
+ addItem(ForwarderStatusItem("nMeasurementsEntries", QString::number(status.getNMeasurementsEntries())));
+ addItem(ForwarderStatusItem("nCsEntries", QString::number(status.getNCsEntries())));
+ addItem(ForwarderStatusItem("nInInterests", QString::number(status.getNInInterests())));
+ addItem(ForwarderStatusItem("nOutInterests", QString::number(status.getNOutInterests())));
+ addItem(ForwarderStatusItem("nInDatas", QString::number(status.getNInDatas())));
+ addItem(ForwarderStatusItem("nOutDatas", QString::number(status.getNOutDatas())));
+ endResetModel();
+}
+
+void
+ForwarderStatusModel::onTimeout(const Interest& interest)
+{
+ std::cerr << "Request timed out (should not really happen)" << std::endl;
+}
+
+} // namespace ndn
diff --git a/qt5/forwarder-status.hpp b/qt5/forwarder-status.hpp
new file mode 100644
index 0000000..2c3f3b6
--- /dev/null
+++ b/qt5/forwarder-status.hpp
@@ -0,0 +1,111 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014, Regents of the University of California,
+ *
+ * This file is part of NFD Control Center. See AUTHORS.md for complete list of NFD
+ * authors and contributors.
+ *
+ * NFD Control Center is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD Control Center 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NFD
+ * Control Center, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NCC_FORWARDER_STATUS_HPP
+#define NCC_FORWARDER_STATUS_HPP
+
+#include <QtCore/QAbstractListModel>
+#include <QtCore/QStringList>
+
+#include <ndn-cxx/face.hpp>
+
+namespace ndn {
+
+class ForwarderStatusItem
+{
+public:
+ ForwarderStatusItem(const QString& type, const QString& value)
+ : m_type(type)
+ , m_value(value)
+ {
+ }
+
+ const QString&
+ type() const
+ {
+ return m_type;
+ }
+
+ const QString&
+ value() const
+ {
+ return m_value;
+ }
+
+private:
+ QString m_type;
+ QString m_value;
+};
+
+
+class ForwarderStatusModel : public QAbstractListModel
+{
+ Q_OBJECT
+
+signals:
+ void
+ onDataReceived(ndn::shared_ptr<const ndn::Data>);
+
+public:
+
+ enum ForwarderStatusRoles {
+ TypeRole = Qt::UserRole + 1,
+ ValueRole
+ };
+
+ explicit
+ ForwarderStatusModel(Face& face, QObject* parent = 0);
+
+ int
+ rowCount(const QModelIndex& parent = QModelIndex()) const;
+
+ void
+ addItem(const ForwarderStatusItem& item);
+
+ QVariant
+ data(const QModelIndex& index, int role) const;
+
+ QHash<int, QByteArray>
+ roleNames() const;
+
+ Q_INVOKABLE void
+ fetchVersionInformation();
+
+ void
+ clear();
+
+ void
+ afterFetchedVersionInformation(const Data& data);
+
+ void
+ onTimeout(const Interest& interest);
+
+private slots:
+
+ void
+ updateStatus(ndn::shared_ptr<const ndn::Data> data);
+
+private:
+ Face& m_face;
+ QList<ForwarderStatusItem> m_items;
+};
+
+} // namespace ndn
+
+#endif // NCC_FORWARDER_STATUS_HPP
diff --git a/qt5/main.cpp b/qt5/main.cpp
new file mode 100644
index 0000000..81a7ba6
--- /dev/null
+++ b/qt5/main.cpp
@@ -0,0 +1,144 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014, Regents of the University of California,
+ *
+ * This file is part of NFD Control Center. See AUTHORS.md for complete list of NFD
+ * authors and contributors.
+ *
+ * NFD Control Center is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD Control Center 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NFD
+ * Control Center, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <QtQml/QQmlApplicationEngine>
+#include <QtWidgets/QApplication>
+#include <QtQml/QQmlContext>
+
+#include "forwarder-status.hpp"
+#include "fib-status.hpp"
+#include "tray-menu.hpp"
+
+#include <ndn-cxx/face.hpp>
+#include <boost/thread.hpp>
+
+namespace ndn {
+
+class Ncc
+{
+public:
+ Ncc()
+ : m_isActive(true)
+ , m_forwarderModel(m_face)
+ , m_fibModel(m_face)
+ {
+ QQmlContext* context = m_engine.rootContext();
+
+ context->setContextProperty("forwarderModel", &m_forwarderModel);
+ context->setContextProperty("fibModel", &m_fibModel);
+ context->setContextProperty("trayModel", &m_tray);
+
+ m_engine.load((QUrl("qrc:/main.qml")));
+
+ m_nfdThread = boost::thread(&Ncc::nfdConnectionLoop, this);
+ }
+
+ void
+ nfdConnectionLoop()
+ {
+ try {
+#ifdef BOOST_THREAD_USES_CHRONO
+ time::seconds retryTimeout = time::seconds(5);
+#else
+ boost::posix_time::time_duration retryTimeout = boost::posix_time::seconds(1);
+#endif
+
+ while (m_isActive) {
+ try {
+ while (m_isActive) {
+ m_face.expressInterest(Interest("/localhost/nfd/status"),
+ bind(&Ncc::onStatusRetrieved, this),
+ bind(&Ncc::onStatusTimeout, this));
+ m_face.processEvents(time::milliseconds::zero(), true);
+ }
+ }
+ catch (const std::exception&) {
+ emit m_tray.nfdActivityUpdate(false);
+#ifdef BOOST_THREAD_USES_CHRONO
+ boost::this_thread::sleep_for(retryTimeout);
+#else
+ boost::this_thread::sleep(retryTimeout);
+#endif
+ }
+ }
+ }
+ catch (const boost::thread_interrupted&) {
+ // done
+ }
+ }
+
+ void
+ onStatusRetrieved()
+ {
+ emit m_tray.nfdActivityUpdate(true);
+ }
+
+ void
+ onStatusTimeout()
+ {
+ emit m_tray.nfdActivityUpdate(false);
+
+ std::cerr << "Should not really happen, most likely a serious problem" << std::endl;
+ m_face.expressInterest(Interest("/localhost/nfd/status"),
+ bind(&Ncc::onStatusRetrieved, this),
+ bind(&Ncc::onStatusTimeout, this));
+ }
+
+ void
+ stop()
+ {
+ m_isActive = false;
+ m_face.shutdown();
+ m_nfdThread.interrupt();
+ m_nfdThread.join();
+ }
+
+private:
+ volatile bool m_isActive;
+ boost::thread m_nfdThread;
+
+ Face m_face;
+
+ QQmlApplicationEngine m_engine;
+
+ ForwarderStatusModel m_forwarderModel;
+ FibStatusModel m_fibModel;
+ TrayMenu m_tray;
+};
+
+} // namespace ndn
+
+Q_DECLARE_METATYPE(ndn::shared_ptr<const ndn::Data>)
+
+int
+main(int argc, char *argv[])
+{
+ qRegisterMetaType<ndn::shared_ptr<const ndn::Data> >();
+
+ QApplication app(argc, argv);
+
+ ndn::Ncc controlCenterGui;
+
+ QApplication::setQuitOnLastWindowClosed(false);
+ int retval = app.exec();
+
+ controlCenterGui.stop();
+
+ return retval;
+}
diff --git a/qt5/main.qml b/qt5/main.qml
new file mode 100644
index 0000000..c7a151f
--- /dev/null
+++ b/qt5/main.qml
@@ -0,0 +1,175 @@
+import QtQuick 2.2
+import QtQuick.Window 2.1
+import QtQuick.Controls 1.1
+import QtQuick.Layouts 1.0
+
+ApplicationWindow {
+ visible: false
+ id: window
+ title: "NFD Control Center"
+ minimumWidth: 600
+ minimumHeight: 400
+
+ TabView {
+ anchors.fill: parent
+ anchors.topMargin: 20
+ anchors.bottomMargin: 20
+ anchors.leftMargin: 20
+ anchors.rightMargin: 20
+
+ Tab {
+ title: "General"
+ ColumnLayout {
+ anchors.fill: parent
+ GroupBox {
+ title: "Basic"
+ id: checkboxControl
+ anchors.top: parent.top
+ anchors.left: parent.left
+ anchors.right: parent.right
+ anchors.topMargin: 20
+ anchors.leftMargin: 20
+ anchors.rightMargin: 20
+ anchors.bottomMargin: 20
+ Column {
+ spacing: 5
+ anchors.fill: parent
+ anchors.topMargin: 10
+ anchors.bottomMargin: 10
+ anchors.leftMargin: 10
+ anchors.rightMargin: 10
+ CheckBox {
+ id: startOnLogin
+ enabled: false
+ text: "Automatically start NFD Control Center on login"
+ }
+ CheckBox {
+ id: discoverHub
+ text: "Discover nearest NDN hub"
+ onCheckedChanged: {
+ if (this.checked) {
+ trayModel.autoConfig()
+ }
+ }
+ }
+ CheckBox {
+ id: checkUpdate
+ enabled: false
+ text: "Check for software updates"
+ }
+ }
+ }
+ GroupBox {
+ title: "Status"
+ id: status
+ anchors.top: checkboxControl.bottom
+ anchors.left: parent.left
+ anchors.right: parent.right
+ anchors.topMargin: 20
+ anchors.leftMargin: 20
+ anchors.rightMargin: 20
+ anchors.bottomMargin: 20
+ Row {
+ spacing: 20
+ anchors.topMargin: 10
+ anchors.leftMargin: 10
+ anchors.rightMargin: 10
+ anchors.bottomMargin: 10
+ anchors.fill: parent
+ Button {
+ text: "Traffic map"
+ onClicked: Qt.openUrlExternally('http://ndnmap.arl.wustl.edu')
+ }
+ Button {
+ text: "Routing status"
+ onClicked: Qt.openUrlExternally('http://netlab.cs.memphis.edu/script/htm/status.htm')
+ }
+ }
+ }
+ }
+ }
+ Tab {
+ title: "FIB status"
+ TableView {
+ anchors.fill: parent
+ anchors.topMargin: 20
+ anchors.bottomMargin: 20
+ anchors.leftMargin: 20
+ anchors.rightMargin: 20
+ TableViewColumn{
+ role: "prefix"
+ title: "NDN prefix"
+ width: 300
+ }
+ TableViewColumn{
+ role: "faceId"
+ title: "Face ID"
+ width: 50
+ }
+ TableViewColumn{
+ role: "cost"
+ title: "Cost"
+ width: 50
+ }
+ model: fibModel
+ }
+ }
+ Tab {
+ title: "Forwarder status"
+ TableView {
+ anchors.fill: parent
+ anchors.topMargin: 20
+ anchors.bottomMargin: 20
+ anchors.leftMargin: 20
+ anchors.rightMargin: 20
+ model: forwarderModel
+ TableViewColumn{
+ role: "type"
+ title: "Type"
+ width: 200
+ }
+ TableViewColumn{
+ role: "value"
+ title: "Value"
+ width: 200
+ }
+ }
+ }
+ Tab {
+ title: "Security"
+ Column {
+ spacing: 2
+ anchors.fill: parent
+ anchors.topMargin: 20
+ anchors.bottomMargin: 20
+ anchors.leftMargin: 20
+ anchors.rightMargin: 20
+ Button {
+ text: "Obtain NDN Certificate"
+ onClicked: Qt.openUrlExternally('http://ndncert.named-data.net')
+ }
+ }
+ }
+ }
+ Connections {
+ target: trayModel;
+ onShowApp: {
+ window.show()
+ window.raise()
+ }
+ }
+ Timer {
+ interval: 1000; running: true; repeat: true
+ onTriggered: {
+ trayModel.checkNfdRunning()
+ fibModel.fetchFibInformation()
+ }
+ }
+
+ Timer {
+ interval: 5500; running: true; repeat: true
+ onTriggered: {
+ forwarderModel.fetchVersionInformation()
+ }
+ }
+}
diff --git a/qt/nfd-control-center.desktop.in b/qt5/nfd-control-center.desktop.in
similarity index 100%
copy from qt/nfd-control-center.desktop.in
copy to qt5/nfd-control-center.desktop.in
diff --git a/qt5/qml.qrc b/qt5/qml.qrc
new file mode 100644
index 0000000..19a180f
--- /dev/null
+++ b/qt5/qml.qrc
@@ -0,0 +1,13 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ <file>resources/icon-connected-white.png</file>
+ <file>resources/icon-disconnected-white.png</file>
+ <file>resources/GenericNetworkIcon_22_128x128x32.png</file>
+ <file>resources/Keychain_22_128x128x32.png</file>
+ <file>resources/System Preferences_22_128x128x32.png</file>
+ <file>resources/ToolbarAdvanced_22_128x128x32.png</file>
+ <file>resources/icon-connected-black.png</file>
+ <file>resources/icon-disconnected-black.png</file>
+ </qresource>
+</RCC>
diff --git a/qt5/resources/GenericNetworkIcon_22_128x128x32.png b/qt5/resources/GenericNetworkIcon_22_128x128x32.png
new file mode 100644
index 0000000..35bc465
--- /dev/null
+++ b/qt5/resources/GenericNetworkIcon_22_128x128x32.png
Binary files differ
diff --git a/qt5/resources/Keychain_22_128x128x32.png b/qt5/resources/Keychain_22_128x128x32.png
new file mode 100644
index 0000000..fbb89eb
--- /dev/null
+++ b/qt5/resources/Keychain_22_128x128x32.png
Binary files differ
diff --git a/qt5/resources/System Preferences_22_128x128x32.png b/qt5/resources/System Preferences_22_128x128x32.png
new file mode 100644
index 0000000..54bec62
--- /dev/null
+++ b/qt5/resources/System Preferences_22_128x128x32.png
Binary files differ
diff --git a/qt5/resources/ToolbarAdvanced_22_128x128x32.png b/qt5/resources/ToolbarAdvanced_22_128x128x32.png
new file mode 100644
index 0000000..1ea369f
--- /dev/null
+++ b/qt5/resources/ToolbarAdvanced_22_128x128x32.png
Binary files differ
diff --git a/qt5/resources/icon-connected-black.png b/qt5/resources/icon-connected-black.png
new file mode 100644
index 0000000..3ce424f
--- /dev/null
+++ b/qt5/resources/icon-connected-black.png
Binary files differ
diff --git a/qt/Resources/icon-connected-white.png b/qt5/resources/icon-connected-white.png
similarity index 100%
copy from qt/Resources/icon-connected-white.png
copy to qt5/resources/icon-connected-white.png
Binary files differ
diff --git a/qt5/resources/icon-disconnected-black.png b/qt5/resources/icon-disconnected-black.png
new file mode 100644
index 0000000..0670f42
--- /dev/null
+++ b/qt5/resources/icon-disconnected-black.png
Binary files differ
diff --git a/qt/Resources/icon-disconnected-white.png b/qt5/resources/icon-disconnected-white.png
similarity index 100%
copy from qt/Resources/icon-disconnected-white.png
copy to qt5/resources/icon-disconnected-white.png
Binary files differ
diff --git a/qt5/tray-menu.cpp b/qt5/tray-menu.cpp
new file mode 100644
index 0000000..43c5727
--- /dev/null
+++ b/qt5/tray-menu.cpp
@@ -0,0 +1,153 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014, Regents of the University of California,
+ *
+ * This file is part of NFD Control Center. See AUTHORS.md for complete list of NFD
+ * authors and contributors.
+ *
+ * NFD Control Center is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD Control Center 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NFD
+ * Control Center, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.hpp"
+#include "tray-menu.hpp"
+
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/interest.hpp>
+
+
+#ifdef OSX_BUILD
+#define CONNECT_ICON ":/resources/icon-connected-black.png"
+#define DISCONNECT_ICON ":/resources/icon-disconnected-black.png"
+#else
+#define CONNECT_ICON ":/resources/icon-connected-white.png"
+#define DISCONNECT_ICON ":/resources/icon-disconnected-white.png"
+#endif
+
+#ifdef WAF
+#include "tray-menu.moc"
+// #include "tray-menu.cpp.moc"
+#endif
+
+namespace ndn {
+
+TrayMenu::TrayMenu()
+{
+ menu = new QMenu(this);
+ pref = new QAction("Preferences...", menu);
+ quit = new QAction("Quit", menu);
+
+ // connect(start, SIGNAL(triggered()), this, SLOT(startNfd()));
+ // connect(stop, SIGNAL(triggered()), this, SLOT(stopNfd()));
+ connect(pref, SIGNAL(triggered()), this, SIGNAL(showApp()));
+ connect(quit, SIGNAL(triggered()), this, SLOT(quitApp()));
+
+ connect(this, SIGNAL(nfdActivityUpdate(bool)), this, SLOT(updateNfdActivityIcon(bool)));
+
+ // menu->addAction(start);
+ // menu->addAction(stop);
+ menu->addAction(pref);
+ menu->addAction(quit);
+ tray = new QSystemTrayIcon(this);
+ tray->setContextMenu(menu);
+ connect(tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
+ this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
+ tray->setIcon(QIcon(DISCONNECT_ICON));
+ tray->show();
+}
+
+TrayMenu::~TrayMenu()
+{
+}
+
+Q_INVOKABLE void
+TrayMenu::checkNfdRunning()
+{
+ // Face face;
+ // Interest interest("/localhost/nfd/status");
+ // face.expressInterest(interest, 0, 0);
+ // try {
+ // face.processEvents();
+ // tray->setIcon(QIcon(CONNECT_ICON));
+ // } catch (Tlv::Error) {
+ // tray->setIcon(QIcon(DISCONNECT_ICON));
+ // }
+}
+
+Q_INVOKABLE void
+TrayMenu::autoConfig()
+{
+ std::cout << "auto config" <<std::endl;
+ QProcess* proc = new QProcess();
+ connect(proc,SIGNAL(finished(int)), proc, SLOT(deleteLater()));
+ proc->start(NFD_AUTOCONFIG_COMMAND);
+}
+
+void
+TrayMenu::quitApp()
+{
+ QCoreApplication::exit(0);
+}
+
+void
+TrayMenu::iconActivated(QSystemTrayIcon::ActivationReason reason)
+{
+ switch (reason) {
+ // case QSystemTrayIcon::Trigger:
+ // emit showApp();
+ // break;
+ case QSystemTrayIcon::Context:
+ break;
+ default:
+ break;
+ }
+}
+
+void
+TrayMenu::startNfd()
+{
+ QProcess * proc = new QProcess();
+ connect(proc,SIGNAL(finished(int)), proc, SLOT(deleteLater()));
+#ifdef __linux__
+ proc->start("gksudo", QStringList() << NFD_START_COMMAND);
+#else
+ proc->start("osascript", QStringList()
+ << "-e"
+ << "do shell script \"" NFD_START_COMMAND "\" with administrator privileges");
+#endif
+}
+
+void
+TrayMenu::stopNfd()
+{
+ QProcess * proc = new QProcess();
+ connect(proc,SIGNAL(finished(int)), proc, SLOT(deleteLater()));
+#ifdef __linux__
+ proc->start("gksudo", QStringList() << NFD_STOP_COMMAND);
+#else
+ proc->start("osascript", QStringList()
+ << "-e"
+ << "do shell script \"" NFD_STOP_COMMAND "\" with administrator privileges");
+#endif
+}
+
+void
+TrayMenu::updateNfdActivityIcon(bool isActive)
+{
+ if (isActive) {
+ tray->setIcon(QIcon(CONNECT_ICON));
+ }
+ else {
+ tray->setIcon(QIcon(DISCONNECT_ICON));
+ }
+}
+
+} // namespace ndn
diff --git a/qt5/tray-menu.hpp b/qt5/tray-menu.hpp
new file mode 100644
index 0000000..b4c2c33
--- /dev/null
+++ b/qt5/tray-menu.hpp
@@ -0,0 +1,83 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014, Regents of the University of California,
+ *
+ * This file is part of NFD Control Center. See AUTHORS.md for complete list of NFD
+ * authors and contributors.
+ *
+ * NFD Control Center is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD Control Center 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NFD
+ * Control Center, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NCC_TRAY_MENU_HPP
+#define NCC_TRAY_MENU_HPP
+
+#include <QtCore/QObject>
+#include <QtCore/QProcess>
+#include <QtCore/QCoreApplication>
+
+#include <QtWidgets/QSystemTrayIcon>
+#include <QtWidgets/QAction>
+#include <QtWidgets/QMenu>
+
+namespace ndn {
+
+class TrayMenu : public QWidget
+{
+ Q_OBJECT
+
+signals:
+ void
+ showApp();
+
+ void
+ nfdActivityUpdate(bool isActive);
+
+public:
+ TrayMenu();
+
+ ~TrayMenu();
+
+ Q_INVOKABLE void
+ checkNfdRunning();
+
+ Q_INVOKABLE void
+ autoConfig();
+
+private slots:
+
+ void
+ quitApp();
+
+ void
+ iconActivated(QSystemTrayIcon::ActivationReason reason);
+
+ void
+ startNfd();
+
+ void
+ stopNfd();
+
+ void
+ updateNfdActivityIcon(bool isActive);
+
+private:
+ QSystemTrayIcon *tray;
+ QMenu* menu;
+ QAction* pref;
+ QAction* quit;
+ // QAction* start;
+ // QAction* stop;
+};
+
+} // namespace ndn
+
+#endif // NCC_TRAY_MENU_HPP
diff --git a/qt5/wscript b/qt5/wscript
new file mode 100644
index 0000000..2447fa8
--- /dev/null
+++ b/qt5/wscript
@@ -0,0 +1,46 @@
+# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+from waflib import Logs, Utils, Task, TaskGen
+
+top = '..'
+
+def configure(conf):
+ conf.load(['gnu_dirs', 'qt5'])
+
+ conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
+ uselib_store='NDN_CXX', mandatory=True)
+
+ conf.define('RESOURCES_DIR', Utils.subst_vars("${DATAROOTDIR}/nfd-control-center", conf.env))
+
+ if Utils.unversioned_sys_platform() == "darwin":
+ conf.define('OSX_BUILD', 1)
+
+def build(bld):
+ app = bld(
+ features=['qt5', 'cxxprogram', 'cxx'],
+ includes = ".. .",
+
+ use = "NDN_CXX BOOST QT5CORE QT5DBUS QT5QML QT5WIDGETS",
+
+ defines = "WAF",
+ source = bld.path.ant_glob(['*.cpp', '**/*.qrc', '**/*.ui', '**/*.qrc']),
+ )
+
+ if Utils.unversioned_sys_platform() != "darwin":
+ app.target = "../nfd-control-center",
+
+ bld(features = "subst",
+ source = 'nfd-control-center.desktop.in',
+ target = 'nfd-control-center.desktop',
+ BINARY = "nfd-control-center",
+ install_path = "${DATAROOTDIR}/nfd-control-center"
+ )
+
+ bld.install_files("${DATAROOTDIR}/nfd-control-center",
+ bld.path.ant_glob(['Resources/*']))
+ else:
+ app.target = "../NFD Control Center"
+ app.mac_app = True
+ app.mac_plist = '../osx/Info.plist'
+ app.mac_resources = [i.path_from(bld.path)
+ for i in bld.path.parent.ant_glob('osx/Resources/*')]
diff --git a/waf b/waf
index f916f71..7828844 100755
--- a/waf
+++ b/waf
Binary files differ
diff --git a/waf-tools/boost.py b/waf-tools/boost.py
new file mode 100644
index 0000000..305945a
--- /dev/null
+++ b/waf-tools/boost.py
@@ -0,0 +1,378 @@
+#!/usr/bin/env python
+# encoding: utf-8
+#
+# partially based on boost.py written by Gernot Vormayr
+# written by Ruediger Sonderfeld <ruediger@c-plusplus.de>, 2008
+# modified by Bjoern Michaelsen, 2008
+# modified by Luca Fossati, 2008
+# rewritten for waf 1.5.1, Thomas Nagy, 2008
+# rewritten for waf 1.6.2, Sylvain Rouquette, 2011
+
+'''
+
+This is an extra tool, not bundled with the default waf binary.
+To add the boost tool to the waf file:
+$ ./waf-light --tools=compat15,boost
+ or, if you have waf >= 1.6.2
+$ ./waf update --files=boost
+
+When using this tool, the wscript will look like:
+
+ def options(opt):
+ opt.load('compiler_cxx boost')
+
+ def configure(conf):
+ conf.load('compiler_cxx boost')
+ conf.check_boost(lib='system filesystem')
+
+ def build(bld):
+ bld(source='main.cpp', target='app', use='BOOST')
+
+Options are generated, in order to specify the location of boost includes/libraries.
+The `check_boost` configuration function allows to specify the used boost libraries.
+It can also provide default arguments to the --boost-static and --boost-mt command-line arguments.
+Everything will be packaged together in a BOOST component that you can use.
+
+When using MSVC, a lot of compilation flags need to match your BOOST build configuration:
+ - you may have to add /EHsc to your CXXFLAGS or define boost::throw_exception if BOOST_NO_EXCEPTIONS is defined.
+ Errors: C4530
+ - boost libraries will try to be smart and use the (pretty but often not useful) auto-linking feature of MSVC
+ So before calling `conf.check_boost` you might want to disabling by adding:
+ conf.env.DEFINES_BOOST += ['BOOST_ALL_NO_LIB']
+ Errors:
+ - boost might also be compiled with /MT, which links the runtime statically.
+ If you have problems with redefined symbols,
+ self.env['DEFINES_%s' % var] += ['BOOST_ALL_NO_LIB']
+ self.env['CXXFLAGS_%s' % var] += ['/MD', '/EHsc']
+Passing `--boost-linkage_autodetect` might help ensuring having a correct linkage in some basic cases.
+
+'''
+
+import sys
+import re
+from waflib import Utils, Logs, Errors
+from waflib.Configure import conf
+
+BOOST_LIBS = ['/usr/lib', '/usr/local/lib', '/opt/local/lib', '/sw/lib', '/lib', '/usr/lib/x86_64-linux-gnu', '/usr/lib/i386-linux-gnu', '/usr/local/ndn/lib']
+BOOST_INCLUDES = ['/usr/include', '/usr/local/include', '/opt/local/include', '/sw/include', '/usr/local/ndn/include']
+BOOST_VERSION_FILE = 'boost/version.hpp'
+BOOST_VERSION_CODE = '''
+#include <iostream>
+#include <boost/version.hpp>
+int main() { std::cout << BOOST_LIB_VERSION << ":" << BOOST_VERSION << std::endl; }
+'''
+BOOST_SYSTEM_CODE = '''
+#include <boost/system/error_code.hpp>
+int main() { boost::system::error_code c; }
+'''
+BOOST_THREAD_CODE = '''
+#include <boost/thread.hpp>
+int main() { boost::thread t; }
+'''
+
+# toolsets from {boost_dir}/tools/build/v2/tools/common.jam
+PLATFORM = Utils.unversioned_sys_platform()
+detect_intel = lambda env: (PLATFORM == 'win32') and 'iw' or 'il'
+detect_clang = lambda env: (PLATFORM == 'darwin') and 'clang-darwin' or 'clang'
+detect_mingw = lambda env: (re.search('MinGW', env.CXX[0])) and 'mgw' or 'gcc'
+BOOST_TOOLSETS = {
+ 'borland': 'bcb',
+ 'clang': detect_clang,
+ 'como': 'como',
+ 'cw': 'cw',
+ 'darwin': 'xgcc',
+ 'edg': 'edg',
+ 'g++': detect_mingw,
+ 'gcc': detect_mingw,
+ 'icpc': detect_intel,
+ 'intel': detect_intel,
+ 'kcc': 'kcc',
+ 'kylix': 'bck',
+ 'mipspro': 'mp',
+ 'mingw': 'mgw',
+ 'msvc': 'vc',
+ 'qcc': 'qcc',
+ 'sun': 'sw',
+ 'sunc++': 'sw',
+ 'tru64cxx': 'tru',
+ 'vacpp': 'xlc'
+}
+
+
+def options(opt):
+ opt = opt.add_option_group('Boost Options')
+
+ opt.add_option('--boost-includes', type='string',
+ default='', dest='boost_includes',
+ help='''path to the directory where the boost includes are, e.g., /path/to/boost_1_55_0/stage/include''')
+ opt.add_option('--boost-libs', type='string',
+ default='', dest='boost_libs',
+ help='''path to the directory where the boost libs are, e.g., /path/to/boost_1_55_0/stage/lib''')
+ opt.add_option('--boost-static', action='store_true',
+ default=False, dest='boost_static',
+ help='link with static boost libraries (.lib/.a)')
+ opt.add_option('--boost-mt', action='store_true',
+ default=False, dest='boost_mt',
+ help='select multi-threaded libraries')
+ opt.add_option('--boost-abi', type='string', default='', dest='boost_abi',
+ help='''select libraries with tags (dgsyp, d for debug), see doc Boost, Getting Started, chapter 6.1''')
+ opt.add_option('--boost-linkage_autodetect', action="store_true", dest='boost_linkage_autodetect',
+ help="auto-detect boost linkage options (don't get used to it / might break other stuff)")
+ opt.add_option('--boost-toolset', type='string',
+ default='', dest='boost_toolset',
+ help='force a toolset e.g. msvc, vc90, gcc, mingw, mgw45 (default: auto)')
+ py_version = '%d%d' % (sys.version_info[0], sys.version_info[1])
+ opt.add_option('--boost-python', type='string',
+ default=py_version, dest='boost_python',
+ help='select the lib python with this version (default: %s)' % py_version)
+
+
+@conf
+def __boost_get_version_file(self, d):
+ dnode = self.root.find_dir(d)
+ if dnode:
+ return dnode.find_node(BOOST_VERSION_FILE)
+ return None
+
+@conf
+def boost_get_version(self, d):
+ """silently retrieve the boost version number"""
+ node = self.__boost_get_version_file(d)
+ if node:
+ try:
+ txt = node.read()
+ except (OSError, IOError):
+ Logs.error("Could not read the file %r" % node.abspath())
+ else:
+ re_but1 = re.compile('^#define\\s+BOOST_LIB_VERSION\\s+"(.+)"', re.M)
+ m1 = re_but1.search(txt)
+
+ re_but2 = re.compile('^#define\\s+BOOST_VERSION\\s+(\\d+)', re.M)
+ m2 = re_but2.search(txt)
+
+ if m1 and m2:
+ return (m1.group(1), m2.group(1))
+
+ return self.check_cxx(fragment=BOOST_VERSION_CODE, includes=[d], execute=True, define_ret=True).split(":")
+
+@conf
+def boost_get_includes(self, *k, **kw):
+ includes = k and k[0] or kw.get('includes', None)
+ if includes and self.__boost_get_version_file(includes):
+ return includes
+ for d in Utils.to_list(self.environ.get('INCLUDE', '')) + BOOST_INCLUDES:
+ if self.__boost_get_version_file(d):
+ return d
+ if includes:
+ self.end_msg('headers not found in %s' % includes)
+ self.fatal('The configuration failed')
+ else:
+ self.end_msg('headers not found, please provide a --boost-includes argument (see help)')
+ self.fatal('The configuration failed')
+
+
+@conf
+def boost_get_toolset(self, cc):
+ toolset = cc
+ if not cc:
+ build_platform = Utils.unversioned_sys_platform()
+ if build_platform in BOOST_TOOLSETS:
+ cc = build_platform
+ else:
+ cc = self.env.CXX_NAME
+ if cc in BOOST_TOOLSETS:
+ toolset = BOOST_TOOLSETS[cc]
+ return isinstance(toolset, str) and toolset or toolset(self.env)
+
+
+@conf
+def __boost_get_libs_path(self, *k, **kw):
+ ''' return the lib path and all the files in it '''
+ if 'files' in kw:
+ return self.root.find_dir('.'), Utils.to_list(kw['files'])
+ libs = k and k[0] or kw.get('libs', None)
+ if libs:
+ path = self.root.find_dir(libs)
+ files = path.ant_glob('*boost_*')
+ if not libs or not files:
+ for d in Utils.to_list(self.environ.get('LIB', [])) + BOOST_LIBS:
+ path = self.root.find_dir(d)
+ if path:
+ files = path.ant_glob('*boost_*')
+ if files:
+ break
+ path = self.root.find_dir(d + '64')
+ if path:
+ files = path.ant_glob('*boost_*')
+ if files:
+ break
+ if not path:
+ if libs:
+ self.end_msg('libs not found in %s' % libs)
+ self.fatal('The configuration failed')
+ else:
+ self.end_msg('libs not found, please provide a --boost-libs argument (see help)')
+ self.fatal('The configuration failed')
+
+ self.to_log('Found the boost path in %r with the libraries:' % path)
+ for x in files:
+ self.to_log(' %r' % x)
+ return path, files
+
+@conf
+def boost_get_libs(self, *k, **kw):
+ '''
+ return the lib path and the required libs
+ according to the parameters
+ '''
+ path, files = self.__boost_get_libs_path(**kw)
+ t = []
+ if kw.get('mt', False):
+ t.append('mt')
+ if kw.get('abi', None):
+ t.append(kw['abi'])
+ tags = t and '(-%s)+' % '-'.join(t) or ''
+ toolset = self.boost_get_toolset(kw.get('toolset', ''))
+ toolset_pat = '(-%s[0-9]{0,3})+' % toolset
+ version = '(-%s)+' % self.env.BOOST_VERSION
+
+ def find_lib(re_lib, files):
+ for file in files:
+ if re_lib.search(file.name):
+ self.to_log('Found boost lib %s' % file)
+ return file
+ return None
+
+ def format_lib_name(name):
+ if name.startswith('lib') and self.env.CC_NAME != 'msvc':
+ name = name[3:]
+ return name[:name.rfind('.')]
+
+ libs = []
+ for lib in Utils.to_list(k and k[0] or kw.get('lib', None)):
+ py = (lib == 'python') and '(-py%s)+' % kw['python'] or ''
+ # Trying libraries, from most strict match to least one
+ for pattern in ['boost_%s%s%s%s%s' % (lib, toolset_pat, tags, py, version),
+ 'boost_%s%s%s%s' % (lib, tags, py, version),
+ 'boost_%s%s%s' % (lib, tags, version),
+ # Give up trying to find the right version
+ 'boost_%s%s%s%s' % (lib, toolset_pat, tags, py),
+ 'boost_%s%s%s' % (lib, tags, py),
+ 'boost_%s%s' % (lib, tags)]:
+ self.to_log('Trying pattern %s' % pattern)
+ file = find_lib(re.compile(pattern), files)
+ if file:
+ libs.append(format_lib_name(file.name))
+ break
+ else:
+ self.end_msg('lib %s not found in %s' % (lib, path.abspath()))
+ self.fatal('The configuration failed')
+
+ return path.abspath(), libs
+
+
+@conf
+def check_boost(self, *k, **kw):
+ """
+ Initialize boost libraries to be used.
+
+ Keywords: you can pass the same parameters as with the command line (without "--boost-").
+ Note that the command line has the priority, and should preferably be used.
+ """
+ if not self.env['CXX']:
+ self.fatal('load a c++ compiler first, conf.load("compiler_cxx")')
+
+ params = {'lib': k and k[0] or kw.get('lib', None)}
+ for key, value in self.options.__dict__.items():
+ if not key.startswith('boost_'):
+ continue
+ key = key[len('boost_'):]
+ params[key] = value and value or kw.get(key, '')
+
+ var = kw.get('uselib_store', 'BOOST')
+
+ self.start_msg('Checking boost includes')
+ self.env['INCLUDES_%s' % var] = inc = self.boost_get_includes(**params)
+ versions = self.boost_get_version(inc)
+ self.env.BOOST_VERSION = versions[0]
+ self.env.BOOST_VERSION_NUMBER = int(versions[1])
+ self.end_msg("%d.%d.%d" % (int(versions[1]) / 100000,
+ int(versions[1]) / 100 % 1000,
+ int(versions[1]) % 100))
+ if Logs.verbose:
+ Logs.pprint('CYAN', ' path : %s' % self.env['INCLUDES_%s' % var])
+
+ if not params['lib']:
+ return
+ self.start_msg('Checking boost libs')
+ suffix = params.get('static', None) and 'ST' or ''
+ path, libs = self.boost_get_libs(**params)
+ self.env['%sLIBPATH_%s' % (suffix, var)] = [path]
+ self.env['%sLIB_%s' % (suffix, var)] = libs
+ self.end_msg('ok')
+ if Logs.verbose:
+ Logs.pprint('CYAN', ' path : %s' % path)
+ Logs.pprint('CYAN', ' libs : %s' % libs)
+
+
+ def try_link():
+ if 'system' in params['lib']:
+ self.check_cxx(
+ fragment=BOOST_SYSTEM_CODE,
+ use=var,
+ execute=False,
+ )
+ if 'thread' in params['lib']:
+ self.check_cxx(
+ fragment=BOOST_THREAD_CODE,
+ use=var,
+ execute=False,
+ )
+
+ if params.get('linkage_autodetect', False):
+ self.start_msg("Attempting to detect boost linkage flags")
+ toolset = self.boost_get_toolset(kw.get('toolset', ''))
+ if toolset in ['vc']:
+ # disable auto-linking feature, causing error LNK1181
+ # because the code wants to be linked against
+ self.env['DEFINES_%s' % var] += ['BOOST_ALL_NO_LIB']
+
+ # if no dlls are present, we guess the .lib files are not stubs
+ has_dlls = False
+ for x in Utils.listdir(path):
+ if x.endswith(self.env.cxxshlib_PATTERN % ''):
+ has_dlls = True
+ break
+ if not has_dlls:
+ self.env['STLIBPATH_%s' % var] = [path]
+ self.env['STLIB_%s' % var] = libs
+ del self.env['LIB_%s' % var]
+ del self.env['LIBPATH_%s' % var]
+
+ # we attempt to play with some known-to-work CXXFLAGS combinations
+ for cxxflags in (['/MD', '/EHsc'], []):
+ self.env.stash()
+ self.env["CXXFLAGS_%s" % var] += cxxflags
+ try:
+ try_link()
+ self.end_msg("ok: winning cxxflags combination: %s" % (self.env["CXXFLAGS_%s" % var]))
+ e = None
+ break
+ except Errors.ConfigurationError as exc:
+ self.env.revert()
+ e = exc
+
+ if e is not None:
+ self.end_msg("Could not auto-detect boost linking flags combination, you may report it to boost.py author", ex=e)
+ self.fatal('The configuration failed')
+ else:
+ self.end_msg("Boost linkage flags auto-detection not implemented (needed ?) for this toolchain")
+ self.fatal('The configuration failed')
+ else:
+ self.start_msg('Checking for boost linkage')
+ try:
+ try_link()
+ except Errors.ConfigurationError as e:
+ self.end_msg("Could not link against boost libraries using supplied options")
+ self.fatal('The configuration failed')
+ self.end_msg('ok')
diff --git a/waf-tools/default-compiler-flags.py b/waf-tools/default-compiler-flags.py
new file mode 100644
index 0000000..af237f5
--- /dev/null
+++ b/waf-tools/default-compiler-flags.py
@@ -0,0 +1,62 @@
+# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+#
+# Copyright (c) 2014, Regents of the University of California
+#
+# GPL 3.0 license, see the COPYING.md file for more information
+
+from waflib import Logs, Configure
+
+def options(opt):
+ opt.add_option('--debug', '--with-debug', action='store_true', default=False, dest='debug',
+ help='''Compile in debugging mode without all optimizations (-O0)''')
+ opt.add_option('--with-c++11', action='store_true', default=False, dest='use_cxx11',
+ help='''Enable C++11 mode (experimental, may not work)''')
+
+def configure(conf):
+ areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
+ defaultFlags = []
+
+ if conf.options.use_cxx11:
+ defaultFlags += ['-std=c++0x', '-std=c++11']
+ else:
+ defaultFlags += ['-std=c++03']
+
+ defaultFlags += ['-pedantic', '-Wall', '-Wno-long-long', '-Wno-unneeded-internal-declaration']
+
+ if conf.options.debug:
+ conf.define('_DEBUG', 1)
+ defaultFlags += ['-O0',
+ '-Og', # gcc >= 4.8
+ '-g3',
+ '-fcolor-diagnostics', # clang
+ '-fdiagnostics-color', # gcc >= 4.9
+ '-Werror',
+ '-Wno-error=maybe-uninitialized', # Bug #1560
+ ]
+ if areCustomCxxflagsPresent:
+ missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
+ if len(missingFlags) > 0:
+ Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
+ % " ".join(conf.env.CXXFLAGS))
+ Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
+ else:
+ conf.add_supported_cxxflags(defaultFlags)
+ else:
+ defaultFlags += ['-O2', '-g']
+ if not areCustomCxxflagsPresent:
+ conf.add_supported_cxxflags(defaultFlags)
+
+@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=['-Werror', flag], mandatory=False):
+ supportedFlags += [flag]
+
+ self.end_msg(' '.join(supportedFlags))
+ self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS
diff --git a/wscript b/wscript
index 66b998a..97f13a2 100644
--- a/wscript
+++ b/wscript
@@ -6,18 +6,20 @@
def options(opt):
opt.load('compiler_c compiler_cxx qt4 gnu_dirs')
- opt.load('sparkle xcode', tooldir='waf-tools')
+ opt.load('boost sparkle xcode default-compiler-flags', tooldir='waf-tools')
grp = opt.add_option_group('NFD Control Center options')
grp.add_option('--with-nfd', dest='with_nfd', type=str, default='/usr/local',
help='''Root path to NFD installation (default: /usr/local)''')
if Utils.unversioned_sys_platform () == "darwin":
- grp.add_option('--with-qt', help='''Build QT4 app, instead of native one''',
- action='store_true', dest='with_qt', default=False)
+ grp.add_option('--with-qt4', help='''Build QT4 app, instead of native one''',
+ action='store_true', dest='with_qt4', default=False)
+ grp.add_option('--with-qt5', help='''Build QT5 app, instead of native one''',
+ action='store_true', dest='with_qt5', default=False)
def configure(conf):
- conf.load('compiler_c compiler_cxx')
+ conf.load('compiler_c compiler_cxx default-compiler-flags boost')
conf.start_msg('Checking for NFD tools in %s' % conf.options.with_nfd)
if not conf.find_file(['nfd-start', 'nfd-stop'],
@@ -34,12 +36,18 @@
conf.define('NFD_STOP_COMMAND', '%s/bin/nfd-stop' % conf.options.with_nfd)
conf.define('NFD_AUTOCONFIG_COMMAND', '%s/bin/ndn-autoconfig' % conf.options.with_nfd)
- if not conf.options.with_qt and Utils.unversioned_sys_platform() == "darwin":
- # conf.fatal("Native implementation of NFD Control Center is not yet available")
+ conf.check_boost(lib="system thread")
+
+ if not conf.options.with_qt4 and not not conf.options.with_qt4 and Utils.unversioned_sys_platform() == "darwin":
conf.env.BUILD_OSX_NATIVE = 1
conf.recurse('osx')
else:
- conf.recurse('qt')
+ if conf.options.with_qt5:
+ conf.env.BUILD_QT5 = 1
+ conf.recurse('qt5')
+ else:
+ conf.env.BUILD_QT4 = 1
+ conf.recurse('qt4')
conf.write_config_header('config.hpp')
@@ -47,4 +55,7 @@
if bld.env.BUILD_OSX_NATIVE:
bld.recurse('osx')
else:
- bld.recurse('qt')
+ if bld.env.BUILD_QT5:
+ bld.recurse('qt5')
+ else:
+ bld.recurse('qt4')