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