29 #include "usCoreModuleContext_p.h"
31 #include "usStaticInit_p.h"
39 typedef US_UNORDERED_MAP_TYPE<std::string, Module*>
ModuleMap;
41 US_GLOBAL_STATIC(CoreModuleContext, coreModuleContext)
46 void operator()(GlobalStatic<T>& globalStatic)
const
48 ModuleMap* moduleMap = globalStatic.pointer;
49 for (ModuleMap::const_iterator i = moduleMap->begin();
50 i != moduleMap->end(); ++i)
54 DefaultGlobalStaticDeleter<T> defaultDeleter;
55 defaultDeleter(globalStatic);
63 US_GLOBAL_STATIC_WITH_DELETER(
ModuleMap, modules, ModuleDeleter)
68 US_GLOBAL_STATIC(Mutex, modulesLock)
73 US_GLOBAL_STATIC(Mutex, countLock)
77 static long regCount = 0;
83 MutexLock lock(*modulesLock());
84 module = modules()->operator[](info->name);
94 MutexLock lock(*modulesLock());
96 for (ModuleMap::const_iterator i = map->begin();
99 if (i->second->GetLocation() == info->location &&
100 i->second->GetName() == info->name)
112 info->id = ++regCount;
113 assert(info->id == 1 ? info->name ==
"CppMicroServices" :
true);
114 countLock()->Unlock();
116 module->Init(coreModuleContext(), info);
118 MutexLock lock(*modulesLock());
120 map->insert(std::make_pair(info->name, module));
124 module->Init(coreModuleContext(), info);
137 MutexLock lock(*modulesLock());
138 curr = modules()->operator[](info->
name);
145 Module* ModuleRegistry::GetModule(
long id)
147 MutexLock lock(*modulesLock());
149 ModuleMap::const_iterator iter = modules()->begin();
150 ModuleMap::const_iterator iterEnd = modules()->end();
151 for (; iter != iterEnd; ++iter)
153 if (iter->second->GetModuleId() == id)
161 Module* ModuleRegistry::GetModule(
const std::string& name)
163 MutexLock lock(*modulesLock());
165 ModuleMap::const_iterator iter = modules()->find(name);
166 if (iter != modules()->end())
173 std::vector<Module*> ModuleRegistry::GetModules()
175 MutexLock lock(*modulesLock());
177 std::vector<Module*> result;
179 ModuleMap::const_iterator iter = map->begin();
180 ModuleMap::const_iterator iterEnd = map->end();
181 for (; iter != iterEnd; ++iter)
183 result.push_back(iter->second);
188 std::vector<Module*> ModuleRegistry::GetLoadedModules()
190 MutexLock lock(*modulesLock());
192 std::vector<Module*> result;
193 ModuleMap::const_iterator iter = modules()->begin();
194 ModuleMap::const_iterator iterEnd = modules()->end();
195 for (; iter != iterEnd; ++iter)
197 if (iter->second->IsLoaded())
199 result.push_back(iter->second);
206 struct StaticInitializationOrder
208 StaticInitializationOrder()
210 ModuleSettings::GetLogLevel();
US_UNORDERED_MAP_TYPE< std::string, Module * > ModuleMap
static void info(const char *fmt,...)
#define US_INITIALIZE_MODULE
Creates initialization code for a module.
static StaticInitializationOrder _staticInitializationOrder