Add logging to ConfigStore and RawTextConfig

This commit is contained in:
Peter D. Barnes, Jr.
2016-09-21 14:13:18 -07:00
parent ca94d87ace
commit 5179503673
3 changed files with 57 additions and 0 deletions

View File

@@ -80,6 +80,7 @@ ConfigStore::GetInstanceTypeId (void) const
ConfigStore::ConfigStore ()
{
NS_LOG_FUNCTION (this);
ObjectBase::ConstructSelf (AttributeConstructionList ());
#ifdef HAVE_LIBXML2
@@ -128,10 +129,14 @@ ConfigStore::ConfigStore ()
}
}
m_file->SetFilename (m_filename);
NS_LOG_FUNCTION (this << ": format: " << m_fileFormat
<< ", mode: " << m_mode
<< ", file name: " << m_filename);
}
ConfigStore::~ConfigStore ()
{
NS_LOG_FUNCTION (this);
delete m_file;
m_file = 0;
}
@@ -139,30 +144,59 @@ ConfigStore::~ConfigStore ()
void
ConfigStore::SetMode (enum Mode mode)
{
NS_LOG_FUNCTION (this << mode);
m_mode = mode;
}
void
ConfigStore::SetFileFormat (enum FileFormat format)
{
NS_LOG_FUNCTION (this << format);
m_fileFormat = format;
}
void
ConfigStore::SetFilename (std::string filename)
{
NS_LOG_FUNCTION (this << filename);
m_filename = filename;
}
void
ConfigStore::ConfigureAttributes (void)
{
NS_LOG_FUNCTION (this);
m_file->Attributes ();
}
void
ConfigStore::ConfigureDefaults (void)
{
NS_LOG_FUNCTION (this);
m_file->Default ();
m_file->Global ();
}
std::ostream &
operator << (std::ostream & os, ConfigStore::Mode & mode)
{
switch (mode)
{
case ConfigStore::LOAD: os << "LOAD"; break;
case ConfigStore::SAVE: os << "SAVE"; break;
case ConfigStore::NONE: os << "NONE"; break;
default: os << "UNKNOWN";
}
return os;
}
std::ostream &
operator << (std::ostream & os, ConfigStore::FileFormat & format)
{
switch (format)
{
case ConfigStore::XML: os << "XML"; break;
case ConfigStore::RAW_TEXT: os << "RAW_TEXT"; break;
}
return os;
}
} // namespace ns3

View File

@@ -83,6 +83,14 @@ private:
FileConfig *m_file;
};
/**
* @{
* \ingroup configstore
*/
std::ostream & operator << (std::ostream & os, ConfigStore::Mode & mode);
std::ostream & operator << (std::ostream & os, ConfigStore::FileFormat & format);
/**@}*/
} // namespace ns3
#endif /* CONFIG_STORE_H */

View File

@@ -33,9 +33,11 @@ NS_LOG_COMPONENT_DEFINE ("RawTextConfig");
RawTextConfigSave::RawTextConfigSave ()
: m_os (0)
{
NS_LOG_FUNCTION (this);
}
RawTextConfigSave::~RawTextConfigSave ()
{
NS_LOG_FUNCTION (this);
if (m_os != 0)
{
m_os->close ();
@@ -46,12 +48,14 @@ RawTextConfigSave::~RawTextConfigSave ()
void
RawTextConfigSave::SetFilename (std::string filename)
{
NS_LOG_FUNCTION (this << filename);
m_os = new std::ofstream ();
m_os->open (filename.c_str (), std::ios::out);
}
void
RawTextConfigSave::Default (void)
{
NS_LOG_FUNCTION (this);
class RawTextDefaultIterator : public AttributeDefaultIterator
{
public:
@@ -63,6 +67,7 @@ private:
m_typeId = name;
}
virtual void DoVisitAttribute (std::string name, std::string defaultValue) {
NS_LOG_DEBUG ("Saving " << m_typeId << "::" << name);
*m_os << "default " << m_typeId << "::" << name << " \"" << defaultValue << "\"" << std::endl;
}
std::string m_typeId;
@@ -75,16 +80,19 @@ private:
void
RawTextConfigSave::Global (void)
{
NS_LOG_FUNCTION (this);
for (GlobalValue::Iterator i = GlobalValue::Begin (); i != GlobalValue::End (); ++i)
{
StringValue value;
(*i)->GetValue (value);
NS_LOG_LOGIC ("Saving " << (*i)->GetName ());
*m_os << "global " << (*i)->GetName () << " \"" << value.Get () << "\"" << std::endl;
}
}
void
RawTextConfigSave::Attributes (void)
{
NS_LOG_FUNCTION (this);
class RawTextAttributeIterator : public AttributeIterator
{
public:
@@ -94,6 +102,7 @@ private:
virtual void DoVisitAttribute (Ptr<Object> object, std::string name) {
StringValue str;
object->GetAttribute (name, str);
NS_LOG_DEBUG ("Saving " << GetCurrentPath ());
*m_os << "value " << GetCurrentPath () << " \"" << str.Get () << "\"" << std::endl;
}
std::ostream *m_os;
@@ -106,9 +115,11 @@ private:
RawTextConfigLoad::RawTextConfigLoad ()
: m_is (0)
{
NS_LOG_FUNCTION (this);
}
RawTextConfigLoad::~RawTextConfigLoad ()
{
NS_LOG_FUNCTION (this);
if (m_is != 0)
{
m_is->close ();
@@ -119,6 +130,7 @@ RawTextConfigLoad::~RawTextConfigLoad ()
void
RawTextConfigLoad::SetFilename (std::string filename)
{
NS_LOG_FUNCTION (this << filename);
m_is = new std::ifstream ();
m_is->open (filename.c_str (), std::ios::in);
}
@@ -135,6 +147,7 @@ RawTextConfigLoad::Strip (std::string value)
void
RawTextConfigLoad::Default (void)
{
NS_LOG_FUNCTION (this);
m_is->clear ();
m_is->seekg (0);
std::string type, name, value;
@@ -153,6 +166,7 @@ RawTextConfigLoad::Default (void)
void
RawTextConfigLoad::Global (void)
{
NS_LOG_FUNCTION (this);
m_is->clear ();
m_is->seekg (0);
std::string type, name, value;
@@ -171,6 +185,7 @@ RawTextConfigLoad::Global (void)
void
RawTextConfigLoad::Attributes (void)
{
NS_LOG_FUNCTION (this);
m_is->seekg (0);
std::string type, path, value;
*m_is >> type >> path >> value;