• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

cache.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
00003 // 
00004 // This program is free software; you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation; either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 // 
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017 //
00018 
00019 #ifndef __CACHE_H__
00020 #define __CACHE_H__
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include "gnashconfig.h"
00024 #endif
00025 
00026 #include <string>
00027 #include <map> 
00028 #include <iostream>
00029 #include <boost/shared_ptr.hpp>
00030 
00031 #include "statistics.h"
00032 #include "diskstream.h"
00033 #include "getclocktime.hpp"
00034 #include "dsodefs.h"
00035 
00038 namespace gnash {
00039 
00040 // max size of files to map enirely into the cache
00041 static const size_t CACHE_LIMIT = 102400000;
00042 
00043 // forward instatiate
00044 //class DiskStream;
00045 
00047 //
00048 class DSOEXPORT Cache {
00049 public:
00050     Cache();
00051     ~Cache();
00052     DSOEXPORT static Cache& getDefaultInstance();
00053     
00054     void DSOEXPORT addPath(const std::string &name, const std::string &fullpath);
00055     std::string &findPath(const std::string &name);
00056     void removePath(const std::string &name);
00057     
00058     void addResponse(const std::string &name, const std::string &response);
00059     std::string &findResponse(const std::string &name);
00060     void removeResponse(const std::string &name);
00061     
00062     void addFile(const std::string &name, boost::shared_ptr<DiskStream > &file);
00063     boost::shared_ptr<DiskStream> & findFile(const std::string &name);
00064     void removeFile(const std::string &name);
00065     
00068     void dump() const { dump(std::cerr); }
00070     void dump(std::ostream& os) const;    
00071 
00072 #ifdef USE_STATS_CACHE
00073     std::string DSOEXPORT stats(bool xml) const;
00074 #endif
00075 private:
00078     std::map<std::string, std::string> _pathnames;
00081     std::map<std::string, std::string> _responses;
00084     std::map<std::string, boost::shared_ptr<DiskStream> > _files;
00085 
00088     size_t _max_size;
00089 
00091 #ifdef USE_STATS_CACHE
00092     struct timespec _last_access;
00093     long        _pathname_lookups;
00094     long        _pathname_hits;
00095     long        _response_lookups;
00096     long        _response_hits;
00097     long        _file_lookups;
00098     long        _file_hits;
00099 #endif
00100 
00101 
00102     size_t      _pagesize;    
00103 
00104 cygnal::AMF::filetype_e  _filetype; // FIXME: this shouldn't be here still
00105 };
00106 
00108 inline std::ostream& operator << (std::ostream& os, const Cache& cache)
00109 {
00110         cache.dump(os);
00111         return os;
00112 }
00113 
00114 } // end of cygnal namespace
00115 
00116 #endif // __CACHE_H__
00117 
00118 // local Variables:
00119 // mode: C++
00120 // indent-tabs-mode: nil
00121 // End:

Generated on Thu Sep 30 2010 14:34:56 for Gnash by  doxygen 1.7.1