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