Demo Application for the Celeritous Breakout Board

Dependencies:   mbed

Committer:
celeritous
Date:
Fri May 18 03:55:10 2012 +0000
Revision:
0:1a3da73fe36a
Celeritous_BreakoutBoardDemo

Who changed what in which revision?

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