2007-04-05 09:09:17 +02:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
|
|
|
* ===============================================================
|
|
|
|
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
|
|
|
|
* ===============================================================
|
|
|
|
*
|
|
|
|
* This file is not open source and may not be copied without explicit
|
|
|
|
* written permission of AlliedModders LLC. This file may not be redistributed
|
|
|
|
* in whole or significant part.
|
|
|
|
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
2007-04-05 09:08:39 +02:00
|
|
|
#ifndef _INCLUDE_DATABASE_MANAGER_H_
|
|
|
|
#define _INCLUDE_DATABASE_MANAGER_H_
|
|
|
|
|
|
|
|
#include <IDBDriver.h>
|
|
|
|
#include "sm_globals.h"
|
|
|
|
#include <sh_vector.h>
|
2007-06-01 04:30:29 +02:00
|
|
|
#include <sh_string.h>
|
|
|
|
#include <sh_list.h>
|
|
|
|
#include <ITextParsers.h>
|
|
|
|
#include "sm_memtable.h"
|
2007-07-13 21:20:12 +02:00
|
|
|
#include <IThreader.h>
|
|
|
|
#include "sm_simple_prioqueue.h"
|
|
|
|
#include "PluginSys.h"
|
2007-04-05 09:08:39 +02:00
|
|
|
|
|
|
|
using namespace SourceHook;
|
|
|
|
|
2007-06-01 04:30:29 +02:00
|
|
|
struct ConfDbInfo
|
|
|
|
{
|
|
|
|
ConfDbInfo() : name(-1), driver(-1), host(-1), user(-1), pass(-1),
|
|
|
|
database(-1), realDriver(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
int name;
|
|
|
|
int driver;
|
|
|
|
int host;
|
|
|
|
int user;
|
|
|
|
int pass;
|
|
|
|
int database;
|
|
|
|
IDBDriver *realDriver;
|
|
|
|
DatabaseInfo info;
|
|
|
|
};
|
|
|
|
|
2007-04-05 09:08:39 +02:00
|
|
|
class DBManager :
|
|
|
|
public IDBManager,
|
|
|
|
public SMGlobalClass,
|
2007-06-01 04:30:29 +02:00
|
|
|
public IHandleTypeDispatch,
|
2007-07-13 21:20:12 +02:00
|
|
|
public ITextListener_SMC,
|
|
|
|
public IThread,
|
|
|
|
public IThreadWorkerCallbacks,
|
|
|
|
public IPluginsListener
|
2007-04-05 09:08:39 +02:00
|
|
|
{
|
2007-06-01 04:30:29 +02:00
|
|
|
public:
|
|
|
|
DBManager();
|
2007-05-29 10:32:12 +02:00
|
|
|
public:
|
2007-04-05 09:08:39 +02:00
|
|
|
const char *GetInterfaceName();
|
|
|
|
unsigned int GetInterfaceVersion();
|
|
|
|
public: //SMGlobalClass
|
|
|
|
void OnSourceModAllInitialized();
|
2007-06-01 04:30:29 +02:00
|
|
|
void OnSourceModLevelChange(const char *mapName);
|
2007-07-24 04:24:37 +02:00
|
|
|
void OnSourceModIdentityDropped(IdentityToken_t *pToken);
|
2007-05-29 10:32:12 +02:00
|
|
|
void OnSourceModShutdown();
|
2007-04-05 09:08:39 +02:00
|
|
|
public: //IHandleTypeDispatch
|
|
|
|
void OnHandleDestroy(HandleType_t type, void *object);
|
|
|
|
public: //IDBManager
|
2007-05-29 10:32:12 +02:00
|
|
|
void AddDriver(IDBDriver *pDrivera);
|
2007-04-05 09:08:39 +02:00
|
|
|
void RemoveDriver(IDBDriver *pDriver);
|
|
|
|
const DatabaseInfo *FindDatabaseConf(const char *name);
|
2007-05-29 10:32:12 +02:00
|
|
|
bool Connect(const char *name, IDBDriver **pdr, IDatabase **pdb, bool persistent, char *error, size_t maxlength);
|
2007-04-05 09:08:39 +02:00
|
|
|
unsigned int GetDriverCount();
|
2007-05-29 10:32:12 +02:00
|
|
|
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);
|
2007-06-01 04:30:29 +02:00
|
|
|
public: //ITextListener_SMC
|
|
|
|
void ReadSMC_ParseStart();
|
|
|
|
SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes);
|
|
|
|
SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
|
|
|
|
SMCParseResult ReadSMC_LeavingSection();
|
|
|
|
void ReadSMC_ParseEnd(bool halted, bool failed);
|
2007-07-13 21:20:12 +02:00
|
|
|
public: //IThread
|
|
|
|
void RunThread(IThreadHandle *pThread);
|
|
|
|
void OnTerminate(IThreadHandle *pThread, bool cancel);
|
|
|
|
public: //IThreadWorkerCallbacks
|
|
|
|
void OnWorkerStart(IThreadWorker *pWorker);
|
|
|
|
void OnWorkerStop(IThreadWorker *pWorker);
|
|
|
|
public: //IPluginsListener
|
|
|
|
void OnPluginUnloaded(IPlugin *plugin);
|
2007-06-01 04:30:29 +02:00
|
|
|
public:
|
|
|
|
ConfDbInfo *GetDatabaseConf(const char *name);
|
|
|
|
IDBDriver *FindOrLoadDriver(const char *name);
|
|
|
|
IDBDriver *GetDefaultDriver();
|
2007-07-13 21:20:12 +02:00
|
|
|
const char *GetDefaultDriverName();
|
|
|
|
bool AddToThreadQueue(IDBThreadOperation *op, PrioQueueLevel prio);
|
|
|
|
void LockConfig();
|
|
|
|
void UnlockConfig();
|
|
|
|
void RunFrame();
|
|
|
|
inline HandleType_t GetDatabaseType()
|
|
|
|
{
|
|
|
|
return m_DatabaseType;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
void KillWorkerThread();
|
2007-04-05 09:08:39 +02:00
|
|
|
private:
|
2007-05-29 10:32:12 +02:00
|
|
|
CVector<IDBDriver *> m_drivers;
|
2007-07-13 21:20:12 +02:00
|
|
|
|
|
|
|
/* Threading stuff */
|
|
|
|
PrioQueue<IDBThreadOperation *> m_OpQueue;
|
|
|
|
Queue<IDBThreadOperation *> m_ThinkQueue;
|
|
|
|
CVector<bool> m_drSafety; /* which drivers are safe? */
|
|
|
|
IThreadWorker *m_pWorker; /* Worker thread object */
|
|
|
|
IMutex *m_pConfigLock; /* Configuration lock */
|
|
|
|
IMutex *m_pQueueLock; /* Queue safety lock */
|
|
|
|
IMutex *m_pThinkLock; /* Think-queue lock */
|
|
|
|
|
2007-06-01 04:30:29 +02:00
|
|
|
List<ConfDbInfo> m_confs;
|
2007-04-05 09:08:39 +02:00
|
|
|
HandleType_t m_DriverType;
|
|
|
|
HandleType_t m_DatabaseType;
|
2007-06-01 04:30:29 +02:00
|
|
|
String m_DefDriver;
|
|
|
|
BaseStringTable m_StrTab;
|
|
|
|
char m_Filename[PLATFORM_MAX_PATH];
|
|
|
|
unsigned int m_ParseLevel;
|
|
|
|
unsigned int m_ParseState;
|
|
|
|
IDBDriver *m_pDefault;
|
2007-04-05 09:08:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern DBManager g_DBMan;
|
|
|
|
|
|
|
|
#endif //_INCLUDE_DATABASE_MANAGER_H_
|