ds@1952: /** ds@1952: * vim: set ts=4 : ds@1952: * ============================================================================= ds@1952: * SourceMod ds@1952: * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. ds@1952: * ============================================================================= ds@1952: * ds@1952: * This program is free software; you can redistribute it and/or modify it under ds@1952: * the terms of the GNU General Public License, version 3.0, as published by the ds@1952: * Free Software Foundation. ds@1952: * ds@1952: * This program is distributed in the hope that it will be useful, but WITHOUT ds@1952: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ds@1952: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ds@1952: * details. ds@1952: * ds@1952: * You should have received a copy of the GNU General Public License along with ds@1952: * this program. If not, see . ds@1952: * ds@1952: * As a special exception, AlliedModders LLC gives you permission to link the ds@1952: * code of this program (as well as its derivative works) to "Half-Life 2," the ds@1952: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software ds@1952: * by the Valve Corporation. You must obey the GNU General Public License in ds@1952: * all respects for all other code used. Additionally, AlliedModders LLC grants ds@1952: * this exception to all derivative works. AlliedModders LLC defines further ds@1952: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), ds@1952: * or . ds@1952: * ds@1952: * Version: $Id$ ds@1952: */ ds@1952: ds@1952: #ifndef _INCLUDE_DATABASE_MANAGER_H_ ds@1952: #define _INCLUDE_DATABASE_MANAGER_H_ ds@1952: ds@1952: #include ds@1952: #include "sm_globals.h" ds@1952: #include ds@1952: #include ds@1952: #include ds@1952: #include ds@1952: #include "sm_memtable.h" ds@1952: #include ds@1952: #include "sm_simple_prioqueue.h" ds@1952: #include "PluginSys.h" ds@1952: ds@1952: using namespace SourceHook; ds@1952: ds@1952: struct ConfDbInfo ds@1952: { ds@1952: ConfDbInfo() : name(-1), driver(-1), host(-1), user(-1), pass(-1), ds@1952: database(-1), realDriver(NULL) ds@1952: { ds@1952: } ds@1952: int name; ds@1952: int driver; ds@1952: int host; ds@1952: int user; ds@1952: int pass; ds@1952: int database; ds@1952: IDBDriver *realDriver; ds@1952: DatabaseInfo info; ds@1952: }; ds@1952: ds@1952: class DBManager : ds@1952: public IDBManager, ds@1952: public SMGlobalClass, ds@1952: public IHandleTypeDispatch, ds@1952: public ITextListener_SMC, ds@1952: public IThread, ds@1952: public IThreadWorkerCallbacks, ds@1952: public IPluginsListener ds@1952: { ds@1952: public: ds@1952: DBManager(); ds@1952: public: ds@1952: const char *GetInterfaceName(); ds@1952: unsigned int GetInterfaceVersion(); ds@1952: public: //SMGlobalClass ds@1952: void OnSourceModAllInitialized(); ds@1952: void OnSourceModLevelChange(const char *mapName); ds@1952: void OnSourceModIdentityDropped(IdentityToken_t *pToken); ds@1952: void OnSourceModShutdown(); ds@1952: public: //IHandleTypeDispatch ds@1952: void OnHandleDestroy(HandleType_t type, void *object); ds@1952: public: //IDBManager ds@1952: void AddDriver(IDBDriver *pDrivera); ds@1952: void RemoveDriver(IDBDriver *pDriver); ds@1952: const DatabaseInfo *FindDatabaseConf(const char *name); ds@1952: bool Connect(const char *name, IDBDriver **pdr, IDatabase **pdb, bool persistent, char *error, size_t maxlength); ds@1952: unsigned int GetDriverCount(); ds@1952: IDBDriver *GetDriver(unsigned int index); ds@1952: Handle_t CreateHandle(DBHandleType type, void *ptr, IdentityToken_t *pToken); ds@1952: HandleError ReadHandle(Handle_t hndl, DBHandleType type, void **ptr); ds@1952: HandleError ReleaseHandle(Handle_t hndl, DBHandleType type, IdentityToken_t *token); ds@1952: public: //ITextListener_SMC ds@1952: void ReadSMC_ParseStart(); ds@1952: SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name); ds@1952: SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value); ds@1952: SMCResult ReadSMC_LeavingSection(const SMCStates *states); ds@1952: void ReadSMC_ParseEnd(bool halted, bool failed); ds@1952: public: //IThread ds@1952: void RunThread(IThreadHandle *pThread); ds@1952: void OnTerminate(IThreadHandle *pThread, bool cancel); ds@1952: public: //IThreadWorkerCallbacks ds@1952: void OnWorkerStart(IThreadWorker *pWorker); ds@1952: void OnWorkerStop(IThreadWorker *pWorker); ds@1952: public: //IPluginsListener ds@1952: void OnPluginUnloaded(IPlugin *plugin); ds@1952: public: ds@1952: ConfDbInfo *GetDatabaseConf(const char *name); ds@1952: IDBDriver *FindOrLoadDriver(const char *name); ds@1952: IDBDriver *GetDefaultDriver(); ds@1952: const char *GetDefaultDriverName(); ds@1952: bool AddToThreadQueue(IDBThreadOperation *op, PrioQueueLevel prio); ds@1952: void LockConfig(); ds@1952: void UnlockConfig(); ds@1952: void RunFrame(); ds@1952: inline HandleType_t GetDatabaseType() ds@1952: { ds@1952: return m_DatabaseType; ds@1952: } ds@1952: private: ds@1952: void KillWorkerThread(); ds@1952: private: ds@1952: CVector m_drivers; ds@1952: ds@1952: /* Threading stuff */ ds@1952: PrioQueue m_OpQueue; ds@1952: Queue m_ThinkQueue; ds@1952: CVector m_drSafety; /* which drivers are safe? */ ds@1952: IThreadWorker *m_pWorker; /* Worker thread object */ ds@1952: IMutex *m_pConfigLock; /* Configuration lock */ ds@1952: IMutex *m_pQueueLock; /* Queue safety lock */ ds@1952: IMutex *m_pThinkLock; /* Think-queue lock */ ds@1952: ds@1952: List m_confs; ds@1952: HandleType_t m_DriverType; ds@1952: HandleType_t m_DatabaseType; ds@1952: String m_DefDriver; ds@1952: BaseStringTable m_StrTab; ds@1952: char m_Filename[PLATFORM_MAX_PATH]; ds@1952: unsigned int m_ParseLevel; ds@1952: unsigned int m_ParseState; ds@1952: IDBDriver *m_pDefault; ds@1952: }; ds@1952: ds@1952: extern DBManager g_DBMan; ds@1952: ds@1952: #endif //_INCLUDE_DATABASE_MANAGER_H_