mgmt: avoid virtual methods in FaceTraits
Change-Id: Ic9d156eb98ca435993212d14662303e5dd2bad57
Refs: #3903
diff --git a/src/mgmt/nfd/face-event-notification.cpp b/src/mgmt/nfd/face-event-notification.cpp
index a322ae9..f3ea655 100644
--- a/src/mgmt/nfd/face-event-notification.cpp
+++ b/src/mgmt/nfd/face-event-notification.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -20,8 +20,9 @@
*/
#include "face-event-notification.hpp"
-#include "encoding/tlv-nfd.hpp"
#include "encoding/block-helpers.hpp"
+#include "encoding/encoding-buffer.hpp"
+#include "encoding/tlv-nfd.hpp"
#include "util/concepts.hpp"
namespace ndn {
@@ -34,7 +35,7 @@
"FaceEventNotification::Error must inherit from tlv::Error");
FaceEventNotification::FaceEventNotification()
- : m_kind(static_cast<FaceEventKind>(0))
+ : m_kind(FACE_EVENT_NONE)
{
}
@@ -169,19 +170,15 @@
return *this;
}
-void
-FaceEventNotification::wireReset() const
-{
- m_wire.reset();
-}
-
std::ostream&
operator<<(std::ostream& os, const FaceEventNotification& notification)
{
os << "FaceEventNotification(";
- switch (notification.getKind())
- {
+ switch (notification.getKind()) {
+ case FACE_EVENT_NONE:
+ os << "Kind: none, ";
+ break;
case FACE_EVENT_CREATED:
os << "Kind: created, ";
break;
@@ -194,7 +191,7 @@
case FACE_EVENT_DOWN:
os << "Kind: down, ";
break;
- }
+ }
os << "FaceID: " << notification.getFaceId() << ", "
<< "RemoteUri: " << notification.getRemoteUri() << ", "
diff --git a/src/mgmt/nfd/face-event-notification.hpp b/src/mgmt/nfd/face-event-notification.hpp
index 0126b64..6abfee1 100644
--- a/src/mgmt/nfd/face-event-notification.hpp
+++ b/src/mgmt/nfd/face-event-notification.hpp
@@ -23,7 +23,6 @@
#define NDN_MGMT_NFD_FACE_EVENT_NOTIFICATION_HPP
#include "face-traits.hpp"
-#include "../../encoding/block.hpp"
namespace ndn {
namespace nfd {
@@ -32,6 +31,7 @@
* \ingroup management
*/
enum FaceEventKind {
+ FACE_EVENT_NONE = 0,
FACE_EVENT_CREATED = 1, ///< face created
FACE_EVENT_DESTROYED = 2, ///< face destroyed
FACE_EVENT_UP = 3, ///< face went UP (from DOWN state)
@@ -41,7 +41,7 @@
/**
* \ingroup management
* \brief represents a Face status change notification
- * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Face-Status-Change-Notification
+ * \sa https://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Face-Status-Change-Notification
*/
class FaceEventNotification : public FaceTraits<FaceEventNotification>
{
@@ -77,14 +77,8 @@
FaceEventNotification&
setKind(FaceEventKind kind);
-protected:
- void
- wireReset() const override;
-
private:
FaceEventKind m_kind;
-
- mutable Block m_wire;
};
std::ostream&
diff --git a/src/mgmt/nfd/face-status.cpp b/src/mgmt/nfd/face-status.cpp
index 9417e28..ea0d546 100644
--- a/src/mgmt/nfd/face-status.cpp
+++ b/src/mgmt/nfd/face-status.cpp
@@ -328,12 +328,6 @@
return *this;
}
-void
-FaceStatus::wireReset() const
-{
- m_wire.reset();
-}
-
bool
operator==(const FaceStatus& a, const FaceStatus& b)
{
diff --git a/src/mgmt/nfd/face-status.hpp b/src/mgmt/nfd/face-status.hpp
index 9bffa81..bde34b8 100644
--- a/src/mgmt/nfd/face-status.hpp
+++ b/src/mgmt/nfd/face-status.hpp
@@ -23,7 +23,6 @@
#define NDN_MGMT_NFD_FACE_STATUS_HPP
#include "face-traits.hpp"
-#include "../../encoding/block.hpp"
#include "../../util/time.hpp"
namespace ndn {
@@ -147,10 +146,6 @@
FaceStatus&
setNOutBytes(uint64_t nOutBytes);
-protected:
- void
- wireReset() const override;
-
private:
optional<time::milliseconds> m_expirationPeriod;
uint64_t m_nInInterests;
@@ -161,8 +156,6 @@
uint64_t m_nOutNacks;
uint64_t m_nInBytes;
uint64_t m_nOutBytes;
-
- mutable Block m_wire;
};
bool
diff --git a/src/mgmt/nfd/face-traits.hpp b/src/mgmt/nfd/face-traits.hpp
index dee973c..58a9245 100644
--- a/src/mgmt/nfd/face-traits.hpp
+++ b/src/mgmt/nfd/face-traits.hpp
@@ -22,15 +22,16 @@
#ifndef NDN_MGMT_NFD_FACE_TRAITS_HPP
#define NDN_MGMT_NFD_FACE_TRAITS_HPP
-#include "../../encoding/tlv-nfd.hpp"
+#include "../../encoding/block.hpp"
+#include "../../encoding/nfd-constants.hpp"
namespace ndn {
namespace nfd {
-/** \ingroup management
- * \brief providers getters and setters of face information fields
- * \tparam C the concrete class; it must provide a wireReset() member
- * function to clear the wire encoding when a field changes
+/**
+ * \ingroup management
+ * \brief provides getters and setters for face information fields
+ * \tparam C the concrete subclass
*/
template<class C>
class FaceTraits
@@ -46,18 +47,6 @@
}
};
- FaceTraits()
- : m_faceId(INVALID_FACE_ID)
- , m_faceScope(FACE_SCOPE_NON_LOCAL)
- , m_facePersistency(FACE_PERSISTENCY_PERSISTENT)
- , m_linkType(LINK_TYPE_POINT_TO_POINT)
- , m_flags(0x0)
- {
- }
-
- virtual
- ~FaceTraits() = default;
-
uint64_t
getFaceId() const
{
@@ -67,7 +56,7 @@
C&
setFaceId(uint64_t faceId)
{
- wireReset();
+ m_wire.reset();
m_faceId = faceId;
return static_cast<C&>(*this);
}
@@ -81,7 +70,7 @@
C&
setRemoteUri(const std::string& remoteUri)
{
- wireReset();
+ m_wire.reset();
m_remoteUri = remoteUri;
return static_cast<C&>(*this);
}
@@ -95,7 +84,7 @@
C&
setLocalUri(const std::string& localUri)
{
- wireReset();
+ m_wire.reset();
m_localUri = localUri;
return static_cast<C&>(*this);
}
@@ -109,7 +98,7 @@
C&
setFaceScope(FaceScope faceScope)
{
- wireReset();
+ m_wire.reset();
m_faceScope = faceScope;
return static_cast<C&>(*this);
}
@@ -123,7 +112,7 @@
C&
setFacePersistency(FacePersistency facePersistency)
{
- wireReset();
+ m_wire.reset();
m_facePersistency = facePersistency;
return static_cast<C&>(*this);
}
@@ -137,7 +126,7 @@
C&
setLinkType(LinkType linkType)
{
- wireReset();
+ m_wire.reset();
m_linkType = linkType;
return static_cast<C&>(*this);
}
@@ -151,7 +140,7 @@
C&
setFlags(uint64_t flags)
{
- wireReset();
+ m_wire.reset();
m_flags = flags;
return static_cast<C&>(*this);
}
@@ -162,7 +151,6 @@
if (bit >= 64) {
BOOST_THROW_EXCEPTION(std::out_of_range("bit must be within range [0, 64)"));
}
-
return m_flags & (1 << bit);
}
@@ -173,7 +161,7 @@
BOOST_THROW_EXCEPTION(std::out_of_range("bit must be within range [0, 64)"));
}
- wireReset();
+ m_wire.reset();
if (value) {
m_flags |= (1 << bit);
@@ -186,8 +174,14 @@
}
protected:
- virtual void
- wireReset() const = 0;
+ FaceTraits()
+ : m_faceId(INVALID_FACE_ID)
+ , m_faceScope(FACE_SCOPE_NON_LOCAL)
+ , m_facePersistency(FACE_PERSISTENCY_PERSISTENT)
+ , m_linkType(LINK_TYPE_POINT_TO_POINT)
+ , m_flags(0)
+ {
+ }
protected:
uint64_t m_faceId;
@@ -197,6 +191,8 @@
FacePersistency m_facePersistency;
LinkType m_linkType;
uint64_t m_flags;
+
+ mutable Block m_wire;
};
} // namespace nfd