HttpServer Library for "mbed classic" which added a snapshot handler.
Dependents: GR-PEACH_WebCamera_OV5642_fixedIP GR-PEACH_WebCamera_AP
Fork of HttpServer by
Handler/SimpleHandler.cpp@0:fdf9c2c5200f, 2014-02-20 (annotated)
- Committer:
- yueee_yt
- Date:
- Thu Feb 20 05:36:19 2014 +0000
- Revision:
- 0:fdf9c2c5200f
- Child:
- 4:1b6b021ee21d
Initialize version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yueee_yt | 0:fdf9c2c5200f | 1 | |
yueee_yt | 0:fdf9c2c5200f | 2 | /* |
yueee_yt | 0:fdf9c2c5200f | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
yueee_yt | 0:fdf9c2c5200f | 4 | |
yueee_yt | 0:fdf9c2c5200f | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
yueee_yt | 0:fdf9c2c5200f | 6 | of this software and associated documentation files (the "Software"), to deal |
yueee_yt | 0:fdf9c2c5200f | 7 | in the Software without restriction, including without limitation the rights |
yueee_yt | 0:fdf9c2c5200f | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
yueee_yt | 0:fdf9c2c5200f | 9 | copies of the Software, and to permit persons to whom the Software is |
yueee_yt | 0:fdf9c2c5200f | 10 | furnished to do so, subject to the following conditions: |
yueee_yt | 0:fdf9c2c5200f | 11 | |
yueee_yt | 0:fdf9c2c5200f | 12 | The above copyright notice and this permission notice shall be included in |
yueee_yt | 0:fdf9c2c5200f | 13 | all copies or substantial portions of the Software. |
yueee_yt | 0:fdf9c2c5200f | 14 | |
yueee_yt | 0:fdf9c2c5200f | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
yueee_yt | 0:fdf9c2c5200f | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
yueee_yt | 0:fdf9c2c5200f | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
yueee_yt | 0:fdf9c2c5200f | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
yueee_yt | 0:fdf9c2c5200f | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
yueee_yt | 0:fdf9c2c5200f | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
yueee_yt | 0:fdf9c2c5200f | 21 | THE SOFTWARE. |
yueee_yt | 0:fdf9c2c5200f | 22 | */ |
yueee_yt | 0:fdf9c2c5200f | 23 | |
yueee_yt | 0:fdf9c2c5200f | 24 | #include "SimpleHandler.h" |
yueee_yt | 0:fdf9c2c5200f | 25 | |
yueee_yt | 0:fdf9c2c5200f | 26 | //#define __DEBUG |
yueee_yt | 0:fdf9c2c5200f | 27 | //#include "dbg/dbg.h" |
yueee_yt | 0:fdf9c2c5200f | 28 | |
yueee_yt | 0:fdf9c2c5200f | 29 | SimpleHandler::SimpleHandler(const char* rootPath, const char* path, TCPSocketConnection* pTCPSocketConnection) : HTTPRequestHandler(rootPath, path, pTCPSocketConnection) |
yueee_yt | 0:fdf9c2c5200f | 30 | { |
yueee_yt | 0:fdf9c2c5200f | 31 | printf("++++(SimpleHeader)Initialize\r\n"); |
yueee_yt | 0:fdf9c2c5200f | 32 | } |
yueee_yt | 0:fdf9c2c5200f | 33 | |
yueee_yt | 0:fdf9c2c5200f | 34 | SimpleHandler::~SimpleHandler() |
yueee_yt | 0:fdf9c2c5200f | 35 | { |
yueee_yt | 0:fdf9c2c5200f | 36 | printf("++++(SimpleHeader)Handler destroyed\r\n"); |
yueee_yt | 0:fdf9c2c5200f | 37 | } |
yueee_yt | 0:fdf9c2c5200f | 38 | |
yueee_yt | 0:fdf9c2c5200f | 39 | void SimpleHandler::doGet() |
yueee_yt | 0:fdf9c2c5200f | 40 | { |
yueee_yt | 0:fdf9c2c5200f | 41 | printf("++++(SimpleHeader) doGet()\r\n"); |
yueee_yt | 0:fdf9c2c5200f | 42 | const char* resp = "Hello world !"; |
yueee_yt | 0:fdf9c2c5200f | 43 | setContentLen( strlen(resp) ); |
yueee_yt | 0:fdf9c2c5200f | 44 | respHeaders()["Connection"] = "close"; |
yueee_yt | 0:fdf9c2c5200f | 45 | writeData(resp, strlen(resp)); |
yueee_yt | 0:fdf9c2c5200f | 46 | printf("++++(SimpleHeader) doGet Exit\r\n"); |
yueee_yt | 0:fdf9c2c5200f | 47 | } |
yueee_yt | 0:fdf9c2c5200f | 48 | |
yueee_yt | 0:fdf9c2c5200f | 49 | void SimpleHandler::doPost() |
yueee_yt | 0:fdf9c2c5200f | 50 | { |
yueee_yt | 0:fdf9c2c5200f | 51 | |
yueee_yt | 0:fdf9c2c5200f | 52 | } |
yueee_yt | 0:fdf9c2c5200f | 53 | |
yueee_yt | 0:fdf9c2c5200f | 54 | void SimpleHandler::doHead() |
yueee_yt | 0:fdf9c2c5200f | 55 | { |
yueee_yt | 0:fdf9c2c5200f | 56 | |
yueee_yt | 0:fdf9c2c5200f | 57 | } |
yueee_yt | 0:fdf9c2c5200f | 58 | |
yueee_yt | 0:fdf9c2c5200f | 59 | |
yueee_yt | 0:fdf9c2c5200f | 60 | void SimpleHandler::onReadable() //Data has been read |
yueee_yt | 0:fdf9c2c5200f | 61 | { |
yueee_yt | 0:fdf9c2c5200f | 62 | |
yueee_yt | 0:fdf9c2c5200f | 63 | } |
yueee_yt | 0:fdf9c2c5200f | 64 | |
yueee_yt | 0:fdf9c2c5200f | 65 | void SimpleHandler::onWriteable() //Data has been written & buf is free |
yueee_yt | 0:fdf9c2c5200f | 66 | { |
yueee_yt | 0:fdf9c2c5200f | 67 | printf("\r\n++++SimpleHandler::onWriteable() event\r\n"); |
yueee_yt | 0:fdf9c2c5200f | 68 | close(); //Data written, we can close the connection |
yueee_yt | 0:fdf9c2c5200f | 69 | } |
yueee_yt | 0:fdf9c2c5200f | 70 | |
yueee_yt | 0:fdf9c2c5200f | 71 | void SimpleHandler::onClose() //Connection is closing |
yueee_yt | 0:fdf9c2c5200f | 72 | { |
yueee_yt | 0:fdf9c2c5200f | 73 | //Nothing to do |
yueee_yt | 0:fdf9c2c5200f | 74 | } |