1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 #include "nel/net/service.h"
28 //-----------------------------------------------------------------------------
29 // class CServiceClass
30 //-----------------------------------------------------------------------------
32 class CServiceClass
: public NLNET::IService
46 //-----------------------------------------------------------------------------
47 // class IScheduledTask
48 //-----------------------------------------------------------------------------
50 class IScheduledTask
: public NLMISC::CRefCount
53 //-------------------------------------------------------------------------
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 //-----------------------------------------------------------------------------
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
83 // prohibit instantiation because we're a singleton
87 typedef NLMISC::CSmartPtr
<IScheduledTask
> TScheduledTaskSmartPtr
;
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
107 //-------------------------------------------------------------------------
108 // make the dtor virtual...
110 virtual ~ISelfTestClass() {}
113 //-------------------------------------------------------------------------
114 // routine that runs the test - returns _ErrorCount
116 virtual uint32
runTest() =0;
119 //-------------------------------------------------------------------------
122 void init(NLMISC::CLog
& errorLog
, NLMISC::CLog
& progressLog
, NLMISC::CLog
& verboseLog
);
125 //-------------------------------------------------------------------------
128 void errorLog(const char* fmt
,...) const;
129 void progressLog(const char* fmt
,...) const;
130 void verboseLog(const char* fmt
,...) const;
133 //-------------------------------------------------------------------------
136 void addError() const;
137 uint32
getErrorCount() const;
141 //-------------------------------------------------------------------------
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
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
);
168 // prohibit instantiation because we're a singleton
172 typedef NLMISC::CSmartPtr
<ISelfTestClass
> TSelfTestClassSmartPtr
;
173 typedef std::map
<TSelfTestClassSmartPtr
,NLMISC::CSString
> TTests
; // map from test object pointer to description
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 //-----------------------------------------------------------------------------