Counter Strike : Global Offensive Source Code
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.

187 lines
3.9 KiB

  1. //========= Copyright � 1996-2009, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=====================================================================================//
  6. #ifndef _DATACENTER_H_
  7. #define _DATACENTER_H_
  8. #include "utlvector.h"
  9. #include "utlmap.h"
  10. #include "x360_xlsp_cmd.h"
  11. class CDatacenterCmdBatchImpl;
  12. class CDatacenter :
  13. public IDatacenter,
  14. public IMatchEventsSink
  15. {
  16. public :
  17. CDatacenter();
  18. virtual ~CDatacenter();
  19. //
  20. // IDatacenter implementation
  21. //
  22. public:
  23. //
  24. // EnableUpdate
  25. // controls whether data can be updated in the background
  26. //
  27. virtual void EnableUpdate( bool bEnable );
  28. //
  29. // GetStats
  30. // retrieves the last received datacenter stats
  31. //
  32. virtual KeyValues * GetDataInfo();
  33. virtual KeyValues * GetStats();
  34. //
  35. // CreateCmdBatch
  36. // creates a new instance of cmd batch to communicate
  37. // with datacenter backend
  38. //
  39. virtual IDatacenterCmdBatch * CreateCmdBatch( bool bMustSupportPII );
  40. //
  41. // CanReachDatacenter
  42. // returns true if we were able to establish a connection with the
  43. // datacenter backend regardless if it returned valid data or not.
  44. virtual bool CanReachDatacenter();
  45. // IMatchEventsSink
  46. public:
  47. virtual void OnEvent( KeyValues *pEvent );
  48. protected:
  49. void StorageDeviceWriteInfo( int iCtrlr );
  50. void TrySaveInfoToUserStorage();
  51. void OnDatacenterInfoUpdated();
  52. //
  53. // Interface for match system
  54. //
  55. public:
  56. void Update();
  57. void OnCmdBatchReleased( CDatacenterCmdBatchImpl *pCmdBatch );
  58. protected:
  59. void RequestStart();
  60. void RequestUpdate();
  61. void RequestStop();
  62. void PushAwayNextUpdate();
  63. void OnStorageDeviceAvailable( int iCtrlr );
  64. protected:
  65. KeyValues *m_pDataInfo;
  66. KeyValues *m_pInfoChunks;
  67. #ifdef _X360
  68. CXlspConnection *m_pXlspConnection;
  69. CXlspConnectionCmdBatch *m_pXlspBatch;
  70. bool m_bStorageDeviceAvail[ XUSER_MAX_COUNT ];
  71. int m_nVersionStored;
  72. int m_nVersionApplied;
  73. int m_numDelayedMountAttempts;
  74. float m_flDcRequestDelayUntil;
  75. #elif !defined( NO_STEAM ) && !defined( NO_STEAM_GAMECOORDINATOR ) && !defined( SWDS )
  76. friend class CGCClientJobDataRequest;
  77. JobID_t m_JobIDDataRequest;
  78. #endif
  79. float m_flNextSearchTime;
  80. bool m_bCanReachDatacenter;
  81. enum State_t
  82. {
  83. STATE_IDLE,
  84. STATE_REQUESTING_DATA,
  85. STATE_REQUESTING_CHUNKS,
  86. STATE_PAUSED,
  87. };
  88. State_t m_eState;
  89. CUtlVector< CDatacenterCmdBatchImpl * > m_arrCmdBatchObjects;
  90. };
  91. class CDatacenterCmdBatchImpl : public IDatacenterCmdBatch
  92. {
  93. public:
  94. explicit CDatacenterCmdBatchImpl( CDatacenter *pParent, bool bMustSupportPII );
  95. public:
  96. //
  97. // AddCommand
  98. // enqueues a command in command batch queue
  99. //
  100. virtual void AddCommand( KeyValues *pCommand );
  101. //
  102. // IsFinished
  103. // whether command batch queue has finished running / error occurred
  104. //
  105. virtual bool IsFinished();
  106. //
  107. // GetNumResults
  108. // returns number of results retrieved for which data is available
  109. //
  110. virtual int GetNumResults();
  111. //
  112. // GetResult
  113. // returns the result by index
  114. //
  115. virtual KeyValues * GetResult( int idx );
  116. //
  117. // Destroy
  118. // destroys the command batch object and all contained results
  119. //
  120. virtual void Destroy();
  121. //
  122. // SetDestroyWhenFinished
  123. // destroys the command batch object automatically after
  124. // it finishes communication with datacenter
  125. //
  126. virtual void SetDestroyWhenFinished( bool bDestroyWhenFinished );
  127. //
  128. // SetNumRetriesAllowedPerCmd
  129. // configures retry attempts per command
  130. //
  131. virtual void SetNumRetriesAllowedPerCmd( int numRetriesAllowed );
  132. //
  133. // SetRetryCmdTimeout
  134. // configures retry timeout per command
  135. //
  136. virtual void SetRetryCmdTimeout( float flRetryCmdTimeout );
  137. public:
  138. virtual void Update();
  139. protected:
  140. #ifdef _X360
  141. CXlspConnection *m_pXlspConnection;
  142. CXlspConnectionCmdBatch *m_pXlspBatch;
  143. #endif
  144. CDatacenter *m_pParent;
  145. CUtlVector< KeyValues * > m_arrCommands;
  146. int m_numRetriesAllowedPerCmd;
  147. float m_flRetryCmdTimeout;
  148. bool m_bDestroyWhenFinished;
  149. bool m_bMustSupportPII;
  150. };
  151. extern class CDatacenter *g_pDatacenter;
  152. #endif // _DATACENTER_H_