Add infos into target window
[ryzomcore.git] / ryzom / server / src / patchman_service / file_repository.h
blob7bb7271ce69d7b8b8a3d5b65ca9c17f075765a50
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 /**
18 * ***********************************************************************
19 * ****************************** IMPORTANT ******************************
20 * ***********************************************************************
22 * The following set of routines all need to be called by the derived
23 * class for the repositry to function correctly:
24 * - init()
25 * - onModuleUp()
26 * - onModuleDown()
27 * - onModuleUpdate()
28 * - onDispatchMessage()
29 * - getModuleManifest()
31 * ***********************************************************************
35 #ifndef FILE_REPOSITORY_H
36 #define FILE_REPOSITORY_H
39 //-----------------------------------------------------------------------------
40 // includes
41 //-----------------------------------------------------------------------------
43 // nel
44 #include "nel/misc/md5.h"
45 #include "nel/net/module_builder_parts.h"
47 // game share
48 //#include "game_share/deployment_configuration.h"
50 // local
51 #include "module_admin_itf.h"
52 #include "administered_module.h"
55 //-----------------------------------------------------------------------------
56 // namespace PATCHMAN
57 //-----------------------------------------------------------------------------
59 namespace PATCHMAN
62 //-----------------------------------------------------------------------------
63 // class CFileRepository
64 //-----------------------------------------------------------------------------
66 class CFileRepository:
67 public CFileRepositorySkel,
68 public IFileRequestValidator,
69 public IFileInfoUpdateListener
71 public:
72 // get the module manifest component required for CFileReceiver modules to recognise us
73 std::string buildModuleManifest() const;
75 public:
76 // ctor and init
77 CFileRepository();
79 // methods for use in derived classes
80 void init(NLNET::IModule* parent,const NLMISC::CSString& rootDirectory);
81 void onModuleUp(NLNET::IModuleProxy *module);
82 void onModuleDown(NLNET::IModuleProxy *module);
83 void onModuleUpdate();
85 // update methods
86 void rescanFull();
87 void rescanPartial();
88 void updateFile(const NLMISC::CSString& fileName);
90 // overloadable method for getting the file list for subscribers
91 virtual void getFileInfo(const NLMISC::CSString& fileSpec,TFileInfoVector& result,const NLNET::IModuleProxy* sender) const;
93 // query methods
94 TRepositoryDirectoryPtr getRepositoryDirectory();
95 void getFile(const NLMISC::CSString& fileName,NLMISC::CSString& resultData,const NLNET::IModuleProxy* sender) const;
96 void dump(NLMISC::CLog& log);
98 // stats system accessors
99 void setMaxHistorySize(uint32 maxHistorySize);
100 uint32 getMaxHistorySize() const;
102 protected:
103 // treatment of incoming file requests
104 void requestFileInfo(NLNET::IModuleProxy *sender,const NLMISC::CSString& fileSpec);
105 void requestFileData(NLNET::IModuleProxy *sender, const NLMISC::CSString &fileName, uint32 startOffset, uint32 numBytes);
107 // treatment of subscriptions and unsubscriptions
108 void subscribe(NLNET::IModuleProxy *sender, const NLMISC::CSString &fileSpec);
109 void unsubscribe(NLNET::IModuleProxy *sender, const NLMISC::CSString &fileSpec);
110 void unsubscribeAll(NLNET::IModuleProxy *sender);
111 void getInfo(NLNET::IModuleProxy *sender, const NLMISC::CSString &fileSpec);
113 // IFileInfoUpdateListener specialisation implementation
114 void cbFileInfoUpdate(const SFileInfo& fileInfo);
115 void cbFileInfoErased(const NLMISC::CSString& fileName);
117 // broadcast a set of file info changes to all subscribers
118 void _broadcastFileInfoChanges(const TFileInfoVector& fileInfoChanges);
120 // overloadable method for treating my module down
121 virtual void onFileRepositoryModuleDown(NLNET::IModuleProxy *module);
123 private:
124 // private data
126 typedef NLNET::CInterceptorForwarder<CFileRepository> TInterceptor;
127 /// module interceptor forwarder
128 TInterceptor _Interceptor;
130 friend class NLNET::CInterceptorForwarder<CFileRepository>;
132 // the module object that this object is part of
133 NLNET::IModule* _Parent;
135 // a wrapper round '_Parent' to allow us to log to the parent's CAdministeredModuleBase interface
136 CAdministeredModuleWrapper _AdministeredModuleWrapper;
138 // the set of subscribers
139 typedef std::map<NLMISC::CSString,NLNET::IModuleProxy*> TSubscribers;
140 TSubscribers _Subscribers;
142 // the recent info changes that the subscribers may be interested in
143 TFileInfoVector _FileInfoChanges;
145 // system for history of recent info requests and data requests
146 uint32 _MaxHistorySize;
147 typedef std::list<NLMISC::CSString> THistory;
149 // the history for info requests
150 THistory _FileInfoHistory;
151 uint32 _FileInfoHistorySize;
152 uint32 _FileInfoCount;
154 // the history for file data requests
155 THistory _FileRequestHistory;
156 uint32 _FileRequestHistorySize;
157 uint32 _FileRequestCount;
159 protected:
160 // data that may be accessed directlry by derived objects
162 // a smart pointers to our repository directory
163 TRepositoryDirectoryPtr _Directory;
166 protected:
167 // declaration of NLMISC_COMMANDS implemented by this class
168 NLMISC_CLASS_COMMAND_DECL(dump);
169 NLMISC_CLASS_COMMAND_DECL(incRescan);
170 NLMISC_CLASS_COMMAND_DECL(fullRescan);
171 NLMISC_CLASS_COMMAND_DECL(getFile);
172 NLMISC_CLASS_COMMAND_DECL(getFileInfo);
173 NLMISC_CLASS_COMMAND_DECL(updateFile);
174 NLMISC_CLASS_COMMAND_DECL(MaxHistorySize);
176 // macro for adding the NLMISC_COMMANDS provided here to the derived class's command table
177 #define NLMISC_COMMAND_HANDLER_ADDS_FOR_FILE_REPOSITORY(className) \
178 NLMISC_COMMAND_HANDLER_ADD(className, incRescan, "Perform next increment of incremental rescan", "no args")\
179 NLMISC_COMMAND_HANDLER_ADD(className, fullRescan, "Perform a full rescan", "no args")\
180 NLMISC_COMMAND_HANDLER_ADD(className, getFile, "get a file", "<file name>")\
181 NLMISC_COMMAND_HANDLER_ADD(className, getFileInfo, "get info on a set of files", "<file spec>")\
182 NLMISC_COMMAND_HANDLER_ADD(className, updateFile, "force a rescan of a given file", "<file name>")\
183 NLMISC_COMMAND_HANDLER_ADD(className, MaxHistorySize, "the maximum size allowed for the history buffers", "[<num entries>]")
186 } // end of namespace
188 #endif