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: EthernetInterface mbed-rpc mbed-rtos mbed
Diff: RequestHandler.cpp
- Revision:
- 5:8ab27ca793cd
- Parent:
- 0:9e4bcb10b3e3
- Child:
- 7:838d7ea07e18
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/RequestHandler.cpp Wed Jul 17 15:01:05 2013 +0000
@@ -0,0 +1,91 @@
+#include "RequestHandler.h"
+#include "mbed_rpc.h"
+#include "RPCObjectManager.h"
+#include "RPCCommand.h"
+
+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 ");
+ 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");
+ break;
+ default:
+ strcat(reply, "Invalid RPC command");
+ break;
+ }
+}
+
+void PutRequestHandler::handle(const RPCCommand& cmd, char *reply)
+{
+ switch(cmd.get_type())
+ {
+ case DELETE:
+ strcat(reply, "You must send a DELETE request to remove an object ");
+ break;
+ case FUNCTION_CALL:
+ strcat(reply, "You must send a GET request to call a function");
+ break;
+ case CREATE:
+ RPC::call(cmd.get_cmd(), reply);
+ if(strlen(reply) > 0)
+ {
+ RPCObjectManager::instance().store_object(reply);
+ strcat(reply, " has been created");
+ }
+ else
+ strcat(reply, "Error while creating object.");
+ break;
+ default:
+ strcat(reply, "Invalid RPC command");
+ break;
+ }
+}
+
+void DeleteRequestHandler::handle(const RPCCommand& cmd, char *reply)
+{
+ switch(cmd.get_type())
+ {
+ case CREATE:
+ strcat(reply, "You must send a PUT request to remove an object ");
+ break;
+ case FUNCTION_CALL:
+ strcat(reply, "You must send a GET request to call a function");
+ break;
+ case DELETE:
+ RPC::call(cmd.get_cmd(), reply);
+ RPCObjectManager::instance().remove_object(cmd.get_obj_name());
+ strcat(reply, "Deleted object ");
+ strcat(reply, cmd.get_obj_name());
+ break;
+ default:
+ strcat(reply, "Invalid RPC command");
+ break;
+ }
+}
+
+void ComplexRequestHandler::handle(const RPCCommand& cmd, char *reply)
+{
+ switch(cmd.get_type())
+ {
+ case CREATE :
+ putHandler.handle(cmd, reply);
+ break;
+ case DELETE :
+ deleteHandler.handle(cmd, reply);
+ break;
+ case FUNCTION_CALL :
+ getHandler.handle(cmd, reply);
+ break;
+ default :
+ strcat(reply, "Invalid RPC command");
+ break;
+ }
+}
+