documentation - p3configmgr.h

added rstatus config constant id

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2719 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2010-04-15 11:26:44 +00:00
parent 261637ad08
commit e2c8053eee
2 changed files with 81 additions and 51 deletions

View File

@ -60,7 +60,7 @@ void p3ConfigMgr::tick()
if (it->second->HasConfigChanged(0)) if (it->second->HasConfigChanged(0))
{ {
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::tick() Config Changed - Element: "; std::cerr << "p3ConfigMgr::tick() Config Changed - Element: ";
std::cerr << it->first; std::cerr << it->first;
std::cerr << std::endl; std::cerr << std::endl;
@ -88,7 +88,7 @@ void p3ConfigMgr::saveConfiguration()
{ {
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/ RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::saveConfiguration()"; std::cerr << "p3ConfigMgr::saveConfiguration()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -100,7 +100,7 @@ void p3ConfigMgr::saveConfiguration()
{ {
if (it->second->HasConfigChanged(1)) if (it->second->HasConfigChanged(1))
{ {
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::saveConfiguration() Saving Element: "; std::cerr << "p3ConfigMgr::saveConfiguration() Saving Element: ";
std::cerr << it->first; std::cerr << it->first;
std::cerr << std::endl; std::cerr << std::endl;
@ -109,7 +109,7 @@ void p3ConfigMgr::saveConfiguration()
} }
/* save metaconfig */ /* save metaconfig */
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::saveConfiguration() Element: "; std::cerr << "p3ConfigMgr::saveConfiguration() Element: ";
std::cerr << it->first << " Hash: " << it->second->Hash(); std::cerr << it->first << " Hash: " << it->second->Hash();
std::cerr << std::endl; std::cerr << std::endl;
@ -130,7 +130,7 @@ void p3ConfigMgr::saveConfiguration()
item->tlvkvs.pairs.push_back(kv); item->tlvkvs.pairs.push_back(kv);
} }
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::saveConfiguration() Complete MetaConfigItem: "; std::cerr << "p3ConfigMgr::saveConfiguration() Complete MetaConfigItem: ";
std::cerr << std::endl; std::cerr << std::endl;
item->print(std::cerr, 20); item->print(std::cerr, 20);
@ -169,7 +169,7 @@ void p3ConfigMgr::saveConfiguration()
BinMemInterface *signbio = new BinMemInterface(signature.c_str(), BinMemInterface *signbio = new BinMemInterface(signature.c_str(),
signature.length(), BIN_FLAGS_READABLE); signature.length(), BIN_FLAGS_READABLE);
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::saveConfiguration() MetaFile Signature:"; std::cerr << "p3ConfigMgr::saveConfiguration() MetaFile Signature:";
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << signature; std::cerr << signature;
@ -288,7 +288,7 @@ void p3ConfigMgr::loadConfiguration()
{ {
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/ RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::loadConfiguration()"; std::cerr << "p3ConfigMgr::loadConfiguration()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -351,7 +351,7 @@ void p3ConfigMgr::loadConfiguration()
return; return;
} }
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::loadConfiguration() Loaded MetaConfigItem: "; std::cerr << "p3ConfigMgr::loadConfiguration() Loaded MetaConfigItem: ";
std::cerr << std::endl; std::cerr << std::endl;
item->print(std::cerr, 20); item->print(std::cerr, 20);
@ -381,7 +381,7 @@ void p3ConfigMgr::loadConfiguration()
cit = configs.find(confId); cit = configs.find(confId);
if (cit != configs.end()) if (cit != configs.end())
{ {
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::loadConfiguration() Element: "; std::cerr << "p3ConfigMgr::loadConfiguration() Element: ";
std::cerr << confId << " Hash: " << hashin; std::cerr << confId << " Hash: " << hashin;
std::cerr << std::endl; std::cerr << std::endl;
@ -395,7 +395,7 @@ void p3ConfigMgr::loadConfiguration()
delete item; delete item;
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::loadConfiguration() Done!"; std::cerr << "p3ConfigMgr::loadConfiguration() Done!";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -587,7 +587,7 @@ bool p3Config::getHashAttempt(const std::string& loadHash, std::string& hashstr,
while(NULL != (item = stream.GetItem())) while(NULL != (item = stream.GetItem()))
{ {
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "p3Config::loadConfiguration() loaded item:"; std::cerr << "p3Config::loadConfiguration() loaded item:";
std::cerr << std::endl; std::cerr << std::endl;
item->print(std::cerr, 0); item->print(std::cerr, 0);
@ -596,7 +596,7 @@ bool p3Config::getHashAttempt(const std::string& loadHash, std::string& hashstr,
load.push_back(item); load.push_back(item);
} }
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "p3Config::loadConfiguration() loaded " << load.size(); std::cerr << "p3Config::loadConfiguration() loaded " << load.size();
std::cerr << " Elements from File: " << cfg_fname; std::cerr << " Elements from File: " << cfg_fname;
std::cerr << std::endl; std::cerr << std::endl;
@ -609,7 +609,7 @@ bool p3Config::getHashAttempt(const std::string& loadHash, std::string& hashstr,
if (hashstr != loadHash) if (hashstr != loadHash)
{ {
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "p3Config::loadConfiguration() ERROR: Hash != MATCHloaded"; std::cerr << "p3Config::loadConfiguration() ERROR: Hash != MATCHloaded";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -639,7 +639,7 @@ bool p3Config::saveConfiguration()
std::string cfg_fname = Filename(); // get configuration file name std::string cfg_fname = Filename(); // get configuration file name
std::string cfg_fname_backup = Filename()+".tmp"; // backup file for two pass save std::string cfg_fname_backup = Filename()+".tmp"; // backup file for two pass save
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "Writting p3config file " << cfg_fname << std::endl ; std::cerr << "Writting p3config file " << cfg_fname << std::endl ;
std::cerr << "p3Config::saveConfiguration() toSave " << toSave.size(); std::cerr << "p3Config::saveConfiguration() toSave " << toSave.size();
std::cerr << " Elements to File: " << cfg_fname; std::cerr << " Elements to File: " << cfg_fname;
@ -790,7 +790,7 @@ p3GeneralConfig::p3GeneralConfig()
// General Configuration System // General Configuration System
std::string p3GeneralConfig::getSetting(std::string opt) std::string p3GeneralConfig::getSetting(std::string opt)
{ {
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "p3GeneralConfig::getSetting(" << opt << ")"; std::cerr << "p3GeneralConfig::getSetting(" << opt << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -808,7 +808,7 @@ std::string p3GeneralConfig::getSetting(std::string opt)
void p3GeneralConfig::setSetting(std::string opt, std::string val) void p3GeneralConfig::setSetting(std::string opt, std::string val)
{ {
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "p3GeneralConfig::setSetting(" << opt << " = " << val << ")"; std::cerr << "p3GeneralConfig::setSetting(" << opt << " = " << val << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -845,7 +845,7 @@ std::list<RsItem *> p3GeneralConfig::saveList(bool &cleanup)
{ {
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/ RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "p3GeneralConfig::saveList() KV sets: " << settings.size(); std::cerr << "p3GeneralConfig::saveList() KV sets: " << settings.size();
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -878,10 +878,10 @@ std::list<RsItem *> p3GeneralConfig::saveList(bool &cleanup)
return savelist; return savelist;
} }
bool p3GeneralConfig::loadList(std::list<RsItem *> load) bool p3GeneralConfig::loadList(std::list<RsItem *> load)
{ {
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
std::cerr << "p3GeneralConfig::loadList() count: " << load.size(); std::cerr << "p3GeneralConfig::loadList() count: " << load.size();
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -898,7 +898,7 @@ bool p3GeneralConfig::loadList(std::list<RsItem *> load)
item = dynamic_cast<RsConfigKeyValueSet *>(*it); item = dynamic_cast<RsConfigKeyValueSet *>(*it);
if (item) if (item)
{ {
for(kit = item->tlvkvs.pairs.begin(); for(kit = item->tlvkvs.pairs.begin();
kit != item->tlvkvs.pairs.end(); kit++) kit != item->tlvkvs.pairs.end(); kit++)
{ {
settings[kit->key] = kit->value; settings[kit->key] = kit->value;
@ -915,7 +915,7 @@ bool p3GeneralConfig::loadList(std::list<RsItem *> load)
/**** MUTEX NOTE: /**** MUTEX NOTE:
* have protected all, but think that * have protected all, but think that
* only the Indication and hash really need it * only the Indication and hash really need it
*/ */
@ -926,49 +926,49 @@ pqiConfig::pqiConfig(uint32_t t)
} }
pqiConfig::~pqiConfig() pqiConfig::~pqiConfig()
{ {
return; return;
} }
uint32_t pqiConfig::Type() uint32_t pqiConfig::Type()
{ {
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/ RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
return type; return type;
} }
std::string pqiConfig::Filename() std::string pqiConfig::Filename()
{ {
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/ RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
return filename; return filename;
}
std::string pqiConfig::Hash()
{
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
return hash;
} }
void pqiConfig::IndicateConfigChanged() std::string pqiConfig::Hash()
{ {
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/ RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
ConfInd.IndicateChanged(); return hash;
} }
bool pqiConfig::HasConfigChanged(uint16_t idx) void pqiConfig::IndicateConfigChanged()
{ {
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/ RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
return ConfInd.Changed(idx); ConfInd.IndicateChanged();
} }
void pqiConfig::setFilename(std::string name) bool pqiConfig::HasConfigChanged(uint16_t idx)
{ {
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/ RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
filename = name; return ConfInd.Changed(idx);
} }
void pqiConfig::setHash(std::string h) void pqiConfig::setFilename(std::string name)
{ {
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/ RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
hash = h; filename = name;
}
void pqiConfig::setHash(std::string h)
{
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
hash = h;
} }

View File

@ -76,7 +76,7 @@ const uint32_t CONFIG_TYPE_FT_EXTRA_LIST= 0x0008;
const uint32_t CONFIG_TYPE_FT_CONTROL = 0x0009; const uint32_t CONFIG_TYPE_FT_CONTROL = 0x0009;
const uint32_t CONFIG_TYPE_FT_DWLQUEUE = 0x000A; const uint32_t CONFIG_TYPE_FT_DWLQUEUE = 0x000A;
/* turtle router */ /// turtle router
const uint32_t CONFIG_TYPE_TURTLE = 0x0020; const uint32_t CONFIG_TYPE_TURTLE = 0x0020;
/* wish these ids where higher... /* wish these ids where higher...
@ -84,6 +84,7 @@ const uint32_t CONFIG_TYPE_TURTLE = 0x0020;
*/ */
const uint32_t CONFIG_TYPE_RANK_LINK = 0x0011; const uint32_t CONFIG_TYPE_RANK_LINK = 0x0011;
const uint32_t CONFIG_TYPE_CHAT = 0x0012; const uint32_t CONFIG_TYPE_CHAT = 0x0012;
const uint32_t CONFIG_TYPE_STATUS = 0x0013;
/* standard services */ /* standard services */
const uint32_t CONFIG_TYPE_QBLOG = 0x0101; const uint32_t CONFIG_TYPE_QBLOG = 0x0101;
@ -98,6 +99,8 @@ const uint32_t CONFIG_TYPE_CACHE = 0xff01;
class p3ConfigMgr; class p3ConfigMgr;
//! abstract class for configuration saving
/*! /*!
* Aim is that active objects in retroshare can dervie from this class * Aim is that active objects in retroshare can dervie from this class
* and implement their method of saving and loading their configuration * and implement their method of saving and loading their configuration
@ -109,12 +112,15 @@ class pqiConfig
virtual ~pqiConfig(); virtual ~pqiConfig();
/** /**
* loadHash This is the hash that will be compared to confirm saved configuration has not * loads configuration of object
* @param loadHash This is the hash that will be compared to confirm saved configuration has not
* been tampered with * been tampered with
*/ */
virtual bool loadConfiguration(std::string &loadHash) = 0; virtual bool loadConfiguration(std::string &loadHash) = 0;
/**
* save configuration of object
*/
virtual bool saveConfiguration() = 0; virtual bool saveConfiguration() = 0;
/** /**
@ -181,6 +187,12 @@ void setHash(std::string h);
class p3ConfigMgr class p3ConfigMgr
{ {
public: public:
/**
* @param bdir base directory: where config files will be saved
* @param fname file name for global configuration
* @param signame file name for global signature
*/
p3ConfigMgr(std::string bdir, std::string fname, std::string signame); p3ConfigMgr(std::string bdir, std::string fname, std::string signame);
/** /**
@ -191,11 +203,12 @@ class p3ConfigMgr
/** /**
* save all added configuation including configuration files * save all added configuation including configuration files
* creates global signature file
*/ */
void saveConfiguration(); void saveConfiguration();
/** /**
* save all loaded configurations * loads all configurations
*/ */
void loadConfiguration(); void loadConfiguration();
@ -244,6 +257,12 @@ std::map<uint32_t, pqiConfig *> configs;
/***************************************************************************************************/ /***************************************************************************************************/
//! abstract class for configuration saving, aimed at rs services that uses RsItem config data
/*!
* The aim of this class is to provide a way for rs services and object to save particular
* configurations an items (and load them up as well).
*/
class p3Config: public pqiConfig class p3Config: public pqiConfig
{ {
public: public:
@ -257,8 +276,19 @@ virtual bool saveConfiguration();
/* Key Functions to be overloaded for Full Configuration */ /* Key Functions to be overloaded for Full Configuration */
virtual RsSerialiser *setupSerialiser() = 0; virtual RsSerialiser *setupSerialiser() = 0;
/**
* saves list of derived object
* @return list of config items derived object wants to saves
*/
virtual std::list<RsItem *> saveList(bool &cleanup) = 0; virtual std::list<RsItem *> saveList(bool &cleanup) = 0;
/**
* loads up list of configs items for derived object
* @param load list of config items to load up
*/
virtual bool loadList(std::list<RsItem *> load) = 0; virtual bool loadList(std::list<RsItem *> load) = 0;
/** /**
* callback for mutex unlocking * callback for mutex unlocking
* in derived classes (should only be needed if cleanup = false) * in derived classes (should only be needed if cleanup = false)