src: Change adjacency status from uint32_t to enum

refs: #1946

Change-Id: Ic1abd2610061860d0ac183074395a1d3796e870a
diff --git a/src/adjacency-list.cpp b/src/adjacency-list.cpp
index f2e0aaf..5c98ed8 100644
--- a/src/adjacency-list.cpp
+++ b/src/adjacency-list.cpp
@@ -61,15 +61,18 @@
   }
 }
 
-int32_t
-AdjacencyList::updateAdjacentStatus(const ndn::Name& adjName, int32_t s)
+bool
+AdjacencyList::updateAdjacentStatus(const ndn::Name& adjName, Adjacent::Status s)
 {
   std::list<Adjacent>::iterator it = find(adjName);
+
   if (it == m_adjList.end()) {
-    return -1;
+    return false;
   }
-  (*it).setStatus(s);
-  return 0;
+  else {
+    it->setStatus(s);
+    return true;
+  }
 }
 
 Adjacent
@@ -163,22 +166,25 @@
   return (*it).getInterestTimedOutNo();
 }
 
-uint32_t
+Adjacent::Status
 AdjacencyList::getStatusOfNeighbor(const ndn::Name& neighbor)
 {
   std::list<Adjacent>::iterator it = find(neighbor);
+
   if (it == m_adjList.end()) {
-    return -1;
+    return Adjacent::STATUS_UNKNOWN;
   }
-  return (*it).getStatus();
+  else {
+    return it->getStatus();
+  }
 }
 
 void
-AdjacencyList::setStatusOfNeighbor(const ndn::Name& neighbor, int32_t status)
+AdjacencyList::setStatusOfNeighbor(const ndn::Name& neighbor, Adjacent::Status status)
 {
   std::list<Adjacent>::iterator it = find(neighbor);
   if (it != m_adjList.end()) {
-    (*it).setStatus(status);
+    it->setStatus(status);
   }
 }
 
@@ -192,9 +198,9 @@
 AdjacencyList::isAdjLsaBuildable(Nlsr& pnlsr)
 {
   uint32_t nbrCount = 0;
-  for (std::list<Adjacent>::iterator it = m_adjList.begin();
-       it != m_adjList.end() ; it++) {
-    if (((*it).getStatus() == 1)) {
+  for (std::list<Adjacent>::iterator it = m_adjList.begin(); it != m_adjList.end() ; it++) {
+
+    if (it->getStatus() == Adjacent::STATUS_ACTIVE) {
       nbrCount++;
     }
     else {
@@ -214,9 +220,9 @@
 AdjacencyList::getNumOfActiveNeighbor()
 {
   int32_t actNbrCount = 0;
-  for (std::list<Adjacent>::iterator it = m_adjList.begin();
-       it != m_adjList.end(); it++) {
-    if (((*it).getStatus() == 1)) {
+  for (std::list<Adjacent>::iterator it = m_adjList.begin(); it != m_adjList.end(); it++) {
+
+    if (it->getStatus() == Adjacent::STATUS_ACTIVE) {
       actNbrCount++;
     }
   }
diff --git a/src/adjacency-list.hpp b/src/adjacency-list.hpp
index 320dc40..76c9e5f 100644
--- a/src/adjacency-list.hpp
+++ b/src/adjacency-list.hpp
@@ -42,8 +42,8 @@
   int32_t
   insert(Adjacent& adjacent);
 
-  int32_t
-  updateAdjacentStatus(const ndn::Name& adjName, int32_t s);
+  bool
+  updateAdjacentStatus(const ndn::Name& adjName, Adjacent::Status s);
 
   int32_t
   updateAdjacentLinkCost(const ndn::Name& adjName, double lc);
@@ -60,11 +60,11 @@
   int32_t
   getTimedOutInterestCount(const ndn::Name& neighbor);
 
-  uint32_t
+  Adjacent::Status
   getStatusOfNeighbor(const ndn::Name& neighbor);
 
   void
-  setStatusOfNeighbor(const ndn::Name& neighbor, int32_t status);
+  setStatusOfNeighbor(const ndn::Name& neighbor, Adjacent::Status status);
 
   void
   setTimedOutInterestCount(const ndn::Name& neighbor, uint32_t count);
diff --git a/src/adjacent.cpp b/src/adjacent.cpp
index f551686..b0a9058 100644
--- a/src/adjacent.cpp
+++ b/src/adjacent.cpp
@@ -41,7 +41,7 @@
     : m_name()
     , m_connectingFaceUri()
     , m_linkCost(DEFAULT_LINK_COST)
-    , m_status(ADJACENT_STATUS_INACTIVE)
+    , m_status(STATUS_INACTIVE)
     , m_interestTimedOutNo(0)
     , m_faceId(0)
 {
@@ -51,14 +51,14 @@
     : m_name(an)
     , m_connectingFaceUri()
     , m_linkCost(DEFAULT_LINK_COST)
-    , m_status(ADJACENT_STATUS_INACTIVE)
+    , m_status(STATUS_INACTIVE)
     , m_interestTimedOutNo(0)
     , m_faceId(0)
   {
   }
 
 Adjacent::Adjacent(const ndn::Name& an, const std::string& cfu,  double lc,
-          uint32_t s, uint32_t iton, uint64_t faceId)
+                   Status s, uint32_t iton, uint64_t faceId)
     : m_name(an)
     , m_connectingFaceUri(cfu)
     , m_linkCost(lc)
diff --git a/src/adjacent.hpp b/src/adjacent.hpp
index 967265f..d12d553 100644
--- a/src/adjacent.hpp
+++ b/src/adjacent.hpp
@@ -30,21 +30,23 @@
 
 namespace nlsr {
 
-enum {
-  ADJACENT_STATUS_INACTIVE = 0,
-  ADJACENT_STATUS_ACTIVE = 1
-};
-
 class Adjacent
 {
 
 public:
+  enum Status
+  {
+    STATUS_UNKNOWN = -1,
+    STATUS_INACTIVE = 0,
+    STATUS_ACTIVE = 1
+  };
+
   Adjacent();
 
   Adjacent(const ndn::Name& an);
 
   Adjacent(const ndn::Name& an, const std::string& cfu,  double lc,
-          uint32_t s, uint32_t iton, uint64_t faceId);
+           Status s, uint32_t iton, uint64_t faceId);
 
   const ndn::Name&
   getName() const
@@ -83,14 +85,14 @@
     m_linkCost = lc;
   }
 
-  uint32_t
+  Status
   getStatus() const
   {
     return m_status;
   }
 
   void
-  setStatus(uint32_t s)
+  setStatus(Status s)
   {
     m_status = s;
   }
@@ -150,7 +152,7 @@
   ndn::Name m_name;
   std::string m_connectingFaceUri;
   double m_linkCost;
-  uint32_t m_status;
+  Status m_status;
   uint32_t m_interestTimedOutNo;
   uint64_t m_faceId;
 };
diff --git a/src/conf-file-processor.cpp b/src/conf-file-processor.cpp
index 726d2af..45890d1 100644
--- a/src/conf-file-processor.cpp
+++ b/src/conf-file-processor.cpp
@@ -338,7 +338,7 @@
                                                        Adjacent::DEFAULT_LINK_COST);
         ndn::Name neighborName(name);
         if (!neighborName.empty()) {
-          Adjacent adj(name, faceUri, linkCost, ADJACENT_STATUS_INACTIVE, 0, 0);
+          Adjacent adj(name, faceUri, linkCost, Adjacent::STATUS_INACTIVE, 0, 0);
           m_nlsr.getAdjacencyList().insert(adj);
         }
         else {
diff --git a/src/hello-protocol.cpp b/src/hello-protocol.cpp
index 98ab9cd..764c7d3 100644
--- a/src/hello-protocol.cpp
+++ b/src/hello-protocol.cpp
@@ -102,7 +102,7 @@
     _LOG_DEBUG("Sending out data for name: " << interest.getName());
     m_nlsr.getNlsrFace().put(*data);
     Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor);
-    if (adjacent->getStatus() == 0) {
+    if (adjacent->getStatus() == Adjacent::STATUS_INACTIVE) {
       if(adjacent->getFaceId() != 0){
         /* interest name: /<neighbor>/NLSR/INFO/<router> */
         ndn::Name interestName(neighbor);
@@ -132,7 +132,9 @@
   ndn::Name neighbor = interestName.getPrefix(-3);
   _LOG_DEBUG("Neighbor: " << neighbor);
   m_nlsr.getAdjacencyList().incrementTimedOutInterestCount(neighbor);
-  int status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
+
+  Adjacent::Status status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
+
   uint32_t infoIntTimedOutCount =
     m_nlsr.getAdjacencyList().getTimedOutInterestCount(neighbor);
   _LOG_DEBUG("Status: " << status);
@@ -146,9 +148,9 @@
     expressInterest(interestName,
                     m_nlsr.getConfParameter().getInterestResendTime());
   }
-  else if ((status == 1) &&
+  else if ((status == Adjacent::STATUS_ACTIVE) &&
            (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber())) {
-    m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, 0);
+    m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, Adjacent::STATUS_INACTIVE);
     m_nlsr.incrementAdjBuildCount();
     if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
       _LOG_DEBUG("Scheduling scheduledAdjLsaBuild");
@@ -184,10 +186,12 @@
   _LOG_DEBUG("Data validation successful for INFO(name): " << dataName);
   if (dataName.get(-3).toUri() == INFO_COMPONENT) {
     ndn::Name neighbor = dataName.getPrefix(-4);
-    int oldStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
-    m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, 1);
+
+    Adjacent::Status oldStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
+    m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, Adjacent::STATUS_ACTIVE);
     m_nlsr.getAdjacencyList().setTimedOutInterestCount(neighbor, 0);
-    int newStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
+    Adjacent::Status newStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
+
     _LOG_DEBUG("Neighbor : " << neighbor);
     _LOG_DEBUG("Old Status: " << oldStatus << " New Status: " << newStatus);
     // change in Adjacency list
@@ -272,12 +276,12 @@
   Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(name);
   if (adjacent != 0) {
     adjacent->setInterestTimedOutNo(adjacent->getInterestTimedOutNo() + 1);
-    int status = adjacent->getStatus();
+    Adjacent::Status status = adjacent->getStatus();
     uint32_t infoIntTimedOutCount = adjacent->getInterestTimedOutNo();
 
     if (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber()) {
-      if ( status == 1) {
-        adjacent->setStatus(0);
+      if (status == Adjacent::STATUS_ACTIVE) {
+        adjacent->setStatus(Adjacent::STATUS_INACTIVE);
       }
       m_nlsr.incrementAdjBuildCount();
       if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
diff --git a/src/lsa.cpp b/src/lsa.cpp
index 854d89f..9fa7421 100644
--- a/src/lsa.cpp
+++ b/src/lsa.cpp
@@ -218,7 +218,7 @@
   m_noLink = nl;
   std::list<Adjacent> al = adl.getAdjList();
   for (std::list<Adjacent>::iterator it = al.begin(); it != al.end(); it++) {
-    if ((*it).getStatus() == 1) {
+    if (it->getStatus() == Adjacent::STATUS_ACTIVE) {
       addAdjacent((*it));
     }
   }
@@ -286,7 +286,7 @@
       ndn::Name adjName(*tok_iter++);
       std::string connectingFaceUri(*tok_iter++);
       double linkCost = boost::lexical_cast<double>(*tok_iter++);
-      Adjacent adjacent(adjName, connectingFaceUri, linkCost, 0, 0, 0);
+      Adjacent adjacent(adjName, connectingFaceUri, linkCost, Adjacent::STATUS_INACTIVE, 0, 0);
       addAdjacent(adjacent);
     }
     catch (std::exception& e) {