pion  5.0.6
Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
pion::plugins::FileService Class Reference

#include <FileService.hpp>

Inherits pion::http::plugin_service.

Public Member Functions

virtual void set_option (const std::string &name, const std::string &value)
 
virtual void operator() (pion::http::request_ptr &http_request_ptr, pion::tcp::connection_ptr &tcp_conn)
 handles requests for FileService
 
virtual void start (void)
 called when the web service's server is starting
 
virtual void stop (void)
 called when the web service's server is stopping
 
void set_logger (logger log_ptr)
 sets the logger to be used
 
logger get_logger (void)
 returns the logger currently in use
 
- Public Member Functions inherited from pion::http::plugin_service
 plugin_service (void)
 default constructor
 
virtual ~plugin_service ()
 virtual destructor
 
void set_resource (const std::string &str)
 sets the URI stem or resource that is bound to the web service
 
const std::string & get_resource (void) const
 returns the URI stem or resource that is bound to the web service
 
std::string get_relative_resource (const std::string &resource_requested) const
 returns the path to the resource requested, relative to the web service's location
 

Protected Types

typedef PION_HASH_MAP< std::string, DiskFile, PION_HASH_STRING > CacheMap
 data type for map of file names to cache entries
 
typedef PION_HASH_MAP< std::string, std::string, PION_HASH_STRING > MIMETypeMap
 data type for map of file extensions to MIME types
 

Protected Member Functions

void scanDirectory (const boost::filesystem::path &dir_path)
 
std::pair< CacheMap::iterator, bool > addCacheEntry (const std::string &relative_path, const boost::filesystem::path &file_path, const bool placeholder)
 
void sendNotFoundResponse (pion::http::request_ptr &http_request_ptr, pion::tcp::connection_ptr &tcp_conn)
 

Static Protected Member Functions

static std::string findMIMEType (const std::string &file_name)
 

Protected Attributes

logger m_logger
 primary logging interface used by this class
 

Detailed Description

FileService: web service that serves regular files

Definition at line 235 of file FileService.hpp.

Member Function Documentation

std::pair< FileService::CacheMap::iterator, bool > pion::plugins::FileService::addCacheEntry ( const std::string &  relative_path,
const boost::filesystem::path &  file_path,
const bool  placeholder 
)
protected

adds a single file to the cache

Parameters
relative_pathpath for the file relative to the root directory
file_pathactual path to the file on disk
placeholderif true, the file's contents are not cached
Returns
std::pair<CacheMap::iterator, bool> if an entry is added to the cache, second will be true and first will point to the new entry

Definition at line 665 of file FileService.cpp.

References findMIMEType(), pion::plugins::DiskFile::getFileSize(), m_logger, pion::plugins::DiskFile::read(), and pion::plugins::DiskFile::update().

Referenced by scanDirectory(), and start().

std::string pion::plugins::FileService::findMIMEType ( const std::string &  file_name)
staticprotected

searches for a MIME type that matches a file

Parameters
file_namename of the file to search for
Returns
MIME type corresponding with the file, or DEFAULT_MIME_TYPE if none found

Definition at line 716 of file FileService.cpp.

Referenced by addCacheEntry(), and operator()().

void pion::plugins::FileService::scanDirectory ( const boost::filesystem::path &  dir_path)
protected

adds all files within a directory to the cache

Parameters
dir_paththe directory to scan (sub-directories are included)

Definition at line 625 of file FileService.cpp.

References addCacheEntry(), pion::http::plugin_service::get_resource(), and m_logger.

Referenced by start().

void pion::plugins::FileService::set_option ( const std::string &  name,
const std::string &  value 
)
virtual

configuration options supported by FileService:

directory: all files within the directory will be made available file: cache: scan: max_chunk_size: writable:

Reimplemented from pion::http::plugin_service.

Definition at line 53 of file FileService.cpp.

References pion::plugin::check_cygwin_path().


The documentation for this class was generated from the following files: