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.
Dependencies: NySNICInterface mbed-rtos mbed
Fork of RESTServerSample by
Diff: RequestHandler.cpp
- Revision:
- 5:70c9f6045f2d
- Parent:
- 4:99a67256b765
- Child:
- 6:d148c8a213ef
diff -r 99a67256b765 -r 70c9f6045f2d RequestHandler.cpp
--- a/RequestHandler.cpp Sun Feb 15 02:55:36 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,86 +0,0 @@
-#include "mbed.h"
-#include "RequestHandler.h"
-#include "RPCObject.h"
-#include "HTTPServer.h"
-
-
-int GetRequestHandler::handle(RPCObject& cmd, char* reply)
-{
- int value;
- std::map<PinName, RPCClass*>::iterator itor;
-
- printf("handling GET request.\r\n");
- itor = cmd.pinObjects.find(cmd.get_pin_name());
- if(itor == cmd.pinObjects.end()){
- printf("The pin is not created.\r\n");
- return HTTP_404_NOTFOUND;
- }
- value = itor->second->read();
-
- reply[0] = '0' + value;
- reply[1] = '\0';
-
- return HTTP_200_OK;
-}
-
-
-int PostRequestHandler::handle(RPCObject& cmd, char* reply)
-{
- int value = cmd.get_value();
- std::map<PinName, RPCClass*>::iterator itor;
-
- printf("handling POST request.\r\n");
- switch(value){
- case 0:
- case 1:
- //update
- printf("now updating the object to %d.\r\n", value);
- itor = cmd.pinObjects.find(cmd.get_pin_name());
- if(itor == cmd.pinObjects.end()){
- printf("The pin is not created.\r\n");
- return HTTP_404_NOTFOUND;
- }
- itor->second->write(value);
- break;
- case -1:
- //create
- printf("now createing the object.\r\n");
- if(!cmd.create_pin_object(reply)){
- return -1;
- }
- break;
- case -2:
- // delete
- itor = cmd.pinObjects.find(cmd.get_pin_name());
- if(itor == cmd.pinObjects.end()){
- printf("The pin is not created.\r\n");
- return HTTP_404_NOTFOUND;
- }
- delete itor->second;
- cmd.pinObjects.erase(cmd.pinObjects.find(cmd.get_pin_name()));
- break;
- default:
- return -1;
- }
-
- return HTTP_200_OK;
-}
-
-
-int DeleteRequestHandler::handle(RPCObject& cmd, char* reply)
-{
- std::map<PinName, RPCClass*>::iterator itor;
-
- printf("handling DELETE request.\r\n");
- itor = cmd.pinObjects.find(cmd.get_pin_name());
- if(itor == cmd.pinObjects.end()){
- printf("The pin is not created.\r\n");
- return HTTP_404_NOTFOUND;
- }
- delete itor->second;
- cmd.pinObjects.erase(cmd.pinObjects.find(cmd.get_pin_name()));
-
- return HTTP_200_OK;
-}
-
-

