Browse Source

More local.conf stuff.

Adam Ierymenko 11 years ago
parent
commit
33728840ec
2 changed files with 41 additions and 0 deletions
  1. 23 0
      node/NodeConfig.cpp
  2. 18 0
      node/NodeConfig.hpp

+ 23 - 0
node/NodeConfig.cpp

@@ -118,6 +118,29 @@ NodeConfig::~NodeConfig()
 	_writeLocalConfig();
 	_writeLocalConfig();
 }
 }
 
 
+void NodeConfig::putLocalConfig(const std::string &key,const char *value)
+{
+	Mutex::Lock _l(_localConfig_m);
+	_localConfig[key] = value;
+	_writeLocalConfig();
+}
+
+void NodeConfig::putLocalConfig(const std::string &key,const std::string &value)
+{
+	Mutex::Lock _l(_localConfig_m);
+	_localConfig[key] = value;
+	_writeLocalConfig();
+}
+
+std::string NodeConfig::getLocalConfig(const std::string &key) const
+{
+	Mutex::Lock _l(_localConfig_m);
+	Dictionary::const_iterator i(_localConfig.find(key));
+	if (i == _localConfig.end())
+		return std::string();
+	return i->second;
+}
+
 void NodeConfig::clean()
 void NodeConfig::clean()
 {
 {
 	Mutex::Lock _l(_networks_m);
 	Mutex::Lock _l(_networks_m);

+ 18 - 0
node/NodeConfig.hpp

@@ -68,6 +68,24 @@ public:
 
 
 	~NodeConfig();
 	~NodeConfig();
 
 
+	/**
+	 * Store something in local configuration cache
+	 *
+	 * By convention, keys starting with _ will not be shown in the command bus
+	 * local config functions.
+	 *
+	 * @param key Configuration key
+	 * @param value Configuration value
+	 */
+	void putLocalConfig(const std::string &key,const char *value);
+	void putLocalConfig(const std::string &key,const std::string &value);
+
+	/**
+	 * @param key Configuration key
+	 * @return Value or empty string if not found
+	 */
+	std::string getLocalConfig(const std::string &key) const;
+
 	/**
 	/**
 	 * @param nwid Network ID
 	 * @param nwid Network ID
 	 * @return Network or NULL if no network for that ID
 	 * @return Network or NULL if no network for that ID