Remote Procedure Call (RPC) over Websockets (uses MbedJSONValue)

Dependents:   RPC_mbed_client RPC_Wifly_HelloWorld RPC_Ethernet_HelloWorld

Revision:
2:af408b5cae75
Parent:
0:a53d1c86196c
Child:
3:4a3bc3a2314f
--- a/MbedJSONRpc.h	Thu Sep 22 10:20:52 2011 +0000
+++ b/MbedJSONRpc.h	Thu Sep 22 10:38:50 2011 +0000
@@ -37,7 +37,7 @@
 #include "Websocket.h"
 #include "Wifly.h"
 #include "mbed.h"
-#include "MbedJSONRpcValue.h"
+#include "MbedJSONValue.h"
 #include <string>
 
 #define NB_METH 30
@@ -58,7 +58,7 @@
 */
 enum RPC_TYPE {
     JSON_PARSE_ERROR,       /*!< Json parse error */
-    RPC_PARSE_ERROR,        /*!< rpc parse error (the message doesn't contain good identifiers in a TypeObject MbedRpcValue)*/ 
+    RPC_PARSE_ERROR,        /*!< rpc parse error (the message doesn't contain good identifiers in a TypeObject MbedJSONValue)*/ 
     PROC_NOT_FOUND,         /*!< The user wants to call an inexisting method or procedure */
     CLIENT_NOT_CONNECTED,   /*!< The user wants to call a method or procedure on a client not connected (no response from the client within 3s) */
     SERVER_NOT_CONNECTED,   /*!< No response from the server within 5s */
@@ -71,19 +71,19 @@
 
 class ObjBase {
 public:
-    virtual void execute(MbedRpcValue& val, MbedRpcValue& res) = 0;
+    virtual void execute(MbedJSONValue& val, MbedJSONValue& res) = 0;
 };
 
 template <class T>
 class Obj : public ObjBase {
 public:
 
-    Obj(T * ptr, void (T::*fn_ptr)(MbedRpcValue& , MbedRpcValue& )) {
+    Obj(T * ptr, void (T::*fn_ptr)(MbedJSONValue& , MbedJSONValue& )) {
         obj_ptr = ptr;
         fn = fn_ptr;
     };
 
-    virtual void execute(MbedRpcValue& val, MbedRpcValue& res) {
+    virtual void execute(MbedJSONValue& val, MbedJSONValue& res) {
         ((*obj_ptr).*fn)(val, res);
     }
 
@@ -91,7 +91,7 @@
     T * obj_ptr;
 
     //method
-    void (T::*fn)(MbedRpcValue& , MbedRpcValue& );
+    void (T::*fn)(MbedJSONValue& , MbedJSONValue& );
 
 };
 
@@ -230,7 +230,7 @@
  *   #endif
  *   
  *   RPC_TYPE t;
- *   MbedRpcValue arg, resp;
+ *   MbedJSONValue arg, resp;
  *   arg[0] = "Hello";
  *
  *   // print all methods and procedure available on the client "server"
@@ -271,16 +271,16 @@
     *
     * @param public_name the method will be seen and called by this name
     * @param obj_ptr a pointeur on the object which contains the method to register
-    * @param fn the method to register (this method must have this signature: void fn(MbedRpcValue& val, MbedRpcValue& res)
+    * @param fn the method to register (this method must have this signature: void fn(MbedJSONValue& val, MbedJSONValue& res)
     * @return if REGISTER_OK, the method is registered, otherwise, there is an error
     *
     */
-    template<typename T> RPC_TYPE registerMethod(const char * public_name, T * obj_ptr, void (T::*fn)(MbedRpcValue& val, MbedRpcValue& res)) {
+    template<typename T> RPC_TYPE registerMethod(const char * public_name, T * obj_ptr, void (T::*fn)(MbedJSONValue& val, MbedJSONValue& res)) {
         char json[100];
         RPC_TYPE t;
         Timer tmr;
         int id = rand() % 100;
-        MbedRpcValue tmp;
+        MbedJSONValue tmp;
 
         sprintf(json, (const char *)MSG_REGISTER, my_id, id, public_name);
         webs->Send(json);
@@ -300,11 +300,11 @@
     * Register a procedure
     *
     * @param public_name the method will be seen and called by this name
-    * @param fn the procedure to register (this procedure must have this signature: void fn(MbedRpcValue& val, MbedRpcValue& res)
+    * @param fn the procedure to register (this procedure must have this signature: void fn(MbedJSONValue& val, MbedJSONValue& res)
     * @return if REGISTER_OK, the procedure is registered, otherwise, there is an error
     *
     */
-    RPC_TYPE registerMethod(const char * public_name, void (*fn)(MbedRpcValue& val, MbedRpcValue& res) );
+    RPC_TYPE registerMethod(const char * public_name, void (*fn)(MbedJSONValue& val, MbedJSONValue& res) );
     
     
     /**
@@ -320,7 +320,7 @@
     *         Refer to the RPC_TYPE description
     *
     */
-    RPC_TYPE call(char * fn, char * dest,  MbedRpcValue& val, MbedRpcValue& resp);
+    RPC_TYPE call(char * fn, char * dest,  MbedJSONValue& val, MbedJSONValue& resp);
     
     
     /**
@@ -336,12 +336,12 @@
 
 private:
 
-    typedef void (*FNPTR)(MbedRpcValue& , MbedRpcValue& );
+    typedef void (*FNPTR)(MbedJSONValue& , MbedJSONValue& );
 
     int methodAlreadyRegistered(char *);
     int procAlreadyRegistered(char *);
-    RPC_TYPE decodeMsg(MbedRpcValue& , int);
-    RPC_TYPE waitAnswer(MbedRpcValue& , int, char *);
+    RPC_TYPE decodeMsg(MbedJSONValue& , int);
+    RPC_TYPE waitAnswer(MbedJSONValue& , int, char *);
 
     Websocket * webs;