Modified to run on Renesas GR Peach board

Dependents:   GR-PeachAHRSWeb

Fork of HTTP-Server by Francois Berder

Committer:
feb11
Date:
Wed Jul 17 10:15:05 2013 +0000
Revision:
0:9e4bcb10b3e3
Child:
7:838d7ea07e18
Initial import

Who changed what in which revision?

UserRevisionLine numberNew contents of line
feb11 0:9e4bcb10b3e3 1 #include "RequestHandler.h"
feb11 0:9e4bcb10b3e3 2 #include "mbed_rpc.h"
feb11 0:9e4bcb10b3e3 3 #include "RPCObjectManager.h"
feb11 0:9e4bcb10b3e3 4 #include "RPCCommand.h"
feb11 0:9e4bcb10b3e3 5
feb11 0:9e4bcb10b3e3 6 void GetRequestHandler::handle(const RPCCommand& cmd, char *reply)
feb11 0:9e4bcb10b3e3 7 {
feb11 0:9e4bcb10b3e3 8 switch(cmd.get_type())
feb11 0:9e4bcb10b3e3 9 {
feb11 0:9e4bcb10b3e3 10 case DELETE:
feb11 0:9e4bcb10b3e3 11 strcat(reply, "You must send a DELETE request to remove an object ");
feb11 0:9e4bcb10b3e3 12 break;
feb11 0:9e4bcb10b3e3 13 case FUNCTION_CALL:
feb11 0:9e4bcb10b3e3 14 RPC::call(cmd.get_cmd(), reply);
feb11 0:9e4bcb10b3e3 15 break;
feb11 0:9e4bcb10b3e3 16 case CREATE:
feb11 0:9e4bcb10b3e3 17 strcat(reply, "You must send a PUT request to call a function");
feb11 0:9e4bcb10b3e3 18 break;
feb11 0:9e4bcb10b3e3 19 default:
feb11 0:9e4bcb10b3e3 20 strcat(reply, "Invalid RPC command");
feb11 0:9e4bcb10b3e3 21 break;
feb11 0:9e4bcb10b3e3 22 }
feb11 0:9e4bcb10b3e3 23 }
feb11 0:9e4bcb10b3e3 24
feb11 0:9e4bcb10b3e3 25 void PutRequestHandler::handle(const RPCCommand& cmd, char *reply)
feb11 0:9e4bcb10b3e3 26 {
feb11 0:9e4bcb10b3e3 27 switch(cmd.get_type())
feb11 0:9e4bcb10b3e3 28 {
feb11 0:9e4bcb10b3e3 29 case DELETE:
feb11 0:9e4bcb10b3e3 30 strcat(reply, "You must send a DELETE request to remove an object ");
feb11 0:9e4bcb10b3e3 31 break;
feb11 0:9e4bcb10b3e3 32 case FUNCTION_CALL:
feb11 0:9e4bcb10b3e3 33 strcat(reply, "You must send a GET request to call a function");
feb11 0:9e4bcb10b3e3 34 break;
feb11 0:9e4bcb10b3e3 35 case CREATE:
feb11 0:9e4bcb10b3e3 36 RPC::call(cmd.get_cmd(), reply);
feb11 0:9e4bcb10b3e3 37 if(strlen(reply) > 0)
feb11 0:9e4bcb10b3e3 38 {
feb11 0:9e4bcb10b3e3 39 RPCObjectManager::instance().store_object(reply);
feb11 0:9e4bcb10b3e3 40 strcat(reply, " has been created");
feb11 0:9e4bcb10b3e3 41 }
feb11 0:9e4bcb10b3e3 42 else
feb11 0:9e4bcb10b3e3 43 strcat(reply, "Error while creating object.");
feb11 0:9e4bcb10b3e3 44 break;
feb11 0:9e4bcb10b3e3 45 default:
feb11 0:9e4bcb10b3e3 46 strcat(reply, "Invalid RPC command");
feb11 0:9e4bcb10b3e3 47 break;
feb11 0:9e4bcb10b3e3 48 }
feb11 0:9e4bcb10b3e3 49 }
feb11 0:9e4bcb10b3e3 50
feb11 0:9e4bcb10b3e3 51 void DeleteRequestHandler::handle(const RPCCommand& cmd, char *reply)
feb11 0:9e4bcb10b3e3 52 {
feb11 0:9e4bcb10b3e3 53 switch(cmd.get_type())
feb11 0:9e4bcb10b3e3 54 {
feb11 0:9e4bcb10b3e3 55 case CREATE:
feb11 0:9e4bcb10b3e3 56 strcat(reply, "You must send a PUT request to remove an object ");
feb11 0:9e4bcb10b3e3 57 break;
feb11 0:9e4bcb10b3e3 58 case FUNCTION_CALL:
feb11 0:9e4bcb10b3e3 59 strcat(reply, "You must send a GET request to call a function");
feb11 0:9e4bcb10b3e3 60 break;
feb11 0:9e4bcb10b3e3 61 case DELETE:
feb11 0:9e4bcb10b3e3 62 RPC::call(cmd.get_cmd(), reply);
feb11 0:9e4bcb10b3e3 63 RPCObjectManager::instance().remove_object(cmd.get_obj_name());
feb11 0:9e4bcb10b3e3 64 strcat(reply, "Deleted object ");
feb11 0:9e4bcb10b3e3 65 strcat(reply, cmd.get_obj_name());
feb11 0:9e4bcb10b3e3 66 break;
feb11 0:9e4bcb10b3e3 67 default:
feb11 0:9e4bcb10b3e3 68 strcat(reply, "Invalid RPC command");
feb11 0:9e4bcb10b3e3 69 break;
feb11 0:9e4bcb10b3e3 70 }
feb11 0:9e4bcb10b3e3 71 }
feb11 0:9e4bcb10b3e3 72
feb11 0:9e4bcb10b3e3 73 void ComplexRequestHandler::handle(const RPCCommand& cmd, char *reply)
feb11 0:9e4bcb10b3e3 74 {
feb11 0:9e4bcb10b3e3 75 switch(cmd.get_type())
feb11 0:9e4bcb10b3e3 76 {
feb11 0:9e4bcb10b3e3 77 case CREATE :
feb11 0:9e4bcb10b3e3 78 putHandler.handle(cmd, reply);
feb11 0:9e4bcb10b3e3 79 break;
feb11 0:9e4bcb10b3e3 80 case DELETE :
feb11 0:9e4bcb10b3e3 81 deleteHandler.handle(cmd, reply);
feb11 0:9e4bcb10b3e3 82 break;
feb11 0:9e4bcb10b3e3 83 case FUNCTION_CALL :
feb11 0:9e4bcb10b3e3 84 getHandler.handle(cmd, reply);
feb11 0:9e4bcb10b3e3 85 break;
feb11 0:9e4bcb10b3e3 86 default :
feb11 0:9e4bcb10b3e3 87 strcat(reply, "Invalid RPC command");
feb11 0:9e4bcb10b3e3 88 break;
feb11 0:9e4bcb10b3e3 89 }
feb11 0:9e4bcb10b3e3 90 }
feb11 0:9e4bcb10b3e3 91