# pion::plugins::FileService Class Reference

`#include <FileService.hpp>`

Inherits pion::net::WebService.

List of all members.

## Detailed Description

FileService: web service that serves regular files

Definition at line 235 of file FileService.hpp.

## Public Member Functions

| FileService (void)
virtual | ~FileService ()
virtual void | setOption (const std::string &name, const std::string &value)
virtual void | operator() (pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &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 | setLogger (PionLogger log_ptr)
| sets the logger to be used
PionLogger | getLogger (void)
| returns the logger currently in use

## 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::net::HTTPRequestPtr &http_request, pion::net::TCPConnectionPtr &tcp_conn)

## Static Protected Member Functions

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

## Protected Attributes

PionLogger | m_logger
| primary logging interface used by this class

## Classes

class | DirectoryNotFoundException
| exception thrown if the directory configured is not found More...
class | FileNotFoundException
| exception thrown if the file configured is not found More...
class | FileReadException
| exception thrown if we are unable to read a file from disk More...
class | InvalidCacheException
| exception thrown if the cache option is set to an invalid value More...
class | InvalidOptionValueException
| exception thrown if an option is set to an invalid value More...
class | InvalidScanException
| exception thrown if the scan option is set to an invalid value More...
class | NotADirectoryException
| exception thrown if the directory configuration option is not a directory More...
class | NotAFileException
| exception thrown if the file configuration option is not a file More...
class | UndefinedResponseException
| exception thrown if we do not know how to respond (should never happen) More...

## 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_path | path for the file relative to the root directory
  | file_path | actual path to the file on disk
  | placeholder | if 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 627 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 | ) | `[static, protected]`

searches for a MIME type that matches a file

Parameters:

  | file_name | name of the file to search for

Returns:
  MIME type corresponding with the file, or DEFAULT_MIME_TYPE if none found

Definition at line 659 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_path | the directory to scan (sub-directories are included)

Definition at line 597 of file FileService.cpp.

References addCacheEntry(), pion::net::WebService::getResource(), and m_logger.

Referenced by start().

void pion::plugins::FileService::setOption | ( | 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::net::WebService.

Definition at line 50 of file FileService.cpp.

References pion::PionPlugin::checkCygwinPath().

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

- net/services/FileService.hpp
- net/services/FileService.cpp