diff options
| author | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
|---|---|---|
| committer | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
| commit | 39ed87570bdb2f86969d4be821c94b722dc71179 (patch) | |
| tree | abc53757f75f40c80278e87650ea92808274aa59 /mp/src/utils/common/MySqlDatabase.h | |
| download | source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip | |
First version of the SOurce SDK 2013
Diffstat (limited to 'mp/src/utils/common/MySqlDatabase.h')
| -rw-r--r-- | mp/src/utils/common/MySqlDatabase.h | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/mp/src/utils/common/MySqlDatabase.h b/mp/src/utils/common/MySqlDatabase.h new file mode 100644 index 00000000..caa5855c --- /dev/null +++ b/mp/src/utils/common/MySqlDatabase.h @@ -0,0 +1,104 @@ +//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#ifndef MYSQLDATABASE_H
+#define MYSQLDATABASE_H
+#ifdef _WIN32
+#pragma once
+#endif
+
+#include <windows.h>
+#include "ISQLDBReplyTarget.h"
+#include "utlvector.h"
+#include "UtlLinkedList.h"
+
+class ISQLDBCommand;
+
+//-----------------------------------------------------------------------------
+// Purpose: Generic MySQL accessing database
+// Provides threaded I/O queue functionality for accessing a mysql db
+//-----------------------------------------------------------------------------
+class CMySqlDatabase
+{
+public:
+ // constructor
+ CMySqlDatabase();
+ ~CMySqlDatabase();
+
+ // initialization - must be called before this object can be used
+ bool Initialize();
+
+ // Dispatches responses to SQLDB queries
+ bool RunFrame();
+
+ // load info - returns the number of sql db queries waiting to be processed
+ virtual int QueriesInOutQueue();
+
+ // number of queries finished processing, waiting to be responded to
+ virtual int QueriesInFinishedQueue();
+
+ // activates the thread
+ void RunThread();
+
+ // command queues
+ void AddCommandToQueue(ISQLDBCommand *cmd, ISQLDBReplyTarget *replyTarget, int returnState = 0);
+
+private:
+
+ // threading data
+ bool m_bRunThread;
+ CRITICAL_SECTION m_csThread;
+ CRITICAL_SECTION m_csInQueue;
+ CRITICAL_SECTION m_csOutQueue;
+ CRITICAL_SECTION m_csDBAccess;
+
+ // wait event
+ HANDLE m_hEvent;
+
+ struct msg_t
+ {
+ ISQLDBCommand *cmd;
+ ISQLDBReplyTarget *replyTarget;
+ int result;
+ int returnState;
+ };
+
+ // command queues
+ CUtlLinkedList<msg_t, int> m_InQueue;
+ CUtlLinkedList<msg_t, int> m_OutQueue;
+};
+
+class Connection;
+
+//-----------------------------------------------------------------------------
+// Purpose: Interface to a command
+//-----------------------------------------------------------------------------
+class ISQLDBCommand
+{
+public:
+ // makes the command run (blocking), returning the success code
+ virtual int RunCommand() = 0;
+
+ // return data
+ virtual void *GetReturnData() { return NULL; }
+
+ // returns the command ID
+ virtual int GetID() { return 0; }
+
+ // gets information about the command for if it failed
+ virtual void GetDebugInfo(char *buf, int bufSize) { buf[0] = 0; }
+
+ // use to delete
+ virtual void deleteThis() = 0;
+
+protected:
+ // protected destructor, so that it has to be deleted through deleteThis()
+ virtual ~ISQLDBCommand() {}
+};
+
+
+#endif // MYSQLDATABASE_H
|