This programme Sets a web server using light weigh ip (using Donatien Garnier's server code) which reads a voltage and saves it value in an htm file to be displayed on local page. Server 2 2nd edition Two issues here 1 ) the compiler throws a warning about assignment in RPCHandler.cpp and 2) the local .htm file created on the mbed flash memory is always date stamped with the default date 01/01/2008 11:00
Dependencies: EthernetNetIf NTPClient_NetServices mbed
server/impl/SimpleHandler.cpp@0:03e1db2fe866, 2010-08-08 (annotated)
- Committer:
- pmr1
- Date:
- Sun Aug 08 22:00:39 2010 +0000
- Revision:
- 0:03e1db2fe866
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pmr1 | 0:03e1db2fe866 | 1 | |
pmr1 | 0:03e1db2fe866 | 2 | /* |
pmr1 | 0:03e1db2fe866 | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
pmr1 | 0:03e1db2fe866 | 4 | |
pmr1 | 0:03e1db2fe866 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
pmr1 | 0:03e1db2fe866 | 6 | of this software and associated documentation files (the "Software"), to deal |
pmr1 | 0:03e1db2fe866 | 7 | in the Software without restriction, including without limitation the rights |
pmr1 | 0:03e1db2fe866 | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
pmr1 | 0:03e1db2fe866 | 9 | copies of the Software, and to permit persons to whom the Software is |
pmr1 | 0:03e1db2fe866 | 10 | furnished to do so, subject to the following conditions: |
pmr1 | 0:03e1db2fe866 | 11 | |
pmr1 | 0:03e1db2fe866 | 12 | The above copyright notice and this permission notice shall be included in |
pmr1 | 0:03e1db2fe866 | 13 | all copies or substantial portions of the Software. |
pmr1 | 0:03e1db2fe866 | 14 | |
pmr1 | 0:03e1db2fe866 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
pmr1 | 0:03e1db2fe866 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
pmr1 | 0:03e1db2fe866 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
pmr1 | 0:03e1db2fe866 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
pmr1 | 0:03e1db2fe866 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
pmr1 | 0:03e1db2fe866 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
pmr1 | 0:03e1db2fe866 | 21 | THE SOFTWARE. |
pmr1 | 0:03e1db2fe866 | 22 | */ |
pmr1 | 0:03e1db2fe866 | 23 | |
pmr1 | 0:03e1db2fe866 | 24 | #include "SimpleHandler.h" |
pmr1 | 0:03e1db2fe866 | 25 | |
pmr1 | 0:03e1db2fe866 | 26 | //#define __DEBUG |
pmr1 | 0:03e1db2fe866 | 27 | #include "dbg/dbg.h" |
pmr1 | 0:03e1db2fe866 | 28 | |
pmr1 | 0:03e1db2fe866 | 29 | SimpleHandler::SimpleHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket) : HTTPRequestHandler(rootPath, path, pTCPSocket) |
pmr1 | 0:03e1db2fe866 | 30 | {} |
pmr1 | 0:03e1db2fe866 | 31 | |
pmr1 | 0:03e1db2fe866 | 32 | SimpleHandler::~SimpleHandler() |
pmr1 | 0:03e1db2fe866 | 33 | { |
pmr1 | 0:03e1db2fe866 | 34 | DBG("\r\nHandler destroyed\r\n"); |
pmr1 | 0:03e1db2fe866 | 35 | } |
pmr1 | 0:03e1db2fe866 | 36 | |
pmr1 | 0:03e1db2fe866 | 37 | void SimpleHandler::doGet() |
pmr1 | 0:03e1db2fe866 | 38 | { |
pmr1 | 0:03e1db2fe866 | 39 | DBG("\r\nIn SimpleHandler::doGet()\r\n"); |
pmr1 | 0:03e1db2fe866 | 40 | const char* resp = "Hello world !"; |
pmr1 | 0:03e1db2fe866 | 41 | setContentLen( strlen(resp) ); |
pmr1 | 0:03e1db2fe866 | 42 | respHeaders()["Connection"] = "close"; |
pmr1 | 0:03e1db2fe866 | 43 | writeData(resp, strlen(resp)); |
pmr1 | 0:03e1db2fe866 | 44 | DBG("\r\nExit SimpleHandler::doGet()\r\n"); |
pmr1 | 0:03e1db2fe866 | 45 | } |
pmr1 | 0:03e1db2fe866 | 46 | |
pmr1 | 0:03e1db2fe866 | 47 | void SimpleHandler::doPost() |
pmr1 | 0:03e1db2fe866 | 48 | { |
pmr1 | 0:03e1db2fe866 | 49 | |
pmr1 | 0:03e1db2fe866 | 50 | } |
pmr1 | 0:03e1db2fe866 | 51 | |
pmr1 | 0:03e1db2fe866 | 52 | void SimpleHandler::doHead() |
pmr1 | 0:03e1db2fe866 | 53 | { |
pmr1 | 0:03e1db2fe866 | 54 | |
pmr1 | 0:03e1db2fe866 | 55 | } |
pmr1 | 0:03e1db2fe866 | 56 | |
pmr1 | 0:03e1db2fe866 | 57 | |
pmr1 | 0:03e1db2fe866 | 58 | void SimpleHandler::onReadable() //Data has been read |
pmr1 | 0:03e1db2fe866 | 59 | { |
pmr1 | 0:03e1db2fe866 | 60 | |
pmr1 | 0:03e1db2fe866 | 61 | } |
pmr1 | 0:03e1db2fe866 | 62 | |
pmr1 | 0:03e1db2fe866 | 63 | void SimpleHandler::onWriteable() //Data has been written & buf is free |
pmr1 | 0:03e1db2fe866 | 64 | { |
pmr1 | 0:03e1db2fe866 | 65 | DBG("\r\nSimpleHandler::onWriteable() event\r\n"); |
pmr1 | 0:03e1db2fe866 | 66 | close(); //Data written, we can close the connection |
pmr1 | 0:03e1db2fe866 | 67 | } |
pmr1 | 0:03e1db2fe866 | 68 | |
pmr1 | 0:03e1db2fe866 | 69 | void SimpleHandler::onClose() //Connection is closing |
pmr1 | 0:03e1db2fe866 | 70 | { |
pmr1 | 0:03e1db2fe866 | 71 | //Nothing to do |
pmr1 | 0:03e1db2fe866 | 72 | } |