10 #ifndef __PION_FILESERVICE_HEADER__
11 #define __PION_FILESERVICE_HEADER__
13 #include <boost/shared_ptr.hpp>
14 #include <boost/functional/hash.hpp>
15 #include <boost/filesystem/path.hpp>
16 #include <boost/thread/once.hpp>
17 #include <boost/thread/mutex.hpp>
18 #include <boost/shared_array.hpp>
19 #include <pion/PionLogger.hpp>
20 #include <pion/PionException.hpp>
21 #include <pion/PionHashMap.hpp>
22 #include <pion/net/WebService.hpp>
23 #include <pion/net/HTTPRequest.hpp>
24 #include <pion/net/HTTPResponseWriter.hpp>
25 #include <pion/net/HTTPServer.hpp>
45 char *content,
unsigned long size,
46 std::time_t modified,
const std::string& mime)
134 public boost::enable_shared_from_this<DiskFileSender>,
135 private boost::noncopyable
146 static inline boost::shared_ptr<DiskFileSender>
148 pion::net::HTTPRequestPtr& request,
149 pion::net::TCPConnectionPtr& tcp_conn,
150 unsigned long max_chunk_size = 0)
152 return boost::shared_ptr<DiskFileSender>(
new DiskFileSender(file, request,
153 tcp_conn, max_chunk_size));
182 pion::net::HTTPRequestPtr& request,
183 pion::net::TCPConnectionPtr& tcp_conn,
184 unsigned long max_chunk_size);
192 void handleWrite(
const boost::system::error_code& write_error,
193 std::size_t bytes_written);
206 pion::net::HTTPResponseWriterPtr m_writer;
209 boost::filesystem::ifstream m_file_stream;
212 boost::shared_array<char> m_content_buf;
219 unsigned long m_max_chunk_size;
222 unsigned long m_file_bytes_to_send;
225 unsigned long m_bytes_sent;
229 typedef boost::shared_ptr<DiskFileSender> DiskFileSenderPtr;
251 :
PionException(
"FileService option is not a directory: ", dir) {}
265 :
PionException(
"FileService option is not a file: ", file) {}
272 :
PionException(
"FileService invalid value for cache option: ", value) {}
279 :
PionException(
"FileService invalid value for scan option: ", value) {}
286 :
PionException(
"FileService invalid value for " + option +
" option: ", value) {}
293 :
PionException(
"FileService unable to read file: ", value) {}
300 :
PionException(
"FileService has an undefined response: ", value) {}
318 virtual void setOption(
const std::string& name,
const std::string& value);
321 virtual void operator()(pion::net::HTTPRequestPtr& request,
322 pion::net::TCPConnectionPtr& tcp_conn);
325 virtual void start(
void);
328 virtual void stop(
void);
340 typedef PION_HASH_MAP<std::string, DiskFile, PION_HASH_STRING >
CacheMap;
343 typedef PION_HASH_MAP<std::string, std::string, PION_HASH_STRING >
MIMETypeMap;
362 std::pair<CacheMap::iterator, bool>
364 const boost::filesystem::path& file_path,
365 const bool placeholder);
373 static std::string
findMIMEType(
const std::string& file_name);
375 void sendNotFoundResponse(pion::net::HTTPRequestPtr& http_request,
376 pion::net::TCPConnectionPtr& tcp_conn);
385 static void createMIMETypes(
void);
389 static const std::string DEFAULT_MIME_TYPE;
392 static const unsigned int DEFAULT_CACHE_SETTING;
395 static const unsigned int DEFAULT_SCAN_SETTING;
398 static const unsigned long DEFAULT_MAX_CACHE_SIZE;
401 static const unsigned long DEFAULT_MAX_CHUNK_SIZE;
404 static boost::once_flag m_mime_types_init_flag;
411 boost::filesystem::path m_directory;
414 boost::filesystem::path m_file;
420 boost::mutex m_cache_mutex;
428 unsigned int m_cache_setting;
437 unsigned int m_scan_setting;
443 unsigned long m_max_cache_size;
450 unsigned long m_max_chunk_size;