Changeset - b440870d9b2a
[Not reviewed]
0 2 0
HanzZ - 15 years ago 2011-02-13 22:52:46
hanzz.k@gmail.com
onConfigReloaded signal
2 files changed with 7 insertions and 0 deletions:
0 comments (0 inline, 0 general)
include/transport/config.h
Show inline comments
 
@@ -16,38 +16,43 @@
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#pragma once
 

	
 
#include <boost/program_options.hpp>
 
#include <boost/foreach.hpp>
 
#include <boost/format.hpp>
 
#include <boost/algorithm/string.hpp>
 
#include <boost/assign.hpp>
 
#include <boost/bind.hpp>
 
#include <boost/signal.hpp>
 

	
 

	
 
#define CONFIG_STRING(PTR, KEY) (*PTR)[KEY].as<std::string>()
 
#define CONFIG_INT(PTR, KEY) (*PTR)[KEY].as<int>()
 
#define CONFIG_BOOL(PTR, KEY) (*PTR)[KEY].as<bool>()
 
#define CONFIG_LIST(PTR, KEY) (*PTR)[KEY].as<std::list<std::string> >()
 

	
 
namespace Transport {
 

	
 
typedef boost::program_options::variables_map Variables;
 

	
 
class Config {
 
	public:
 
		Config() {}
 
		virtual ~Config() {}
 
		bool load(const std::string &configfile, boost::program_options::options_description &opts);
 
		bool load(const std::string &configfile);
 

	
 
		const boost::program_options::variable_value &operator[] (const std::string &key) {
 
			return m_variables[key];
 
		}
 

	
 
		boost::signal<void ()> onConfigReloaded;
 
	
 
	private:
 
		Variables m_variables;
 
};
 

	
 
}
src/config.cpp
Show inline comments
 
@@ -33,21 +33,23 @@ bool Config::load(const std::string &configfile, boost::program_options::options
 
	opts.add_options()
 
		("service.jid", value<std::string>()->default_value(""), "Transport Jabber ID")
 
		("service.server", value<std::string>()->default_value(""), "Server to connect to")
 
		("service.password", value<std::string>()->default_value(""), "Password used to auth the server")
 
		("service.port", value<int>()->default_value(0), "Port the server is listening on")
 
		("database.database", value<std::string>()->default_value(""), "Database used to store data")
 
		("database.prefix", value<std::string>()->default_value(""), "Prefix of tables in database")
 
	;
 

	
 
    store(parse_config_file(ifs, opts), m_variables);
 
	notify(m_variables);
 

	
 
	onConfigReloaded();
 

	
 
	return true;
 
}
 

	
 
bool Config::load(const std::string &configfile) {
 
	options_description opts("Transport options");
 
	return load(configfile, opts);
 
}
 

	
 
}
0 comments (0 inline, 0 general)