InspIRCd  3.0
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
ModuleManager Class Reference

#include <modules.h>

Inheritance diagram for ModuleManager:
fakederef< ModuleManager >

Public Types

typedef std::vector< ServiceProvider * > ServiceList
typedef std::map< std::string, Module * > ModuleMap

Public Member Functions

 ModuleManager ()
 ~ModuleManager ()
bool SetPriority (Module *mod, Implementation i, Priority s, Module *which=NULL)
void SetPriority (Module *mod, Priority s)
bool Attach (Implementation i, Module *mod)
bool Detach (Implementation i, Module *mod)
void Attach (Implementation *i, Module *mod, size_t sz)
void DetachAll (Module *mod)
void AttachAll (Module *mod)
std::string & LastError ()
bool Load (const std::string &filename, bool defer=false)
bool Unload (Module *module)
void LoadAll ()
void UnloadAll ()
void DoSafeUnload (Module *)
bool CanUnload (Module *mod)
ModuleFind (const std::string &name)
void AddService (ServiceProvider &)
void DelService (ServiceProvider &)
void AddServices (const ServiceList &list)
void AddServices (ServiceProvider **list, int count)
ServiceProviderFindService (ServiceType Type, const std::string &name)
template<typename T >
T * FindDataService (const std::string &name)
const ModuleMap & GetModules () const
void AddReferent (const std::string &name, ServiceProvider *service)
void DelReferent (ServiceProvider *service)
- Public Member Functions inherited from fakederef< ModuleManager >
ModuleManageroperator-> ()

Static Public Member Functions

static std::string ExpandModName (const std::string &modname)

Public Attributes

IntModuleList EventHandlers [I_END]
std::multimap< std::string, ServiceProvider * > DataProviders
ServiceList * NewServices

Detailed Description

ModuleManager takes care of all things module-related in the core.

Constructor & Destructor Documentation

◆ ModuleManager()

ModuleManager::ModuleManager ( )

Simple, bog-standard, boring constructor.

◆ ~ModuleManager()

ModuleManager::~ModuleManager ( )


Member Function Documentation

◆ AddReferent()

void ModuleManager::AddReferent ( const std::string &  name,
ServiceProvider service 

Make a service referenceable by dynamic_references

nameName that will be used by dynamic_references to find the object
serviceService to make referenceable by dynamic_references

◆ AddService()

void ModuleManager::AddService ( ServiceProvider item)

Register a service provided by a module

◆ AddServices()

void ModuleManager::AddServices ( const ServiceList &  list)

Register all services in a given ServiceList

listThe list containing the services to register

◆ Attach() [1/2]

bool ModuleManager::Attach ( Implementation  i,
Module mod 

Attach an event to a module. You may later detatch the event with ModuleManager::Detach(). If your module is unloaded, all events are automatically detatched.

iEvent type to attach
modModule to attach event to
True if the event was attached

◆ Attach() [2/2]

void ModuleManager::Attach ( Implementation *  i,
Module mod,
size_t  sz 

Attach an array of events to a module

iEvent types (array) to attach
modModule to attach events to
szThe size of the implementation array

◆ AttachAll()

void ModuleManager::AttachAll ( Module mod)

Attach all events to a module (used on module load)

modModule to attach to all events

◆ CanUnload()

bool ModuleManager::CanUnload ( Module mod)

Check if a module can be unloaded and if yes, prepare it for unload

modModule to be unloaded
True if the module is unloadable, false otherwise. If true the module must be unloaded in the current main loop iteration.

◆ DelReferent()

void ModuleManager::DelReferent ( ServiceProvider service)

Make a service no longer referenceable by dynamic_references

serviceService to make no longer referenceable by dynamic_references

◆ DelService()

void ModuleManager::DelService ( ServiceProvider item)

Unregister a service provided by a module

◆ Detach()

bool ModuleManager::Detach ( Implementation  i,
Module mod 

Detatch an event from a module. This is not required when your module unloads, as the core will automatically detatch your module from all events it is attached to.

iEvent type to detach
modModule to detach event from
True if the event was detached

◆ DetachAll()

void ModuleManager::DetachAll ( Module mod)

Detach all events from a module (used on unload)

modModule to detach from

◆ ExpandModName()

std::string ModuleManager::ExpandModName ( const std::string &  modname)

Expands the name of a module by prepending "m_" and appending ".so". No-op if the name already has the ".so" extension.

modnameModule name to expand
Module name starting with "m_" and ending with ".so"

◆ Find()

Module * ModuleManager::Find ( const std::string &  name)

Find a module by name, and return a Module* to it. This is preferred over iterating the module lists yourself.

nameThe module name to look up
A pointer to the module, or NULL if the module cannot be found

◆ FindService()

ServiceProvider * ModuleManager::FindService ( ServiceType  Type,
const std::string &  name 

Find a service by name. If multiple modules provide a given service, the first one loaded will be chosen.

◆ GetModules()

const ModuleMap& ModuleManager::GetModules ( ) const

Get a map of all loaded modules keyed by their name

A ModuleMap containing all loaded modules

◆ LastError()

std::string & ModuleManager::LastError ( )

Returns text describing the last module error

The last error message to occur

◆ Load()

bool ModuleManager::Load ( const std::string &  filename,
bool  defer = false 

Load a given module file

filenameThe file to load
deferDefer module init (loading many modules)
True if the module was found and loaded

◆ LoadAll()

void ModuleManager::LoadAll ( )

Called by the InspIRCd constructor to load all modules from the config file.

◆ SetPriority() [1/2]

bool ModuleManager::SetPriority ( Module mod,
Implementation  i,
Priority  s,
Module which = NULL 

Change the priority of one event in a module. Each module event has a list of modules which are attached to that event type. If you wish to be called before or after other specific modules, you may use this method (usually within void Module::Prioritize()) to set your events priority. You may use this call in other methods too, however, this is not supported behaviour for a module.

modThe module to change the priority of
iThe event to change the priority of
sThe state you wish to use for this event. Use one of PRIO_FIRST to set the event to be first called, PRIO_LAST to set it to be the last called, or PRIO_BEFORE and PRIORITY_AFTER to set it to be before or after one or more other modules.
whichIf PRIO_BEFORE or PRIORITY_AFTER is set in parameter 's', then this contains a the module that your module must be placed before or after.

To change the priority of a module, we first find its position in the vector, then we find the position of the other modules in the vector that this module wants to be before/after. We pick off either the first or last of these depending on which they want, and we make sure our module is at least before or after the first or last of this subset, depending again on the type of priority.

◆ SetPriority() [2/2]

void ModuleManager::SetPriority ( Module mod,
Priority  s 

Change the priority of all events in a module.

modThe module to set the priority of
sThe priority of all events in the module. Note that with this method, it is not possible to effectively use PRIO_BEFORE or PRIORITY_AFTER, you should use the more fine tuned SetPriority method for this, where you may specify other modules to be prioritized against.

◆ Unload()

bool ModuleManager::Unload ( Module module)

Unload a given module file. Note that the module will not be completely gone until the cull list has finished processing.

true on success; if false, LastError will give a reason

Member Data Documentation

◆ DataProviders

std::multimap<std::string, ServiceProvider*> ModuleManager::DataProviders

List of data services keyed by name

◆ EventHandlers

IntModuleList ModuleManager::EventHandlers[I_END]

Event handler hooks. This needs to be public to be used by FOREACH_MOD and friends.

◆ NewServices

ServiceList* ModuleManager::NewServices

A list of ServiceProviders waiting to be registered. Non-NULL when constructing a Module, NULL otherwise. When non-NULL ServiceProviders add themselves to this list on creation and the core automatically registers them (that is, call AddService()) after the Module is constructed, and before Module::init() is called. If a service is created after the construction of the Module (for example in init()) it has to be registered manually.

The documentation for this class was generated from the following files: