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.

122 lines
3.7 KiB

  1. //========= Copyright 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 _WIN32
  11. #pragma once
  12. #endif
  13. #include "tier1/interface.h"
  14. //-----------------------------------------------------------------------------
  15. // Client systems are singleton objects in the client codebase responsible for
  16. // various tasks
  17. // The order in which the client systems appear in this list are the
  18. // order in which they are initialized and updated. They are shut down in
  19. // reverse order from which they are initialized.
  20. //-----------------------------------------------------------------------------
  21. enum InitReturnVal_t
  22. {
  23. INIT_FAILED = 0,
  24. INIT_OK,
  25. INIT_LAST_VAL,
  26. };
  27. abstract_class IAppSystem
  28. {
  29. public:
  30. // Here's where the app systems get to learn about each other
  31. virtual bool Connect( CreateInterfaceFn factory ) = 0;
  32. virtual void Disconnect() = 0;
  33. // Here's where systems can access other interfaces implemented by this object
  34. // Returns NULL if it doesn't implement the requested interface
  35. virtual void *QueryInterface( const char *pInterfaceName ) = 0;
  36. // Init, shutdown
  37. virtual InitReturnVal_t Init() = 0;
  38. virtual void Shutdown() = 0;
  39. };
  40. //-----------------------------------------------------------------------------
  41. // Helper empty implementation of an IAppSystem
  42. //-----------------------------------------------------------------------------
  43. template< class IInterface >
  44. class CBaseAppSystem : public IInterface
  45. {
  46. public:
  47. // Here's where the app systems get to learn about each other
  48. virtual bool Connect( CreateInterfaceFn factory ) { return true; }
  49. virtual void Disconnect() {}
  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 ) { return NULL; }
  53. // Init, shutdown
  54. virtual InitReturnVal_t Init() { return INIT_OK; }
  55. virtual void Shutdown() {}
  56. };
  57. //-----------------------------------------------------------------------------
  58. // Helper implementation of an IAppSystem for tier0
  59. //-----------------------------------------------------------------------------
  60. template< class IInterface >
  61. class CTier0AppSystem : public CBaseAppSystem< IInterface >
  62. {
  63. public:
  64. CTier0AppSystem( bool bIsPrimaryAppSystem = true )
  65. {
  66. m_bIsPrimaryAppSystem = bIsPrimaryAppSystem;
  67. }
  68. protected:
  69. // NOTE: a single DLL may have multiple AppSystems it's trying to
  70. // expose. If this is true, you must return true from only
  71. // one of those AppSystems; not doing so will cause all static
  72. // libraries connected to it to connect/disconnect multiple times
  73. // NOTE: We don't do this as a virtual function to avoid
  74. // having to up the version on all interfaces
  75. bool IsPrimaryAppSystem() { return m_bIsPrimaryAppSystem; }
  76. private:
  77. bool m_bIsPrimaryAppSystem;
  78. };
  79. //-----------------------------------------------------------------------------
  80. // This is the version of IAppSystem shipped 10/15/04
  81. // NOTE: Never change this!!!
  82. //-----------------------------------------------------------------------------
  83. abstract_class IAppSystemV0
  84. {
  85. public:
  86. // Here's where the app systems get to learn about each other
  87. virtual bool Connect( CreateInterfaceFn factory ) = 0;
  88. virtual void Disconnect() = 0;
  89. // Here's where systems can access other interfaces implemented by this object
  90. // Returns NULL if it doesn't implement the requested interface
  91. virtual void *QueryInterface( const char *pInterfaceName ) = 0;
  92. // Init, shutdown
  93. virtual InitReturnVal_t Init() = 0;
  94. virtual void Shutdown() = 0;
  95. };
  96. #endif // IAPPSYSTEM_H