27 #include "usModulePrivate.h"
30 #include "usCoreModuleContext_p.h"
32 #include "usCoreConfig.h"
36 const std::string& Module::PROP_ID()
38 static const std::string s(
"module.id");
41 const std::string& Module::PROP_NAME()
43 static const std::string s(
"module.name");
46 const std::string& Module::PROP_LOCATION()
48 static const std::string s(
"module.location");
51 const std::string& Module::PROP_VERSION()
53 static const std::string s(
"module.version");
57 const std::string&Module::PROP_VENDOR()
59 static const std::string s(
"module.vendor");
63 const std::string&Module::PROP_DESCRIPTION()
65 static const std::string s(
"module.description");
69 const std::string&Module::PROP_AUTOLOAD_DIR()
71 static const std::string s(
"module.autoload_dir");
75 const std::string&Module::PROP_AUTOLOADED_MODULES()
77 static const std::string s(
"module.autoloaded_modules");
92 void Module::Init(CoreModuleContext* coreCtx,
95 ModulePrivate* mp =
new ModulePrivate(
this, coreCtx, info);
100 void Module::Uninit()
102 if (d->moduleContext != NULL)
105 d->RemoveModuleResources();
106 delete d->moduleContext;
107 d->moduleContext = 0;
110 d->moduleActivator = 0;
116 return d->moduleContext != 0;
122 if (d->moduleContext)
124 US_WARN <<
"Module " << d->info.name <<
" already started.";
130 typedef ModuleActivator*(*ModuleActivatorHook)(void);
131 ModuleActivatorHook activatorHook = NULL;
133 std::string activator_func =
"_us_module_activator_instance_" + d->info.name;
134 void* activatorHookSym = ModuleUtils::GetSymbol(d->info, activator_func.c_str());
135 std::memcpy(&activatorHook, &activatorHookSym,
sizeof(
void*));
144 d->moduleActivator = activatorHook();
148 US_ERROR <<
"Creating the module activator of " << d->info.name <<
" failed";
156 d->moduleActivator->Load(d->moduleContext);
159 #ifdef US_ENABLE_AUTOLOADING_SUPPORT
163 if (!loadedPaths.empty())
175 if (d->moduleContext == 0)
177 US_WARN <<
"Module " << d->info.name <<
" already stopped.";
185 if (d->moduleActivator)
187 d->moduleActivator->Unload(d->moduleContext);
192 US_WARN <<
"Calling the module activator Unload() method of " << d->info.name <<
" failed!";
208 return d->moduleContext;
218 return d->info.location;
233 return d->moduleManifest.GetValue(key);
238 return d->moduleManifest.GetKeys();
243 std::vector<ServiceRegistrationBase> sr;
244 std::vector<ServiceReferenceU> res;
245 d->coreCtx->services.GetRegisteredByModule(d, sr);
246 for (std::vector<ServiceRegistrationBase>::const_iterator i = sr.begin();
249 res.push_back(i->GetReference());
256 std::vector<ServiceRegistrationBase> sr;
257 std::vector<ServiceReferenceU> res;
258 d->coreCtx->services.GetUsedByModule(const_cast<Module*>(
this), sr);
259 for (std::vector<ServiceRegistrationBase>::const_iterator i = sr.begin();
262 res.push_back(i->GetReference());
269 if (!d->resourceContainer.IsValid())
274 if (result)
return result;
281 std::vector<ModuleResource> result;
282 if (!d->resourceContainer.IsValid())
287 std::string normalizedPath = path;
289 if (normalizedPath.empty()) normalizedPath.push_back(
'/');
290 if (*normalizedPath.begin() !=
'/') normalizedPath =
'/' + normalizedPath;
291 if (*normalizedPath.rbegin() !=
'/') normalizedPath.push_back(
'/');
292 d->resourceContainer.FindNodes(d->info.name + normalizedPath,
293 filePattern.empty() ?
"*" : filePattern,
302 std::ostream&
operator<<(std::ostream& os,
const Module& module)
304 os <<
"Module[" <<
"id=" << module.GetModuleId() <<
305 ", loc=" << module.GetLocation() <<
306 ", name=" << module.GetName() <<
"]";
310 std::ostream&
operator<<(std::ostream& os, Module
const * module)
std::string GetName() const
static bool IsAutoLoadingEnabled()
static void info(const char *fmt,...)
Any GetProperty(const std::string &key) const
ModuleVersion GetVersion() const
static const std::string & PROP_AUTOLOADED_MODULES()
std::vector< std::string > GetPropertyKeys() const
std::string GetLocation() const
US_Core_EXPORT std::ostream & operator<<(std::ostream &os, ModuleEvent::Type eventType)
ModuleContext * GetModuleContext() const
std::vector< std::string > AutoLoadModules(const ModuleInfo &moduleInfo)
static void swap(T &x, T &y)
std::vector< ServiceReferenceU > GetServicesInUse() const
std::vector< ModuleResource > FindResources(const std::string &path, const std::string &filePattern, bool recurse) const
ModuleResource GetResource(const std::string &path) const
std::vector< ServiceReferenceU > GetRegisteredServices() const