Added ai command setEquipment
[ryzomcore.git] / ryzom / server / src / backup_service / backup_service.h
blob114f6356ba9f5d28e15cd8cf5e3b991fd3c71d02
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/>.
20 #ifndef BACKUP_SERVICE_H
21 #define BACKUP_SERVICE_H
24 // net
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"
30 // stl
31 #include <string>
34 #include "backup_file_access.h"
37 /**
38 * CBackupService
40 * \author Alain Saffray
41 * \author Nevrax France
42 * \date 2004
44 class CBackupService : public NLNET::IService
46 public :
47 /**
48 * init the service
50 void init();
52 /**
53 * main loop
55 bool update();
57 /**
58 * release
60 void release();
62 // stall shard
63 void stallShard(const std::string& fileName);
65 /**
66 * get Instance
68 static CBackupService * getInstance() { return (CBackupService *) NLNET::IService::getInstance(); }
70 /**
71 * get stall, return true if we must not try to save file because previous pb are occurs
73 bool getStall() { return _SaveStall; }
75 /**
76 * set stall mode
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);
86 public:
89 CFileAccessManager FileManager;
91 private:
93 bool _SaveStall;
95 NLNET::TModulePtr _BackupModule;
97 // A layer 3 server to serve synchronous file load
98 NLNET::CCallbackServer *_CallbackServer;
99 };
102 extern NLMISC::CVariable<std::string> StatDirFilter;
105 class CDirectoryRateStat
107 public:
109 CDirectoryRateStat()
111 clear();
114 void clear();
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);
126 private:
128 struct CDirectory
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;
134 uint32 Size;
135 std::string Filename;
136 uint32 Duration;
139 typedef std::deque<CFileQueueEntry> TFileQueue;
141 // read stats
142 TFileQueue ReadQueue;
143 uint64 ReadBytes;
144 uint32 ReadFiles;
146 // write stats
147 TFileQueue WrittenQueue;
148 uint64 WrittenBytes;
149 uint32 WrittenFiles;
151 CDirectory()
153 clear();
156 void clear()
158 ReadBytes = 0;
159 ReadFiles = 0;
161 WrittenBytes = 0;
162 WrittenFiles = 0;
165 void read(NLMISC::TTime now, uint32 filesize)
167 updateTime(now - 60*1000);
168 ReadBytes += filesize;
169 ++ReadFiles;
170 ReadQueue.push_back(CFileQueueEntry(now, filesize));
173 void write(NLMISC::TTime now, uint32 filesize)
175 updateTime(now - 60*1000);
176 WrittenBytes += filesize;
177 ++WrittenFiles;
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;
186 --WrittenFiles;
187 WrittenQueue.pop_front();
189 while (!ReadQueue.empty() && ReadQueue.front().ActionTime < limit)
191 ReadBytes -= ReadQueue.front().Size;
192 --ReadFiles;
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 */