Modified to run on Renesas GR Peach board

Dependents:   GR-PeachAHRSWeb

Fork of HTTP-Server by Francois Berder

Revision:
7:838d7ea07e18
Parent:
0:9e4bcb10b3e3
Child:
11:d03f12a19999
diff -r d03e189ebbfe -r 838d7ea07e18 RequestHandler.cpp
--- a/RequestHandler.cpp	Wed Jul 17 15:18:41 2013 +0000
+++ b/RequestHandler.cpp	Wed Jul 17 16:23:35 2013 +0000
@@ -3,21 +3,29 @@
 #include "RPCObjectManager.h"
 #include "RPCCommand.h"
 
+const char* INVALID_CMD = "Invalid RPC command";
+const char* DELETE_ERROR = "You must send a DELETE request to remove an object ";
+const char* CREATE_ERROR = "You must send a PUT request to create an object";
+const char* FUNC_CALL_ERROR = "You must send a GET request to call a function";
+
 void GetRequestHandler::handle(const RPCCommand& cmd, char *reply)
 {
     switch(cmd.get_type())
     {
         case DELETE:
-            strcat(reply, "You must send a DELETE request to remove an object ");
+            printf("Error: %s\n", DELETE_ERROR);
+            strcat(reply, DELETE_ERROR);
             break;
         case FUNCTION_CALL:
             RPC::call(cmd.get_cmd(), reply);
             break;
         case CREATE:
-            strcat(reply, "You must send a PUT request to call a function");
+            printf("Error: %s\n", CREATE_ERROR);
+            strcat(reply, CREATE_ERROR);
             break;
         default:
-            strcat(reply, "Invalid RPC command");
+            printf("Error: %s\n", INVALID_CMD);
+            strcat(reply, INVALID_CMD);
             break;
     }
 }
@@ -27,10 +35,12 @@
     switch(cmd.get_type())
     {
         case DELETE:
-            strcat(reply, "You must send a DELETE request to remove an object ");
+            printf("Error: %s\n", DELETE_ERROR);
+            strcat(reply, DELETE_ERROR);
             break;
         case FUNCTION_CALL:
-            strcat(reply, "You must send a GET request to call a function");
+            printf("Error: %s\n", FUNC_CALL_ERROR);
+            strcat(reply, FUNC_CALL_ERROR);
             break;
         case CREATE:
             RPC::call(cmd.get_cmd(), reply);
@@ -40,10 +50,14 @@
                 strcat(reply, " has been created");
             }
             else
+            {
+                printf("Error while creating object\n");
                 strcat(reply, "Error while creating object.");
+            }
             break;
         default:
-            strcat(reply, "Invalid RPC command");
+            printf("Error: %s\n", INVALID_CMD);
+            strcat(reply, INVALID_CMD);
             break;
     }
 }
@@ -53,10 +67,12 @@
     switch(cmd.get_type())
     {
         case CREATE:
-            strcat(reply, "You must send a PUT request to remove an object ");
+            printf("Error: %s\n", CREATE_ERROR);
+            strcat(reply, CREATE_ERROR);
             break;
         case FUNCTION_CALL:
-            strcat(reply, "You must send a GET request to call a function");
+            printf("Error: %s\n", FUNC_CALL_ERROR);
+            strcat(reply, FUNC_CALL_ERROR);
             break;
         case DELETE:
             RPC::call(cmd.get_cmd(), reply);
@@ -65,7 +81,8 @@
             strcat(reply, cmd.get_obj_name());
             break;
         default:
-            strcat(reply, "Invalid RPC command");
+            printf("Error: %s\n", INVALID_CMD);
+            strcat(reply, INVALID_CMD);
             break;
     }
 }
@@ -84,7 +101,8 @@
             getHandler.handle(cmd, reply);
             break;
         default :
-            strcat(reply, "Invalid RPC command");
+            printf("Error: %s\n", INVALID_CMD);
+            strcat(reply, INVALID_CMD);
             break;
     }
 }