summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-06-21 12:31:54 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-06-21 12:31:54 +0000
commitfbc5d6b616ec9738579ce8800eca78716512515a (patch)
treeb824d0692cc981d89562c9b0826abc0a1ed2c348
parentb0d03755f23f72e747e9874c32d00b5cf3f955cf (diff)
Added Server::PublishFeature(),
Server::UnpublishFeature(), Server::FindFeature(). See comments in modules.h for usage git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4041 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/modules.h47
-rw-r--r--src/modules.cpp31
2 files changed, 75 insertions, 3 deletions
diff --git a/include/modules.h b/include/modules.h
index 426ec9a65..d303f7c72 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -78,6 +78,9 @@ enum TargetTypeFlags {
class Server;
class ServerConfig;
+// Forward-delacare module for ModuleMessage etc
+class Module;
+
/** Low level definition of a FileReader classes file cache area
*/
typedef std::deque<std::string> file_cache;
@@ -88,6 +91,10 @@ typedef file_cache string_list;
typedef std::deque<userrec*> chanuserlist;
+/** Holds a list of 'published features' for modules.
+ */
+typedef std::map<std::string,Module*> featurelist;
+
/**
* This #define allows us to call a method in all
* loaded modules in a readable simple way, e.g.:
@@ -164,9 +171,6 @@ class Admin : public classbase
Admin(std::string name, std::string email, std::string nick);
};
-// Forward-delacare module for ModuleMessage etc
-class Module;
-
/** The ModuleMessage class is the base class of Request and Event
* This class is used to represent a basic data structure which is passed
* between modules for safe inter-module communications.
@@ -1302,6 +1306,43 @@ class Server : public classbase
*/
std::string GetVersion();
+ /** Publish a 'feature'.
+ * There are two ways for a module to find another module it depends on.
+ * Either by name, using Server::FindModule, or by feature, using this
+ * function. A feature is an arbitary string which identifies something this
+ * module can do. For example, if your module provides SSL support, but other
+ * modules provide SSL support too, all the modules supporting SSL should
+ * publish an identical 'SSL' feature. This way, any module requiring use
+ * of SSL functions can just look up the 'SSL' feature using FindFeature,
+ * then use the module pointer they are given.
+ * @param FeatureName The case sensitive feature name to make available
+ * @param Mod a pointer to your module class
+ * @returns True on success, false if the feature is already published by
+ * another module.
+ */
+ bool PublishFeature(std::string FeatureName, Module* Mod);
+
+ /** Unpublish a 'feature'.
+ * When your module exits, it must call this method for every feature it
+ * is providing so that the feature table is cleaned up.
+ * @param FeatureName the feature to remove
+ */
+ bool UnpublishFeature(std::string FeatureName);
+
+ /** Find a 'feature'.
+ * There are two ways for a module to find another module it depends on.
+ * Either by name, using Server::FindModule, or by feature, using the
+ * Server::PublishFeature method. A feature is an arbitary string which
+ * identifies something this module can do. For example, if your module
+ * provides SSL support, but other modules provide SSL support too, all
+ * the modules supporting SSL should publish an identical 'SSL' feature.
+ * To find a module capable of providing the feature you want, simply
+ * call this method with the feature name you are looking for.
+ * @param FeatureName The feature name you wish to obtain the module for
+ * @returns A pointer to a valid module class on success, NULL on failure.
+ */
+ Module* FindFeature(std::string FeatureName);
+
/** Writes a log string.
* This method writes a line of text to the log. If the level given is lower than the
* level given in the configuration, this command has no effect.
diff --git a/src/modules.cpp b/src/modules.cpp
index 24b3e1945..b2fdc512d 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -60,6 +60,7 @@ extern command_table cmdlist;
class Server;
ExtModeList EMode;
+featurelist Features;
// returns true if an extended mode character is in use
bool ModeDefined(char modechar, int type)
@@ -350,6 +351,36 @@ long Server::PriorityBefore(const std::string &modulename)
return PRIORITY_DONTCARE;
}
+bool Server::PublishFeature(std::string FeatureName, Module* Mod)
+{
+ if (Features.find(FeatureName) == Features.end())
+ {
+ Features[FeatureName] = Mod;
+ return true;
+ }
+ return false;
+}
+
+bool Server::UnpublishFeature(std::string FeatureName)
+{
+ featurelist::iterator iter = Features.find(FeatureName);
+
+ if (iter == Features.end())
+ return false;
+
+ Features.erase(iter);
+}
+
+Module* Server::FindFeature(std::string FeatureName)
+{
+ featurelist::iterator iter = Features.find(FeatureName);
+
+ if (iter == Features.end())
+ return NULL;
+
+ return iter->second;
+}
+
void Server::RehashServer()
{
WriteOpers("*** Rehashing config file");