#ifndef SCHEMASYSTEM_H #define SCHEMASYSTEM_H #ifdef _WIN32 #pragma once #endif #include "tier0/threadtools.h" #include "tier1/convar.h" #include "tier1/utlstring.h" #include "tier1/UtlStringMap.h" #include "tier1/utltshash.h" #include "tier1/utlvector.h" #include "appframework/IAppSystem.h" #include "schemasystem/schematypes.h" class CBufferString; class CKeyValues3Context; struct ResourceManifestDesc_t; enum SchemaTypeScope_t : uint8 { SCHEMA_TYPESCOPE_GLOBAL = 0, SCHEMA_TYPESCOPE_LOCAL, SCHEMA_TYPESCOPE_DEFAULT, }; typedef void (*CompleteModuleRegistrationCallbackFn_t)(void*); abstract_class ISchemaSystemTypeScope { public: virtual CSchemaClassInfo* InstallSchemaClassBinding( const char* pszModuleName, CSchemaClassInfo* pClassInfo ) = 0; virtual CSchemaEnumInfo* InstallSchemaEnumBinding( const char* pszModuleName, CSchemaEnumInfo* pEnumInfo ) = 0; virtual SchemaMetaInfoHandle_t FindDeclaredClass( const char* pszClassName ) = 0; virtual SchemaMetaInfoHandle_t FindDeclaredEnum( const char* pszEnumName ) = 0; virtual SchemaMetaInfoHandle_t FindBuiltinTypeByName( const char* pszBuiltinName ) = 0; virtual SchemaMetaInfoHandle_t Type_Builtin( SchemaBuiltinType_t eBuiltinType ) = 0; virtual SchemaMetaInfoHandle_t Type_Ptr( CSchemaType* pObjectType ) = 0; virtual SchemaMetaInfoHandle_t Type_Atomic( const char* pszAtomicName, uint16 nSize, uint8 nAlignment ) = 0; virtual SchemaMetaInfoHandle_t Type_Atomic_T( const char* pszAtomicName, uint16 nSize, uint8 nAlignment, CSchemaType* pTemplateType ) = 0; virtual SchemaMetaInfoHandle_t Type_Atomic_CollectionOfT( const char* pszAtomicName, uint16 nSize, uint8 nAlignment, uint16 nElementSize, CSchemaType* pTemplateType, SchemaAtomicManipulatorFn_t manipulator ) = 0; virtual SchemaMetaInfoHandle_t Type_Atomic_TF( const char* pszAtomicName, uint16 nSize, uint8 nAlignment, CSchemaType* pTemplateType, int nFuncPtrSize ) = 0; virtual SchemaMetaInfoHandle_t Type_Atomic_TT( const char* pszAtomicName, uint16 nSize, uint8 nAlignment, CSchemaType* pTemplateType, CSchemaType* pTemplateType2 ) = 0; virtual SchemaMetaInfoHandle_t Type_Atomic_TTF( const char* pszAtomicName, uint16 nSize, uint8 nAlignment, CSchemaType* pTemplateType, CSchemaType* pTemplateType2, int nFuncPtrSize ) = 0; virtual SchemaMetaInfoHandle_t Type_Atomic_I( const char* pszAtomicName, uint16 nSize, uint8 nAlignment, int nInterger ) = 0; virtual SchemaMetaInfoHandle_t Type_DeclaredClass( const char* pszClassName ) = 0; virtual SchemaMetaInfoHandle_t Type_DeclaredEnum( const char* pszEnumName ) = 0; virtual SchemaMetaInfoHandle_t Type_FixedArray( CSchemaType* pElementType, int nElementCount, uint16 nElementSize, uint8 nElementAlignment ) = 0; virtual SchemaMetaInfoHandle_t Type_FixedArray_Multidimensional( CSchemaType* pElementType, uint16 nElementSize, uint8 nElementAlignment, ... ) = 0; virtual SchemaMetaInfoHandle_t Type_Bitfield( int nSize ) = 0; virtual SchemaMetaInfoHandle_t FindType_Atomic( int nAtomicID ) = 0; virtual SchemaMetaInfoHandle_t FindType_Atomic_T( int nAtomicID, CSchemaType* pTemplateType ) = 0; virtual SchemaMetaInfoHandle_t FindType_Atomic_CollectionOfT( int nAtomicID, CSchemaType* pTemplateType, SchemaAtomicManipulatorFn_t manipulator ) = 0; virtual SchemaMetaInfoHandle_t FindType_Atomic_TF( int nAtomicID, CSchemaType* pTemplateType, int nFuncPtrSize ) = 0; virtual SchemaMetaInfoHandle_t FindType_Atomic_TT( int nAtomicID, CSchemaType* pTemplateType, CSchemaType* pTemplateType2 ) = 0; virtual SchemaMetaInfoHandle_t FindType_Atomic_TTF( int nAtomicID, CSchemaType* pTemplateType, CSchemaType* pTemplateType2, int nFuncPtrSize ) = 0; virtual SchemaMetaInfoHandle_t FindType_Atomic_I( int nAtomicID, int nInteger ) = 0; virtual CSchemaType_DeclaredClass* FindType_DeclaredClass( const char* pszClassName ) = 0; virtual CSchemaType_DeclaredEnum* FindType_DeclaredEnum( const char* pszEnumName ) = 0; virtual CSchemaClassInfo* FindRawClassBinding( const char* pszClassName ) = 0; virtual CSchemaClassInfo* FindRawClassBinding( uint nClassID ) = 0; virtual CSchemaEnumInfo* FindRawEnumBinding( const char* pszEnumName ) = 0; virtual CSchemaEnumInfo* FindRawEnumBinding( uint nEnumID ) = 0; virtual const char* GetScopeName() = 0; virtual bool IsGlobalScope() = 0; virtual void MarkClassAsRequiringGlobalPromotion( const CSchemaClassInfo* pClassInfo ) = 0; virtual void MarkEnumAsRequiringGlobalPromotion( const CSchemaEnumInfo* pEnumInfo ) = 0; virtual void ResolveAtomicInfoThreadsafe( const SchemaAtomicTypeInfo_t** ppAtomicInfo, const char* pszAtomicName, int nAtomicID ) = 0; virtual void ResolveEnumInfoThreadsafe( const CSchemaEnumInfo** pEnumInfo, const char* pszEnumName ) = 0; virtual void ResolveClassInfoThreadsafe( const CSchemaClassInfo** pClassInfo, const char* pszClassName ) = 0; }; class CSchemaSystemTypeScope : public ISchemaSystemTypeScope { public: char m_szScopeName[256]; CSchemaSystemTypeScope* m_pGlobalTypeScope; bool m_bBuiltinTypesInitialized; CSchemaType_Builtin m_BuiltinTypes[SCHEMA_BUILTIN_COUNT]; CSchemaPtrMap m_Ptrs; CSchemaPtrMap m_Atomics; CSchemaPtrMap m_AtomicsT; CSchemaPtrMap m_AtomicsCollectionOfT; CSchemaPtrMap m_AtomicsTF; CSchemaPtrMap m_AtomicsTT; CSchemaPtrMap m_AtomicsTTF; CSchemaPtrMap m_AtomicsI; CSchemaPtrMap m_DeclaredClasses; CSchemaPtrMap m_DeclaredEnums; CSchemaPtrMap m_AtomicInfos; CSchemaPtrMap m_FixedArrays; CSchemaPtrMap m_Bitfields; CUtlTSHash m_ClassBindings; CUtlTSHash m_EnumBindings; }; #define SCHEMASYSTEM_INTERFACE_VERSION "SchemaSystem_001" abstract_class ISchemaSystem : public IAppSystem { public: virtual CSchemaSystemTypeScope* GlobalTypeScope() = 0; virtual CSchemaSystemTypeScope* FindOrCreateTypeScopeForModule( const char* pszModuleName, const char** ppszBindingName = NULL ) = 0; virtual CSchemaSystemTypeScope* FindTypeScopeForModule( const char* pszModuleName, const char** ppszBindingName = NULL ) = 0; virtual CSchemaSystemTypeScope* GetTypeScopeForBinding( SchemaTypeScope_t eTypeScope, const char* pszModuleName, const char** ppszBindingName = NULL ) = 0; virtual bool DefaultTypeScopeIsLocal() = 0; virtual SchemaMetaInfoHandle_t FindClassByScopedName( const char* pszScopedName ) = 0; virtual void ScopedNameForClass( const CSchemaClassInfo* pClassInfo, CBufferString& scopedName ) = 0; virtual SchemaMetaInfoHandle_t FindEnumByScopedName( const char* pszScopedName ) = 0; virtual void ScopedNameForEnum( const CSchemaEnumInfo* pEnumInfo, CBufferString& scopedName ) = 0; virtual void FindDescendentsOfClass( const CSchemaClassInfo* pClassInfo, int, CUtlVector *descendents, bool ) = 0; virtual void LoadSchemaDataForModules( const char** ppszModules, int nModules ) = 0; virtual const char* GetClassModuleName( const CSchemaClassInfo* pClassInfo ) = 0; virtual const char* GetClassProjectName( const CSchemaClassInfo* pClassInfo ) = 0; virtual const char* GetEnumModuleName( const CSchemaEnumInfo* pEnumInfo ) = 0; virtual const char* GetEnumProjectName( const CSchemaEnumInfo* pEnumInfo ) = 0; virtual bool SchemaSystemIsReady() = 0; virtual void VerifySchemaBindingConsistency( bool ) = 0; virtual void CompleteModuleRegistration( const char* pszModuleName ) = 0; virtual void RegisterAtomicType( const SchemaAtomicTypeInfo_t* pAtomicType ) = 0; virtual void PrintSchemaStats( const char* pszOptions ) = 0; virtual void PrintSchemaMetaStats( const char* pszOptions ) = 0; virtual void RegisterAtomics( const char* pszModuleName, const char* pszProjectName, CSchemaType** ppSchemaTypes, int, SchemaAtomicTypeInfo_t** ppAtomicTypes ) = 0; virtual void RegisterEnums( const char* pszModuleName, const char* pszProjectName, CSchemaType** ppSchemaTypes, int, CSchemaEnumInfo** ppEnumInfos ) = 0; virtual bool RegisterClasses( const char* pszModuleName, const char* pszProjectName, CSchemaType** ppSchemaTypes, int, CSchemaClassInfo** ppClassInfos, CBufferString* pErrorStr ) = 0; virtual void ValidateClasses( CSchemaClassInfo** ppClassInfos ) = 0; virtual bool ConvertOldIntrospectedResourceDataToKV3( void*, void*, void*, CKeyValues3Context*, const char* ) = 0; virtual void FindClassesByMeta( const char* pszMetaName, int, CUtlVector *classes ) = 0; virtual void InstallCompleteModuleRegistrationCallback( CompleteModuleRegistrationCallbackFn_t pfnCallback, void* pArgument ) = 0; virtual void RemoveCompleteModuleRegistrationCallback( CompleteModuleRegistrationCallbackFn_t pfnCallback, void* pArgument ) = 0; virtual SchemaMetaInfoHandle_t GetSchemaBuiltinType( SchemaBuiltinType_t eBuiltinType ) = 0; virtual ~ISchemaSystem() = 0; }; class CSchemaSystem : public ISchemaSystem { struct DetectedSchemaMismatch_t { CUtlString m_sBinding; CUtlString m_sMismatch; CUtlString m_sModule1; CUtlString m_sModule2; }; struct BindingsAddressRangeForModule_t { uintp m_minAddr; uintp m_maxAddr; }; struct CompleteModuleRegistrationCallback_t { CompleteModuleRegistrationCallbackFn_t m_pfnCallback; void* m_pArgument; }; public: CUtlVector m_ResourceManifestDescs; int m_nNumConnections; CThreadFastMutex m_Mutex; #ifdef CONVAR_WORK_FINISHED CConCommandMemberAccessor m_SchemaListBindings; CConCommandMemberAccessor m_SchemaAllListBindings; CConCommandMemberAccessor m_SchemaDumpBinding; CConCommandMemberAccessor m_SchemaDetailedClassLayout; CConCommandMemberAccessor m_SchemaStats; CConCommandMemberAccessor m_SchemaMetaStats; #else #ifdef _WIN32 uint8 pad[288]; #else uint8 pad[384]; #endif // _WIN32 #endif // CONVAR_WORK_FINISHED CUtlVector m_LoadedModules; CUtlVector m_DetectedSchemaMismatches; bool m_bDefaultTypeScopeIsLocal; bool m_bSchemaSystemIsReady; CUtlStringMap m_TypeScopes; CUtlStringMap m_BindingsAddressRanges; int m_nRegistrations; int m_nIgnored; int m_nRedundant; size_t m_nIgnoredBytes; CUtlVector m_CompleteModuleRegistrationCallbacks; }; #endif // SCHEMASYSTEM_H