00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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