Permalink
Browse files

Changed loadModule() method to return a Module* instead of a boolean

so that once a module is loaded, its name, id, etc can be determined
if it wasn't known previously.
  • Loading branch information...
1 parent 70ca38a commit 04cc483c238537f6a8735af4e7bd59590d4bd66a @dlongley dlongley committed Oct 17, 2007
Showing with 34 additions and 5 deletions.
  1. +17 −3 modest/cpp/db/modest/ModuleLibrary.cpp
  2. +17 −2 modest/cpp/db/modest/ModuleLibrary.h
@@ -32,9 +32,9 @@ Module* ModuleLibrary::findModule(const char* name)
return rval;
}
-bool ModuleLibrary::loadModule(const char* filename)
+Module* ModuleLibrary::loadModule(const char* filename)
{
- bool rval = false;
+ Module* rval = NULL;
lock();
{
@@ -52,7 +52,7 @@ bool ModuleLibrary::loadModule(const char* filename)
// add Module to the map and list
mModules[mi->module->getId().name] = mi;
mLoadOrder.push_back(mi->module->getId().name);
- rval = true;
+ rval = mi->module;
}
else
{
@@ -137,6 +137,20 @@ void ModuleLibrary::unloadAllModules()
}
}
+Module* ModuleLibrary::getModule(const char* name)
+{
+ Module* rval = NULL;
+
+ lock();
+ {
+ // find Module
+ rval = findModule(name);
+ }
+ unlock();
+
+ return rval;
+}
+
const ModuleId* ModuleLibrary::getModuleId(const char* name)
{
const ModuleId* rval = NULL;
@@ -82,6 +82,10 @@ class ModuleLibrary : public virtual db::rt::Object
/**
* Finds a loaded Module by its name.
+ *
+ * @param name the name of the Module.
+ *
+ * @return the Module or NULL if none exists by the given name.
*/
Module* findModule(const char* name);
@@ -103,9 +107,9 @@ class ModuleLibrary : public virtual db::rt::Object
*
* @param filename the name of the file where the Module resides.
*
- * @return true if the Module was loaded, false if not.
+ * @return the Module, if it was loaded, NULL if not.
*/
- virtual bool loadModule(const char* filename);
+ virtual Module* loadModule(const char* filename);
/**
* Unloads a Module from this ModuleLibrary, if it is loaded.
@@ -120,9 +124,20 @@ class ModuleLibrary : public virtual db::rt::Object
*/
virtual void unloadAllModules();
+ /**
+ * Gets a Module by its name.
+ *
+ * @param name the name of the Module.
+ *
+ * @return the Module or NULL if it does not exist.
+ */
+ virtual Module* getModule(const char* name);
+
/**
* Gets the ModuleId for the Module with the given name.
*
+ * @param name the name of the Module to get the ID for.
+ *
* @return the ModuleId for the Module with the given name or NULL if one
* does not exist.
*/

0 comments on commit 04cc483

Please sign in to comment.