]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modules/reload.h
Remove the Kiwi links from the readme.
[user/henk/code/inspircd.git] / include / modules / reload.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2015 Attila Molnar <attilamolnar@hush.com>
5  *
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.
9  *
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
13  * details.
14  *
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/>.
17  */
18
19
20 #pragma once
21
22 #include "event.h"
23
24 namespace ReloadModule
25 {
26         class EventListener;
27         class DataKeeper;
28
29         /** Container for data saved by modules before another module is reloaded.
30          */
31         class CustomData
32         {
33                 struct Data
34                 {
35                         EventListener* handler;
36                         void* data;
37                         Data(EventListener* Handler, void* moddata) : handler(Handler), data(moddata) { }
38                 };
39                 typedef std::vector<Data> List;
40                 List list;
41
42          public:
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
45                  * provided.
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
48                  * reload finishes
49                  */
50                 void add(EventListener* handler, void* data)
51                 {
52                         list.push_back(Data(handler, data));
53                 }
54
55                 friend class DataKeeper;
56         };
57
58         class EventListener : public Events::ModuleEventListener
59         {
60          public:
61                 EventListener(Module* mod)
62                         : ModuleEventListener(mod, "event/reloadmodule")
63                 {
64                 }
65
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.
70                  */
71                 virtual void OnReloadModuleSave(Module* mod, CustomData& cd) = 0;
72
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
76                  * was saved
77                  */
78                 virtual void OnReloadModuleRestore(Module* mod, void* data) = 0;
79         };
80 }