Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
RestMeterHandler.cpp
00001 #include "RestMeterHandler.h" 00002 00003 RestMeterHandler::RestMeterHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket) : HTTPRequestHandler(rootPath, path, pTCPSocket) { 00004 } 00005 00006 RestMeterHandler::~RestMeterHandler() { 00007 } 00008 00009 const char *(*RestMeterHandler::callback)(const char*) = NULL; 00010 00011 void RestMeterHandler::attach(const char *(*cb)(const char * command)) { 00012 callback = cb; 00013 } 00014 00015 void RestMeterHandler::doGet() { 00016 const char * p = path().c_str(); 00017 const char * q = strstr(p,"cmd="); 00018 00019 if (q && q[4]) 00020 { 00021 q+=4; 00022 } else { 00023 q = "none"; 00024 }; 00025 00026 const char * resp = "No callback"; 00027 00028 printf("Calling back with %s, cb=%p\n\r", q,callback); 00029 00030 if (callback) 00031 resp = (*callback)(q); 00032 00033 setContentLen( strlen(resp) ); 00034 respHeaders()["Connection"] = "close"; 00035 writeData(resp, strlen(resp)); 00036 } 00037 00038 void RestMeterHandler::doPost() { 00039 } 00040 00041 void RestMeterHandler::doHead() { 00042 } 00043 00044 void RestMeterHandler::onReadable() { //Data has been read 00045 } 00046 00047 void RestMeterHandler::onWriteable() { //Data has been written & buf is free 00048 close(); //Data written, we can close the connection 00049 } 00050 00051 void RestMeterHandler::onClose() { //Connection is closing 00052 //Nothing to do 00053 }
Generated on Tue Jul 12 2022 17:22:32 by
1.7.2