ConfigFile thread safe.
This commit is contained in:
@@ -232,6 +232,8 @@ ConfigFile::~ConfigFile()
|
|||||||
|
|
||||||
void ConfigFile::fillBuffer() {
|
void ConfigFile::fillBuffer() {
|
||||||
|
|
||||||
|
boost::mutex::scoped_lock lock(m_configMutex);
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
string tempString("");
|
string tempString("");
|
||||||
|
|
||||||
@@ -257,7 +259,9 @@ void ConfigFile::fillBuffer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigFile::writeBuffer() {
|
void ConfigFile::writeBuffer() const {
|
||||||
|
|
||||||
|
boost::mutex::scoped_lock lock(m_configMutex);
|
||||||
|
|
||||||
//write buffer to disc if enabled
|
//write buffer to disc if enabled
|
||||||
if(!noWriteAccess) {
|
if(!noWriteAccess) {
|
||||||
@@ -286,6 +290,8 @@ void ConfigFile::writeBuffer() {
|
|||||||
|
|
||||||
void ConfigFile::updateConfig(ConfigState myConfigState) {
|
void ConfigFile::updateConfig(ConfigState myConfigState) {
|
||||||
|
|
||||||
|
boost::mutex::scoped_lock lock(m_configMutex);
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if(myConfigState == NONEXISTING) {
|
if(myConfigState == NONEXISTING) {
|
||||||
@@ -369,8 +375,10 @@ void ConfigFile::updateConfig(ConfigState myConfigState) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string ConfigFile::readConfigString(string varName)
|
string ConfigFile::readConfigString(string varName) const
|
||||||
{
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_configMutex);
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
string tempString("");
|
string tempString("");
|
||||||
|
|
||||||
@@ -404,8 +412,10 @@ string ConfigFile::readConfigString(string varName)
|
|||||||
return tempString;
|
return tempString;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigFile::readConfigInt(string varName)
|
int ConfigFile::readConfigInt(string varName) const
|
||||||
{
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_configMutex);
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
string tempString("");
|
string tempString("");
|
||||||
int tempInt=0;
|
int tempInt=0;
|
||||||
@@ -449,7 +459,9 @@ int ConfigFile::readConfigInt(string varName)
|
|||||||
|
|
||||||
|
|
||||||
void ConfigFile::writeConfigInt(string varName, int varCont)
|
void ConfigFile::writeConfigInt(string varName, int varCont)
|
||||||
{
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_configMutex);
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
string tempString;
|
string tempString;
|
||||||
ostringstream intToString;
|
ostringstream intToString;
|
||||||
@@ -464,7 +476,9 @@ void ConfigFile::writeConfigInt(string varName, int varCont)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ConfigFile::writeConfigString(string varName, string varCont)
|
void ConfigFile::writeConfigString(string varName, string varCont)
|
||||||
{
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_configMutex);
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i=0; i<configBufferList.size(); i++) {
|
for (i=0; i<configBufferList.size(); i++) {
|
||||||
if (configBufferList[i].name == varName) { configBufferList[i].defaultValue = varCont; }
|
if (configBufferList[i].name == varName) { configBufferList[i].defaultValue = varCont; }
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
enum ConfigState { NONEXISTING, OLD };
|
enum ConfigState { NONEXISTING, OLD };
|
||||||
enum ConfigType { CONFIG_TYPE_INT, CONFIG_TYPE_STRING };
|
enum ConfigType { CONFIG_TYPE_INT, CONFIG_TYPE_STRING };
|
||||||
@@ -38,19 +38,20 @@ public:
|
|||||||
~ConfigFile();
|
~ConfigFile();
|
||||||
|
|
||||||
void fillBuffer();
|
void fillBuffer();
|
||||||
void writeBuffer();
|
void writeBuffer() const;
|
||||||
|
|
||||||
void updateConfig(ConfigState);
|
void updateConfig(ConfigState);
|
||||||
|
|
||||||
std::string readConfigString(std::string varName);
|
std::string readConfigString(std::string varName) const;
|
||||||
void writeConfigString(std::string varName, std::string varCont);
|
void writeConfigString(std::string varName, std::string varCont);
|
||||||
|
|
||||||
int readConfigInt(std::string varName);
|
int readConfigInt(std::string varName) const;
|
||||||
void writeConfigInt(std::string varName, int varCont);
|
void writeConfigInt(std::string varName, int varCont);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
mutable boost::mutex m_configMutex;
|
||||||
|
|
||||||
struct ConfigInfo
|
struct ConfigInfo
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user