00001 /* -*- Mode:c++ -*- */ 00002 /* 00003 * this is part of Spm 00004 * 00005 * Copyright (c) 2008 Guillaume Chevallereau 00006 * 00007 * This program is free software. You can redistribute it and/or modify it 00008 * under the terms of the GNU General Public License as published by the 00009 * Free Software Foundation. Either version 2 of the license or (at your 00010 * option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be usefull but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00015 * more details. 00016 * 00017 * You should have received a copy of the GNU General Public License along 00018 * with this program; if not, write to the Free Software Foundation, Inc., 00019 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 00020 */ 00021 #ifndef __FILESYSTEM_MANAGER__ 00022 #define __FILESYSTEM_MANAGER__ 00023 00024 #include <util/object.h> 00025 #include <boost/filesystem/path.hpp> 00026 #include <core/installedVersion.h> 00027 #include <core/store.h> 00028 00029 namespace Spm 00030 { 00031 namespace Core 00032 { 00033 class PackageManager; 00034 struct fileSystemElement_ 00035 { 00036 miniXml::ustring path_; 00037 miniXml::ustring checkSum_; 00038 std::list<miniXml::ustring> fakeRefs_; 00039 std::list<InstalledVersion *> references_; 00040 }; 00041 typedef struct fileSystemElement_ fileSystemElement_t; 00042 00043 class FileSystemManager : public Util::Object 00044 { 00045 public : 00046 friend class PackageManager; 00047 friend class FileSystemManagerStore; 00048 private: 00049 miniXml::ustring user_; 00050 std::vector<fileSystemElement_t> paths_; 00051 FileSystemManagerStore * pStore_; 00052 // void load (); 00053 // void save (); 00054 void checkFilesToErase (); 00055 static std::map<miniXml::ustring, 00056 boost::shared_ptr<FileSystemManager> > instances_; 00057 FileSystemManager(const miniXml::ustring & user = ""); 00058 void link (PackageManager * pSystem); 00059 bool modified_; 00060 void save(); 00061 public : 00062 typedef std::vector<fileSystemElement_t>::iterator iterator; 00063 typedef std::vector<fileSystemElement_t>::const_iterator const_iterator; 00064 ~FileSystemManager(); 00065 static boost::shared_ptr<FileSystemManager> create (const miniXml::ustring & user); 00066 00067 void reference (boost::filesystem::path & path, 00068 InstalledVersion * package); 00069 void unreference (boost::filesystem::path & path, 00070 InstalledVersion * package); 00071 void unreference (InstalledVersion * package); 00072 const std::list<InstalledVersion *> & getPackages (const boost::filesystem::path & path); 00073 std::list<boost::filesystem::path> getFiles (const InstalledVersion * package); 00074 const miniXml::ustring user() const 00075 { 00076 return user_; 00077 } 00078 00079 iterator begin () 00080 { 00081 return paths_.begin (); 00082 } 00083 00084 const_iterator begin () const 00085 { 00086 return paths_.begin (); 00087 } 00088 00089 iterator end () 00090 { 00091 return paths_.end (); 00092 } 00093 00094 const_iterator end () const 00095 { 00096 return paths_.end (); 00097 } 00098 00099 std::size_t size () const 00100 { 00101 return paths_.size (); 00102 } 00103 }; 00104 00109 unsigned long long size (const Versionned * version); 00110 00115 unsigned long long size (const Branch * branch); 00116 00121 unsigned long long size (const InstalledVersion * version); 00122 } 00123 } 00124 00125 #endif