an untested interface id trace resolver
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sun, 12 Aug 2007 18:28:13 +0200
changeset 1346 47de68729c86
parent 1345 eb06ae6eb180
child 1347 83786345b743
an untested interface id trace resolver
src/core/object.cc
--- a/src/core/object.cc	Sun Aug 12 18:27:52 2007 +0200
+++ b/src/core/object.cc	Sun Aug 12 18:28:13 2007 +0200
@@ -35,6 +35,7 @@
 public:
   void SetParent (uint16_t child, const uint16_t *parent);
   uint16_t LookupParent (uint16_t child);
+
 private:
   std::vector<const uint16_t *> m_parents;
 };
@@ -56,6 +57,54 @@
 
 namespace ns3 {
 
+class InterfaceIdTraceResolver : public TraceResolver
+{
+public:
+  InterfaceIdTraceResolver (Ptr<Object> aggregate);
+  virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context);
+  virtual void Disconnect (std::string path, CallbackBase const &cb);
+private:
+  Ptr<Object> ParseForInterface (std::string path);
+  Ptr<Object> m_aggregate;
+};
+
+InterfaceIdTraceResolver::InterfaceIdTraceResolver (Ptr<Object> aggregate)
+  : m_aggregate (aggregate)
+{}
+Ptr<Object>
+InterfaceIdTraceResolver::ParseForInterface (std::string path)
+{
+  std::string element = GetElement (path);
+  std::string::size_type dollar_pos = element.find ("$");
+  if (dollar_pos != 0)
+    {
+      return 0;
+    }
+  std::string interfaceName = element.substr (1, std::string::npos);
+  InterfaceId interfaceId = InterfaceId::LookupByName (interfaceName);
+  Ptr<Object> interface = m_aggregate->QueryInterface<Object> (interfaceId);
+  return interface;
+}
+void 
+InterfaceIdTraceResolver::Connect (std::string path, CallbackBase const &cb, const TraceContext &context)
+{
+  Ptr<Object> interface = ParseForInterface (path);
+  if (interface != 0)
+    {
+      interface->TraceConnect (GetSubpath (path), cb, context);
+    }
+}
+void 
+InterfaceIdTraceResolver::Disconnect (std::string path, CallbackBase const &cb)
+{
+  Ptr<Object> interface = ParseForInterface (path);
+  if (interface != 0)
+    {
+      interface->TraceDisconnect (GetSubpath (path), cb);
+    }
+}
+
+
 InterfaceId::InterfaceId (uint16_t iid)
   : m_iid (iid)
 {}
@@ -197,7 +246,9 @@
 Ptr<TraceResolver>
 Object::GetTraceResolver (void)
 {
-  return Create<EmptyTraceResolver> ();
+  Ptr<InterfaceIdTraceResolver> resolver =
+    Create<InterfaceIdTraceResolver> (this);
+  return resolver;
 }
 
 bool