2008-03-30 09:00:22 +02:00
|
|
|
/**
|
2013-08-21 09:01:28 +02:00
|
|
|
* vim: set ts=4 sw=4 tw=99 noet :
|
2008-03-30 09:00:22 +02:00
|
|
|
* =============================================================================
|
|
|
|
* SourceMod
|
|
|
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
|
|
|
* =============================================================================
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE_DATABASE_MANAGER_H_
|
|
|
|
#define _INCLUDE_DATABASE_MANAGER_H_
|
|
|
|
|
2013-10-09 14:43:08 +02:00
|
|
|
#include "common_logic.h"
|
2008-03-30 09:00:22 +02:00
|
|
|
#include <sh_vector.h>
|
2018-06-19 18:35:37 +02:00
|
|
|
#include <am-string.h>
|
2008-03-30 09:00:22 +02:00
|
|
|
#include <sh_list.h>
|
|
|
|
#include <IThreader.h>
|
2013-03-29 19:37:29 +01:00
|
|
|
#include <IPluginSys.h>
|
2013-08-23 02:10:59 +02:00
|
|
|
#include <am-thread-utils.h>
|
2008-03-30 09:00:22 +02:00
|
|
|
#include "sm_simple_prioqueue.h"
|
2018-06-19 18:35:37 +02:00
|
|
|
#include <am-refcounting.h>
|
|
|
|
#include "DatabaseConfBuilder.h"
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
using namespace SourceHook;
|
|
|
|
|
|
|
|
|
|
|
|
class DBManager :
|
|
|
|
public IDBManager,
|
|
|
|
public SMGlobalClass,
|
|
|
|
public IHandleTypeDispatch,
|
2016-03-13 21:58:46 +01:00
|
|
|
public IPluginsListener
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
DBManager();
|
|
|
|
public:
|
|
|
|
const char *GetInterfaceName();
|
|
|
|
unsigned int GetInterfaceVersion();
|
|
|
|
public: //SMGlobalClass
|
|
|
|
void OnSourceModAllInitialized();
|
|
|
|
void OnSourceModLevelChange(const char *mapName);
|
|
|
|
void OnSourceModIdentityDropped(IdentityToken_t *pToken);
|
|
|
|
void OnSourceModShutdown();
|
|
|
|
public: //IHandleTypeDispatch
|
|
|
|
void OnHandleDestroy(HandleType_t type, void *object);
|
|
|
|
public: //IDBManager
|
|
|
|
void AddDriver(IDBDriver *pDrivera);
|
|
|
|
void RemoveDriver(IDBDriver *pDriver);
|
|
|
|
const DatabaseInfo *FindDatabaseConf(const char *name);
|
2018-06-19 18:35:37 +02:00
|
|
|
ConfDbInfo *GetDatabaseConf(const char *name);
|
2008-03-30 09:00:22 +02:00
|
|
|
bool Connect(const char *name, IDBDriver **pdr, IDatabase **pdb, bool persistent, char *error, size_t maxlength);
|
|
|
|
unsigned int GetDriverCount();
|
|
|
|
IDBDriver *GetDriver(unsigned int index);
|
|
|
|
Handle_t CreateHandle(DBHandleType type, void *ptr, IdentityToken_t *pToken);
|
|
|
|
HandleError ReadHandle(Handle_t hndl, DBHandleType type, void **ptr);
|
|
|
|
HandleError ReleaseHandle(Handle_t hndl, DBHandleType type, IdentityToken_t *token);
|
2008-07-01 08:12:16 +02:00
|
|
|
void AddDependency(IExtension *myself, IDBDriver *driver);
|
2013-08-21 09:01:28 +02:00
|
|
|
public: //ke::IRunnable
|
|
|
|
void Run();
|
|
|
|
void ThreadMain();
|
2008-03-30 09:00:22 +02:00
|
|
|
public: //IPluginsListener
|
2015-11-01 08:36:20 +01:00
|
|
|
void OnPluginWillUnload(IPlugin *plugin);
|
2008-03-30 09:00:22 +02:00
|
|
|
public:
|
|
|
|
IDBDriver *FindOrLoadDriver(const char *name);
|
|
|
|
IDBDriver *GetDefaultDriver();
|
2018-06-19 18:35:37 +02:00
|
|
|
ke::AString GetDefaultDriverName();
|
2008-03-30 09:00:22 +02:00
|
|
|
bool AddToThreadQueue(IDBThreadOperation *op, PrioQueueLevel prio);
|
|
|
|
void RunFrame();
|
|
|
|
inline HandleType_t GetDatabaseType()
|
|
|
|
{
|
|
|
|
return m_DatabaseType;
|
|
|
|
}
|
|
|
|
private:
|
2010-10-17 07:27:34 +02:00
|
|
|
void ClearConfigs();
|
2008-03-30 09:00:22 +02:00
|
|
|
void KillWorkerThread();
|
|
|
|
private:
|
|
|
|
CVector<IDBDriver *> m_drivers;
|
|
|
|
|
|
|
|
/* Threading stuff */
|
|
|
|
PrioQueue<IDBThreadOperation *> m_OpQueue;
|
|
|
|
Queue<IDBThreadOperation *> m_ThinkQueue;
|
|
|
|
CVector<bool> m_drSafety; /* which drivers are safe? */
|
2013-08-21 09:01:28 +02:00
|
|
|
ke::AutoPtr<ke::Thread> m_Worker;
|
|
|
|
ke::ConditionVariable m_QueueEvent;
|
|
|
|
ke::Mutex m_ThinkLock;
|
|
|
|
bool m_Terminate;
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2018-06-19 18:35:37 +02:00
|
|
|
DatabaseConfBuilder m_Builder;
|
2008-03-30 09:00:22 +02:00
|
|
|
HandleType_t m_DriverType;
|
|
|
|
HandleType_t m_DatabaseType;
|
|
|
|
char m_Filename[PLATFORM_MAX_PATH];
|
|
|
|
IDBDriver *m_pDefault;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern DBManager g_DBMan;
|
|
|
|
|
|
|
|
#endif //_INCLUDE_DATABASE_MANAGER_H_
|