25 #include "usModulePrivate.h"
27 #include "usCoreModuleContext_p.h"
28 #include "usServiceRegistry_p.h"
29 #include "usServiceReferenceBasePrivate.h"
35 class ModuleContextPrivate {
39 ModuleContextPrivate(ModulePrivate* module)
43 ModulePrivate* module;
47 ModuleContext::ModuleContext(ModulePrivate* module)
48 : d(new ModuleContextPrivate(module))
63 return d->module->coreCtx->moduleHooks.FilterModule(
this, ModuleRegistry::GetModule(
id));
68 return ModuleRegistry::GetModule(name);
73 std::vector<Module*> modules = ModuleRegistry::GetModules();
74 d->module->coreCtx->moduleHooks.FilterModules(
this, modules);
81 return d->module->coreCtx->services.RegisterService(d->module, service, properties);
85 const std::string& filter)
87 std::vector<ServiceReferenceU> result;
88 std::vector<ServiceReferenceBase> refs;
89 d->module->coreCtx->services.Get(clazz, filter, d->module, refs);
90 for (std::vector<ServiceReferenceBase>::const_iterator iter = refs.begin();
91 iter != refs.end(); ++iter)
100 return d->module->coreCtx->services.Get(d->module, clazz);
107 throw std::invalid_argument(
"Default constructed ServiceReference is not a valid input to GetService()");
109 return reference.d->GetService(d->module->q);
116 throw std::invalid_argument(
"Default constructed ServiceReference is not a valid input to GetService()");
118 return reference.d->GetServiceInterfaceMap(d->module->q);
123 ServiceReferenceBase ref = reference;
124 return ref.d->UngetService(d->module->q,
true);
128 const std::string& filter)
130 d->module->coreCtx->listeners.AddServiceListener(
this, delegate, NULL, filter);
135 d->module->coreCtx->listeners.RemoveServiceListener(
this, delegate, NULL);
140 d->module->coreCtx->listeners.AddModuleListener(
this, delegate, NULL);
145 d->module->coreCtx->listeners.RemoveModuleListener(
this, delegate, NULL);
149 const std::string &filter)
151 d->module->coreCtx->listeners.AddServiceListener(
this, delegate, data, filter);
156 d->module->coreCtx->listeners.RemoveServiceListener(
this, delegate, data);
161 d->module->coreCtx->listeners.AddModuleListener(
this, delegate, data);
166 d->module->coreCtx->listeners.RemoveModuleListener(
this, delegate, data);
172 #ifdef US_PLATFORM_WINDOWS
173 static const char separator =
'\\';
175 static const char separator =
'/';
178 std::string baseStoragePath = ModuleSettings::GetStoragePath();
179 if (baseStoragePath.empty())
return std::string();
180 if (baseStoragePath != d->module->baseStoragePath)
182 d->module->baseStoragePath = baseStoragePath;
183 d->module->storagePath.clear();
186 if (d->module->storagePath.empty())
189 sprintf(buf,
"%ld", d->module->info.id);
190 d->module->storagePath = baseStoragePath + separator + buf +
"_" + d->module->info.name + separator;
192 return d->module->storagePath +
filename;
ServiceReference< void > ServiceReferenceU
ServiceRegistrationU RegisterService(const InterfaceMap &service, const ServiceProperties &properties=ServiceProperties())
void RemoveModuleListener(const ModuleListener &delegate)
bool UngetService(const ServiceReferenceBase &reference)
ServiceReference< S > GetServiceReference()
std::map< std::string, void * > InterfaceMap
void * GetService(const ServiceReferenceBase &reference)
US_MODULE_LISTENER_FUNCTOR ModuleListener
Module * GetModule() const
static const std::string filename
std::string GetDataFile(const std::string &filename) const
ServiceRegistration< void > ServiceRegistrationU
US_BEGIN_NAMESPACE typedef US_SERVICE_LISTENER_FUNCTOR ServiceListener
std::vector< ServiceReferenceU > GetServiceReferences(const std::string &clazz, const std::string &filter=std::string())
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
std::vector< Module * > GetModules() const
void AddModuleListener(const ModuleListener &delegate)
void RemoveServiceListener(const ServiceListener &delegate)
void AddServiceListener(const ServiceListener &delegate, const std::string &filter=std::string())