replace TraceResolver::PrintAvailable with TraceResolver::CollectSources
This commit is contained in:
@@ -62,7 +62,8 @@ public:
|
||||
// inherited from TraceResolver
|
||||
virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context);
|
||||
virtual void Disconnect (std::string path, CallbackBase const &cb);
|
||||
virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os);
|
||||
virtual void CollectSources (std::string path, const TraceContext &context,
|
||||
SourceCollection *collection);
|
||||
|
||||
private:
|
||||
class IteratorBase
|
||||
@@ -166,7 +167,8 @@ ArrayTraceResolver<INDEX>::Disconnect (std::string path, CallbackBase const &cb)
|
||||
}
|
||||
template <typename INDEX>
|
||||
void
|
||||
ArrayTraceResolver<INDEX>::PrintAvailable (std::string path, const TraceContext &context, std::ostream &os)
|
||||
ArrayTraceResolver<INDEX>::CollectSources (std::string path, const TraceContext &context,
|
||||
SourceCollection *collection)
|
||||
{
|
||||
path.append ("/[0-n]");
|
||||
uint32_t j = 0;
|
||||
@@ -176,11 +178,12 @@ ArrayTraceResolver<INDEX>::PrintAvailable (std::string path, const TraceContext
|
||||
INDEX index = j;
|
||||
tmp.AddElement (index);
|
||||
Ptr<Object> obj = m_iter->Get ();
|
||||
obj->GetTraceResolver ()->PrintAvailable (path, tmp, os);
|
||||
obj->GetTraceResolver ()->CollectSources (path, tmp, collection);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
#endif /* ARRAY_TRACE_RESOLVER_H */
|
||||
|
||||
@@ -54,7 +54,15 @@ CompositeTraceResolver::Add (std::string name,
|
||||
{maker ()->Connect (subpath, cb, context);}
|
||||
virtual void Disconnect (std::string subpath, const CallbackBase &cb)
|
||||
{maker ()->Disconnect (subpath, cb);}
|
||||
|
||||
virtual void CollectSources (std::string path, const TraceContext &context,
|
||||
SourceCollection *collection)
|
||||
{
|
||||
path.append ("/");
|
||||
path.append (this->name);
|
||||
TraceContext ctx = context;
|
||||
ctx.Union (this->context);
|
||||
this->maker ()->CollectSources (path, ctx, collection);
|
||||
}
|
||||
Callback<Ptr<TraceResolver> > maker;
|
||||
} *item = new MakerCompositeItem ();
|
||||
item->name = name;
|
||||
@@ -82,13 +90,15 @@ CompositeTraceResolver::DoAddSource (std::string name,
|
||||
{if (subpath == "") {trace->AddCallback (cb, context);}}
|
||||
virtual void Disconnect (std::string subpath, const CallbackBase &cb)
|
||||
{if (subpath == "") {trace->RemoveCallback (cb);}}
|
||||
virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os)
|
||||
virtual void CollectSources (std::string path, const TraceContext &context,
|
||||
SourceCollection *collection)
|
||||
{
|
||||
os << path << "/" << this->name << " [";
|
||||
path.append ("/");
|
||||
path.append (this->name);
|
||||
TraceContext ctx = context;
|
||||
ctx.Union (this->context);
|
||||
ctx.PrintAvailable (os, ",");
|
||||
os << "]" << std::endl;
|
||||
// XXX help string
|
||||
collection->AddUnique (path, ctx, "");
|
||||
}
|
||||
TraceSource *trace;
|
||||
} *item = new SourceCompositeItem ();
|
||||
@@ -116,13 +126,14 @@ CompositeTraceResolver::DoAddChild (std::string name, Ptr<Object> child, const T
|
||||
{child->GetTraceResolver ()->Connect (subpath, cb, context);}
|
||||
virtual void Disconnect (std::string subpath, const CallbackBase &cb)
|
||||
{child->TraceDisconnect (subpath, cb);}
|
||||
virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os)
|
||||
virtual void CollectSources (std::string path, const TraceContext &context,
|
||||
SourceCollection *collection)
|
||||
{
|
||||
path.append ("/");
|
||||
path.append (this->name);
|
||||
TraceContext ctx = context;
|
||||
ctx.Union (this->context);
|
||||
this->child->GetTraceResolver ()->PrintAvailable (path, ctx, os);
|
||||
this->child->GetTraceResolver ()->CollectSources (path, ctx, collection);
|
||||
}
|
||||
|
||||
Ptr<Object> child;
|
||||
@@ -264,20 +275,23 @@ CompositeTraceResolver::Disconnect (std::string path, CallbackBase const &cb)
|
||||
} operation = DisconnectOperation (cb);
|
||||
DoRecursiveOperation (path, operation);
|
||||
}
|
||||
|
||||
void
|
||||
CompositeTraceResolver::PrintAvailable (std::string path, const TraceContext &context, std::ostream &os)
|
||||
CompositeTraceResolver::CollectSources (std::string path, const TraceContext &context,
|
||||
SourceCollection *collection)
|
||||
{
|
||||
for (TraceItems::const_iterator i = m_items.begin (); i != m_items.end (); i++)
|
||||
{
|
||||
NS_DEBUG ("print " << (*i)->name);
|
||||
(*i)->PrintAvailable (path, context, os);
|
||||
(*i)->CollectSources (path, context, collection);
|
||||
}
|
||||
if (m_parent != 0)
|
||||
{
|
||||
m_parent->PrintAvailable (path, context, os);
|
||||
m_parent->CollectSources (path, context, collection);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
#ifdef RUN_SELF_TESTS
|
||||
|
||||
@@ -91,7 +91,8 @@ public:
|
||||
|
||||
virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context);
|
||||
virtual void Disconnect (std::string path, CallbackBase const &cb);
|
||||
virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os);
|
||||
virtual void CollectSources (std::string path, const TraceContext &context,
|
||||
SourceCollection *collection);
|
||||
|
||||
private:
|
||||
class CompositeItem
|
||||
@@ -100,7 +101,8 @@ private:
|
||||
virtual ~CompositeItem () {}
|
||||
virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) = 0;
|
||||
virtual void Disconnect (std::string subpath, const CallbackBase &cb) = 0;
|
||||
virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) {}
|
||||
virtual void CollectSources (std::string path, const TraceContext &context,
|
||||
SourceCollection *collection) = 0;
|
||||
|
||||
std::string name;
|
||||
TraceContext context;
|
||||
@@ -157,13 +159,16 @@ CompositeTraceResolver::AddArray (std::string name,
|
||||
{array->Connect (subpath, cb, context);}
|
||||
virtual void Disconnect (std::string subpath, const CallbackBase &cb)
|
||||
{array->Disconnect (subpath, cb);}
|
||||
virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os)
|
||||
virtual void CollectSources (std::string path, const TraceContext &context,
|
||||
SourceCollection *collection)
|
||||
{
|
||||
path.append ("/");
|
||||
path.append (this->name);
|
||||
TraceContext ctx = context;
|
||||
ctx.Union (this->context);
|
||||
array->PrintAvailable (path, ctx, os);}
|
||||
array->CollectSources (path, ctx, collection);
|
||||
}
|
||||
|
||||
Ptr<ArrayTraceResolver<INDEX> > array;
|
||||
} *item = new ArrayCompositeItem ();
|
||||
item->name = name;
|
||||
|
||||
@@ -63,7 +63,8 @@ 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);
|
||||
virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os);
|
||||
virtual void CollectSources (std::string path, const TraceContext &context,
|
||||
SourceCollection *collection);
|
||||
private:
|
||||
Ptr<Object> ParseForInterface (std::string path);
|
||||
Ptr<Object> m_aggregate;
|
||||
@@ -105,9 +106,10 @@ InterfaceIdTraceResolver::Disconnect (std::string path, CallbackBase const &cb)
|
||||
}
|
||||
}
|
||||
void
|
||||
InterfaceIdTraceResolver::PrintAvailable (std::string path, const TraceContext &context, std::ostream &os)
|
||||
InterfaceIdTraceResolver::CollectSources (std::string path, const TraceContext &context,
|
||||
SourceCollection *collection)
|
||||
{
|
||||
|
||||
m_aggregate->DoCollectSources (path, context, collection);
|
||||
}
|
||||
|
||||
|
||||
@@ -128,6 +130,12 @@ InterfaceId::LookupParent (InterfaceId iid)
|
||||
{
|
||||
return Singleton<IidTree>::Get ()->LookupParent (iid.m_iid);
|
||||
}
|
||||
std::string
|
||||
InterfaceId::GetName (void) const
|
||||
{
|
||||
std::string name = Singleton<IidManager>::Get ()->LookupByUid (m_iid);
|
||||
return name;
|
||||
}
|
||||
|
||||
bool operator == (const InterfaceId &a, const InterfaceId &b)
|
||||
{
|
||||
@@ -284,6 +292,34 @@ Object::MaybeDelete (void) const
|
||||
} while (current != end);
|
||||
}
|
||||
|
||||
void
|
||||
Object::DoCollectSources (std::string path, const TraceContext &context,
|
||||
TraceResolver::SourceCollection *collection)
|
||||
{
|
||||
Object *current = this->m_next;
|
||||
if (collection->IsFlagSet ())
|
||||
{
|
||||
return;
|
||||
}
|
||||
collection->SetFlag ();
|
||||
while (current != this)
|
||||
{
|
||||
NS_ASSERT (current != 0);
|
||||
InterfaceId cur = current->m_iid;
|
||||
while (cur != Object::iid)
|
||||
{
|
||||
std::string name = cur.GetName ();
|
||||
std::string fullpath = path;
|
||||
fullpath.append ("/$");
|
||||
fullpath.append (name);
|
||||
current->GetTraceResolver ()->CollectSources (fullpath, context, collection);
|
||||
cur = InterfaceId::LookupParent (cur);
|
||||
}
|
||||
current = current->m_next;
|
||||
}
|
||||
collection->ClearFlag ();
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
|
||||
|
||||
@@ -24,10 +24,10 @@
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include "ptr.h"
|
||||
#include "trace-resolver.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class TraceResolver;
|
||||
class TraceContext;
|
||||
class CallbackBase;
|
||||
|
||||
@@ -60,6 +60,11 @@ public:
|
||||
* id is not a valid interface id.
|
||||
*/
|
||||
static InterfaceId LookupParent (InterfaceId iid);
|
||||
|
||||
/**
|
||||
* \returns the name of this interface.
|
||||
*/
|
||||
std::string GetName (void) const;
|
||||
~InterfaceId ();
|
||||
private:
|
||||
InterfaceId (uint16_t iid);
|
||||
@@ -156,7 +161,10 @@ protected:
|
||||
*/
|
||||
virtual void DoDispose (void);
|
||||
private:
|
||||
friend class InterfaceIdTraceResolver;
|
||||
Ptr<Object> DoQueryInterface (InterfaceId iid) const;
|
||||
void DoCollectSources (std::string path, const TraceContext &context,
|
||||
TraceResolver::SourceCollection *collection);
|
||||
bool Check (void) const;
|
||||
void MaybeDelete (void) const;
|
||||
mutable uint32_t m_count;
|
||||
|
||||
@@ -272,16 +272,23 @@ TraceContext::IsSimilar (const TraceContext &o) const
|
||||
uint16_t myI = 0;
|
||||
uint8_t otherCurrentUid;
|
||||
uint16_t otherI = 0;
|
||||
do {
|
||||
myCurrentUid = m_data->data[myI];
|
||||
otherCurrentUid = o.m_data->data[otherI];
|
||||
uint8_t mySize = ElementRegistry::GetSize (myCurrentUid);
|
||||
uint8_t otherSize = ElementRegistry::GetSize (otherCurrentUid);
|
||||
myI += 1 + mySize;
|
||||
otherI += 1 + otherSize;
|
||||
} while (myCurrentUid == otherCurrentUid &&
|
||||
myCurrentUid != 0 &&
|
||||
otherCurrentUid != 0);
|
||||
|
||||
myCurrentUid = m_data->data[myI];
|
||||
otherCurrentUid = o.m_data->data[otherI];
|
||||
|
||||
while (myCurrentUid == otherCurrentUid &&
|
||||
myCurrentUid != 0 &&
|
||||
otherCurrentUid != 0 &&
|
||||
myI < m_data->size &&
|
||||
otherI < o.m_data->size)
|
||||
{
|
||||
uint8_t mySize = ElementRegistry::GetSize (myCurrentUid);
|
||||
uint8_t otherSize = ElementRegistry::GetSize (otherCurrentUid);
|
||||
myI += 1 + mySize;
|
||||
otherI += 1 + otherSize;
|
||||
myCurrentUid = m_data->data[myI];
|
||||
otherCurrentUid = o.m_data->data[otherI];
|
||||
}
|
||||
if (myCurrentUid == 0 && otherCurrentUid == 0)
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -105,4 +105,22 @@ TraceResolver::SourceCollection::Print (std::ostream &os) const
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TraceResolver::SourceCollection::SetFlag (void)
|
||||
{
|
||||
m_flag = true;
|
||||
}
|
||||
|
||||
void
|
||||
TraceResolver::SourceCollection::ClearFlag (void)
|
||||
{
|
||||
m_flag = false;
|
||||
}
|
||||
bool
|
||||
TraceResolver::SourceCollection::IsFlagSet (void)
|
||||
{
|
||||
return m_flag;
|
||||
}
|
||||
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
@@ -70,15 +70,15 @@ public:
|
||||
*/
|
||||
virtual void Disconnect (std::string path, CallbackBase const &cb) = 0;
|
||||
|
||||
virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) = 0;
|
||||
|
||||
|
||||
class SourceCollection
|
||||
{
|
||||
public:
|
||||
void Print (std::ostream &os) const;
|
||||
void AddUnique (std::string path, const TraceContext &context,
|
||||
std::string help);
|
||||
void SetFlag (void);
|
||||
void ClearFlag (void);
|
||||
bool IsFlagSet (void);
|
||||
private:
|
||||
struct Source
|
||||
{
|
||||
@@ -88,9 +88,10 @@ public:
|
||||
};
|
||||
typedef std::vector<struct Source> SourceVector;
|
||||
SourceVector m_sources;
|
||||
bool m_flag;
|
||||
};
|
||||
virtual void CollectSources (std::string path, const TraceContext &context,
|
||||
SourceCollection *collection) {}
|
||||
SourceCollection *collection) = 0;
|
||||
protected:
|
||||
/**
|
||||
* \param path a namespace path
|
||||
|
||||
@@ -17,7 +17,9 @@ int main (int argc, char *argv[])
|
||||
Ptr<CsmaCdNetDevice> csma = Create<CsmaCdNetDevice> (node);
|
||||
csma->AddQueue (Queue::CreateDefault ());
|
||||
|
||||
NodeList::GetTraceResolver ()->PrintAvailable ("", TraceContext (), std::cout);
|
||||
TraceResolver::SourceCollection collection;
|
||||
NodeList::GetTraceResolver ()->CollectSources ("", TraceContext (), &collection);
|
||||
collection.Print (std::cout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user