Modified to run on Renesas GR Peach board

Dependents:   GR-PeachAHRSWeb

Fork of HTTP-Server by Francois Berder

Committer:
webOnBoard
Date:
Wed Oct 07 20:35:31 2015 +0000
Revision:
11:d03f12a19999
Parent:
7:838d7ea07e18
Modified for GRPeach

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 7:838d7ea07e18 6 const char* INVALID_CMD = "Invalid RPC command";
feb11 7:838d7ea07e18 7 const char* DELETE_ERROR = "You must send a DELETE request to remove an object ";
feb11 7:838d7ea07e18 8 const char* CREATE_ERROR = "You must send a PUT request to create an object";
feb11 7:838d7ea07e18 9 const char* FUNC_CALL_ERROR = "You must send a GET request to call a function";
feb11 7:838d7ea07e18 10
feb11 0:9e4bcb10b3e3 11 void GetRequestHandler::handle(const RPCCommand& cmd, char *reply)
feb11 0:9e4bcb10b3e3 12 {
webOnBoard 11:d03f12a19999 13 printf("in getrequesthandler\n\r");
feb11 0:9e4bcb10b3e3 14 switch(cmd.get_type())
feb11 0:9e4bcb10b3e3 15 {
feb11 0:9e4bcb10b3e3 16 case DELETE:
feb11 7:838d7ea07e18 17 printf("Error: %s\n", DELETE_ERROR);
feb11 7:838d7ea07e18 18 strcat(reply, DELETE_ERROR);
feb11 0:9e4bcb10b3e3 19 break;
feb11 0:9e4bcb10b3e3 20 case FUNCTION_CALL:
feb11 0:9e4bcb10b3e3 21 RPC::call(cmd.get_cmd(), reply);
feb11 0:9e4bcb10b3e3 22 break;
feb11 0:9e4bcb10b3e3 23 case CREATE:
feb11 7:838d7ea07e18 24 printf("Error: %s\n", CREATE_ERROR);
feb11 7:838d7ea07e18 25 strcat(reply, CREATE_ERROR);
feb11 0:9e4bcb10b3e3 26 break;
feb11 0:9e4bcb10b3e3 27 default:
feb11 7:838d7ea07e18 28 printf("Error: %s\n", INVALID_CMD);
feb11 7:838d7ea07e18 29 strcat(reply, INVALID_CMD);
feb11 0:9e4bcb10b3e3 30 break;
feb11 0:9e4bcb10b3e3 31 }
feb11 0:9e4bcb10b3e3 32 }
feb11 0:9e4bcb10b3e3 33
feb11 0:9e4bcb10b3e3 34 void PutRequestHandler::handle(const RPCCommand& cmd, char *reply)
feb11 0:9e4bcb10b3e3 35 {
feb11 0:9e4bcb10b3e3 36 switch(cmd.get_type())
feb11 0:9e4bcb10b3e3 37 {
feb11 0:9e4bcb10b3e3 38 case DELETE:
feb11 7:838d7ea07e18 39 printf("Error: %s\n", DELETE_ERROR);
feb11 7:838d7ea07e18 40 strcat(reply, DELETE_ERROR);
feb11 0:9e4bcb10b3e3 41 break;
feb11 0:9e4bcb10b3e3 42 case FUNCTION_CALL:
feb11 7:838d7ea07e18 43 printf("Error: %s\n", FUNC_CALL_ERROR);
feb11 7:838d7ea07e18 44 strcat(reply, FUNC_CALL_ERROR);
feb11 0:9e4bcb10b3e3 45 break;
feb11 0:9e4bcb10b3e3 46 case CREATE:
feb11 0:9e4bcb10b3e3 47 RPC::call(cmd.get_cmd(), reply);
feb11 0:9e4bcb10b3e3 48 if(strlen(reply) > 0)
feb11 0:9e4bcb10b3e3 49 {
feb11 0:9e4bcb10b3e3 50 RPCObjectManager::instance().store_object(reply);
feb11 0:9e4bcb10b3e3 51 strcat(reply, " has been created");
feb11 0:9e4bcb10b3e3 52 }
feb11 0:9e4bcb10b3e3 53 else
feb11 7:838d7ea07e18 54 {
feb11 7:838d7ea07e18 55 printf("Error while creating object\n");
feb11 0:9e4bcb10b3e3 56 strcat(reply, "Error while creating object.");
feb11 7:838d7ea07e18 57 }
feb11 0:9e4bcb10b3e3 58 break;
feb11 0:9e4bcb10b3e3 59 default:
feb11 7:838d7ea07e18 60 printf("Error: %s\n", INVALID_CMD);
feb11 7:838d7ea07e18 61 strcat(reply, INVALID_CMD);
feb11 0:9e4bcb10b3e3 62 break;
feb11 0:9e4bcb10b3e3 63 }
feb11 0:9e4bcb10b3e3 64 }
feb11 0:9e4bcb10b3e3 65
feb11 0:9e4bcb10b3e3 66 void DeleteRequestHandler::handle(const RPCCommand& cmd, char *reply)
feb11 0:9e4bcb10b3e3 67 {
feb11 0:9e4bcb10b3e3 68 switch(cmd.get_type())
feb11 0:9e4bcb10b3e3 69 {
feb11 0:9e4bcb10b3e3 70 case CREATE:
feb11 7:838d7ea07e18 71 printf("Error: %s\n", CREATE_ERROR);
feb11 7:838d7ea07e18 72 strcat(reply, CREATE_ERROR);
feb11 0:9e4bcb10b3e3 73 break;
feb11 0:9e4bcb10b3e3 74 case FUNCTION_CALL:
feb11 7:838d7ea07e18 75 printf("Error: %s\n", FUNC_CALL_ERROR);
feb11 7:838d7ea07e18 76 strcat(reply, FUNC_CALL_ERROR);
feb11 0:9e4bcb10b3e3 77 break;
feb11 0:9e4bcb10b3e3 78 case DELETE:
feb11 0:9e4bcb10b3e3 79 RPC::call(cmd.get_cmd(), reply);
feb11 0:9e4bcb10b3e3 80 RPCObjectManager::instance().remove_object(cmd.get_obj_name());
feb11 0:9e4bcb10b3e3 81 strcat(reply, "Deleted object ");
feb11 0:9e4bcb10b3e3 82 strcat(reply, cmd.get_obj_name());
feb11 0:9e4bcb10b3e3 83 break;
feb11 0:9e4bcb10b3e3 84 default:
feb11 7:838d7ea07e18 85 printf("Error: %s\n", INVALID_CMD);
feb11 7:838d7ea07e18 86 strcat(reply, INVALID_CMD);
feb11 0:9e4bcb10b3e3 87 break;
feb11 0:9e4bcb10b3e3 88 }
feb11 0:9e4bcb10b3e3 89 }
feb11 0:9e4bcb10b3e3 90
feb11 0:9e4bcb10b3e3 91 void ComplexRequestHandler::handle(const RPCCommand& cmd, char *reply)
feb11 0:9e4bcb10b3e3 92 {
feb11 0:9e4bcb10b3e3 93 switch(cmd.get_type())
feb11 0:9e4bcb10b3e3 94 {
feb11 0:9e4bcb10b3e3 95 case CREATE :
feb11 0:9e4bcb10b3e3 96 putHandler.handle(cmd, reply);
feb11 0:9e4bcb10b3e3 97 break;
feb11 0:9e4bcb10b3e3 98 case DELETE :
feb11 0:9e4bcb10b3e3 99 deleteHandler.handle(cmd, reply);
feb11 0:9e4bcb10b3e3 100 break;
feb11 0:9e4bcb10b3e3 101 case FUNCTION_CALL :
feb11 0:9e4bcb10b3e3 102 getHandler.handle(cmd, reply);
feb11 0:9e4bcb10b3e3 103 break;
feb11 0:9e4bcb10b3e3 104 default :
feb11 7:838d7ea07e18 105 printf("Error: %s\n", INVALID_CMD);
feb11 7:838d7ea07e18 106 strcat(reply, INVALID_CMD);
feb11 0:9e4bcb10b3e3 107 break;
feb11 0:9e4bcb10b3e3 108 }
feb11 0:9e4bcb10b3e3 109 }
feb11 0:9e4bcb10b3e3 110