mgmt: add sample configuration file and install default configuration
refs: #1332
Change-Id: Ic50aac57382b9760aa3b1c22b7dd2a9fec589cf9
diff --git a/daemon/mgmt/config-file.cpp b/daemon/mgmt/config-file.cpp
index 8018310..e5bbb9d 100644
--- a/daemon/mgmt/config-file.cpp
+++ b/daemon/mgmt/config-file.cpp
@@ -26,11 +26,11 @@
}
void
-ConfigFile::parse(const char* filename, bool isDryRun)
+ConfigFile::parse(const std::string& filename, bool isDryRun)
{
std::ifstream inputFile;
- inputFile.open(filename);
- if (!inputFile.is_open())
+ inputFile.open(filename.c_str());
+ if (!inputFile.good() || !inputFile.is_open())
{
std::string msg = "Failed to read configuration file: ";
msg += filename;
@@ -41,7 +41,7 @@
}
void
-ConfigFile::parse(const std::string& input, bool isDryRun, const char* filename)
+ConfigFile::parse(const std::string& input, bool isDryRun, const std::string& filename)
{
std::istringstream inputStream(input);
parse(inputStream, isDryRun, filename);
@@ -49,7 +49,7 @@
void
-ConfigFile::parse(std::istream& input, bool isDryRun, const char* filename)
+ConfigFile::parse(std::istream& input, bool isDryRun, const std::string& filename)
{
try
{
@@ -59,10 +59,7 @@
{
std::stringstream msg;
msg << "Failed to parse configuration file";
- if (filename != 0)
- {
- msg << " " << filename;
- }
+ msg << " " << filename;
msg << " " << error.message() << " line " << error.line();
throw Error(msg.str());
}
@@ -71,18 +68,16 @@
}
void
-ConfigFile::process(bool isDryRun, const char* filename)
+ConfigFile::process(bool isDryRun, const std::string& filename)
{
+ BOOST_ASSERT(!filename.empty());
// NFD_LOG_DEBUG("processing..." << ((isDryRun)?("dry run"):("")));
if (m_global.begin() == m_global.end())
{
std::string msg = "Error processing configuration file";
- if (filename != 0)
- {
- msg += ": ";
- msg += filename;
- }
+ msg += ": ";
+ msg += filename;
msg += " no data";
throw Error(msg);
}
@@ -101,11 +96,8 @@
else
{
std::string msg = "Error processing configuration file";
- if (filename != 0)
- {
- msg += " ";
- msg += filename;
- }
+ msg += " ";
+ msg += filename;
msg += " no module subscribed for section: " + sectionName;
throw Error(msg);
}
diff --git a/daemon/mgmt/config-file.hpp b/daemon/mgmt/config-file.hpp
index 2b72e7f..2a94fac 100644
--- a/daemon/mgmt/config-file.hpp
+++ b/daemon/mgmt/config-file.hpp
@@ -47,31 +47,31 @@
* \throws ConfigFile::Error if parse error
*/
void
- parse(const char* filename, bool isDryRun=false);
+ parse(const std::string& filename, bool isDryRun);
/**
* \param input configuration (as a string) to parse
* \param isDryRun true if performing a dry run of configuration, false otherwise
- * \param filename optional convenience argument to provide more detailed error messages (if available)
+ * \param filename optional convenience argument to provide more detailed error messages
* \throws ConfigFile::Error if file not found
* \throws ConfigFile::Error if parse error
*/
void
- parse(const std::string& input, bool isDryRun=false, const char* filename=0);
+ parse(const std::string& input, bool isDryRun, const std::string& filename);
/**
* \param input stream to parse
* \param isDryRun true if performing a dry run of configuration, false otherwise
- * \param filename optional convenience argument to provide more detailed error messages (if available)
+ * \param filename optional convenience argument to provide more detailed error messages
* \throws ConfigFile::Error if parse error
*/
void
- parse(std::istream& input, bool isDryRun=false, const char* filename=0);
+ parse(std::istream& input, bool isDryRun, const std::string& filename);
private:
void
- process(bool isDryRun, const char* filename);
+ process(bool isDryRun, const std::string& filename);
private: