Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef MYSQLDATABASE_H
  8. #define MYSQLDATABASE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <windows.h>
  13. #include "ISQLDBReplyTarget.h"
  14. #include "utlvector.h"
  15. #include "UtlLinkedList.h"
  16. class ISQLDBCommand;
  17. //-----------------------------------------------------------------------------
  18. // Purpose: Generic MySQL accessing database
  19. // Provides threaded I/O queue functionality for accessing a mysql db
  20. //-----------------------------------------------------------------------------
  21. class CMySqlDatabase
  22. {
  23. public:
  24. // constructor
  25. CMySqlDatabase();
  26. ~CMySqlDatabase();
  27. // initialization - must be called before this object can be used
  28. bool Initialize();
  29. // Dispatches responses to SQLDB queries
  30. bool RunFrame();
  31. // load info - returns the number of sql db queries waiting to be processed
  32. virtual int QueriesInOutQueue();
  33. // number of queries finished processing, waiting to be responded to
  34. virtual int QueriesInFinishedQueue();
  35. // activates the thread
  36. void RunThread();
  37. // command queues
  38. void AddCommandToQueue(ISQLDBCommand *cmd, ISQLDBReplyTarget *replyTarget, int returnState = 0);
  39. private:
  40. // threading data
  41. bool m_bRunThread;
  42. CRITICAL_SECTION m_csThread;
  43. CRITICAL_SECTION m_csInQueue;
  44. CRITICAL_SECTION m_csOutQueue;
  45. CRITICAL_SECTION m_csDBAccess;
  46. // wait event
  47. HANDLE m_hEvent;
  48. struct msg_t
  49. {
  50. ISQLDBCommand *cmd;
  51. ISQLDBReplyTarget *replyTarget;
  52. int result;
  53. int returnState;
  54. };
  55. // command queues
  56. CUtlLinkedList<msg_t, int> m_InQueue;
  57. CUtlLinkedList<msg_t, int> m_OutQueue;
  58. };
  59. class Connection;
  60. //-----------------------------------------------------------------------------
  61. // Purpose: Interface to a command
  62. //-----------------------------------------------------------------------------
  63. class ISQLDBCommand
  64. {
  65. public:
  66. // makes the command run (blocking), returning the success code
  67. virtual int RunCommand() = 0;
  68. // return data
  69. virtual void *GetReturnData() { return NULL; }
  70. // returns the command ID
  71. virtual int GetID() { return 0; }
  72. // gets information about the command for if it failed
  73. virtual void GetDebugInfo(char *buf, int bufSize) { buf[0] = 0; }
  74. // use to delete
  75. virtual void deleteThis() = 0;
  76. protected:
  77. // protected destructor, so that it has to be deleted through deleteThis()
  78. virtual ~ISQLDBCommand() {}
  79. };
  80. #endif // MYSQLDATABASE_H