fw: use Signal in FaceTable
refs #2272
Change-Id: I831963b8311c257178ad0da16d62e48b476bfee3
diff --git a/common.hpp b/common.hpp
index 94171c7..8316184 100644
--- a/common.hpp
+++ b/common.hpp
@@ -58,7 +58,8 @@
#include <ndn-cxx/common.hpp>
#include <ndn-cxx/interest.hpp>
#include <ndn-cxx/data.hpp>
-#include <ndn-cxx/util/event-emitter.hpp>
+#include <ndn-cxx/util/event-emitter.hpp> // deprecated
+#include <ndn-cxx/util/signal.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/asio.hpp>
@@ -94,7 +95,7 @@
using ndn::Name;
using ndn::Exclude;
using ndn::Block;
-using ndn::util::EventEmitter;
+using ndn::util::EventEmitter; // deprecated
namespace tlv {
// Don't write "namespace tlv = ndn::tlv", because NFD can add other members into this namespace.
@@ -103,6 +104,7 @@
namespace name = ndn::name;
namespace time = ndn::time;
+namespace signal = ndn::util::signal;
} // namespace nfd
diff --git a/daemon/fw/face-table.hpp b/daemon/fw/face-table.hpp
index 70ceb11..435999e 100644
--- a/daemon/fw/face-table.hpp
+++ b/daemon/fw/face-table.hpp
@@ -29,8 +29,7 @@
#include "face/face.hpp"
#include <boost/range/adaptor/map.hpp>
-namespace nfd
-{
+namespace nfd {
class Forwarder;
@@ -73,16 +72,16 @@
const_iterator
end() const;
-public: // events
+public: // signals
/** \brief fires after a Face is added
*/
- EventEmitter<shared_ptr<Face> > onAdd;
+ signal::Signal<FaceTable, shared_ptr<Face>> onAdd;
/** \brief fires before a Face is removed
*
* FaceId is valid when this event is fired
*/
- EventEmitter<shared_ptr<Face> > onRemove;
+ signal::Signal<FaceTable, shared_ptr<Face>> onRemove;
private:
void
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index 03e2f42..6a7bb1e 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -124,6 +124,8 @@
ndn::KeyChain& keyChain)
: ManagerBase(face, FACE_MANAGER_PRIVILEGE, keyChain)
, m_faceTable(faceTable)
+ , m_faceAddConn(m_faceTable.onAdd.connect(bind(&FaceManager::onAddFace, this, _1)))
+ , m_faceRemoveConn(m_faceTable.onRemove.connect(bind(&FaceManager::onRemoveFace, this, _1)))
, m_faceStatusPublisher(m_faceTable, *m_face, FACES_LIST_DATASET_PREFIX, keyChain)
, m_channelStatusPublisher(m_factories, *m_face, CHANNELS_LIST_DATASET_PREFIX, keyChain)
, m_notificationStream(*m_face, FACE_EVENTS_PREFIX, keyChain)
@@ -137,9 +139,6 @@
{
face->setInterestFilter("/localhost/nfd/faces",
bind(&FaceManager::onFaceRequest, this, _2));
-
- m_faceTable.onAdd += bind(&FaceManager::onAddFace, this, _1);
- m_faceTable.onRemove += bind(&FaceManager::onRemoveFace, this, _1);
}
FaceManager::~FaceManager()
diff --git a/daemon/mgmt/face-manager.hpp b/daemon/mgmt/face-manager.hpp
index d4d979b..75477bf 100644
--- a/daemon/mgmt/face-manager.hpp
+++ b/daemon/mgmt/face-manager.hpp
@@ -173,6 +173,8 @@
private:
FaceTable& m_faceTable;
+ signal::ScopedConnection m_faceAddConn;
+ signal::ScopedConnection m_faceRemoveConn;
FaceStatusPublisher m_faceStatusPublisher;
ChannelStatusPublisher m_channelStatusPublisher;
NotificationStream<AppFace> m_notificationStream;
diff --git a/tests/daemon/fw/face-table.cpp b/tests/daemon/fw/face-table.cpp
index 0dd8432..b2bfab4 100644
--- a/tests/daemon/fw/face-table.cpp
+++ b/tests/daemon/fw/face-table.cpp
@@ -34,12 +34,6 @@
BOOST_FIXTURE_TEST_SUITE(FwFaceTable, BaseFixture)
-static inline void
-saveFaceId(std::vector<FaceId>& faceIds, shared_ptr<Face> face)
-{
- faceIds.push_back(face->getId());
-}
-
BOOST_AUTO_TEST_CASE(AddRemove)
{
Forwarder forwarder;
@@ -47,8 +41,12 @@
FaceTable& faceTable = forwarder.getFaceTable();
std::vector<FaceId> onAddHistory;
std::vector<FaceId> onRemoveHistory;
- faceTable.onAdd += bind(&saveFaceId, ndn::ref(onAddHistory ), _1);
- faceTable.onRemove += bind(&saveFaceId, ndn::ref(onRemoveHistory), _1);
+ faceTable.onAdd.connect([&] (shared_ptr<Face> face) {
+ onAddHistory.push_back(face->getId());
+ });
+ faceTable.onRemove.connect([&] (shared_ptr<Face> face) {
+ onRemoveHistory.push_back(face->getId());
+ });
shared_ptr<Face> face1 = make_shared<DummyFace>();
shared_ptr<Face> face2 = make_shared<DummyFace>();