moduleManager.h
Engine/source/module/moduleManager.h
Classes:
class
class
Database locking.
class
Loaded module entry.
Public Defines
define
MODULE_MANAGER_MERGE_FILE() "module.merge"
define
MODULE_MANAGER_MODULE_DEFINITION_EXTENSION() "module.taml"
Public Variables
Detailed Description
Public Defines
MODULE_MANAGER_MERGE_FILE() "module.merge"
MODULE_MANAGER_MODULE_DEFINITION_EXTENSION() "module.taml"
Public Variables
ModuleManager ModuleDatabase
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2013 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _MODULE_MANAGER_H 25#define _MODULE_MANAGER_H 26 27#ifndef _SIMBASE_H_ 28#include "console/simBase.h" 29#endif 30 31#ifndef _TVECTOR_H_ 32#include "core/util/tvector.h" 33#endif 34 35#ifndef _TDICTIONARY_H_ 36#include "core/util/tDictionary.h" 37#endif 38 39#ifndef _TAML_H_ 40#include "persistence/taml/taml.h" 41#endif 42 43#ifndef _MODULE_DEFINITION_H 44#include "moduleDefinition.h" 45#endif 46 47//----------------------------------------------------------------------------- 48 49#define MODULE_MANAGER_MERGE_FILE "module.merge" 50#define MODULE_MANAGER_MODULE_DEFINITION_EXTENSION "module.taml" 51 52//----------------------------------------------------------------------------- 53 54/// @ingroup moduleGroup 55/// @see moduleGroup 56class ModuleManager : public SimObject 57{ 58private: 59 typedef SimObject Parent; 60 61public: 62 /// Module definitions. 63 typedef Vector<ModuleDefinition*> typeModuleDefinitionVector; 64 typedef Vector<const ModuleDefinition*> typeConstModuleDefinitionVector; 65 66private: 67 /// Database locking. 68 struct LockDatabase 69 { 70 public: 71 LockDatabase( ModuleManager* pManager ) : 72 mpManager( pManager ) 73 { 74 mpManager->mDatabaseLocks++; 75 } 76 77 ~LockDatabase() 78 { 79 mpManager->mDatabaseLocks--; 80 81 // Sanity! 82 AssertFatal( mpManager->mDatabaseLocks >= 0, "Module Manager: Cannot unlock database as it is already unlocked." ); 83 } 84 85 private: 86 ModuleManager* mpManager; 87 }; 88 89 /// Loaded module entry. 90 struct ModuleLoadEntry 91 { 92 ModuleLoadEntry( ModuleDefinition* pModuleDefinition, const bool strictVersionId ) : 93 mpModuleDefinition( pModuleDefinition ), 94 mStrictVersionId( strictVersionId ) 95 { 96 } 97 98 ModuleLoadEntry() 99 { 100 mpModuleDefinition = NULL; 101 mStrictVersionId = false; 102 } 103 104 ModuleDefinition* mpModuleDefinition; 105 bool mStrictVersionId; 106 }; 107 108 /// Module loading. 109 typedef Vector<StringTableEntry> typeModuleIdVector; 110 typedef Vector<StringTableEntry> typeGroupVector; 111 typedef HashMap<StringTableEntry, typeModuleIdVector*> typeGroupModuleHash; 112 typedef Vector<ModuleLoadEntry> typeModuleLoadEntryVector; 113 typeGroupModuleHash mGroupModules; 114 typeGroupVector mGroupsLoaded; 115 typeModuleLoadEntryVector mModulesLoaded; 116 117 /// Miscellaneous. 118 bool mEnforceDependencies; 119 bool mEchoInfo; 120 S32 mDatabaseLocks; 121 char mModuleExtension[256]; 122 Taml mTaml; 123 SimSet mNotificationListeners; 124 bool mIgnoreLoadedGroups; 125 126 // Module definition entry. 127 struct ModuleDefinitionEntry : public typeModuleDefinitionVector 128 { 129 public: 130 ModuleDefinitionEntry( StringTableEntry moduleId, StringTableEntry moduleGroup, StringTableEntry moduleType ) : 131 mModuleId( moduleId ), 132 mModuleGroup( moduleGroup ), 133 mModuleType( moduleType ) 134 { 135 } 136 137 const StringTableEntry mModuleId; 138 const StringTableEntry mModuleGroup; 139 const StringTableEntry mModuleType; 140 }; 141 142 /// Module databases. 143 typedef HashMap<StringTableEntry, ModuleDefinitionEntry*> typeModuleIdDatabaseHash; 144 typeModuleIdDatabaseHash mModuleIdDatabase; 145 146public: 147 ModuleManager(); 148 virtual ~ModuleManager() {} 149 150 /// SimObject overrides 151 virtual bool onAdd(); 152 virtual void onRemove(); 153 virtual void onDeleteNotify( SimObject *object ); 154 static void initPersistFields(); 155 156 /// Declare Console Object. 157 DECLARE_CONOBJECT( ModuleManager ); 158 159 /// Module definitions. 160 bool setModuleExtension( const char* pExtension ); 161 162 /// Module discovery. 163 bool scanModules( const char* pPath, const bool rootOnly = false ); 164 165 /// Module unregister. 166 bool registerModule(const char* pModulePath, const char* pModuleFile); 167 bool unregisterModule( const char* pModuleId, const U32 versionId ); 168 169 /// Module (un)loading. 170 bool loadModuleGroup( const char* pModuleGroup ); 171 bool unloadModuleGroup( const char* pModuleGroup ); 172 bool loadModuleExplicit( const char* pModuleId, const U32 versionId = 0 ); 173 bool unloadModuleExplicit( const char* pModuleId ); 174 175 /// Module type enumeration. 176 ModuleDefinition* findModule( const char* pModuleId, const U32 versionId ); 177 ModuleDefinition* findModuleByFilePath(StringTableEntry filePath); 178 ModuleDefinition* findLoadedModule( const char* pModuleId ); 179 void findModules( const bool loadedOnly, typeConstModuleDefinitionVector& moduleDefinitions ); 180 void findModuleTypes( const char* pModuleType, const bool loadedOnly, typeConstModuleDefinitionVector& moduleDefinitions ); 181 182 /// Module synchronization. 183 StringTableEntry copyModule( ModuleDefinition* pSourceModuleDefinition, const char* pTargetModuleId, const char* pTargetPath, const bool useVersionPathing ); 184 bool synchronizeDependencies( ModuleDefinition* pRootModuleDefinition, const char* pTargetDependencyPath ); 185 186 /// Editing modules 187 bool renameModule(ModuleDefinition* pSourceModuleDefinition, const char* pNewModuleName); 188 189 /// Module updates. 190 inline bool isModuleMergeAvailable( void ) const { return Platform::isFile( getModuleMergeFilePath() ); } 191 bool canMergeModules( const char* pMergeSourcePath ); 192 bool mergeModules( const char* pMergeTargetPath, const bool removeMergeDefinition, const bool registerNewModules ); 193 194 /// Module notifications. 195 void addListener( SimObject* pListener ); 196 void removeListener( SimObject* pListener ); 197 198 void setIgnoreLoadedGroups(bool doIgnore) { mIgnoreLoadedGroups = doIgnore; } 199 200private: 201 void clearDatabase( void ); 202 bool removeModuleDefinition( ModuleDefinition* pModuleDefinition ); 203 204 void raiseModulePreLoadNotifications( ModuleDefinition* pModuleDefinition ); 205 void raiseModulePostLoadNotifications( ModuleDefinition* pModuleDefinition ); 206 void raiseModulePreUnloadNotifications( ModuleDefinition* pModuleDefinition ); 207 void raiseModulePostUnloadNotifications( ModuleDefinition* pModuleDefinition ); 208 209 ModuleDefinitionEntry* findModuleId( StringTableEntry moduleId ); 210 ModuleDefinitionEntry::iterator findModuleDefinition( StringTableEntry moduleId, const U32 versionId ); 211 bool resolveModuleDependencies( StringTableEntry moduleId, const U32 versionId, StringTableEntry moduleGroup, bool synchronizedOnly, typeModuleLoadEntryVector& moduleResolvingQueue, typeModuleLoadEntryVector& moduleReadyQueue ); 212 ModuleLoadEntry* findModuleResolving( StringTableEntry moduleId, typeModuleLoadEntryVector& moduleResolvingQueue ); 213 ModuleLoadEntry* findModuleReady( StringTableEntry moduleId, typeModuleLoadEntryVector& moduleReadyQueue ); 214 typeModuleLoadEntryVector::iterator findModuleLoaded( StringTableEntry moduleId, const U32 versionId = 0 ); 215 typeGroupVector::iterator findGroupLoaded( StringTableEntry moduleGroup ); 216 StringTableEntry getModuleMergeFilePath( void ) const; 217}; 218 219//----------------------------------------------------------------------------- 220 221extern ModuleManager ModuleDatabase; 222 223#endif // _MODULE_MANAGER_H 224