testing of combination of LCS and LAN

Dependencies:   mbed

Committer:
damir
Date:
Wed Jan 14 13:29:55 2015 +0000
Revision:
0:a7a6a692162f
Test of LAN

Who changed what in which revision?

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