Patch ZNC core for more control over singleton...

This commit is contained in:
Ingmar Runge
2014-02-06 22:21:44 +01:00
parent 200c5da15f
commit 4c505946ac
3 changed files with 24 additions and 8 deletions
+3 -1
View File
@@ -56,7 +56,7 @@ public:
CString ExpandConfigPath(const CString& sConfigFile, bool bAllowMkDir = true);
bool WriteNewConfig(const CString& sConfigFile);
bool WriteConfig();
bool ParseConfig(const CString& sConfig);
bool ParseConfig(const CString& sConfig, CString& sError);
bool RehashConfig(CString& sError);
void BackupConfigOnce(const CString& sSuffix);
static CString GetVersion();
@@ -131,7 +131,9 @@ public:
// !Getters
// Static allocator
static void CreateInstance();
static CZNC& Get();
static void DestroyInstance();
CUser* FindUser(const CString& sUsername);
CModule* FindModule(const CString& sModName, const CString& sUsername);
CModule* FindModule(const CString& sModName, CUser* pUser);
+4 -1
View File
@@ -193,6 +193,8 @@ int main(int argc, char** argv) {
return 1;
}
CZNC::CreateInstance();
CZNC* pZNC = &CZNC::Get();
pZNC->InitDirs(((argc) ? argv[0] : ""), sDataDir);
@@ -264,7 +266,8 @@ int main(int argc, char** argv) {
/* Fall through to normal bootup */
}
if (!pZNC->ParseConfig(sConfig)) {
CString sConfigError;
if (!pZNC->ParseConfig(sConfig, sConfigError)) {
CUtils::PrintError("Unrecoverable config error.");
delete pZNC;
return 1;
+17 -6
View File
@@ -1022,13 +1022,11 @@ void CZNC::BackupConfigOnce(const CString& sSuffix) {
CUtils::PrintStatus(false, strerror(errno));
}
bool CZNC::ParseConfig(const CString& sConfig)
bool CZNC::ParseConfig(const CString& sConfig, CString& sError)
{
CString s;
m_sConfigFile = ExpandConfigPath(sConfig, false);
return DoRehash(s);
return DoRehash(sError);
}
bool CZNC::RehashConfig(CString& sError)
@@ -1853,9 +1851,22 @@ bool CZNC::DelListener(CListener* pListener) {
return false;
}
static CZNC* s_pZNC = NULL;
void CZNC::CreateInstance() {
if (s_pZNC)
abort();
s_pZNC = new CZNC();
}
CZNC& CZNC::Get() {
static CZNC* pZNC = new CZNC;
return *pZNC;
return *s_pZNC;
}
void CZNC::DestroyInstance() {
delete s_pZNC;
s_pZNC = NULL;
}
CZNC::TrafficStatsMap CZNC::GetTrafficStats(TrafficStatsPair &Users,