Used in Live Traffic Update Nokia LCD Display Project

Fork of NetServices by Segundo Equipo

Committer:
rrajan8
Date:
Wed Mar 06 19:07:23 2013 +0000
Revision:
8:92b57208ab99
Parent:
0:ac1725ba162c
This project utilizes mbed's networking features to display live traffic updates on the Nokia LCD using the MapQuest API's Traffic Web Service.

Who changed what in which revision?

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