Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / patchman_service / service_main.h
blob7c4f884c177bf60e472c26beb9bf44187ae332aa
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 SERVICE_MAIN_H
18 #define SERVICE_MAIN_H
21 //-----------------------------------------------------------------------------
22 // includes
23 //-----------------------------------------------------------------------------
25 #include "nel/net/service.h"
28 //-----------------------------------------------------------------------------
29 // class CServiceClass
30 //-----------------------------------------------------------------------------
32 class CServiceClass : public NLNET::IService
34 public:
35 // service basics
36 void init();
37 bool update();
38 void release();
40 private:
41 // private data
42 bool _ExitRequested;
46 //-----------------------------------------------------------------------------
47 // class IScheduledTask
48 //-----------------------------------------------------------------------------
50 class IScheduledTask: public NLMISC::CRefCount
52 public:
53 //-------------------------------------------------------------------------
54 // virtual dtor...
56 virtual ~IScheduledTask() {}
59 //-------------------------------------------------------------------------
60 // routine that does whatever work this scheduled task is designed for
62 virtual void execute() =0;
66 //-----------------------------------------------------------------------------
67 // class CTaskScheduler
68 //-----------------------------------------------------------------------------
70 class CTaskScheduler
72 public:
73 // getter for the singleton instance
74 static CTaskScheduler& getInstance();
76 // registration method (task and delay in miliseconds before execution)
77 void sceduleTask(IScheduledTask* task,NLMISC::TTime delay);
79 // test method - returns the number of errors found
80 void update();
82 private:
83 // prohibit instantiation because we're a singleton
84 CTaskScheduler();
86 // private data
87 typedef NLMISC::CSmartPtr<IScheduledTask> TScheduledTaskSmartPtr;
88 struct STask
90 TScheduledTaskSmartPtr TaskPtr;
91 NLMISC::TTime ExecutionTime;
93 typedef std::vector<STask> TTasks;
94 TTasks _Tasks; // the current task vector
96 uint32 _MaxTasks; // the largest number of tasks that we have had in the task vector at any one time
100 //-----------------------------------------------------------------------------
101 // class ISelfTestClass
102 //-----------------------------------------------------------------------------
104 class ISelfTestClass: public NLMISC::CRefCount
106 public:
107 //-------------------------------------------------------------------------
108 // make the dtor virtual...
110 virtual ~ISelfTestClass() {}
113 //-------------------------------------------------------------------------
114 // routine that runs the test - returns _ErrorCount
116 virtual uint32 runTest() =0;
119 //-------------------------------------------------------------------------
120 // init
122 void init(NLMISC::CLog& errorLog, NLMISC::CLog& progressLog, NLMISC::CLog& verboseLog);
125 //-------------------------------------------------------------------------
126 // logging
128 void errorLog(const char* fmt,...) const;
129 void progressLog(const char* fmt,...) const;
130 void verboseLog(const char* fmt,...) const;
133 //-------------------------------------------------------------------------
134 // error counter
136 void addError() const;
137 uint32 getErrorCount() const;
140 protected:
141 //-------------------------------------------------------------------------
142 // protected data
144 mutable NLMISC::CLog* _ErrorLog;
145 mutable NLMISC::CLog* _ProgressLog;
146 mutable NLMISC::CLog* _VerboseLog;
147 mutable uint32 _ErrorCount;
151 //-----------------------------------------------------------------------------
152 // class CSelfTestRegistry
153 //-----------------------------------------------------------------------------
155 class CSelfTestRegistry
157 public:
158 // getter for the singleton instance
159 static CSelfTestRegistry& getInstance();
161 // registration method
162 void registerTestObject(ISelfTestClass* testObject,const NLMISC::CSString& description);
164 // test method - returns the number of errors found
165 uint32 runTests(NLMISC::CLog& errorLog, NLMISC::CLog& progressLog, NLMISC::CLog& verboseLog);
167 private:
168 // prohibit instantiation because we're a singleton
169 CSelfTestRegistry();
171 // private data
172 typedef NLMISC::CSmartPtr<ISelfTestClass> TSelfTestClassSmartPtr;
173 typedef std::map<TSelfTestClassSmartPtr,NLMISC::CSString> TTests; // map from test object pointer to description
174 TTests _Tests;
178 //-----------------------------------------------------------------------------
179 // macro REGISTER_SELF_TEST
180 //-----------------------------------------------------------------------------
182 #define REGISTER_SELF_TEST(CLASS,DESCRIPTION)\
183 struct CSelfTestRegisterer_##CLASS\
185 CSelfTestRegisterer_##CLASS() { CSelfTestRegistry::getInstance().registerTestObject(new CLASS,DESCRIPTION); }\
186 } selfTestRegisterer_##CLASS;\
189 //-----------------------------------------------------------------------------
190 #endif