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/>.
20 #ifndef BACKUP_SERVICE_H
21 #define BACKUP_SERVICE_H
25 #include "nel/misc/types_nl.h"
26 #include "nel/misc/log.h"
27 #include "nel/net/service.h"
28 #include "nel/misc/variable.h"
34 #include "backup_file_access.h"
40 * \author Alain Saffray
41 * \author Nevrax France
44 class CBackupService
: public NLNET::IService
63 void stallShard(const std::string
& fileName
);
68 static CBackupService
* getInstance() { return (CBackupService
*) NLNET::IService::getInstance(); }
71 * get stall, return true if we must not try to save file because previous pb are occurs
73 bool getStall() { return _SaveStall
; }
78 void setStall( bool stall
) { _SaveStall
= stall
; }
80 NLNET::IModule
*getBackupModule() { return _BackupModule
; };
82 void setBackupModule(NLNET::IModule
*module
) { _BackupModule
= module
; }
84 void onModuleDown(NLNET::IModuleProxy
*proxy
);
89 CFileAccessManager FileManager
;
95 NLNET::TModulePtr _BackupModule
;
97 // A layer 3 server to serve synchronous file load
98 NLNET::CCallbackServer
*_CallbackServer
;
102 extern NLMISC::CVariable
<std::string
> StatDirFilter
;
105 class CDirectoryRateStat
116 void readFile(const std::string
& filename
, uint32 filesize
);
118 void writeFile(const std::string
& filename
, uint32 filesize
);
120 uint
getMeanReadRate();
122 uint
getMeanWriteRate();
124 void display(NLMISC::CLog
& log
);
130 struct CFileQueueEntry
132 CFileQueueEntry(NLMISC::TTime time
, uint32 size
, const std::string
& filename
= "", uint32 duration
= 0) : ActionTime(time
), Size(size
), Filename(filename
), Duration(duration
) { }
133 NLMISC::TTime ActionTime
;
135 std::string Filename
;
139 typedef std::deque
<CFileQueueEntry
> TFileQueue
;
142 TFileQueue ReadQueue
;
147 TFileQueue WrittenQueue
;
165 void read(NLMISC::TTime now
, uint32 filesize
)
167 updateTime(now
- 60*1000);
168 ReadBytes
+= filesize
;
170 ReadQueue
.push_back(CFileQueueEntry(now
, filesize
));
173 void write(NLMISC::TTime now
, uint32 filesize
)
175 updateTime(now
- 60*1000);
176 WrittenBytes
+= filesize
;
178 WrittenQueue
.push_back(CFileQueueEntry(now
, filesize
));
181 void updateTime(NLMISC::TTime limit
)
183 while (!WrittenQueue
.empty() && WrittenQueue
.front().ActionTime
< limit
)
185 WrittenBytes
-= WrittenQueue
.front().Size
;
187 WrittenQueue
.pop_front();
189 while (!ReadQueue
.empty() && ReadQueue
.front().ActionTime
< limit
)
191 ReadBytes
-= ReadQueue
.front().Size
;
193 ReadQueue
.pop_front();
199 // mapping to filtered directories
200 typedef std::map
<std::string
, CDirectory
> TDirectoryMap
;
201 TDirectoryMap _DirectoryMap
;
207 #endif // BACKUP_SERVICE_H
209 /* End of backup_service.h */