Fork of HttpServer_snapshot_mbed-os library
Fork of HttpServer_snapshot_mbed-os by
Handler/FSHandler.h@16:13f082bef9a9, 2017-09-30 (annotated)
- Committer:
- fxanhkhoa
- Date:
- Sat Sep 30 08:36:29 2017 +0000
- Revision:
- 16:13f082bef9a9
- Parent:
- 11:0700755d64ae
Renesas GR Peach ASEAN Contest
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yueee_yt | 0:fdf9c2c5200f | 1 | /* |
yueee_yt | 0:fdf9c2c5200f | 2 | Permission is hereby granted, free of charge, to any person obtaining a copy |
yueee_yt | 0:fdf9c2c5200f | 3 | of this software and associated documentation files (the "Software"), to deal |
yueee_yt | 0:fdf9c2c5200f | 4 | in the Software without restriction, including without limitation the rights |
yueee_yt | 0:fdf9c2c5200f | 5 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
yueee_yt | 0:fdf9c2c5200f | 6 | copies of the Software, and to permit persons to whom the Software is |
yueee_yt | 0:fdf9c2c5200f | 7 | furnished to do so, subject to the following conditions: |
yueee_yt | 0:fdf9c2c5200f | 8 | |
yueee_yt | 0:fdf9c2c5200f | 9 | The above copyright notice and this permission notice shall be included in |
yueee_yt | 0:fdf9c2c5200f | 10 | all copies or substantial portions of the Software. |
yueee_yt | 0:fdf9c2c5200f | 11 | |
yueee_yt | 0:fdf9c2c5200f | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
yueee_yt | 0:fdf9c2c5200f | 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
yueee_yt | 0:fdf9c2c5200f | 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
yueee_yt | 0:fdf9c2c5200f | 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
yueee_yt | 0:fdf9c2c5200f | 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
yueee_yt | 0:fdf9c2c5200f | 17 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
yueee_yt | 0:fdf9c2c5200f | 18 | THE SOFTWARE. |
yueee_yt | 0:fdf9c2c5200f | 19 | */ |
yueee_yt | 0:fdf9c2c5200f | 20 | |
yueee_yt | 0:fdf9c2c5200f | 21 | #ifndef FS_HANDLER_H |
yueee_yt | 0:fdf9c2c5200f | 22 | #define FS_HANDLER_H |
yueee_yt | 0:fdf9c2c5200f | 23 | |
yueee_yt | 0:fdf9c2c5200f | 24 | #include "../HTTPRequestHandler.h" |
yueee_yt | 0:fdf9c2c5200f | 25 | #include "mbed.h" |
yueee_yt | 0:fdf9c2c5200f | 26 | #include <map> |
yueee_yt | 0:fdf9c2c5200f | 27 | using std::map; |
yueee_yt | 0:fdf9c2c5200f | 28 | |
yueee_yt | 0:fdf9c2c5200f | 29 | #include <string> |
yueee_yt | 0:fdf9c2c5200f | 30 | using std::string; |
yueee_yt | 0:fdf9c2c5200f | 31 | |
yueee_yt | 0:fdf9c2c5200f | 32 | class FSHandler : public HTTPRequestHandler |
yueee_yt | 0:fdf9c2c5200f | 33 | { |
yueee_yt | 0:fdf9c2c5200f | 34 | public: |
dkato | 11:0700755d64ae | 35 | FSHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket); |
yueee_yt | 0:fdf9c2c5200f | 36 | virtual ~FSHandler(); |
yueee_yt | 0:fdf9c2c5200f | 37 | |
yueee_yt | 0:fdf9c2c5200f | 38 | static void mount(const string& fsPath, const string& rootPath); |
yueee_yt | 0:fdf9c2c5200f | 39 | |
yueee_yt | 0:fdf9c2c5200f | 40 | //protected: |
dkato | 11:0700755d64ae | 41 | static inline HTTPRequestHandler* inst(const char* rootPath, const char* path, TCPSocket* pTCPSocket) { return new FSHandler(rootPath, path, pTCPSocket); } //if we ever could do static virtual functions, this would be one |
yueee_yt | 0:fdf9c2c5200f | 42 | |
yueee_yt | 0:fdf9c2c5200f | 43 | virtual void doGet(); |
yueee_yt | 0:fdf9c2c5200f | 44 | virtual void doPost(); |
yueee_yt | 0:fdf9c2c5200f | 45 | virtual void doHead(); |
yueee_yt | 0:fdf9c2c5200f | 46 | |
yueee_yt | 0:fdf9c2c5200f | 47 | virtual void onReadable(); //Data has been read |
yueee_yt | 0:fdf9c2c5200f | 48 | virtual void onWriteable(); //Data has been written & buf is free |
yueee_yt | 0:fdf9c2c5200f | 49 | virtual void onClose(); //Connection is closing |
yueee_yt | 0:fdf9c2c5200f | 50 | |
yueee_yt | 0:fdf9c2c5200f | 51 | private: |
yueee_yt | 0:fdf9c2c5200f | 52 | FILE* m_fp; |
yueee_yt | 0:fdf9c2c5200f | 53 | bool m_err404; |
yueee_yt | 0:fdf9c2c5200f | 54 | static map<string,string> m_lFsPath; |
1050186 | 8:a9fb8fe9b8a3 | 55 | static Semaphore req_sem; |
yueee_yt | 0:fdf9c2c5200f | 56 | }; |
yueee_yt | 0:fdf9c2c5200f | 57 | |
yueee_yt | 0:fdf9c2c5200f | 58 | #endif |
dkato | 11:0700755d64ae | 59 |