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.

123 lines
3.6 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: An application framework
  4. //
  5. // $Revision: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #ifndef IAPPSYSTEM_H
  9. #define IAPPSYSTEM_H
  10. #ifdef COMPILER_MSVC
  11. #pragma once
  12. #endif
  13. #include "tier1/interface.h"
  14. #include "interfaces/interfaces.h"
  15. //-----------------------------------------------------------------------------
  16. // Specifies a module + interface name for initialization
  17. //-----------------------------------------------------------------------------
  18. struct AppSystemInfo_t
  19. {
  20. const char *m_pModuleName;
  21. const char *m_pInterfaceName;
  22. };
  23. //-----------------------------------------------------------------------------
  24. // Client systems are singleton objects in the client codebase responsible for
  25. // various tasks
  26. // The order in which the client systems appear in this list are the
  27. // order in which they are initialized and updated. They are shut down in
  28. // reverse order from which they are initialized.
  29. //-----------------------------------------------------------------------------
  30. enum InitReturnVal_t
  31. {
  32. INIT_FAILED = 0,
  33. INIT_OK,
  34. INIT_LAST_VAL,
  35. };
  36. enum AppSystemTier_t
  37. {
  38. APP_SYSTEM_TIER0 = 0,
  39. APP_SYSTEM_TIER1,
  40. APP_SYSTEM_TIER2,
  41. APP_SYSTEM_TIER3,
  42. APP_SYSTEM_TIER_OTHER,
  43. };
  44. abstract_class IAppSystem
  45. {
  46. public:
  47. // Here's where the app systems get to learn about each other
  48. virtual bool Connect( CreateInterfaceFn factory ) = 0;
  49. virtual void Disconnect() = 0;
  50. // Here's where systems can access other interfaces implemented by this object
  51. // Returns NULL if it doesn't implement the requested interface
  52. virtual void *QueryInterface( const char *pInterfaceName ) = 0;
  53. // Init, shutdown
  54. virtual InitReturnVal_t Init() = 0;
  55. virtual void Shutdown() = 0;
  56. // Returns all dependent libraries
  57. virtual const AppSystemInfo_t* GetDependencies() {return NULL;}
  58. // Returns the tier
  59. virtual AppSystemTier_t GetTier() {return APP_SYSTEM_TIER_OTHER;}
  60. // Reconnect to a particular interface
  61. virtual void Reconnect( CreateInterfaceFn factory, const char *pInterfaceName ) {}
  62. // Is this appsystem a singleton? (returns false if there can be multiple instances of this interface)
  63. virtual bool IsSingleton() { return true; }
  64. };
  65. //-----------------------------------------------------------------------------
  66. // Helper empty implementation of an IAppSystem
  67. //-----------------------------------------------------------------------------
  68. template< class IInterface >
  69. class CBaseAppSystem : public IInterface
  70. {
  71. public:
  72. // Here's where the app systems get to learn about each other
  73. virtual bool Connect( CreateInterfaceFn factory ) { return true; }
  74. virtual void Disconnect() {}
  75. // Here's where systems can access other interfaces implemented by this object
  76. // Returns NULL if it doesn't implement the requested interface
  77. virtual void *QueryInterface( const char *pInterfaceName ) { return NULL; }
  78. // Init, shutdown
  79. virtual InitReturnVal_t Init() { return INIT_OK; }
  80. virtual void Shutdown() {}
  81. virtual const AppSystemInfo_t* GetDependencies() { return NULL; }
  82. virtual AppSystemTier_t GetTier() { return APP_SYSTEM_TIER_OTHER; }
  83. virtual void Reconnect( CreateInterfaceFn factory, const char *pInterfaceName )
  84. {
  85. ReconnectInterface( factory, pInterfaceName );
  86. }
  87. };
  88. //-----------------------------------------------------------------------------
  89. // Helper implementation of an IAppSystem for tier0
  90. //-----------------------------------------------------------------------------
  91. template< class IInterface >
  92. class CTier0AppSystem : public CBaseAppSystem< IInterface >
  93. {
  94. };
  95. #endif // IAPPSYSTEM_H