ソースの整理中ですが、利用はできます。 大きなファイルはできないかもしれません。
Dependencies: EthernetInterface HttpServer TextLCD expatlib mbed-rpc mbed-rtos mbed Socket lwip-eth lwip-sys lwip
Fork of giken9_HTMLServer_Sample by
HttpServer/Handler/SimpleHandler.cpp@2:6f25f8327180, 2014-03-12 (annotated)
- Committer:
- yueee_yt
- Date:
- Wed Mar 12 06:30:30 2014 +0000
- Revision:
- 2:6f25f8327180
- Parent:
- 0:7766f6712673
debug comment
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yueee_yt | 0:7766f6712673 | 1 | /* |
yueee_yt | 0:7766f6712673 | 2 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
yueee_yt | 0:7766f6712673 | 3 | |
yueee_yt | 0:7766f6712673 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
yueee_yt | 0:7766f6712673 | 5 | of this software and associated documentation files (the "Software"), to deal |
yueee_yt | 0:7766f6712673 | 6 | in the Software without restriction, including without limitation the rights |
yueee_yt | 0:7766f6712673 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
yueee_yt | 0:7766f6712673 | 8 | copies of the Software, and to permit persons to whom the Software is |
yueee_yt | 0:7766f6712673 | 9 | furnished to do so, subject to the following conditions: |
yueee_yt | 0:7766f6712673 | 10 | |
yueee_yt | 0:7766f6712673 | 11 | The above copyright notice and this permission notice shall be included in |
yueee_yt | 0:7766f6712673 | 12 | all copies or substantial portions of the Software. |
yueee_yt | 0:7766f6712673 | 13 | |
yueee_yt | 0:7766f6712673 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
yueee_yt | 0:7766f6712673 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
yueee_yt | 0:7766f6712673 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
yueee_yt | 0:7766f6712673 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
yueee_yt | 0:7766f6712673 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
yueee_yt | 0:7766f6712673 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
yueee_yt | 0:7766f6712673 | 20 | THE SOFTWARE. |
yueee_yt | 0:7766f6712673 | 21 | */ |
yueee_yt | 0:7766f6712673 | 22 | //#define _DEBUG_SIMPLE_HANDLER |
yueee_yt | 0:7766f6712673 | 23 | |
yueee_yt | 0:7766f6712673 | 24 | #include "SimpleHandler.h" |
yueee_yt | 0:7766f6712673 | 25 | |
yueee_yt | 0:7766f6712673 | 26 | SimpleHandler::SimpleHandler(const char* rootPath, const char* path, TCPSocketConnection* pTCPSocketConnection) : HTTPRequestHandler(rootPath, path, pTCPSocketConnection) |
yueee_yt | 0:7766f6712673 | 27 | { |
yueee_yt | 0:7766f6712673 | 28 | #ifdef _DEBUG_SIMPLE_HANDLER |
yueee_yt | 0:7766f6712673 | 29 | printf("++++(SimpleHeandler)Initialize\r\n"); |
yueee_yt | 0:7766f6712673 | 30 | #endif |
yueee_yt | 0:7766f6712673 | 31 | } |
yueee_yt | 0:7766f6712673 | 32 | |
yueee_yt | 0:7766f6712673 | 33 | SimpleHandler::~SimpleHandler() |
yueee_yt | 0:7766f6712673 | 34 | { |
yueee_yt | 0:7766f6712673 | 35 | #ifdef _DEBUG_SIMPLE_HANDLER |
yueee_yt | 0:7766f6712673 | 36 | printf("++++(SimpleHeandler)Handler destroyed\r\n"); |
yueee_yt | 0:7766f6712673 | 37 | #endif |
yueee_yt | 0:7766f6712673 | 38 | } |
yueee_yt | 0:7766f6712673 | 39 | |
yueee_yt | 0:7766f6712673 | 40 | void SimpleHandler::doGet() |
yueee_yt | 0:7766f6712673 | 41 | { |
yueee_yt | 0:7766f6712673 | 42 | #ifdef _DEBUG_SIMPLE_HANDLER |
yueee_yt | 0:7766f6712673 | 43 | printf("++++(SimpleHeandler) doGet()\r\n"); |
yueee_yt | 0:7766f6712673 | 44 | #endif |
yueee_yt | 0:7766f6712673 | 45 | const char* resp = "Hello world !"; |
yueee_yt | 0:7766f6712673 | 46 | setContentLen( strlen(resp) ); |
yueee_yt | 0:7766f6712673 | 47 | //respHeaders()["Connection"] = "close"; |
yueee_yt | 0:7766f6712673 | 48 | addRespHeaders("Connection", "close"); |
yueee_yt | 0:7766f6712673 | 49 | writeData(resp, strlen(resp)); |
yueee_yt | 0:7766f6712673 | 50 | #ifdef _DEBUG_SIMPLE_HANDLER |
yueee_yt | 0:7766f6712673 | 51 | printf("++++(SimpleHeandler) doGet Exit\r\n"); |
yueee_yt | 0:7766f6712673 | 52 | #endif |
yueee_yt | 0:7766f6712673 | 53 | } |
yueee_yt | 0:7766f6712673 | 54 | |
yueee_yt | 0:7766f6712673 | 55 | void SimpleHandler::doPost() |
yueee_yt | 0:7766f6712673 | 56 | { |
yueee_yt | 0:7766f6712673 | 57 | |
yueee_yt | 0:7766f6712673 | 58 | } |
yueee_yt | 0:7766f6712673 | 59 | |
yueee_yt | 0:7766f6712673 | 60 | void SimpleHandler::doHead() |
yueee_yt | 0:7766f6712673 | 61 | { |
yueee_yt | 0:7766f6712673 | 62 | |
yueee_yt | 0:7766f6712673 | 63 | } |
yueee_yt | 0:7766f6712673 | 64 | |
yueee_yt | 0:7766f6712673 | 65 | |
yueee_yt | 0:7766f6712673 | 66 | void SimpleHandler::onReadable() //Data has been read |
yueee_yt | 0:7766f6712673 | 67 | { |
yueee_yt | 0:7766f6712673 | 68 | |
yueee_yt | 0:7766f6712673 | 69 | } |
yueee_yt | 0:7766f6712673 | 70 | |
yueee_yt | 0:7766f6712673 | 71 | void SimpleHandler::onWriteable() //Data has been written & buf is free |
yueee_yt | 0:7766f6712673 | 72 | { |
yueee_yt | 0:7766f6712673 | 73 | #ifdef _DEBUG_SIMPLE_HANDLER |
yueee_yt | 0:7766f6712673 | 74 | printf("++++(SimpleHeandler)onWriteable() event\r\n"); |
yueee_yt | 0:7766f6712673 | 75 | #endif |
yueee_yt | 0:7766f6712673 | 76 | // close(); //Data written, we can close the connection |
yueee_yt | 0:7766f6712673 | 77 | } |
yueee_yt | 0:7766f6712673 | 78 | |
yueee_yt | 0:7766f6712673 | 79 | void SimpleHandler::onClose() //Connection is closing |
yueee_yt | 0:7766f6712673 | 80 | { |
yueee_yt | 0:7766f6712673 | 81 | //Nothing to do |
yueee_yt | 0:7766f6712673 | 82 | } |
yueee_yt | 0:7766f6712673 | 83 |