• Main Page
  • Related Pages
  • Classes
  • Files
  • File List

src/UploadCache.hh

00001 /*
00002  * Copyright Staffan Gimåker 2009-2010.
00003  *
00004  * ---
00005  *
00006  * This file is part of peekabot.
00007  *
00008  * peekabot is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 3 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * peekabot is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 #ifndef PEEKABOT_UPLOAD_CACHE_HH_INCLUDED
00023 #define PEEKABOT_UPLOAD_CACHE_HH_INCLUDED
00024 
00025 
00026 #include <map>
00027 #include <string>
00028 #include <boost/utility.hpp>
00029 #include <boost/filesystem/path.hpp>
00030 #include <boost/thread/recursive_mutex.hpp>
00031 #include <boost/shared_ptr.hpp>
00032 #include <boost/cstdint.hpp>
00033 
00034 
00035 namespace peekabot
00036 {
00043     class UploadCache : public boost::noncopyable
00044     {
00045     public:
00046         static boost::shared_ptr<UploadCache> create();
00047 
00048         ~UploadCache();
00049 
00050         void add_file(
00051             const std::string &remote_filename,
00052             const void *data, std::size_t n);
00053 
00054         void remove_file(const std::string &remote_filename);
00055 
00056         void clear();
00057 
00058         bool get_local_path(
00059             const std::string &remote_filename,
00060             boost::filesystem::path &local_path) const;
00061 
00062     private:
00063         UploadCache();
00064 
00065         static boost::filesystem::path get_upload_directory();
00066 
00067         boost::filesystem::path get_cache_directory() const;
00068 
00069         std::string generate_local_filename(
00070             const std::string &remote_filename);
00071 
00072     private:
00073         mutable boost::recursive_mutex m_mutex;
00074 
00075         typedef std::map<std::string, std::string> UploadMap;
00076 
00077         UploadMap m_files;
00078 
00079         boost::uint32_t m_counter;
00080 
00081         const boost::uint32_t m_cache_no;
00082     };
00083 }
00084 
00085 
00086 #endif // PEEKABOT_UPLOAD_CACHE_HH_INCLUDED

Generated on Sun Jan 30 2011 for peekabot by  doxygen 1.7.1