Trial code integration web page update with analogue data and ntp support
Dependencies: NTPClient_NetServices mbed
lpc1768/services/http/server/HTTPRequestHandler.h@0:8cc2035bebfc, 2010-08-06 (annotated)
- Committer:
- pmr1
- Date:
- Fri Aug 06 17:57:45 2010 +0000
- Revision:
- 0:8cc2035bebfc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pmr1 | 0:8cc2035bebfc | 1 | |
pmr1 | 0:8cc2035bebfc | 2 | /* |
pmr1 | 0:8cc2035bebfc | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
pmr1 | 0:8cc2035bebfc | 4 | |
pmr1 | 0:8cc2035bebfc | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
pmr1 | 0:8cc2035bebfc | 6 | of this software and associated documentation files (the "Software"), to deal |
pmr1 | 0:8cc2035bebfc | 7 | in the Software without restriction, including without limitation the rights |
pmr1 | 0:8cc2035bebfc | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
pmr1 | 0:8cc2035bebfc | 9 | copies of the Software, and to permit persons to whom the Software is |
pmr1 | 0:8cc2035bebfc | 10 | furnished to do so, subject to the following conditions: |
pmr1 | 0:8cc2035bebfc | 11 | |
pmr1 | 0:8cc2035bebfc | 12 | The above copyright notice and this permission notice shall be included in |
pmr1 | 0:8cc2035bebfc | 13 | all copies or substantial portions of the Software. |
pmr1 | 0:8cc2035bebfc | 14 | |
pmr1 | 0:8cc2035bebfc | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
pmr1 | 0:8cc2035bebfc | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
pmr1 | 0:8cc2035bebfc | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
pmr1 | 0:8cc2035bebfc | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
pmr1 | 0:8cc2035bebfc | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
pmr1 | 0:8cc2035bebfc | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
pmr1 | 0:8cc2035bebfc | 21 | THE SOFTWARE. |
pmr1 | 0:8cc2035bebfc | 22 | */ |
pmr1 | 0:8cc2035bebfc | 23 | |
pmr1 | 0:8cc2035bebfc | 24 | #ifndef HTTP_REQUEST_HANDLER_H |
pmr1 | 0:8cc2035bebfc | 25 | #define HTTP_REQUEST_HANDLER_H |
pmr1 | 0:8cc2035bebfc | 26 | |
pmr1 | 0:8cc2035bebfc | 27 | #include "api/TCPSocket.h" |
pmr1 | 0:8cc2035bebfc | 28 | //#include "HTTPServer.h" |
pmr1 | 0:8cc2035bebfc | 29 | |
pmr1 | 0:8cc2035bebfc | 30 | #include "mbed.h" |
pmr1 | 0:8cc2035bebfc | 31 | |
pmr1 | 0:8cc2035bebfc | 32 | #include <string> |
pmr1 | 0:8cc2035bebfc | 33 | using std::string; |
pmr1 | 0:8cc2035bebfc | 34 | |
pmr1 | 0:8cc2035bebfc | 35 | #include <map> |
pmr1 | 0:8cc2035bebfc | 36 | using std::map; |
pmr1 | 0:8cc2035bebfc | 37 | |
pmr1 | 0:8cc2035bebfc | 38 | class HTTPRequestHandler : public NetService |
pmr1 | 0:8cc2035bebfc | 39 | { |
pmr1 | 0:8cc2035bebfc | 40 | public: |
pmr1 | 0:8cc2035bebfc | 41 | HTTPRequestHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket); |
pmr1 | 0:8cc2035bebfc | 42 | virtual ~HTTPRequestHandler(); |
pmr1 | 0:8cc2035bebfc | 43 | |
pmr1 | 0:8cc2035bebfc | 44 | //protected: |
pmr1 | 0:8cc2035bebfc | 45 | virtual void doGet() = 0; |
pmr1 | 0:8cc2035bebfc | 46 | virtual void doPost() = 0; |
pmr1 | 0:8cc2035bebfc | 47 | virtual void doHead() = 0; |
pmr1 | 0:8cc2035bebfc | 48 | |
pmr1 | 0:8cc2035bebfc | 49 | virtual void onReadable() = 0; //Data has been read |
pmr1 | 0:8cc2035bebfc | 50 | virtual void onWriteable() = 0; //Data has been written & buf is free |
pmr1 | 0:8cc2035bebfc | 51 | virtual void onTimeout(); //Connection has timed out |
pmr1 | 0:8cc2035bebfc | 52 | virtual void onClose() = 0; //Connection is closing |
pmr1 | 0:8cc2035bebfc | 53 | |
pmr1 | 0:8cc2035bebfc | 54 | virtual void close(); //Close socket and destroy data |
pmr1 | 0:8cc2035bebfc | 55 | |
pmr1 | 0:8cc2035bebfc | 56 | protected: |
pmr1 | 0:8cc2035bebfc | 57 | map<string, string>& reqHeaders() /*const*/; |
pmr1 | 0:8cc2035bebfc | 58 | string& path() /*const*/; |
pmr1 | 0:8cc2035bebfc | 59 | int dataLen() const; |
pmr1 | 0:8cc2035bebfc | 60 | int readData(char* buf, int len); |
pmr1 | 0:8cc2035bebfc | 61 | string& rootPath() /*const*/; |
pmr1 | 0:8cc2035bebfc | 62 | |
pmr1 | 0:8cc2035bebfc | 63 | void setErrCode(int errc); |
pmr1 | 0:8cc2035bebfc | 64 | void setContentLen(int len); |
pmr1 | 0:8cc2035bebfc | 65 | |
pmr1 | 0:8cc2035bebfc | 66 | map<string, string>& respHeaders(); |
pmr1 | 0:8cc2035bebfc | 67 | int writeData(const char* buf, int len); |
pmr1 | 0:8cc2035bebfc | 68 | |
pmr1 | 0:8cc2035bebfc | 69 | void setTimeout(int ms); |
pmr1 | 0:8cc2035bebfc | 70 | void resetTimeout(); |
pmr1 | 0:8cc2035bebfc | 71 | |
pmr1 | 0:8cc2035bebfc | 72 | private: |
pmr1 | 0:8cc2035bebfc | 73 | void readHeaders(); //Called at instanciation |
pmr1 | 0:8cc2035bebfc | 74 | void writeHeaders(); //Called at the first writeData call |
pmr1 | 0:8cc2035bebfc | 75 | void onTCPSocketEvent(TCPSocketEvent e); |
pmr1 | 0:8cc2035bebfc | 76 | |
pmr1 | 0:8cc2035bebfc | 77 | TCPSocket* m_pTCPSocket; |
pmr1 | 0:8cc2035bebfc | 78 | map<string, string> m_reqHeaders; |
pmr1 | 0:8cc2035bebfc | 79 | map<string, string> m_respHeaders; |
pmr1 | 0:8cc2035bebfc | 80 | string m_rootPath; |
pmr1 | 0:8cc2035bebfc | 81 | string m_path; |
pmr1 | 0:8cc2035bebfc | 82 | int m_errc; //Response code |
pmr1 | 0:8cc2035bebfc | 83 | |
pmr1 | 0:8cc2035bebfc | 84 | Timeout m_watchdog; |
pmr1 | 0:8cc2035bebfc | 85 | int m_timeout; |
pmr1 | 0:8cc2035bebfc | 86 | |
pmr1 | 0:8cc2035bebfc | 87 | bool m_closed; |
pmr1 | 0:8cc2035bebfc | 88 | bool m_headersSent; |
pmr1 | 0:8cc2035bebfc | 89 | |
pmr1 | 0:8cc2035bebfc | 90 | int readLine(char* str, int maxLen); |
pmr1 | 0:8cc2035bebfc | 91 | |
pmr1 | 0:8cc2035bebfc | 92 | }; |
pmr1 | 0:8cc2035bebfc | 93 | |
pmr1 | 0:8cc2035bebfc | 94 | #endif |