apps: Switch ndn::App::GetId() to use application ID on the node
Previously, GetId() used ID of the underlying application face, which
is less convenient for simulation trace analyses.
Change-Id: I403182ecb4b9e8fb010c4c25ab007c1e274bc86a
diff --git a/apps/ndn-app.cpp b/apps/ndn-app.cpp
index 802f697..a1c9e80 100644
--- a/apps/ndn-app.cpp
+++ b/apps/ndn-app.cpp
@@ -61,6 +61,7 @@
App::App()
: m_active(false)
, m_face(0)
+ , m_appId(std::numeric_limits<uint32_t>::max())
{
}
@@ -69,6 +70,21 @@
}
void
+App::DoInitialize()
+{
+ NS_LOG_FUNCTION_NOARGS();
+
+ // find out what is application id on the node
+ for (uint32_t id = 0; id < GetNode()->GetNApplications(); ++id) {
+ if (GetNode()->GetApplication(id) == this) {
+ m_appId = id;
+ }
+ }
+
+ Application::DoInitialize();
+}
+
+void
App::DoDispose(void)
{
NS_LOG_FUNCTION_NOARGS();
@@ -82,10 +98,7 @@
uint32_t
App::GetId() const
{
- if (m_face == 0)
- return (uint32_t)-1;
- else
- return m_face->getId();
+ return m_appId;
}
void
diff --git a/apps/ndn-app.hpp b/apps/ndn-app.hpp
index 57dda58..2d84134 100644
--- a/apps/ndn-app.hpp
+++ b/apps/ndn-app.hpp
@@ -85,9 +85,9 @@
typedef void (*DataTraceCallback)(shared_ptr<const Data>, Ptr<App>, shared_ptr<Face>);
protected:
- /**
- * @brief Do cleanup when application is destroyed
- */
+ virtual void
+ DoInitialize();
+
virtual void
DoDispose();
@@ -101,6 +101,7 @@
protected:
bool m_active; ///< @brief Flag to indicate that application is active (set by StartApplication and StopApplication)
shared_ptr<AppFace> m_face; ///< @brief automatically created application face through which application communicates
+ uint32_t m_appId;
TracedCallback<shared_ptr<const Interest>, Ptr<App>, shared_ptr<Face>>
m_receivedInterests; ///< @brief App-level trace of received Interests