Add infos into target window
[ryzomcore.git] / ryzom / server / src / patchman_service / administered_module.h
bloba186836ddda435bd8e34a3ff7025a9a91eb09022
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef ADMINISTERED_MODULE_BASE_H
18 #define ADMINISTERED_MODULE_BASE_H
21 //-----------------------------------------------------------------------------
22 // includes
23 //-----------------------------------------------------------------------------
25 // nel
26 #include "nel/net/module.h"
27 #include "nel/net/module_builder_parts.h"
28 #include "nel/net/module_manager.h"
30 #include "nel/misc/sstring.h"
32 // local
33 #include "module_admin_itf.h"
36 //-----------------------------------------------------------------------------
37 // class CAdministeredModuleBase
38 //-----------------------------------------------------------------------------
40 class CAdministeredModuleBase:
41 public NLNET::CEmptyModuleServiceBehav<NLNET::CEmptyModuleCommBehav<NLNET::CEmptySocketBehav<NLNET::CModuleBase> > >,
42 public PATCHMAN::CAdministeredModuleBaseSkel
44 public:
45 //---------------------------------------------------------------------------------------------
46 // ctors, dtors & init
47 CAdministeredModuleBase();
49 // initialise the module - must be called at start of derived modules' initModule() method
50 NLMISC::CSString init(const NLNET::TParsedCommandLine &initInfo);
52 //---------------------------------------------------------------------------------------------
53 // hooks for methods that this interface implements and that must be called from the parent class
54 void onModuleUp(NLNET::IModuleProxy *module);
55 void onModuleDown(NLNET::IModuleProxy *module);
56 void onModuleUpdate();
57 // bool onDispatchMessage(NLNET::IModuleProxy *sender, const NLNET::CMessage &message);
59 // dissable immediate message dispatching to allow modules on same service to send eachother messages on module up
60 bool isImmediateDispatchingSupported() const { return false; }
63 //---------------------------------------------------------------------------------------------
64 // callbacks on receipt of module messages
66 void installVersion(NLNET::IModuleProxy *sender, const NLMISC::CSString& domainName, uint32 version) {}
67 void launchVersion(NLNET::IModuleProxy *sender, const NLMISC::CSString& domainName, uint32 version) {}
68 void executeCommand(NLNET::IModuleProxy *sender, const NLMISC::CSString &cmdline, const NLMISC::CSString &originator);
71 //---------------------------------------------------------------------------------------------
72 // methods for managing state variables
74 // display an nlwarning and call setStateVariable("Error",...) - keeps track of the number of errors encountered
75 void registerError(const NLMISC::CSString& value) const;
77 // display an nlinfo and call setStateVariable("Latest",...)
78 void registerProgress(const NLMISC::CSString& value) const;
80 // write accessor for state variables
81 void setStateVariable(const NLMISC::CSString& variableName, const NLMISC::CSString& value) const;
83 // concatenating write accessor for state variables
84 // on return, if state variable was not empty then variable = <old value>' '<new value> else variable = <new value>
85 void appendStateVariable(const NLMISC::CSString& variableName, const NLMISC::CSString& value) const;
87 // read accessor for state variables
88 const NLMISC::CSString& getStateVariable(const NLMISC::CSString& variableName) const;
90 // read accessor for getting state as a single complete string
91 // the state variables are each listed with their respective values
92 NLMISC::CSString getStateString() const;
94 // method for clearing state variables
95 void clearStateVariable(const NLMISC::CSString& variableName) const;
97 // general reset for deleting all state variables
98 void clearAllStateVariables() const;
100 // broadcast state info to all connected SPM modules
101 void broadcastStateInfo() const;
103 private:
104 // state variables map (variable name to value)
105 typedef std::map<NLMISC::CSString,NLMISC::CSString> TStateVariables;
106 mutable TStateVariables _StateVariables;
108 // A set of currently connected ServerPatchManager modules
109 typedef std::set<NLNET::IModuleProxy*> TPatchManagers;
110 TPatchManagers _PatchManagers;
112 // a couple of useful context variables
113 bool _Initialised;
114 mutable NLMISC::CSString _LastBroadcastState;
115 mutable uint32 _ErrorCount;
119 //-----------------------------------------------------------------------------
120 // class CAdministeredModuleWrapper
121 //-----------------------------------------------------------------------------
123 class CAdministeredModuleWrapper
125 public:
126 //---------------------------------------------------------------------------------------------
127 // ctors, dtors & init
128 CAdministeredModuleWrapper();
130 // initialise the module - must be called at start of derived modules' initModule() method
131 NLMISC::CSString init(CAdministeredModuleBase* administeredModuleBase);
133 //---------------------------------------------------------------------------------------------
134 // methods for managing state variables
136 // display an nlwarning and call setStateVariable("Error",...) - keeps track of the number of errors encountered
137 void registerError(const NLMISC::CSString& value) const;
139 // display an nlinfo and call setStateVariable("Latest",...)
140 void registerProgress(const NLMISC::CSString& value) const;
142 // write accessor for state variables
143 void setStateVariable(const NLMISC::CSString& variableName, const NLMISC::CSString& value) const;
145 // concatenating write accessor for state variables
146 // on return, if state variable was not empty then variable = <old value>' '<new value> else variable = <new value>
147 void appendStateVariable(const NLMISC::CSString& variableName, const NLMISC::CSString& value) const;
149 // method for clearing state variables
150 void clearStateVariable(const NLMISC::CSString& variableName) const;
152 // general reset for deleting all state variables
153 void clearAllStateVariables() const;
155 // broadcast state info to all connected SPM modules
156 void broadcastStateInfo() const;
158 private:
159 // private data
160 CAdministeredModuleBase* _AdministeredModuleBase;
163 #endif