Streamline ConfDb loading proceedure (#791)

* Create DatabaseConfBuilder & remove locking
* Remove all refcounting

This is part 1/n in regards to this PR's rework
* Move db conf lookup out of RunThreadPart
* Return default configuration for failed lookups
* RefPtr members & stop leaks
* fix uint comparison warning
This commit is contained in:
Michael Flaherty
2018-06-19 09:35:37 -07:00
committed by Kyle Sanderson
parent 53c63def07
commit b9b6832a11
7 changed files with 367 additions and 238 deletions
+10 -8
View File
@@ -314,6 +314,12 @@ public:
error[0] = '\0';
strncopy(dbname, _dbname, sizeof(dbname));
me = scripts->FindPluginByContext(m_pFunction->GetParentContext()->GetContext());
m_pInfo = g_DBMan.GetDatabaseConf(dbname);
if (!m_pInfo)
{
g_pSM->Format(error, sizeof(error), "Could not find database config \"%s\"", dbname);
}
}
IdentityToken_t *GetOwner()
{
@@ -325,15 +331,10 @@ public:
}
void RunThreadPart()
{
g_DBMan.LockConfig();
const DatabaseInfo *pInfo = g_DBMan.FindDatabaseConf(dbname);
if (!pInfo)
if (m_pInfo)
{
g_pSM->Format(error, sizeof(error), "Could not find database config \"%s\"", dbname);
} else {
m_pDatabase = m_pDriver->Connect(pInfo, false, error, sizeof(error));
m_pDatabase = m_pDriver->Connect(&m_pInfo->info, false, error, sizeof(error));
}
g_DBMan.UnlockConfig();
}
void CancelThinkPart()
{
@@ -383,6 +384,7 @@ public:
delete this;
}
private:
ke::RefPtr<ConfDbInfo> m_pInfo;
IPlugin *me;
IPluginFunction *m_pFunction;
IDBDriver *m_pDriver;
@@ -453,7 +455,7 @@ static cell_t ConnectToDbAsync(IPluginContext *pContext, const cell_t *params, A
g_pSM->Format(error,
sizeof(error),
"Could not find driver \"%s\"",
pInfo->driver[0] == '\0' ? g_DBMan.GetDefaultDriverName() : pInfo->driver);
pInfo->driver[0] == '\0' ? g_DBMan.GetDefaultDriverName().chars() : pInfo->driver);
} else if (!driver->IsThreadSafe()) {
g_pSM->Format(error,
sizeof(error),