2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2015 Attila Molnar <attilamolnar@hush.com>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 namespace ReloadModule
29 /** Container for data saved by modules before another module is reloaded.
35 EventListener* handler;
37 Data(EventListener* Handler, void* moddata) : handler(Handler), data(moddata) { }
39 typedef std::vector<Data> List;
43 /** Add data to the saved state of a module.
44 * The provided handler's OnReloadModuleRestore() method will be called when the reload is done with the pointer
46 * @param handler Handler for restoring the data
47 * @param data Pointer to the data, will be passed back to the provided handler's OnReloadModuleRestore() after the
50 void add(EventListener* handler, void* data)
52 list.push_back(Data(handler, data));
55 friend class DataKeeper;
58 class EventListener : public Events::ModuleEventListener
61 EventListener(Module* mod)
62 : ModuleEventListener(mod, "event/reloadmodule")
66 /** Called whenever a module is about to be reloaded. Use this event to save data related to the module that you want
67 * to be restored after the reload.
68 * @param mod Module to be reloaded
69 * @param cd CustomData instance that can store your data once.
71 virtual void OnReloadModuleSave(Module* mod, CustomData& cd) = 0;
73 /** Restore data after a reload. Only called if data was added in OnReloadModuleSave().
74 * @param mod Reloaded module, if NULL the reload failed and the module no longer exists
75 * @param data Pointer that was passed to CustomData::add() in OnReloadModuleSave() at the time when the module's state
78 virtual void OnReloadModuleRestore(Module* mod, void* data) = 0;